activitySection.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 {NoteType} from 'sentry/types/alerts';
  9. import type {Group, GroupActivity} from 'sentry/types/group';
  10. import {GroupActivityType} from 'sentry/types/group';
  11. import type {User} from 'sentry/types/user';
  12. import {uniqueId} from 'sentry/utils/guid';
  13. import useOrganization from 'sentry/utils/useOrganization';
  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 = ConfigStore.get('user');
  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. {...noteProps}
  46. />
  47. </ActivityItem>
  48. {group.activity.map(item => {
  49. const authorName = item.user ? item.user.name : 'Sentry';
  50. if (item.type === GroupActivityType.NOTE) {
  51. return (
  52. <ErrorBoundary mini key={`note-${item.id}`}>
  53. <Note
  54. showTime={false}
  55. text={item.data.text}
  56. noteId={item.id}
  57. user={item.user as User}
  58. dateCreated={item.dateCreated}
  59. authorName={authorName}
  60. onDelete={() => onDelete(item)}
  61. onUpdate={n => {
  62. item.data.text = n.text;
  63. onUpdate(item, n);
  64. }}
  65. {...noteProps}
  66. />
  67. </ErrorBoundary>
  68. );
  69. }
  70. return (
  71. <ErrorBoundary mini key={`item-${item.id}`}>
  72. <ActivityItem
  73. author={{
  74. type: item.user ? 'user' : 'system',
  75. user: item.user ?? undefined,
  76. }}
  77. date={item.dateCreated}
  78. header={
  79. <GroupActivityItem
  80. author={<ActivityAuthor>{authorName}</ActivityAuthor>}
  81. activity={item}
  82. organization={organization}
  83. projectId={group.project.id}
  84. group={group}
  85. />
  86. }
  87. />
  88. </ErrorBoundary>
  89. );
  90. })}
  91. </Fragment>
  92. );
  93. }
  94. export default ActivitySection;