index.tsx 20 KB

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