index.tsx 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  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. {
  378. key: 'mark-review',
  379. label: t('Mark reviewed'),
  380. disabled: !group.inbox || disabled,
  381. details: !group.inbox || disabled ? t('Issue has been reviewed') : undefined,
  382. onAction: () => onUpdate({inbox: false}),
  383. },
  384. {
  385. key: 'share',
  386. label: t('Share'),
  387. disabled: disabled || !shareCap.enabled,
  388. hidden: !organization.features.includes('shared-issues'),
  389. onAction: openShareModal,
  390. },
  391. {
  392. key: bookmarkKey,
  393. label: bookmarkTitle,
  394. onAction: onToggleBookmark,
  395. },
  396. {
  397. key: 'reprocess',
  398. label: t('Reprocess events'),
  399. hidden: !displayReprocessEventAction(organization.features, event),
  400. onAction: onReprocessEvent,
  401. },
  402. {
  403. key: 'delete-issue',
  404. priority: 'danger',
  405. label: t('Delete'),
  406. hidden: !hasDeleteAccess,
  407. disabled: !deleteCap.enabled,
  408. details: deleteCap.disabledReason,
  409. onAction: openDeleteModal,
  410. },
  411. {
  412. key: 'delete-and-discard',
  413. priority: 'danger',
  414. label: t('Delete and discard future events'),
  415. hidden: !hasDeleteAccess,
  416. disabled: !deleteDiscardCap.enabled,
  417. details: deleteDiscardCap.disabledReason,
  418. onAction: openDiscardModal,
  419. },
  420. ]}
  421. />
  422. <SubscribeAction
  423. className="hidden-xs"
  424. disabled={disabled}
  425. disablePriority
  426. group={group}
  427. onClick={handleClick(onToggleSubscribe)}
  428. icon={group.isSubscribed ? <IconSubscribed /> : <IconUnsubscribed />}
  429. size="sm"
  430. />
  431. <div className="hidden-xs">
  432. <EnvironmentPageFilter alignDropdown="right" size="sm" />
  433. </div>
  434. <Feature
  435. hookName="feature-disabled:open-in-discover"
  436. features={['discover-basic']}
  437. organization={organization}
  438. >
  439. <ActionButton
  440. className="hidden-xs"
  441. disabled={disabled}
  442. to={disabled ? '' : getDiscoverUrl()}
  443. onClick={() => trackIssueAction('open_in_discover')}
  444. size="sm"
  445. >
  446. <GuideAnchor target="open_in_discover">{t('Open in Discover')}</GuideAnchor>
  447. </ActionButton>
  448. </Feature>
  449. {isResolved || isIgnored ? (
  450. <ActionButton
  451. priority="primary"
  452. title={
  453. isAutoResolved
  454. ? t(
  455. 'This event is resolved due to the Auto Resolve configuration for this project'
  456. )
  457. : t('Change status to unresolved')
  458. }
  459. size="sm"
  460. icon={
  461. hasEscalatingIssues ? null : isResolved ? <IconCheckmark /> : <IconMute />
  462. }
  463. disabled={disabled || isAutoResolved}
  464. onClick={() =>
  465. onUpdate({
  466. status: ResolutionStatus.UNRESOLVED,
  467. statusDetails: {},
  468. })
  469. }
  470. >
  471. {isIgnored
  472. ? hasEscalatingIssues
  473. ? t('Archived')
  474. : t('Ignored')
  475. : t('Resolved')}
  476. </ActionButton>
  477. ) : (
  478. <Fragment>
  479. {hasEscalatingIssues ? (
  480. <GuideAnchor target="issue_details_archive_button" position="bottom">
  481. <ArchiveActions
  482. className="hidden-xs"
  483. size="sm"
  484. isArchived={isIgnored}
  485. onUpdate={onUpdate}
  486. disabled={disabled}
  487. />
  488. </GuideAnchor>
  489. ) : (
  490. <IgnoreActions
  491. className="hidden-xs"
  492. isIgnored={isIgnored}
  493. onUpdate={onUpdate}
  494. disabled={disabled}
  495. size="sm"
  496. />
  497. )}
  498. <GuideAnchor target="resolve" position="bottom" offset={20}>
  499. <ResolveActions
  500. disabled={disabled}
  501. disableDropdown={disabled}
  502. hasRelease={hasRelease}
  503. latestRelease={project.latestRelease}
  504. onUpdate={onUpdate}
  505. projectSlug={project.slug}
  506. isResolved={isResolved}
  507. isAutoResolved={isAutoResolved}
  508. size="sm"
  509. priority="primary"
  510. />
  511. </GuideAnchor>
  512. </Fragment>
  513. )}
  514. </ActionWrapper>
  515. );
  516. }
  517. const ActionWrapper = styled('div')`
  518. display: flex;
  519. align-items: center;
  520. gap: ${space(0.5)};
  521. `;
  522. export default withApi(withOrganization(Actions));