groupEventAttachmentsDrawer.tsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import styled from '@emotion/styled';
  2. import ProjectAvatar from 'sentry/components/avatar/projectAvatar';
  3. import {
  4. CrumbContainer,
  5. EventDrawerBody,
  6. EventDrawerContainer,
  7. EventDrawerHeader,
  8. EventNavigator,
  9. Header,
  10. NavigationCrumbs,
  11. ShortId,
  12. } from 'sentry/components/events/eventDrawer';
  13. import LoadingError from 'sentry/components/loadingError';
  14. import Pagination from 'sentry/components/pagination';
  15. import {t} from 'sentry/locale';
  16. import {space} from 'sentry/styles/space';
  17. import type {IssueAttachment} from 'sentry/types/group';
  18. import type {Project} from 'sentry/types/project';
  19. import {useLocation} from 'sentry/utils/useLocation';
  20. import useOrganization from 'sentry/utils/useOrganization';
  21. import GroupEventAttachmentsFilter, {
  22. EventAttachmentFilter,
  23. } from './groupEventAttachmentsFilter';
  24. import GroupEventAttachmentsTable from './groupEventAttachmentsTable';
  25. import {useDeleteGroupEventAttachment} from './useDeleteGroupEventAttachment';
  26. import {useGroupEventAttachments} from './useGroupEventAttachments';
  27. type GroupEventAttachmentsProps = {
  28. groupId: string;
  29. project: Project;
  30. };
  31. export function GroupEventAttachmentsDrawer({
  32. project,
  33. groupId,
  34. }: GroupEventAttachmentsProps) {
  35. const location = useLocation();
  36. const organization = useOrganization();
  37. const activeAttachmentsTab =
  38. (location.query.attachmentFilter as EventAttachmentFilter | undefined) ??
  39. EventAttachmentFilter.ALL;
  40. const {attachments, isPending, isError, getResponseHeader, refetch} =
  41. useGroupEventAttachments({
  42. groupId,
  43. activeAttachmentsTab,
  44. });
  45. const {mutate: deleteAttachment} = useDeleteGroupEventAttachment();
  46. const handleDelete = (attachment: IssueAttachment) => {
  47. deleteAttachment({
  48. attachment,
  49. groupId,
  50. orgSlug: organization.slug,
  51. activeAttachmentsTab,
  52. projectSlug: project.slug,
  53. cursor: location.query.cursor as string | undefined,
  54. environment: location.query.environment as string[] | string | undefined,
  55. });
  56. };
  57. const renderAttachmentsTable = () => {
  58. if (isError) {
  59. return <LoadingError onRetry={refetch} message={t('Error loading attachments')} />;
  60. }
  61. return (
  62. <GroupEventAttachmentsTable
  63. isLoading={isPending}
  64. attachments={attachments}
  65. projectSlug={project.slug}
  66. groupId={groupId}
  67. onDelete={handleDelete}
  68. emptyMessage={
  69. activeAttachmentsTab === EventAttachmentFilter.CRASH_REPORTS
  70. ? t('No crash reports found')
  71. : t('No attachments found')
  72. }
  73. />
  74. );
  75. };
  76. return (
  77. <EventDrawerContainer>
  78. <EventDrawerHeader>
  79. <NavigationCrumbs
  80. crumbs={[
  81. {
  82. label: (
  83. <CrumbContainer>
  84. <ProjectAvatar project={project} />
  85. <ShortId>{groupId}</ShortId>
  86. </CrumbContainer>
  87. ),
  88. },
  89. {label: t('Attachments')},
  90. ]}
  91. />
  92. </EventDrawerHeader>
  93. <EventNavigator>
  94. <Header>{t('Attachments')}</Header>
  95. <GroupEventAttachmentsFilter project={project} />
  96. </EventNavigator>
  97. <EventDrawerBody>
  98. <Wrapper>
  99. {/* TODO(issue-details-streamline): Bring back a grid for screenshots */}
  100. {renderAttachmentsTable()}
  101. <NoMarginPagination pageLinks={getResponseHeader?.('Link')} />
  102. </Wrapper>
  103. </EventDrawerBody>
  104. </EventDrawerContainer>
  105. );
  106. }
  107. const NoMarginPagination = styled(Pagination)`
  108. margin: 0;
  109. `;
  110. const Wrapper = styled('div')`
  111. display: flex;
  112. flex-direction: column;
  113. gap: ${space(2)};
  114. `;