index.tsx 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  1. import {Fragment, MouseEvent} from 'react';
  2. import {browserHistory} from 'react-router';
  3. import styled from '@emotion/styled';
  4. import {Query} from 'history';
  5. import {bulkDelete, bulkUpdate} from 'sentry/actionCreators/group';
  6. import {addLoadingMessage, clearIndicators} from 'sentry/actionCreators/indicator';
  7. import {
  8. ModalRenderProps,
  9. openModal,
  10. openReprocessEventModal,
  11. } from 'sentry/actionCreators/modal';
  12. import {Client} from 'sentry/api';
  13. import Feature from 'sentry/components/acl/feature';
  14. import FeatureDisabled from 'sentry/components/acl/featureDisabled';
  15. import ArchiveActions, {getArchiveActions} from 'sentry/components/actions/archive';
  16. import ActionButton from 'sentry/components/actions/button';
  17. import IgnoreActions, {getIgnoreActions} from 'sentry/components/actions/ignore';
  18. import ResolveActions from 'sentry/components/actions/resolve';
  19. import GuideAnchor from 'sentry/components/assistant/guideAnchor';
  20. import {Button} from 'sentry/components/button';
  21. import {DropdownMenu} from 'sentry/components/dropdownMenu';
  22. import {EnvironmentPageFilter} from 'sentry/components/organizations/environmentPageFilter';
  23. import {
  24. IconCheckmark,
  25. IconEllipsis,
  26. IconMute,
  27. IconSubscribed,
  28. IconUnsubscribed,
  29. } from 'sentry/icons';
  30. import {t} from 'sentry/locale';
  31. import GroupStore from 'sentry/stores/groupStore';
  32. import {space} from 'sentry/styles/space';
  33. import {
  34. Group,
  35. GroupStatus,
  36. GroupStatusResolution,
  37. GroupSubstatus,
  38. IssueCategory,
  39. MarkReviewed,
  40. Organization,
  41. Project,
  42. SavedQueryVersions,
  43. } from 'sentry/types';
  44. import {Event} from 'sentry/types/event';
  45. import {trackAnalytics} from 'sentry/utils/analytics';
  46. import {getUtcDateString} from 'sentry/utils/dates';
  47. import EventView from 'sentry/utils/discover/eventView';
  48. import {DiscoverDatasets} from 'sentry/utils/discover/types';
  49. import {displayReprocessEventAction} from 'sentry/utils/displayReprocessEventAction';
  50. import {getAnalyticsDataForGroup} from 'sentry/utils/events';
  51. import {uniqueId} from 'sentry/utils/guid';
  52. import {getConfigForIssueType} from 'sentry/utils/issueTypeConfig';
  53. import withApi from 'sentry/utils/withApi';
  54. import {normalizeUrl} from 'sentry/utils/withDomainRequired';
  55. import withOrganization from 'sentry/utils/withOrganization';
  56. import ShareIssueModal from './shareModal';
  57. import SubscribeAction from './subscribeAction';
  58. type UpdateData =
  59. | {isBookmarked: boolean}
  60. | {isSubscribed: boolean}
  61. | MarkReviewed
  62. | GroupStatusResolution;
  63. const isResolutionStatus = (data: UpdateData): data is GroupStatusResolution => {
  64. return (data as GroupStatusResolution).status !== undefined;
  65. };
  66. type Props = {
  67. api: Client;
  68. disabled: boolean;
  69. group: Group;
  70. organization: Organization;
  71. project: Project;
  72. event?: Event;
  73. query?: Query;
  74. };
  75. export function Actions(props: Props) {
  76. const {api, group, project, organization, disabled, event, query = {}} = props;
  77. const {status, isBookmarked} = group;
  78. const bookmarkKey = isBookmarked ? 'unbookmark' : 'bookmark';
  79. const bookmarkTitle = isBookmarked ? t('Remove bookmark') : t('Bookmark');
  80. const hasRelease = !!project.features?.includes('releases');
  81. const isResolved = status === 'resolved';
  82. const isAutoResolved =
  83. group.status === 'resolved' ? group.statusDetails.autoResolved : undefined;
  84. const isIgnored = status === 'ignored';
  85. const hasEscalatingIssues = organization.features.includes('escalating-issues');
  86. const hasDeleteAccess = organization.access.includes('event:admin');
  87. const {
  88. actions: {delete: deleteCap, deleteAndDiscard: deleteDiscardCap, share: shareCap},
  89. discover: discoverCap,
  90. } = getConfigForIssueType(group);
  91. const getDiscoverUrl = () => {
  92. const {title, type, shortId} = group;
  93. const groupIsOccurrenceBacked =
  94. group.issueCategory === IssueCategory.PERFORMANCE && !!event?.occurrence;
  95. const config = getConfigForIssueType(group);
  96. const discoverQuery = {
  97. id: undefined,
  98. name: title || type,
  99. fields: ['title', 'release', 'environment', 'user.display', 'timestamp'],
  100. orderby: '-timestamp',
  101. query: `issue:${shortId}`,
  102. projects: [Number(project.id)],
  103. version: 2 as SavedQueryVersions,
  104. range: '90d',
  105. dataset:
  106. config.usesIssuePlatform || groupIsOccurrenceBacked
  107. ? DiscoverDatasets.ISSUE_PLATFORM
  108. : undefined,
  109. };
  110. const discoverView = EventView.fromSavedQuery(discoverQuery);
  111. return discoverView.getResultsViewUrlTarget(organization.slug);
  112. };
  113. const trackIssueAction = (
  114. action:
  115. | 'shared'
  116. | 'deleted'
  117. | 'bookmarked'
  118. | 'subscribed'
  119. | 'mark_reviewed'
  120. | 'discarded'
  121. | 'open_in_discover'
  122. | GroupStatus,
  123. substatus?: GroupSubstatus | null,
  124. statusDetailsKey?: string
  125. ) => {
  126. const {alert_date, alert_rule_id, alert_type} = query;
  127. trackAnalytics('issue_details.action_clicked', {
  128. organization,
  129. project_id: parseInt(project.id, 10),
  130. action_type: action,
  131. action_substatus: substatus ?? undefined,
  132. action_status_details: statusDetailsKey,
  133. // Alert properties track if the user came from email/slack alerts
  134. alert_date:
  135. typeof alert_date === 'string' ? getUtcDateString(Number(alert_date)) : undefined,
  136. alert_rule_id: typeof alert_rule_id === 'string' ? alert_rule_id : undefined,
  137. alert_type: typeof alert_type === 'string' ? alert_type : undefined,
  138. ...getAnalyticsDataForGroup(group),
  139. });
  140. };
  141. const onDelete = () => {
  142. addLoadingMessage(t('Delete event\u2026'));
  143. bulkDelete(
  144. api,
  145. {
  146. orgId: organization.slug,
  147. projectId: project.slug,
  148. itemIds: [group.id],
  149. },
  150. {
  151. complete: () => {
  152. clearIndicators();
  153. browserHistory.push(
  154. normalizeUrl({
  155. pathname: `/organizations/${organization.slug}/issues/`,
  156. query: {project: project.id},
  157. })
  158. );
  159. },
  160. }
  161. );
  162. trackIssueAction('deleted');
  163. };
  164. const onUpdate = (data: UpdateData) => {
  165. addLoadingMessage(t('Saving changes\u2026'));
  166. bulkUpdate(
  167. api,
  168. {
  169. orgId: organization.slug,
  170. projectId: project.slug,
  171. itemIds: [group.id],
  172. data,
  173. },
  174. {
  175. complete: clearIndicators,
  176. }
  177. );
  178. if (isResolutionStatus(data)) {
  179. trackIssueAction(
  180. data.status,
  181. data.substatus,
  182. Object.keys(data.statusDetails || {})[0]
  183. );
  184. }
  185. if ((data as {inbox: boolean}).inbox !== undefined) {
  186. trackIssueAction('mark_reviewed');
  187. }
  188. };
  189. const onReprocessEvent = () => {
  190. openReprocessEventModal({organization, groupId: group.id});
  191. };
  192. const onToggleShare = () => {
  193. const newIsPublic = !group.isPublic;
  194. if (newIsPublic) {
  195. trackAnalytics('issue.shared_publicly', {
  196. organization,
  197. });
  198. }
  199. trackIssueAction('shared');
  200. };
  201. const onToggleBookmark = () => {
  202. onUpdate({isBookmarked: !group.isBookmarked});
  203. trackIssueAction('bookmarked');
  204. };
  205. const onToggleSubscribe = () => {
  206. onUpdate({isSubscribed: !group.isSubscribed});
  207. trackIssueAction('subscribed');
  208. };
  209. const onDiscard = () => {
  210. const id = uniqueId();
  211. addLoadingMessage(t('Discarding event\u2026'));
  212. GroupStore.onDiscard(id, group.id);
  213. api.request(`/issues/${group.id}/`, {
  214. method: 'PUT',
  215. data: {discard: true},
  216. success: response => {
  217. GroupStore.onDiscardSuccess(id, group.id, response);
  218. browserHistory.push(
  219. normalizeUrl({
  220. pathname: `/organizations/${organization.slug}/issues/`,
  221. query: {project: project.id},
  222. })
  223. );
  224. },
  225. error: error => {
  226. GroupStore.onDiscardError(id, group.id, error);
  227. },
  228. complete: clearIndicators,
  229. });
  230. trackIssueAction('discarded');
  231. };
  232. const renderDiscardModal = ({Body, Footer, closeModal}: ModalRenderProps) => {
  233. function renderDiscardDisabled({children, ...innerProps}) {
  234. return children({
  235. ...innerProps,
  236. renderDisabled: ({features}: {features: string[]}) => (
  237. <FeatureDisabled
  238. alert
  239. featureName={t('Discard and Delete')}
  240. features={features}
  241. />
  242. ),
  243. });
  244. }
  245. return (
  246. <Feature
  247. features={['projects:discard-groups']}
  248. hookName="feature-disabled:discard-groups"
  249. organization={organization}
  250. project={project}
  251. renderDisabled={renderDiscardDisabled}
  252. >
  253. {({hasFeature, renderDisabled, ...innerProps}) => (
  254. <Fragment>
  255. <Body>
  256. {!hasFeature &&
  257. typeof renderDisabled === 'function' &&
  258. renderDisabled({...innerProps, hasFeature, children: null})}
  259. {t(
  260. `Discarding this event will result in the deletion of most data associated with this issue and future events being discarded before reaching your stream. Are you sure you wish to continue?`
  261. )}
  262. </Body>
  263. <Footer>
  264. <Button onClick={closeModal}>{t('Cancel')}</Button>
  265. <Button
  266. style={{marginLeft: space(1)}}
  267. priority="primary"
  268. onClick={onDiscard}
  269. disabled={!hasFeature}
  270. >
  271. {t('Discard Future Events')}
  272. </Button>
  273. </Footer>
  274. </Fragment>
  275. )}
  276. </Feature>
  277. );
  278. };
  279. const openDeleteModal = () =>
  280. openModal(({Body, Footer, closeModal}: ModalRenderProps) => (
  281. <Fragment>
  282. <Body>
  283. {t('Deleting this issue is permanent. Are you sure you wish to continue?')}
  284. </Body>
  285. <Footer>
  286. <Button onClick={closeModal}>{t('Cancel')}</Button>
  287. <Button style={{marginLeft: space(1)}} priority="primary" onClick={onDelete}>
  288. {t('Delete')}
  289. </Button>
  290. </Footer>
  291. </Fragment>
  292. ));
  293. const openDiscardModal = () => {
  294. openModal(renderDiscardModal);
  295. };
  296. const openShareModal = () => {
  297. openModal(modalProps => (
  298. <ShareIssueModal
  299. {...modalProps}
  300. organization={organization}
  301. projectSlug={group.project.slug}
  302. groupId={group.id}
  303. onToggle={onToggleShare}
  304. />
  305. ));
  306. };
  307. const handleClick = (onClick: (event?: MouseEvent) => void) => {
  308. return function (innerEvent: MouseEvent) {
  309. if (disabled) {
  310. innerEvent.preventDefault();
  311. innerEvent.stopPropagation();
  312. return;
  313. }
  314. onClick(innerEvent);
  315. };
  316. };
  317. const {dropdownItems, onIgnore} = getIgnoreActions({onUpdate});
  318. const {dropdownItems: archiveDropdownItems} = getArchiveActions({
  319. onUpdate,
  320. });
  321. return (
  322. <ActionWrapper>
  323. <DropdownMenu
  324. triggerProps={{
  325. 'aria-label': t('More Actions'),
  326. icon: <IconEllipsis size="xs" />,
  327. showChevron: false,
  328. size: 'sm',
  329. }}
  330. items={[
  331. ...(isIgnored || hasEscalatingIssues
  332. ? []
  333. : [
  334. {
  335. key: 'ignore',
  336. className: 'hidden-sm hidden-md hidden-lg',
  337. label: t('Ignore'),
  338. isSubmenu: true,
  339. disabled,
  340. children: [
  341. {
  342. key: 'ignore-now',
  343. label: t('Ignore Issue'),
  344. onAction: () => onIgnore(),
  345. },
  346. ...dropdownItems,
  347. ],
  348. },
  349. ]),
  350. ...(hasEscalatingIssues
  351. ? isIgnored
  352. ? []
  353. : [
  354. {
  355. key: 'Archive',
  356. className: 'hidden-sm hidden-md hidden-lg',
  357. label: t('Archive'),
  358. isSubmenu: true,
  359. disabled,
  360. children: archiveDropdownItems,
  361. },
  362. ]
  363. : []),
  364. {
  365. key: 'open-in-discover',
  366. className: 'hidden-sm hidden-md hidden-lg',
  367. label: t('Open in Discover'),
  368. to: disabled ? '' : getDiscoverUrl(),
  369. onAction: () => trackIssueAction('open_in_discover'),
  370. },
  371. {
  372. key: group.isSubscribed ? 'unsubscribe' : 'subscribe',
  373. className: 'hidden-sm hidden-md hidden-lg',
  374. label: group.isSubscribed ? t('Unsubscribe') : t('Subscribe'),
  375. disabled: disabled || group.subscriptionDetails?.disabled,
  376. onAction: onToggleSubscribe,
  377. },
  378. {
  379. key: 'mark-review',
  380. label: t('Mark reviewed'),
  381. disabled: !group.inbox || disabled,
  382. details: !group.inbox || disabled ? t('Issue has been reviewed') : undefined,
  383. onAction: () => onUpdate({inbox: false}),
  384. },
  385. {
  386. key: 'share',
  387. label: t('Share'),
  388. disabled: disabled || !shareCap.enabled,
  389. hidden: !organization.features.includes('shared-issues'),
  390. onAction: openShareModal,
  391. },
  392. {
  393. key: bookmarkKey,
  394. label: bookmarkTitle,
  395. onAction: onToggleBookmark,
  396. },
  397. {
  398. key: 'reprocess',
  399. label: t('Reprocess events'),
  400. hidden: !displayReprocessEventAction(organization.features, event),
  401. onAction: onReprocessEvent,
  402. },
  403. {
  404. key: 'delete-issue',
  405. priority: 'danger',
  406. label: t('Delete'),
  407. hidden: !hasDeleteAccess,
  408. disabled: !deleteCap.enabled,
  409. details: deleteCap.disabledReason,
  410. onAction: openDeleteModal,
  411. },
  412. {
  413. key: 'delete-and-discard',
  414. priority: 'danger',
  415. label: t('Delete and discard future events'),
  416. hidden: !hasDeleteAccess,
  417. disabled: !deleteDiscardCap.enabled,
  418. details: deleteDiscardCap.disabledReason,
  419. onAction: openDiscardModal,
  420. },
  421. ]}
  422. />
  423. <SubscribeAction
  424. className="hidden-xs"
  425. disabled={disabled}
  426. disablePriority
  427. group={group}
  428. onClick={handleClick(onToggleSubscribe)}
  429. icon={group.isSubscribed ? <IconSubscribed /> : <IconUnsubscribed />}
  430. size="sm"
  431. />
  432. <div className="hidden-xs">
  433. <EnvironmentPageFilter position="bottom-end" size="sm" />
  434. </div>
  435. {discoverCap.enabled && (
  436. <Feature
  437. hookName="feature-disabled:open-in-discover"
  438. features={['discover-basic']}
  439. organization={organization}
  440. >
  441. <ActionButton
  442. className="hidden-xs"
  443. disabled={disabled}
  444. to={disabled ? '' : getDiscoverUrl()}
  445. onClick={() => trackIssueAction('open_in_discover')}
  446. size="sm"
  447. >
  448. <GuideAnchor target="open_in_discover">{t('Open in Discover')}</GuideAnchor>
  449. </ActionButton>
  450. </Feature>
  451. )}
  452. {isResolved || isIgnored ? (
  453. <ActionButton
  454. priority="primary"
  455. title={
  456. isAutoResolved
  457. ? t(
  458. 'This event is resolved due to the Auto Resolve configuration for this project'
  459. )
  460. : t('Change status to unresolved')
  461. }
  462. size="sm"
  463. icon={
  464. hasEscalatingIssues ? null : isResolved ? <IconCheckmark /> : <IconMute />
  465. }
  466. disabled={disabled || isAutoResolved}
  467. onClick={() =>
  468. onUpdate({
  469. status: GroupStatus.UNRESOLVED,
  470. statusDetails: {},
  471. substatus: GroupSubstatus.ONGOING,
  472. })
  473. }
  474. >
  475. {isIgnored
  476. ? hasEscalatingIssues
  477. ? t('Archived')
  478. : t('Ignored')
  479. : t('Resolved')}
  480. </ActionButton>
  481. ) : (
  482. <Fragment>
  483. {hasEscalatingIssues ? (
  484. <GuideAnchor target="issue_details_archive_button" position="bottom">
  485. <ArchiveActions
  486. className="hidden-xs"
  487. size="sm"
  488. isArchived={isIgnored}
  489. onUpdate={onUpdate}
  490. disabled={disabled}
  491. />
  492. </GuideAnchor>
  493. ) : (
  494. <IgnoreActions
  495. className="hidden-xs"
  496. isIgnored={isIgnored}
  497. onUpdate={onUpdate}
  498. disabled={disabled}
  499. size="sm"
  500. />
  501. )}
  502. <GuideAnchor target="resolve" position="bottom" offset={20}>
  503. <ResolveActions
  504. disabled={disabled}
  505. disableDropdown={disabled}
  506. hasRelease={hasRelease}
  507. latestRelease={project.latestRelease}
  508. onUpdate={onUpdate}
  509. projectSlug={project.slug}
  510. isResolved={isResolved}
  511. isAutoResolved={isAutoResolved}
  512. size="sm"
  513. priority="primary"
  514. />
  515. </GuideAnchor>
  516. </Fragment>
  517. )}
  518. </ActionWrapper>
  519. );
  520. }
  521. const ActionWrapper = styled('div')`
  522. display: flex;
  523. align-items: center;
  524. gap: ${space(0.5)};
  525. `;
  526. export default withApi(withOrganization(Actions));