index.tsx 17 KB

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