mergedToolbar.tsx 3.0 KB

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