useIssueDetailsHeader.tsx 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import {useMemo} from 'react';
  2. import type {Group} from 'sentry/types/group';
  3. import type {Project} from 'sentry/types/project';
  4. import {getMessage} from 'sentry/utils/events';
  5. import {useLocation} from 'sentry/utils/useLocation';
  6. import useOrganization from 'sentry/utils/useOrganization';
  7. import {Tab} from 'sentry/views/issueDetails/types';
  8. import {ReprocessingStatus} from 'sentry/views/issueDetails/utils';
  9. import {ShortIdBreadcrumb} from './shortIdBreadcrumb';
  10. interface IssueDetailsHeaderProps {
  11. baseUrl: string;
  12. group: Group;
  13. groupReprocessingStatus: ReprocessingStatus;
  14. project: Project;
  15. }
  16. export function useIssueDetailsHeader({
  17. group,
  18. groupReprocessingStatus,
  19. baseUrl,
  20. project,
  21. }: IssueDetailsHeaderProps) {
  22. const location = useLocation();
  23. const organization = useOrganization();
  24. const {sort: _sort, query: _query, ...query} = location.query;
  25. const disabledTabs = useMemo(() => {
  26. if (groupReprocessingStatus === ReprocessingStatus.REPROCESSING) {
  27. return [
  28. Tab.ACTIVITY,
  29. Tab.USER_FEEDBACK,
  30. Tab.ATTACHMENTS,
  31. Tab.EVENTS,
  32. Tab.MERGED,
  33. Tab.SIMILAR_ISSUES,
  34. Tab.TAGS,
  35. ];
  36. }
  37. if (groupReprocessingStatus === ReprocessingStatus.REPROCESSED_AND_HASNT_EVENT) {
  38. return [
  39. Tab.DETAILS,
  40. Tab.ATTACHMENTS,
  41. Tab.EVENTS,
  42. Tab.MERGED,
  43. Tab.SIMILAR_ISSUES,
  44. Tab.TAGS,
  45. Tab.USER_FEEDBACK,
  46. ];
  47. }
  48. return [];
  49. }, [groupReprocessingStatus]);
  50. const disableActions = !!disabledTabs.length;
  51. const message = getMessage(group);
  52. const eventRoute = useMemo(() => {
  53. return {
  54. pathname: `${baseUrl}events/`,
  55. query,
  56. };
  57. }, [query, baseUrl]);
  58. const shortIdBreadcrumb = (
  59. <ShortIdBreadcrumb organization={organization} project={project} group={group} />
  60. );
  61. let className = 'group-detail';
  62. if (group.hasSeen) {
  63. className += ' hasSeen';
  64. }
  65. if (group.status === 'resolved') {
  66. className += ' isResolved';
  67. }
  68. return {
  69. disabledTabs,
  70. message,
  71. eventRoute,
  72. disableActions,
  73. shortIdBreadcrumb,
  74. className,
  75. };
  76. }