useReplaysDrawer.tsx 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import {useCallback} from 'react';
  2. import {ReplayDrawer} from 'sentry/components/events/eventReplay/replayDrawer';
  3. import useDrawer from 'sentry/components/globalDrawer';
  4. import {t} from 'sentry/locale';
  5. import type {Group} from 'sentry/types/group';
  6. import type {Project} from 'sentry/types/project';
  7. import {useLocation} from 'sentry/utils/useLocation';
  8. import {useNavigate} from 'sentry/utils/useNavigate';
  9. import {useGroupDetailsRoute} from 'sentry/views/issueDetails/useGroupDetailsRoute';
  10. export function useReplaysDrawer({group, project}: {group: Group; project: Project}) {
  11. const {openDrawer} = useDrawer();
  12. const {baseUrl} = useGroupDetailsRoute();
  13. const navigate = useNavigate();
  14. const location = useLocation();
  15. const openReplaysDrawer = useCallback(() => {
  16. openDrawer(() => <ReplayDrawer group={group} project={project} />, {
  17. ariaLabel: t('Replays'),
  18. onClose: () => {
  19. // Remove drawer state from URL
  20. navigate(
  21. {
  22. pathname: baseUrl,
  23. query: {
  24. ...location.query,
  25. selected_replay_index: undefined,
  26. cursor: undefined,
  27. },
  28. },
  29. {replace: true}
  30. );
  31. },
  32. });
  33. }, [openDrawer, group, project, baseUrl, navigate, location.query]);
  34. return {openReplaysDrawer};
  35. }