index.tsx 17 KB

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