actionSet.tsx 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. import {Fragment} from 'react';
  2. import ArchiveActions from 'sentry/components/actions/archive';
  3. import {makeGroupPriorityDropdownOptions} from 'sentry/components/badge/groupPriority';
  4. import {Button} from 'sentry/components/button';
  5. import {openConfirmModal} from 'sentry/components/confirm';
  6. import type {MenuItemProps} from 'sentry/components/dropdownMenu';
  7. import {DropdownMenu} from 'sentry/components/dropdownMenu';
  8. import {IconEllipsis} from 'sentry/icons';
  9. import {t} from 'sentry/locale';
  10. import GroupStore from 'sentry/stores/groupStore';
  11. import type {BaseGroup} from 'sentry/types/group';
  12. import {GroupStatus} from 'sentry/types/group';
  13. import {getConfigForIssueType} from 'sentry/utils/issueTypeConfig';
  14. import type {IssueTypeConfig} from 'sentry/utils/issueTypeConfig/types';
  15. import useOrganization from 'sentry/utils/useOrganization';
  16. import type {IssueUpdateData} from 'sentry/views/issueList/types';
  17. import {FOR_REVIEW_QUERIES} from 'sentry/views/issueList/utils';
  18. import ResolveActions from './resolveActions';
  19. import ReviewAction from './reviewAction';
  20. import {ConfirmAction, getConfirm, getLabel} from './utils';
  21. type Props = {
  22. allInQuerySelected: boolean;
  23. anySelected: boolean;
  24. issues: Set<string>;
  25. multiSelected: boolean;
  26. onDelete: () => void;
  27. onMerge: () => void;
  28. onShouldConfirm: (action: ConfirmAction) => boolean;
  29. onUpdate: (data: IssueUpdateData) => void;
  30. query: string;
  31. queryCount: number;
  32. selectedProjectSlug?: string;
  33. };
  34. function ActionSet({
  35. queryCount,
  36. query,
  37. allInQuerySelected,
  38. anySelected,
  39. multiSelected,
  40. issues,
  41. onUpdate,
  42. onShouldConfirm,
  43. onDelete,
  44. onMerge,
  45. selectedProjectSlug,
  46. }: Props) {
  47. const organization = useOrganization();
  48. const numIssues = issues.size;
  49. const confirm = getConfirm({
  50. numIssues,
  51. allInQuerySelected,
  52. query,
  53. queryCount,
  54. });
  55. const label = getLabel(numIssues, allInQuerySelected);
  56. const selectedIssues = [...issues]
  57. .map(issueId => GroupStore.get(issueId))
  58. .filter(issue => issue) as BaseGroup[];
  59. // Merges require multiple issues of a single project type
  60. const multipleIssueProjectsSelected = multiSelected && !selectedProjectSlug;
  61. const {enabled: mergeSupported, disabledReason: mergeDisabledReason} =
  62. isActionSupported(selectedIssues, 'merge');
  63. const {enabled: deleteSupported, disabledReason: deleteDisabledReason} =
  64. isActionSupported(selectedIssues, 'delete');
  65. const mergeDisabled =
  66. !multiSelected || multipleIssueProjectsSelected || !mergeSupported;
  67. const ignoreDisabled = !anySelected;
  68. const canMarkReviewed =
  69. anySelected && (allInQuerySelected || selectedIssues.some(issue => !!issue?.inbox));
  70. // determine which ... dropdown options to show based on issue(s) selected
  71. const canAddBookmark =
  72. allInQuerySelected || selectedIssues.some(issue => !issue.isBookmarked);
  73. const canRemoveBookmark =
  74. allInQuerySelected || selectedIssues.some(issue => issue.isBookmarked);
  75. const canSetUnresolved =
  76. allInQuerySelected ||
  77. selectedIssues.some(
  78. issue => issue.status === 'resolved' || issue.status === 'ignored'
  79. );
  80. const makeMergeTooltip = () => {
  81. if (mergeDisabledReason) {
  82. return mergeDisabledReason;
  83. }
  84. if (multipleIssueProjectsSelected) {
  85. return t('Cannot merge issues from different projects');
  86. }
  87. return '';
  88. };
  89. const nestReview = !FOR_REVIEW_QUERIES.includes(query);
  90. const menuItems: MenuItemProps[] = [
  91. {
  92. key: 'merge',
  93. label: t('Merge'),
  94. disabled: mergeDisabled,
  95. details: makeMergeTooltip(),
  96. onAction: () => {
  97. openConfirmModal({
  98. bypass: !onShouldConfirm(ConfirmAction.MERGE),
  99. onConfirm: onMerge,
  100. message: confirm({action: ConfirmAction.MERGE, canBeUndone: false}),
  101. confirmText: label('merge'),
  102. });
  103. },
  104. },
  105. {
  106. key: 'mark-reviewed',
  107. label: t('Mark Reviewed'),
  108. hidden: !nestReview,
  109. disabled: !canMarkReviewed,
  110. onAction: () => onUpdate({inbox: false}),
  111. },
  112. {
  113. key: 'bookmark',
  114. label: t('Add to Bookmarks'),
  115. hidden: !canAddBookmark,
  116. onAction: () => {
  117. openConfirmModal({
  118. bypass: !onShouldConfirm(ConfirmAction.BOOKMARK),
  119. onConfirm: () => onUpdate({isBookmarked: true}),
  120. message: confirm({action: ConfirmAction.BOOKMARK, canBeUndone: false}),
  121. confirmText: label('bookmark'),
  122. });
  123. },
  124. },
  125. {
  126. key: 'remove-bookmark',
  127. label: t('Remove from Bookmarks'),
  128. hidden: !canRemoveBookmark,
  129. onAction: () => {
  130. openConfirmModal({
  131. bypass: !onShouldConfirm(ConfirmAction.UNBOOKMARK),
  132. onConfirm: () => onUpdate({isBookmarked: false}),
  133. message: confirm({
  134. action: ConfirmAction.UNBOOKMARK,
  135. canBeUndone: false,
  136. append: ' from your bookmarks',
  137. }),
  138. confirmText: label('remove', ' from your bookmarks'),
  139. });
  140. },
  141. },
  142. {
  143. key: 'unresolve',
  144. label: t('Set status to: Unresolved'),
  145. hidden: !canSetUnresolved,
  146. onAction: () => {
  147. openConfirmModal({
  148. bypass: !onShouldConfirm(ConfirmAction.UNRESOLVE),
  149. onConfirm: () => onUpdate({status: GroupStatus.UNRESOLVED, statusDetails: {}}),
  150. message: confirm({action: ConfirmAction.UNRESOLVE, canBeUndone: true}),
  151. confirmText: label('unresolve'),
  152. });
  153. },
  154. },
  155. {
  156. key: 'delete',
  157. label: t('Delete'),
  158. priority: 'danger',
  159. disabled: !deleteSupported,
  160. details: deleteDisabledReason,
  161. onAction: () => {
  162. openConfirmModal({
  163. bypass: !onShouldConfirm(ConfirmAction.DELETE),
  164. onConfirm: onDelete,
  165. priority: 'danger',
  166. message: confirm({action: ConfirmAction.DELETE, canBeUndone: false}),
  167. confirmText: label('delete'),
  168. });
  169. },
  170. },
  171. ];
  172. return (
  173. <Fragment>
  174. {query.includes('is:archived') ? (
  175. <Button
  176. size="xs"
  177. onClick={() => {
  178. openConfirmModal({
  179. bypass: !onShouldConfirm(ConfirmAction.UNRESOLVE),
  180. onConfirm: () =>
  181. onUpdate({status: GroupStatus.UNRESOLVED, statusDetails: {}}),
  182. message: confirm({action: ConfirmAction.UNRESOLVE, canBeUndone: true}),
  183. confirmText: label('unarchive'),
  184. });
  185. }}
  186. disabled={!anySelected}
  187. >
  188. {t('Unarchive')}
  189. </Button>
  190. ) : null}
  191. <ResolveActions
  192. onShouldConfirm={onShouldConfirm}
  193. onUpdate={onUpdate}
  194. anySelected={anySelected}
  195. confirm={confirm}
  196. label={label}
  197. selectedProjectSlug={selectedProjectSlug}
  198. />
  199. <ArchiveActions
  200. onUpdate={onUpdate}
  201. shouldConfirm={onShouldConfirm(ConfirmAction.ARCHIVE)}
  202. confirmMessage={() => confirm({action: ConfirmAction.ARCHIVE, canBeUndone: true})}
  203. confirmLabel={label('archive')}
  204. disabled={ignoreDisabled}
  205. />
  206. <DropdownMenu
  207. triggerLabel={t('Set Priority')}
  208. size="xs"
  209. items={makeGroupPriorityDropdownOptions({
  210. onChange: priority => {
  211. openConfirmModal({
  212. bypass: !onShouldConfirm(ConfirmAction.SET_PRIORITY),
  213. onConfirm: () => onUpdate({priority}),
  214. message: confirm({
  215. action: ConfirmAction.SET_PRIORITY,
  216. append: ` to ${priority}`,
  217. canBeUndone: true,
  218. }),
  219. confirmText: label('reprioritize'),
  220. });
  221. },
  222. hasIssueStreamTableLayout: organization.features.includes(
  223. 'issue-stream-table-layout'
  224. ),
  225. })}
  226. />
  227. {!nestReview && <ReviewAction disabled={!canMarkReviewed} onUpdate={onUpdate} />}
  228. <DropdownMenu
  229. size="sm"
  230. items={menuItems}
  231. triggerProps={{
  232. 'aria-label': t('More issue actions'),
  233. icon: <IconEllipsis />,
  234. showChevron: false,
  235. size: 'xs',
  236. }}
  237. isDisabled={!anySelected}
  238. />
  239. </Fragment>
  240. );
  241. }
  242. function isActionSupported(
  243. selectedIssues: BaseGroup[],
  244. actionType: keyof IssueTypeConfig['actions']
  245. ) {
  246. for (const issue of selectedIssues) {
  247. const info = getConfigForIssueType(issue, issue.project).actions[actionType];
  248. if (!info.enabled) {
  249. return info;
  250. }
  251. }
  252. return {enabled: true};
  253. }
  254. export default ActionSet;