actionSet.tsx 8.1 KB

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