index.tsx 18 KB

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