resolve.tsx 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. import {css} from '@emotion/react';
  2. import styled from '@emotion/styled';
  3. import {openModal} from 'sentry/actionCreators/modal';
  4. import {Button, LinkButton} from 'sentry/components/button';
  5. import ButtonBar from 'sentry/components/buttonBar';
  6. import {openConfirmModal} from 'sentry/components/confirm';
  7. import CustomCommitsResolutionModal from 'sentry/components/customCommitsResolutionModal';
  8. import CustomResolutionModal from 'sentry/components/customResolutionModal';
  9. import {DropdownMenu, MenuItemProps} from 'sentry/components/dropdownMenu';
  10. import {Tooltip} from 'sentry/components/tooltip';
  11. import {IconChevron, IconReleases} from 'sentry/icons';
  12. import {t} from 'sentry/locale';
  13. import {space} from 'sentry/styles/space';
  14. import {
  15. GroupStatus,
  16. GroupStatusResolution,
  17. GroupSubstatus,
  18. Project,
  19. ResolvedStatusDetails,
  20. } from 'sentry/types';
  21. import {trackAnalytics} from 'sentry/utils/analytics';
  22. import {formatVersion, isSemverRelease} from 'sentry/utils/formatters';
  23. import useOrganization from 'sentry/utils/useOrganization';
  24. function SetupReleasesPrompt() {
  25. return (
  26. <SetupReleases>
  27. <IconReleases size="xl" />
  28. <div>
  29. <SetupReleasesHeader>
  30. {t('Resolving is better with Releases')}
  31. </SetupReleasesHeader>
  32. {t(
  33. 'Set up Releases so Sentry can bother you when this problem comes back in a future release.'
  34. )}
  35. </div>
  36. <LinkButton
  37. priority="primary"
  38. external
  39. size="xs"
  40. href="https://docs.sentry.io/product/releases/setup/"
  41. analyticsEventName="Issue Actions: Resolve Release Setup Prompt Clicked"
  42. analyticsEventKey="issue_actions.resolve_release_setup_prompt_clicked"
  43. >
  44. {t('Set up Releases Now')}
  45. </LinkButton>
  46. </SetupReleases>
  47. );
  48. }
  49. export interface ResolveActionsProps {
  50. hasRelease: boolean;
  51. onUpdate: (data: GroupStatusResolution) => void;
  52. confirmLabel?: string;
  53. confirmMessage?: React.ReactNode;
  54. disableDropdown?: boolean;
  55. disabled?: boolean;
  56. isAutoResolved?: boolean;
  57. isResolved?: boolean;
  58. latestRelease?: Project['latestRelease'];
  59. multipleProjectsSelected?: boolean;
  60. priority?: 'primary';
  61. projectFetchError?: boolean;
  62. projectSlug?: string;
  63. shouldConfirm?: boolean;
  64. size?: 'xs' | 'sm';
  65. }
  66. function ResolveActions({
  67. size = 'xs',
  68. isResolved = false,
  69. isAutoResolved = false,
  70. confirmLabel = t('Resolve'),
  71. projectSlug,
  72. hasRelease,
  73. latestRelease,
  74. confirmMessage,
  75. shouldConfirm,
  76. disabled,
  77. disableDropdown,
  78. priority,
  79. projectFetchError,
  80. multipleProjectsSelected,
  81. onUpdate,
  82. }: ResolveActionsProps) {
  83. const organization = useOrganization();
  84. function handleCommitResolution(statusDetails: ResolvedStatusDetails) {
  85. onUpdate({
  86. status: GroupStatus.RESOLVED,
  87. statusDetails,
  88. substatus: null,
  89. });
  90. }
  91. function handleAnotherExistingReleaseResolution(statusDetails: ResolvedStatusDetails) {
  92. onUpdate({
  93. status: GroupStatus.RESOLVED,
  94. statusDetails,
  95. substatus: null,
  96. });
  97. trackAnalytics('resolve_issue', {
  98. organization,
  99. release: 'anotherExisting',
  100. });
  101. }
  102. function handleCurrentReleaseResolution() {
  103. if (hasRelease) {
  104. onUpdate({
  105. status: GroupStatus.RESOLVED,
  106. statusDetails: {
  107. inRelease: latestRelease ? latestRelease.version : 'latest',
  108. },
  109. substatus: null,
  110. });
  111. }
  112. trackAnalytics('resolve_issue', {
  113. organization,
  114. release: 'current',
  115. });
  116. }
  117. function handleNextReleaseResolution() {
  118. if (hasRelease) {
  119. onUpdate({
  120. status: GroupStatus.RESOLVED,
  121. statusDetails: {
  122. inNextRelease: true,
  123. },
  124. substatus: null,
  125. });
  126. }
  127. trackAnalytics('resolve_issue', {
  128. organization,
  129. release: 'next',
  130. });
  131. }
  132. function renderResolved() {
  133. return (
  134. <Tooltip
  135. title={
  136. isAutoResolved
  137. ? t(
  138. 'This event is resolved due to the Auto Resolve configuration for this project'
  139. )
  140. : t('Unresolve')
  141. }
  142. >
  143. <Button
  144. priority="primary"
  145. size="xs"
  146. aria-label={t('Unresolve')}
  147. disabled={isAutoResolved}
  148. onClick={() =>
  149. onUpdate({
  150. status: GroupStatus.UNRESOLVED,
  151. statusDetails: {},
  152. substatus: GroupSubstatus.ONGOING,
  153. })
  154. }
  155. />
  156. </Tooltip>
  157. );
  158. }
  159. function renderDropdownMenu() {
  160. if (isResolved) {
  161. return renderResolved();
  162. }
  163. const shouldDisplayCta = !hasRelease && !multipleProjectsSelected;
  164. const actionTitle = shouldDisplayCta
  165. ? t('Set up release tracking in order to use this feature.')
  166. : '';
  167. const onActionOrConfirm = (onAction: () => void) => {
  168. openConfirmModal({
  169. bypass: !shouldConfirm,
  170. onConfirm: onAction,
  171. message: confirmMessage,
  172. confirmText: confirmLabel,
  173. });
  174. };
  175. const isSemver = latestRelease ? isSemverRelease(latestRelease.version) : false;
  176. const items: MenuItemProps[] = [
  177. {
  178. key: 'next-release',
  179. label: t('The next release'),
  180. details: actionTitle,
  181. onAction: () => onActionOrConfirm(handleNextReleaseResolution),
  182. },
  183. {
  184. key: 'current-release',
  185. label: t('The current release'),
  186. details: actionTitle
  187. ? actionTitle
  188. : latestRelease
  189. ? `${formatVersion(latestRelease.version)} (${
  190. isSemver ? t('semver') : t('non-semver')
  191. })`
  192. : null,
  193. onAction: () => onActionOrConfirm(handleCurrentReleaseResolution),
  194. },
  195. {
  196. key: 'another-release',
  197. label: t('Another existing release\u2026'),
  198. onAction: () => openCustomReleaseModal(),
  199. },
  200. {
  201. key: 'a-commit',
  202. label: t('A commit\u2026'),
  203. onAction: () => openCustomCommitModal(),
  204. },
  205. ];
  206. const isDisabled = !projectSlug ? disabled : disableDropdown;
  207. return (
  208. <StyledDropdownMenu
  209. itemsHidden={shouldDisplayCta}
  210. items={items}
  211. trigger={triggerProps => (
  212. <DropdownTrigger
  213. {...triggerProps}
  214. size={size}
  215. priority={priority}
  216. aria-label={t('More resolve options')}
  217. icon={<IconChevron direction="down" size="xs" />}
  218. disabled={isDisabled}
  219. />
  220. )}
  221. disabledKeys={
  222. multipleProjectsSelected
  223. ? ['next-release', 'current-release', 'another-release', 'a-commit']
  224. : disabled || !hasRelease
  225. ? ['next-release', 'current-release', 'another-release']
  226. : []
  227. }
  228. menuTitle={shouldDisplayCta ? <SetupReleasesPrompt /> : t('Resolved In')}
  229. isDisabled={isDisabled}
  230. />
  231. );
  232. }
  233. function openCustomCommitModal() {
  234. openModal(deps => (
  235. <CustomCommitsResolutionModal
  236. {...deps}
  237. onSelected={(statusDetails: ResolvedStatusDetails) =>
  238. handleCommitResolution(statusDetails)
  239. }
  240. orgSlug={organization.slug}
  241. projectSlug={projectSlug}
  242. />
  243. ));
  244. }
  245. function openCustomReleaseModal() {
  246. openModal(deps => (
  247. <CustomResolutionModal
  248. {...deps}
  249. onSelected={(statusDetails: ResolvedStatusDetails) =>
  250. handleAnotherExistingReleaseResolution(statusDetails)
  251. }
  252. organization={organization}
  253. projectSlug={projectSlug}
  254. />
  255. ));
  256. }
  257. if (isResolved) {
  258. return renderResolved();
  259. }
  260. return (
  261. <Tooltip disabled={!projectFetchError} title={t('Error fetching project')}>
  262. <ButtonBar merged>
  263. <ResolveButton
  264. priority={priority}
  265. size={size}
  266. title={t("We'll nag you with a notification if another event is seen.")}
  267. tooltipProps={{delay: 1000, disabled}}
  268. onClick={() =>
  269. openConfirmModal({
  270. bypass: !shouldConfirm,
  271. onConfirm: () =>
  272. onUpdate({
  273. status: GroupStatus.RESOLVED,
  274. statusDetails: {},
  275. substatus: null,
  276. }),
  277. message: confirmMessage,
  278. confirmText: confirmLabel,
  279. })
  280. }
  281. disabled={disabled}
  282. >
  283. {t('Resolve')}
  284. </ResolveButton>
  285. {renderDropdownMenu()}
  286. </ButtonBar>
  287. </Tooltip>
  288. );
  289. }
  290. export default ResolveActions;
  291. const ResolveButton = styled(Button)<{priority?: 'primary'}>`
  292. box-shadow: none;
  293. border-radius: ${p => p.theme.borderRadiusLeft};
  294. ${p =>
  295. p.priority === 'primary' &&
  296. css`
  297. &::after {
  298. content: '';
  299. position: absolute;
  300. top: -1px;
  301. bottom: -1px;
  302. right: -1px;
  303. border-right: solid 1px currentColor;
  304. opacity: 0.25;
  305. }
  306. `}
  307. `;
  308. const DropdownTrigger = styled(Button)`
  309. box-shadow: none;
  310. border-radius: ${p => p.theme.borderRadiusRight};
  311. border-left: none;
  312. `;
  313. /**
  314. * Used to hide the list items when prompting to set up releases
  315. */
  316. const StyledDropdownMenu = styled(DropdownMenu)<{itemsHidden: boolean}>`
  317. ${p =>
  318. p.itemsHidden &&
  319. css`
  320. ul {
  321. display: none;
  322. }
  323. `}
  324. `;
  325. const SetupReleases = styled('div')`
  326. display: flex;
  327. flex-direction: column;
  328. gap: ${space(2)};
  329. align-items: center;
  330. padding: ${space(2)} 0;
  331. text-align: center;
  332. color: ${p => p.theme.gray400};
  333. width: 250px;
  334. white-space: normal;
  335. font-weight: normal;
  336. `;
  337. const SetupReleasesHeader = styled('h6')`
  338. font-size: ${p => p.theme.fontSizeMedium};
  339. margin-bottom: ${space(1)};
  340. `;