resolve.tsx 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  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. GroupStatusResolution,
  16. GroupSubstatus,
  17. Project,
  18. ResolutionStatus,
  19. ResolutionStatusDetails,
  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. priority?: 'primary';
  60. projectFetchError?: boolean;
  61. projectSlug?: string;
  62. shouldConfirm?: boolean;
  63. size?: 'xs' | 'sm';
  64. }
  65. function ResolveActions({
  66. size = 'xs',
  67. isResolved = false,
  68. isAutoResolved = false,
  69. confirmLabel = t('Resolve'),
  70. projectSlug,
  71. hasRelease,
  72. latestRelease,
  73. confirmMessage,
  74. shouldConfirm,
  75. disabled,
  76. disableDropdown,
  77. priority,
  78. projectFetchError,
  79. onUpdate,
  80. }: ResolveActionsProps) {
  81. const organization = useOrganization();
  82. function handleCommitResolution(statusDetails: ResolutionStatusDetails) {
  83. onUpdate({
  84. status: ResolutionStatus.RESOLVED,
  85. statusDetails,
  86. substatus: null,
  87. });
  88. }
  89. function handleAnotherExistingReleaseResolution(
  90. statusDetails: ResolutionStatusDetails
  91. ) {
  92. onUpdate({
  93. status: ResolutionStatus.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: ResolutionStatus.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: ResolutionStatus.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: ResolutionStatus.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 actionTitle = !hasRelease
  164. ? t('Set up release tracking in order to use this feature.')
  165. : '';
  166. const onActionOrConfirm = (onAction: () => void) => {
  167. openConfirmModal({
  168. bypass: !shouldConfirm,
  169. onConfirm: onAction,
  170. message: confirmMessage,
  171. confirmText: confirmLabel,
  172. });
  173. };
  174. const isSemver = latestRelease ? isSemverRelease(latestRelease.version) : false;
  175. const hasIssueReleaseSemver = organization.features.includes('issue-release-semver');
  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:
  186. hasIssueReleaseSemver || !latestRelease
  187. ? t('The current release')
  188. : t('The current release (%s)', formatVersion(latestRelease.version)),
  189. details: actionTitle
  190. ? actionTitle
  191. : hasIssueReleaseSemver && latestRelease
  192. ? `${formatVersion(latestRelease.version)} (${
  193. isSemver ? t('semver') : t('non-semver')
  194. })`
  195. : null,
  196. onAction: () => onActionOrConfirm(handleCurrentReleaseResolution),
  197. },
  198. {
  199. key: 'another-release',
  200. label: t('Another existing release\u2026'),
  201. onAction: () => openCustomReleaseModal(),
  202. },
  203. {
  204. key: 'a-commit',
  205. label: t('A commit\u2026'),
  206. onAction: () => openCustomCommitModal(),
  207. },
  208. ];
  209. const isDisabled = !projectSlug ? disabled : disableDropdown;
  210. const hasResolveReleaseSetup = organization.features.includes(
  211. 'issue-resolve-release-setup'
  212. );
  213. return (
  214. <StyledDropdownMenu
  215. itemsHidden={hasResolveReleaseSetup && !hasRelease}
  216. items={items}
  217. trigger={triggerProps => (
  218. <DropdownTrigger
  219. {...triggerProps}
  220. size={size}
  221. priority={priority}
  222. aria-label={t('More resolve options')}
  223. icon={<IconChevron direction="down" size="xs" />}
  224. disabled={isDisabled}
  225. />
  226. )}
  227. disabledKeys={
  228. disabled || !hasRelease
  229. ? ['next-release', 'current-release', 'another-release']
  230. : []
  231. }
  232. menuTitle={
  233. hasRelease || !hasResolveReleaseSetup ? (
  234. t('Resolved In')
  235. ) : (
  236. <SetupReleasesPrompt />
  237. )
  238. }
  239. isDisabled={isDisabled}
  240. />
  241. );
  242. }
  243. function openCustomCommitModal() {
  244. openModal(deps => (
  245. <CustomCommitsResolutionModal
  246. {...deps}
  247. onSelected={(statusDetails: ResolutionStatusDetails) =>
  248. handleCommitResolution(statusDetails)
  249. }
  250. orgSlug={organization.slug}
  251. projectSlug={projectSlug}
  252. />
  253. ));
  254. }
  255. function openCustomReleaseModal() {
  256. openModal(deps => (
  257. <CustomResolutionModal
  258. {...deps}
  259. onSelected={(statusDetails: ResolutionStatusDetails) =>
  260. handleAnotherExistingReleaseResolution(statusDetails)
  261. }
  262. organization={organization}
  263. projectSlug={projectSlug}
  264. />
  265. ));
  266. }
  267. if (isResolved) {
  268. return renderResolved();
  269. }
  270. return (
  271. <Tooltip disabled={!projectFetchError} title={t('Error fetching project')}>
  272. <ButtonBar merged>
  273. <ResolveButton
  274. priority={priority}
  275. size={size}
  276. title={t("We'll nag you with a notification if another event is seen.")}
  277. tooltipProps={{delay: 1000, disabled}}
  278. onClick={() =>
  279. openConfirmModal({
  280. bypass: !shouldConfirm,
  281. onConfirm: () =>
  282. onUpdate({
  283. status: ResolutionStatus.RESOLVED,
  284. statusDetails: {},
  285. substatus: null,
  286. }),
  287. message: confirmMessage,
  288. confirmText: confirmLabel,
  289. })
  290. }
  291. disabled={disabled}
  292. >
  293. {t('Resolve')}
  294. </ResolveButton>
  295. {renderDropdownMenu()}
  296. </ButtonBar>
  297. </Tooltip>
  298. );
  299. }
  300. export default ResolveActions;
  301. const ResolveButton = styled(Button)<{priority?: 'primary'}>`
  302. box-shadow: none;
  303. border-radius: ${p => p.theme.borderRadiusLeft};
  304. ${p =>
  305. p.priority === 'primary' &&
  306. css`
  307. &::after {
  308. content: '';
  309. position: absolute;
  310. top: -1px;
  311. bottom: -1px;
  312. right: -1px;
  313. border-right: solid 1px currentColor;
  314. opacity: 0.25;
  315. }
  316. `}
  317. `;
  318. const DropdownTrigger = styled(Button)`
  319. box-shadow: none;
  320. border-radius: ${p => p.theme.borderRadiusRight};
  321. border-left: none;
  322. `;
  323. /**
  324. * Used to hide the list items when prompting to set up releases
  325. */
  326. const StyledDropdownMenu = styled(DropdownMenu)<{itemsHidden: boolean}>`
  327. ${p =>
  328. p.itemsHidden &&
  329. css`
  330. ul {
  331. display: none;
  332. }
  333. `}
  334. `;
  335. const SetupReleases = styled('div')`
  336. display: flex;
  337. flex-direction: column;
  338. gap: ${space(2)};
  339. align-items: center;
  340. padding: ${space(2)} 0;
  341. text-align: center;
  342. color: ${p => p.theme.gray400};
  343. width: 250px;
  344. white-space: normal;
  345. font-weight: normal;
  346. `;
  347. const SetupReleasesHeader = styled('h6')`
  348. font-size: ${p => p.theme.fontSizeMedium};
  349. margin-bottom: ${space(1)};
  350. `;