123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367 |
- import {css} from '@emotion/react';
- import styled from '@emotion/styled';
- import {openModal} from 'sentry/actionCreators/modal';
- import {Button, LinkButton} from 'sentry/components/button';
- import ButtonBar from 'sentry/components/buttonBar';
- import {openConfirmModal} from 'sentry/components/confirm';
- import CustomCommitsResolutionModal from 'sentry/components/customCommitsResolutionModal';
- import CustomResolutionModal from 'sentry/components/customResolutionModal';
- import {DropdownMenu, MenuItemProps} from 'sentry/components/dropdownMenu';
- import {Tooltip} from 'sentry/components/tooltip';
- import {IconChevron, IconReleases} from 'sentry/icons';
- import {t} from 'sentry/locale';
- import {space} from 'sentry/styles/space';
- import {
- GroupStatus,
- GroupStatusResolution,
- GroupSubstatus,
- Project,
- ResolvedStatusDetails,
- } from 'sentry/types';
- import {trackAnalytics} from 'sentry/utils/analytics';
- import {formatVersion, isSemverRelease} from 'sentry/utils/formatters';
- import useOrganization from 'sentry/utils/useOrganization';
- function SetupReleasesPrompt() {
- return (
- <SetupReleases>
- <IconReleases size="xl" />
- <div>
- <SetupReleasesHeader>
- {t('Resolving is better with Releases')}
- </SetupReleasesHeader>
- {t(
- 'Set up Releases so Sentry can bother you when this problem comes back in a future release.'
- )}
- </div>
- <LinkButton
- priority="primary"
- external
- size="xs"
- href="https://docs.sentry.io/product/releases/setup/"
- analyticsEventName="Issue Actions: Resolve Release Setup Prompt Clicked"
- analyticsEventKey="issue_actions.resolve_release_setup_prompt_clicked"
- >
- {t('Set up Releases Now')}
- </LinkButton>
- </SetupReleases>
- );
- }
- export interface ResolveActionsProps {
- hasRelease: boolean;
- onUpdate: (data: GroupStatusResolution) => void;
- confirmLabel?: string;
- confirmMessage?: React.ReactNode;
- disableDropdown?: boolean;
- disabled?: boolean;
- isAutoResolved?: boolean;
- isResolved?: boolean;
- latestRelease?: Project['latestRelease'];
- multipleProjectsSelected?: boolean;
- priority?: 'primary';
- projectFetchError?: boolean;
- projectSlug?: string;
- shouldConfirm?: boolean;
- size?: 'xs' | 'sm';
- }
- function ResolveActions({
- size = 'xs',
- isResolved = false,
- isAutoResolved = false,
- confirmLabel = t('Resolve'),
- projectSlug,
- hasRelease,
- latestRelease,
- confirmMessage,
- shouldConfirm,
- disabled,
- disableDropdown,
- priority,
- projectFetchError,
- multipleProjectsSelected,
- onUpdate,
- }: ResolveActionsProps) {
- const organization = useOrganization();
- function handleCommitResolution(statusDetails: ResolvedStatusDetails) {
- onUpdate({
- status: GroupStatus.RESOLVED,
- statusDetails,
- substatus: null,
- });
- }
- function handleAnotherExistingReleaseResolution(statusDetails: ResolvedStatusDetails) {
- onUpdate({
- status: GroupStatus.RESOLVED,
- statusDetails,
- substatus: null,
- });
- trackAnalytics('resolve_issue', {
- organization,
- release: 'anotherExisting',
- });
- }
- function handleCurrentReleaseResolution() {
- if (hasRelease) {
- onUpdate({
- status: GroupStatus.RESOLVED,
- statusDetails: {
- inRelease: latestRelease ? latestRelease.version : 'latest',
- },
- substatus: null,
- });
- }
- trackAnalytics('resolve_issue', {
- organization,
- release: 'current',
- });
- }
- function handleNextReleaseResolution() {
- if (hasRelease) {
- onUpdate({
- status: GroupStatus.RESOLVED,
- statusDetails: {
- inNextRelease: true,
- },
- substatus: null,
- });
- }
- trackAnalytics('resolve_issue', {
- organization,
- release: 'next',
- });
- }
- function renderResolved() {
- return (
- <Tooltip
- title={
- isAutoResolved
- ? t(
- 'This event is resolved due to the Auto Resolve configuration for this project'
- )
- : t('Unresolve')
- }
- >
- <Button
- priority="primary"
- size="xs"
- aria-label={t('Unresolve')}
- disabled={isAutoResolved}
- onClick={() =>
- onUpdate({
- status: GroupStatus.UNRESOLVED,
- statusDetails: {},
- substatus: GroupSubstatus.ONGOING,
- })
- }
- />
- </Tooltip>
- );
- }
- function renderDropdownMenu() {
- if (isResolved) {
- return renderResolved();
- }
- const shouldDisplayCta = !hasRelease && !multipleProjectsSelected;
- const actionTitle = shouldDisplayCta
- ? t('Set up release tracking in order to use this feature.')
- : '';
- const onActionOrConfirm = (onAction: () => void) => {
- openConfirmModal({
- bypass: !shouldConfirm,
- onConfirm: onAction,
- message: confirmMessage,
- confirmText: confirmLabel,
- });
- };
- const isSemver = latestRelease ? isSemverRelease(latestRelease.version) : false;
- const items: MenuItemProps[] = [
- {
- key: 'next-release',
- label: t('The next release'),
- details: actionTitle,
- onAction: () => onActionOrConfirm(handleNextReleaseResolution),
- },
- {
- key: 'current-release',
- label: t('The current release'),
- details: actionTitle
- ? actionTitle
- : latestRelease
- ? `${formatVersion(latestRelease.version)} (${
- isSemver ? t('semver') : t('non-semver')
- })`
- : null,
- onAction: () => onActionOrConfirm(handleCurrentReleaseResolution),
- },
- {
- key: 'another-release',
- label: t('Another existing release\u2026'),
- onAction: () => openCustomReleaseModal(),
- },
- {
- key: 'a-commit',
- label: t('A commit\u2026'),
- onAction: () => openCustomCommitModal(),
- },
- ];
- const isDisabled = !projectSlug ? disabled : disableDropdown;
- return (
- <StyledDropdownMenu
- itemsHidden={shouldDisplayCta}
- items={items}
- trigger={triggerProps => (
- <DropdownTrigger
- {...triggerProps}
- size={size}
- priority={priority}
- aria-label={t('More resolve options')}
- icon={<IconChevron direction="down" size="xs" />}
- disabled={isDisabled}
- />
- )}
- disabledKeys={
- multipleProjectsSelected
- ? ['next-release', 'current-release', 'another-release', 'a-commit']
- : disabled || !hasRelease
- ? ['next-release', 'current-release', 'another-release']
- : []
- }
- menuTitle={shouldDisplayCta ? <SetupReleasesPrompt /> : t('Resolved In')}
- isDisabled={isDisabled}
- />
- );
- }
- function openCustomCommitModal() {
- openModal(deps => (
- <CustomCommitsResolutionModal
- {...deps}
- onSelected={(statusDetails: ResolvedStatusDetails) =>
- handleCommitResolution(statusDetails)
- }
- orgSlug={organization.slug}
- projectSlug={projectSlug}
- />
- ));
- }
- function openCustomReleaseModal() {
- openModal(deps => (
- <CustomResolutionModal
- {...deps}
- onSelected={(statusDetails: ResolvedStatusDetails) =>
- handleAnotherExistingReleaseResolution(statusDetails)
- }
- organization={organization}
- projectSlug={projectSlug}
- />
- ));
- }
- if (isResolved) {
- return renderResolved();
- }
- return (
- <Tooltip disabled={!projectFetchError} title={t('Error fetching project')}>
- <ButtonBar merged>
- <ResolveButton
- priority={priority}
- size={size}
- title={t("We'll nag you with a notification if another event is seen.")}
- tooltipProps={{delay: 1000, disabled}}
- onClick={() =>
- openConfirmModal({
- bypass: !shouldConfirm,
- onConfirm: () =>
- onUpdate({
- status: GroupStatus.RESOLVED,
- statusDetails: {},
- substatus: null,
- }),
- message: confirmMessage,
- confirmText: confirmLabel,
- })
- }
- disabled={disabled}
- >
- {t('Resolve')}
- </ResolveButton>
- {renderDropdownMenu()}
- </ButtonBar>
- </Tooltip>
- );
- }
- export default ResolveActions;
- const ResolveButton = styled(Button)<{priority?: 'primary'}>`
- box-shadow: none;
- border-radius: ${p => p.theme.borderRadiusLeft};
- ${p =>
- p.priority === 'primary' &&
- css`
- &::after {
- content: '';
- position: absolute;
- top: -1px;
- bottom: -1px;
- right: -1px;
- border-right: solid 1px currentColor;
- opacity: 0.25;
- }
- `}
- `;
- const DropdownTrigger = styled(Button)`
- box-shadow: none;
- border-radius: ${p => p.theme.borderRadiusRight};
- border-left: none;
- `;
- /**
- * Used to hide the list items when prompting to set up releases
- */
- const StyledDropdownMenu = styled(DropdownMenu)<{itemsHidden: boolean}>`
- ${p =>
- p.itemsHidden &&
- css`
- ul {
- display: none;
- }
- `}
- `;
- const SetupReleases = styled('div')`
- display: flex;
- flex-direction: column;
- gap: ${space(2)};
- align-items: center;
- padding: ${space(2)} 0;
- text-align: center;
- color: ${p => p.theme.gray400};
- width: 250px;
- white-space: normal;
- font-weight: normal;
- `;
- const SetupReleasesHeader = styled('h6')`
- font-size: ${p => p.theme.fontSizeMedium};
- margin-bottom: ${space(1)};
- `;
|