activitySection.tsx 3.2 KB

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