index.tsx 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  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 ResolveActions from 'sentry/components/actions/resolve';
  14. import GuideAnchor from 'sentry/components/assistant/guideAnchor';
  15. import {Button, LinkButton} from 'sentry/components/button';
  16. import {DropdownMenu} from 'sentry/components/dropdownMenu';
  17. import {EnvironmentPageFilter} from 'sentry/components/organizations/environmentPageFilter';
  18. import {
  19. IconCheckmark,
  20. IconEllipsis,
  21. IconSubscribed,
  22. IconUnsubscribed,
  23. } from 'sentry/icons';
  24. import {t} from 'sentry/locale';
  25. import GroupStore from 'sentry/stores/groupStore';
  26. import IssueListCacheStore from 'sentry/stores/IssueListCacheStore';
  27. import {space} from 'sentry/styles/space';
  28. import type {Event} from 'sentry/types/event';
  29. import type {Group, GroupStatusResolution, MarkReviewed} from 'sentry/types/group';
  30. import {GroupStatus, GroupSubstatus} from 'sentry/types/group';
  31. import type {Organization, SavedQueryVersions} from 'sentry/types/organization';
  32. import type {Project} from 'sentry/types/project';
  33. import {trackAnalytics} from 'sentry/utils/analytics';
  34. import {browserHistory} from 'sentry/utils/browserHistory';
  35. import {getUtcDateString} from 'sentry/utils/dates';
  36. import EventView from 'sentry/utils/discover/eventView';
  37. import {DiscoverDatasets, SavedQueryDatasets} from 'sentry/utils/discover/types';
  38. import {displayReprocessEventAction} from 'sentry/utils/displayReprocessEventAction';
  39. import {getAnalyticsDataForGroup} from 'sentry/utils/events';
  40. import {uniqueId} from 'sentry/utils/guid';
  41. import {getConfigForIssueType} from 'sentry/utils/issueTypeConfig';
  42. import {getAnalyicsDataForProject} from 'sentry/utils/projects';
  43. import normalizeUrl from 'sentry/utils/url/normalizeUrl';
  44. import useOrganization from 'sentry/utils/useOrganization';
  45. import withApi from 'sentry/utils/withApi';
  46. import withOrganization from 'sentry/utils/withOrganization';
  47. import {hasDatasetSelector} from 'sentry/views/dashboards/utils';
  48. import {NewIssueExperienceButton} from 'sentry/views/issueDetails/actions/newIssueExperienceButton';
  49. import {Divider} from 'sentry/views/issueDetails/divider';
  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. event: Event | null;
  65. group: Group;
  66. organization: Organization;
  67. project: Project;
  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 org = useOrganization();
  84. const hasIssuePlatformDeletionUI = org.features.includes('issue-platform-deletion-ui');
  85. const {
  86. actions: {
  87. archiveUntilOccurrence: archiveUntilOccurrenceCap,
  88. delete: deleteCap,
  89. deleteAndDiscard: deleteDiscardCap,
  90. share: shareCap,
  91. resolveInRelease: resolveInReleaseCap,
  92. },
  93. discover: discoverCap,
  94. } = config;
  95. // Update the deleteCap to be enabled if the feature flag is present
  96. const updatedDeleteCap = {
  97. ...deleteCap,
  98. enabled: hasIssuePlatformDeletionUI || deleteCap.enabled,
  99. disabledReason: hasIssuePlatformDeletionUI ? null : deleteCap.disabledReason,
  100. };
  101. const getDiscoverUrl = () => {
  102. const {title, type, shortId} = group;
  103. const discoverQuery = {
  104. id: undefined,
  105. name: title || type,
  106. fields: ['title', 'release', 'environment', 'user.display', 'timestamp'],
  107. orderby: '-timestamp',
  108. query: `issue:${shortId}`,
  109. projects: [Number(project.id)],
  110. version: 2 as SavedQueryVersions,
  111. range: '90d',
  112. dataset: config.usesIssuePlatform ? DiscoverDatasets.ISSUE_PLATFORM : undefined,
  113. };
  114. const discoverView = EventView.fromSavedQuery(discoverQuery);
  115. return discoverView.getResultsViewUrlTarget(
  116. organization.slug,
  117. false,
  118. hasDatasetSelector(organization) ? SavedQueryDatasets.ERRORS : undefined
  119. );
  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: archiveDropdownItems} = getArchiveActions({
  329. onUpdate,
  330. });
  331. return (
  332. <ActionWrapper>
  333. {hasStreamlinedUI &&
  334. (isResolved || isIgnored ? (
  335. <ResolvedActionWapper>
  336. <ResolvedWrapper>
  337. <IconCheckmark />
  338. {isResolved ? t('Resolved') : t('Archived')}
  339. </ResolvedWrapper>
  340. <Divider />
  341. <Button
  342. size="sm"
  343. disabled={disabled || isAutoResolved}
  344. onClick={() =>
  345. onUpdate({
  346. status: GroupStatus.UNRESOLVED,
  347. statusDetails: {},
  348. substatus: GroupSubstatus.ONGOING,
  349. })
  350. }
  351. >
  352. {isResolved ? t('Unresolve') : t('Unarchive')}
  353. </Button>
  354. </ResolvedActionWapper>
  355. ) : (
  356. <Fragment>
  357. <GuideAnchor target="resolve" position="bottom" offset={20}>
  358. <ResolveActions
  359. disableResolveInRelease={!resolveInReleaseCap.enabled}
  360. disabled={disabled}
  361. disableDropdown={disabled}
  362. hasRelease={hasRelease}
  363. latestRelease={project.latestRelease}
  364. onUpdate={onUpdate}
  365. projectSlug={project.slug}
  366. isResolved={isResolved}
  367. isAutoResolved={isAutoResolved}
  368. size="sm"
  369. priority="primary"
  370. />
  371. </GuideAnchor>
  372. <ArchiveActions
  373. className={hasStreamlinedUI ? undefined : 'hidden-xs'}
  374. size="sm"
  375. isArchived={isIgnored}
  376. onUpdate={onUpdate}
  377. disabled={disabled}
  378. disableArchiveUntilOccurrence={!archiveUntilOccurrenceCap.enabled}
  379. />
  380. <SubscribeAction
  381. className={hasStreamlinedUI ? undefined : '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. // XXX: Never show for streamlined UI
  400. ...(isIgnored || hasStreamlinedUI
  401. ? []
  402. : [
  403. {
  404. key: 'Archive',
  405. className: hasStreamlinedUI
  406. ? undefined
  407. : 'hidden-sm hidden-md hidden-lg',
  408. label: t('Archive'),
  409. isSubmenu: true,
  410. disabled,
  411. children: archiveDropdownItems,
  412. },
  413. ]),
  414. {
  415. key: 'open-in-discover',
  416. // XXX: Always show for streamlined UI
  417. className: hasStreamlinedUI ? undefined : 'hidden-sm hidden-md hidden-lg',
  418. label: t('Open in Discover'),
  419. to: disabled ? '' : getDiscoverUrl(),
  420. onAction: () => trackIssueAction('open_in_discover'),
  421. },
  422. // We don't hide the subscribe button for streamlined UI
  423. ...(hasStreamlinedUI
  424. ? []
  425. : [
  426. {
  427. key: group.isSubscribed ? 'unsubscribe' : 'subscribe',
  428. className: 'hidden-sm hidden-md hidden-lg',
  429. label: group.isSubscribed ? t('Unsubscribe') : t('Subscribe'),
  430. disabled: disabled || group.subscriptionDetails?.disabled,
  431. onAction: onToggleSubscribe,
  432. },
  433. ]),
  434. {
  435. key: 'mark-review',
  436. label: t('Mark reviewed'),
  437. disabled: !group.inbox || disabled,
  438. details: !group.inbox || disabled ? t('Issue has been reviewed') : undefined,
  439. onAction: () => onUpdate({inbox: false}),
  440. },
  441. {
  442. key: 'share',
  443. label: t('Share'),
  444. disabled: disabled || !shareCap.enabled,
  445. hidden: !organization.features.includes('shared-issues'),
  446. onAction: openShareModal,
  447. },
  448. {
  449. key: bookmarkKey,
  450. label: bookmarkTitle,
  451. onAction: onToggleBookmark,
  452. },
  453. {
  454. key: 'reprocess',
  455. label: t('Reprocess events'),
  456. hidden: !displayReprocessEventAction(event),
  457. onAction: onReprocessEvent,
  458. },
  459. {
  460. key: 'delete-issue',
  461. priority: 'danger',
  462. label: t('Delete'),
  463. hidden: !hasDeleteAccess,
  464. disabled: !updatedDeleteCap.enabled,
  465. details: updatedDeleteCap.disabledReason,
  466. onAction: openDeleteModal,
  467. },
  468. {
  469. key: 'delete-and-discard',
  470. priority: 'danger',
  471. label: t('Delete and discard future events'),
  472. hidden: !hasDeleteAccess,
  473. disabled: !deleteDiscardCap.enabled,
  474. details: deleteDiscardCap.disabledReason,
  475. onAction: openDiscardModal,
  476. },
  477. ]}
  478. />
  479. {!hasStreamlinedUI && (
  480. <Fragment>
  481. <NewIssueExperienceButton />
  482. <SubscribeAction
  483. className="hidden-xs"
  484. disabled={disabled}
  485. disablePriority
  486. group={group}
  487. onClick={handleClick(onToggleSubscribe)}
  488. icon={group.isSubscribed ? <IconSubscribed /> : <IconUnsubscribed />}
  489. size="sm"
  490. />
  491. <div className="hidden-xs">
  492. <EnvironmentPageFilter position="bottom-end" size="sm" />
  493. </div>
  494. {discoverCap.enabled && (
  495. <Feature
  496. hookName="feature-disabled:open-in-discover"
  497. features="discover-basic"
  498. organization={organization}
  499. >
  500. <LinkButton
  501. className="hidden-xs"
  502. disabled={disabled}
  503. to={disabled ? '' : getDiscoverUrl()}
  504. onClick={() => trackIssueAction('open_in_discover')}
  505. size="sm"
  506. >
  507. <GuideAnchor target="open_in_discover">
  508. {t('Open in Discover')}
  509. </GuideAnchor>
  510. </LinkButton>
  511. </Feature>
  512. )}
  513. {isResolved || isIgnored ? (
  514. <Button
  515. priority="primary"
  516. title={
  517. isAutoResolved
  518. ? t(
  519. 'This event is resolved due to the Auto Resolve configuration for this project'
  520. )
  521. : t('Change status to unresolved')
  522. }
  523. size="sm"
  524. disabled={disabled || isAutoResolved}
  525. onClick={() =>
  526. onUpdate({
  527. status: GroupStatus.UNRESOLVED,
  528. statusDetails: {},
  529. substatus: GroupSubstatus.ONGOING,
  530. })
  531. }
  532. >
  533. {isIgnored ? t('Archived') : t('Resolved')}
  534. </Button>
  535. ) : (
  536. <Fragment>
  537. <ArchiveActions
  538. className="hidden-xs"
  539. size="sm"
  540. isArchived={isIgnored}
  541. onUpdate={onUpdate}
  542. disabled={disabled}
  543. disableArchiveUntilOccurrence={!archiveUntilOccurrenceCap.enabled}
  544. />
  545. <GuideAnchor target="resolve" position="bottom" offset={20}>
  546. <ResolveActions
  547. disableResolveInRelease={!resolveInReleaseCap.enabled}
  548. disabled={disabled}
  549. disableDropdown={disabled}
  550. hasRelease={hasRelease}
  551. latestRelease={project.latestRelease}
  552. onUpdate={onUpdate}
  553. projectSlug={project.slug}
  554. isResolved={isResolved}
  555. isAutoResolved={isAutoResolved}
  556. size="sm"
  557. priority="primary"
  558. />
  559. </GuideAnchor>
  560. </Fragment>
  561. )}
  562. </Fragment>
  563. )}
  564. </ActionWrapper>
  565. );
  566. }
  567. const ActionWrapper = styled('div')`
  568. display: flex;
  569. align-items: center;
  570. gap: ${space(0.5)};
  571. `;
  572. const ResolvedWrapper = styled('div')`
  573. display: flex;
  574. gap: ${space(0.5)};
  575. align-items: center;
  576. color: ${p => p.theme.green400};
  577. font-weight: bold;
  578. font-size: ${p => p.theme.fontSizeLarge};
  579. `;
  580. const ResolvedActionWapper = styled('div')`
  581. display: flex;
  582. gap: ${space(1)};
  583. align-items: center;
  584. `;
  585. export default withApi(withOrganization(Actions));