activitySection.tsx 4.0 KB

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