useSimilarIssuesDrawer.tsx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import {useCallback} from 'react';
  2. import useDrawer from 'sentry/components/globalDrawer';
  3. import {t} from 'sentry/locale';
  4. import type {Group} from 'sentry/types/group';
  5. import type {Project} from 'sentry/types/project';
  6. import {useLocation} from 'sentry/utils/useLocation';
  7. import {useNavigate} from 'sentry/utils/useNavigate';
  8. import {SimilarIssuesDrawer} from 'sentry/views/issueDetails/groupSimilarIssues/similarIssuesDrawer';
  9. import {useGroupDetailsRoute} from 'sentry/views/issueDetails/useGroupDetailsRoute';
  10. export function useSimilarIssuesDrawer({
  11. group,
  12. project,
  13. }: {
  14. group: Group;
  15. project: Project;
  16. }) {
  17. const {openDrawer} = useDrawer();
  18. const {baseUrl} = useGroupDetailsRoute();
  19. const navigate = useNavigate();
  20. const location = useLocation();
  21. const openSimilarIssuesDrawer = useCallback(() => {
  22. openDrawer(() => <SimilarIssuesDrawer group={group} project={project} />, {
  23. ariaLabel: t('Similar Issues'),
  24. shouldCloseOnInteractOutside: () => false,
  25. onClose: () => {
  26. // Remove drawer state from URL
  27. navigate(
  28. {
  29. pathname: baseUrl,
  30. query: {
  31. ...location.query,
  32. cursor: undefined,
  33. },
  34. },
  35. {replace: true}
  36. );
  37. },
  38. });
  39. }, [openDrawer, group, project, baseUrl, navigate, location.query]);
  40. return {openSimilarIssuesDrawer};
  41. }