index.tsx 17 KB

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