activitySection.tsx 3.1 KB

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