activitySection.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. return (
  70. <ErrorBoundary mini key={`item-${item.id}`}>
  71. <ActivityItem
  72. author={{
  73. type: item.user ? 'user' : 'system',
  74. user: item.user ?? undefined,
  75. }}
  76. date={item.dateCreated}
  77. header={
  78. <GroupActivityItem
  79. author={<ActivityAuthor>{authorName}</ActivityAuthor>}
  80. activity={item}
  81. organization={organization}
  82. projectId={group.project.id}
  83. group={group}
  84. />
  85. }
  86. />
  87. </ErrorBoundary>
  88. );
  89. })}
  90. </Fragment>
  91. );
  92. }
  93. export default ActivitySection;