Skip to content

Commit 2b881ec

Browse files
committed
feat(preprod): Add snapshot PR comments toggle to project settings (EME-999)
Add a toggle on the Snapshots tab in project settings to enable/disable snapshot PR comments, matching the existing build distribution toggle. Gated behind the preprod-snapshot-pr-comments feature flag.
1 parent 36c5869 commit 2b881ec

File tree

3 files changed

+74
-1
lines changed

3 files changed

+74
-1
lines changed

static/app/types/project.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ export type Project = {
8888
preprodSizeEnabledQuery?: string | null;
8989
preprodSizeStatusChecksEnabled?: boolean;
9090
preprodSizeStatusChecksRules?: unknown[];
91+
preprodSnapshotPrCommentsEnabled?: boolean;
9192
preprodSnapshotStatusChecksEnabled?: boolean;
9293
preprodSnapshotStatusChecksFailOnAdded?: boolean;
9394
preprodSnapshotStatusChecksFailOnRemoved?: boolean;

static/app/views/settings/project/preprod/index.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {SettingsPageHeader} from 'sentry/views/settings/components/settingsPageH
1717

1818
import {FeatureFilter} from './featureFilter';
1919
import {PrCommentsToggle} from './prCommentsToggle';
20+
import {SnapshotPrCommentsToggle} from './snapshotPrCommentsToggle';
2021
import {SnapshotStatusChecks} from './snapshotStatusChecks';
2122
import {StatusCheckRules} from './statusCheckRules';
2223

@@ -111,7 +112,14 @@ export default function PreprodSettings() {
111112
</Feature>
112113
</Fragment>
113114
)}
114-
{tab === 'snapshots' && <SnapshotStatusChecks />}
115+
{tab === 'snapshots' && (
116+
<Fragment>
117+
<SnapshotStatusChecks />
118+
<Feature features="organizations:preprod-snapshot-pr-comments">
119+
<SnapshotPrCommentsToggle />
120+
</Feature>
121+
</Fragment>
122+
)}
115123
</Stack>
116124
</Feature>
117125
);
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import {Flex, Stack} from '@sentry/scraps/layout';
2+
import {Switch} from '@sentry/scraps/switch';
3+
import {Text} from '@sentry/scraps/text';
4+
5+
import {
6+
addErrorMessage,
7+
addLoadingMessage,
8+
addSuccessMessage,
9+
} from 'sentry/actionCreators/indicator';
10+
import {Panel} from 'sentry/components/panels/panel';
11+
import {PanelBody} from 'sentry/components/panels/panelBody';
12+
import {PanelHeader} from 'sentry/components/panels/panelHeader';
13+
import {t} from 'sentry/locale';
14+
import {useUpdateProject} from 'sentry/utils/project/useUpdateProject';
15+
import {useProjectSettingsOutlet} from 'sentry/views/settings/project/projectSettingsLayout';
16+
17+
const READ_KEY = 'sentry:preprod_snapshot_pr_comments_enabled';
18+
const WRITE_KEY = 'preprodSnapshotPrCommentsEnabled';
19+
20+
export function SnapshotPrCommentsToggle() {
21+
const {project} = useProjectSettingsOutlet();
22+
const {mutate: updateProject} = useUpdateProject(project);
23+
24+
const enabled = (project[WRITE_KEY] ?? project.options?.[READ_KEY]) !== false;
25+
26+
function handleToggle() {
27+
addLoadingMessage(t('Saving...'));
28+
updateProject(
29+
{[WRITE_KEY]: !enabled},
30+
{
31+
onSuccess: () => {
32+
addSuccessMessage(t('PR comment settings updated'));
33+
},
34+
onError: () => {
35+
addErrorMessage(t('Failed to save changes. Please try again.'));
36+
},
37+
}
38+
);
39+
}
40+
41+
return (
42+
<Panel>
43+
<PanelHeader>{t('Snapshots - Pull Request Comments')}</PanelHeader>
44+
<PanelBody>
45+
<Flex align="center" justify="between" padding="xl">
46+
<Stack gap="xs">
47+
<Text size="lg" bold>
48+
{t('Snapshot Pull Request Comments')}
49+
</Text>
50+
<Text size="sm" variant="muted">
51+
{t('Post snapshot comparison results as comments on pull requests.')}
52+
</Text>
53+
</Stack>
54+
<Switch
55+
size="lg"
56+
checked={enabled}
57+
onChange={handleToggle}
58+
aria-label={t('Toggle snapshot PR comments')}
59+
/>
60+
</Flex>
61+
</PanelBody>
62+
</Panel>
63+
);
64+
}

0 commit comments

Comments
 (0)