mergedToolbar.tsx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import type {Location} from 'history';
  2. import {openDiffModal} from 'sentry/actionCreators/modal';
  3. import {Button} from 'sentry/components/button';
  4. import ButtonBar from 'sentry/components/buttonBar';
  5. import Confirm from 'sentry/components/confirm';
  6. import PanelHeader from 'sentry/components/panels/panelHeader';
  7. import {t, tct} from 'sentry/locale';
  8. import GroupingStore from 'sentry/stores/groupingStore';
  9. import {useLegacyStore} from 'sentry/stores/useLegacyStore';
  10. import type {Group} from 'sentry/types/group';
  11. import type {Organization} from 'sentry/types/organization';
  12. import type {Project} from 'sentry/types/project';
  13. type Props = {
  14. groupId: Group['id'];
  15. location: Location;
  16. onToggleCollapse: () => void;
  17. onUnmerge: () => void;
  18. orgId: Organization['slug'];
  19. project: Project;
  20. };
  21. export function MergedToolbar({
  22. groupId,
  23. project,
  24. orgId,
  25. onUnmerge,
  26. onToggleCollapse,
  27. location,
  28. }: Props) {
  29. const {
  30. unmergeList,
  31. mergedItems,
  32. unmergeLastCollapsed,
  33. unmergeDisabled,
  34. enableFingerprintCompare,
  35. } = useLegacyStore(GroupingStore);
  36. const unmergeCount = unmergeList?.size ?? 0;
  37. function handleShowDiff(event: React.MouseEvent) {
  38. event.stopPropagation();
  39. const entries = unmergeList.entries();
  40. // `unmergeList` should only have 2 items in map
  41. if (unmergeList.size !== 2) {
  42. return;
  43. }
  44. // only need eventId, not fingerprint
  45. const [baseEventId, targetEventId] = Array.from(entries).map(
  46. ([, eventId]) => eventId
  47. );
  48. openDiffModal({
  49. targetIssueId: groupId,
  50. project,
  51. baseIssueId: groupId,
  52. orgId,
  53. baseEventId,
  54. targetEventId,
  55. location,
  56. });
  57. }
  58. const unmergeDisabledReason =
  59. mergedItems.length <= 1
  60. ? t('To unmerge, the list must contain 2 or more items')
  61. : unmergeList.size === 0
  62. ? t('To unmerge, 1 or more items must be selected')
  63. : GroupingStore.isAllUnmergedSelected()
  64. ? t('We are unable to unmerge all items at once')
  65. : undefined;
  66. return (
  67. <PanelHeader hasButtons>
  68. <ButtonBar gap={1}>
  69. <Confirm
  70. disabled={unmergeDisabled}
  71. onConfirm={onUnmerge}
  72. message={t(
  73. 'These events will be unmerged and grouped into a new issue. Are you sure you want to unmerge these events?'
  74. )}
  75. >
  76. <Button size="xs" title={unmergeDisabledReason}>
  77. {mergedItems.length <= 1
  78. ? t('Unmerge')
  79. : tct('Unmerge ([itemsSelectedQuantity])', {
  80. itemsSelectedQuantity: unmergeCount,
  81. })}
  82. </Button>
  83. </Confirm>
  84. <Button
  85. size="xs"
  86. disabled={!enableFingerprintCompare}
  87. onClick={handleShowDiff}
  88. title={
  89. !enableFingerprintCompare
  90. ? t('To compare, exactly 2 items must be selected')
  91. : undefined
  92. }
  93. >
  94. {t('Compare')}
  95. </Button>
  96. </ButtonBar>
  97. <Button size="xs" onClick={onToggleCollapse}>
  98. {unmergeLastCollapsed ? t('Expand All') : t('Collapse All')}
  99. </Button>
  100. </PanelHeader>
  101. );
  102. }