useGroupEventAttachmentsDrawer.tsx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import {useCallback} from 'react';
  2. import useDrawer from 'sentry/components/globalDrawer';
  3. import type {Group} from 'sentry/types/group';
  4. import type {Project} from 'sentry/types/project';
  5. import {useLocation} from 'sentry/utils/useLocation';
  6. import {useNavigate} from 'sentry/utils/useNavigate';
  7. import {GroupEventAttachmentsDrawer} from 'sentry/views/issueDetails/groupEventAttachments/groupEventAttachmentsDrawer';
  8. import {useGroupDetailsRoute} from 'sentry/views/issueDetails/useGroupDetailsRoute';
  9. export function useGroupEventAttachmentsDrawer({
  10. project,
  11. group,
  12. }: {
  13. group: Group;
  14. project: Project;
  15. }) {
  16. const location = useLocation();
  17. const navigate = useNavigate();
  18. const drawer = useDrawer();
  19. const {baseUrl} = useGroupDetailsRoute();
  20. const openAttachmentDrawer = useCallback(() => {
  21. drawer.openDrawer(
  22. () => <GroupEventAttachmentsDrawer project={project} groupId={group.id} />,
  23. {
  24. ariaLabel: 'attachments drawer',
  25. onClose: () => {
  26. // Remove drawer state from URL
  27. navigate(
  28. {
  29. pathname: baseUrl,
  30. query: {
  31. ...location.query,
  32. attachmentFilter: undefined,
  33. cursor: undefined,
  34. },
  35. },
  36. {replace: true}
  37. );
  38. },
  39. shouldCloseOnInteractOutside: element => {
  40. // Prevent closing the drawer when deleting an attachment
  41. if (document.querySelector('[role="dialog"]')?.contains(element)) {
  42. return false;
  43. }
  44. return true;
  45. },
  46. }
  47. );
  48. }, [location, navigate, drawer, project, group, baseUrl]);
  49. return {openAttachmentDrawer};
  50. }