activitySection.tsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import {Fragment, useState} from 'react';
  2. import {ActivityAuthor} from 'sentry/components/activity/author';
  3. import {ActivityItem} from 'sentry/components/activity/item';
  4. import {Note} from 'sentry/components/activity/note';
  5. import {NoteInputWithStorage} from 'sentry/components/activity/note/inputWithStorage';
  6. import ErrorBoundary from 'sentry/components/errorBoundary';
  7. import ConfigStore from 'sentry/stores/configStore';
  8. import type {Group, GroupActivity, User} from 'sentry/types';
  9. import type {NoteType} from 'sentry/types/alerts';
  10. import {GroupActivityType} from 'sentry/types/group';
  11. import {uniqueId} from 'sentry/utils/guid';
  12. import useOrganization from 'sentry/utils/useOrganization';
  13. import GroupActivityItem from 'sentry/views/issueDetails/groupActivityItem';
  14. type Props = {
  15. group: Group;
  16. onCreate: (n: NoteType, me: User) => void;
  17. onDelete: (item: GroupActivity) => void;
  18. onUpdate: (item: GroupActivity, n: NoteType) => void;
  19. placeholderText: string;
  20. };
  21. function ActivitySection(props: Props) {
  22. const {group, placeholderText, onCreate, onDelete, onUpdate} = props;
  23. const organization = useOrganization();
  24. const [inputId, setInputId] = useState(uniqueId());
  25. const me = ConfigStore.get('user');
  26. const projectSlugs = group?.project ? [group.project.slug] : [];
  27. const noteProps = {
  28. minHeight: 140,
  29. group,
  30. projectSlugs,
  31. placeholder: placeholderText,
  32. };
  33. return (
  34. <Fragment>
  35. <ActivityItem noPadding author={{type: 'user', user: me}}>
  36. <NoteInputWithStorage
  37. key={inputId}
  38. storageKey="groupinput:latest"
  39. itemKey={group.id}
  40. onCreate={n => {
  41. onCreate(n, me);
  42. setInputId(uniqueId());
  43. }}
  44. {...noteProps}
  45. />
  46. </ActivityItem>
  47. {group.activity.map(item => {
  48. const authorName = item.user ? item.user.name : 'Sentry';
  49. if (item.type === GroupActivityType.NOTE) {
  50. return (
  51. <ErrorBoundary mini key={`note-${item.id}`}>
  52. <Note
  53. showTime={false}
  54. text={item.data.text}
  55. noteId={item.id}
  56. user={item.user as User}
  57. dateCreated={item.dateCreated}
  58. authorName={authorName}
  59. onDelete={() => onDelete(item)}
  60. onUpdate={n => {
  61. item.data.text = n.text;
  62. onUpdate(item, n);
  63. }}
  64. {...noteProps}
  65. />
  66. </ErrorBoundary>
  67. );
  68. }
  69. if (
  70. item.type === GroupActivityType.SET_PRIORITY &&
  71. !organization.features.includes('issue-priority-ui')
  72. ) {
  73. return null;
  74. }
  75. return (
  76. <ErrorBoundary mini key={`item-${item.id}`}>
  77. <ActivityItem
  78. author={{
  79. type: item.user ? 'user' : 'system',
  80. user: item.user ?? undefined,
  81. }}
  82. date={item.dateCreated}
  83. header={
  84. <GroupActivityItem
  85. author={<ActivityAuthor>{authorName}</ActivityAuthor>}
  86. activity={item}
  87. organization={organization}
  88. projectId={group.project.id}
  89. group={group}
  90. />
  91. }
  92. />
  93. </ErrorBoundary>
  94. );
  95. })}
  96. </Fragment>
  97. );
  98. }
  99. export default ActivitySection;