Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions static/app/types/project.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export type Project = {
preprodSizeEnabledQuery?: string | null;
preprodSizeStatusChecksEnabled?: boolean;
preprodSizeStatusChecksRules?: unknown[];
preprodSnapshotPrCommentsEnabled?: boolean;
preprodSnapshotStatusChecksEnabled?: boolean;
preprodSnapshotStatusChecksFailOnAdded?: boolean;
preprodSnapshotStatusChecksFailOnRemoved?: boolean;
Expand Down
10 changes: 9 additions & 1 deletion static/app/views/settings/project/preprod/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {SettingsPageHeader} from 'sentry/views/settings/components/settingsPageH

import {FeatureFilter} from './featureFilter';
import {PrCommentsToggle} from './prCommentsToggle';
import {SnapshotPrCommentsToggle} from './snapshotPrCommentsToggle';
import {SnapshotStatusChecks} from './snapshotStatusChecks';
import {StatusCheckRules} from './statusCheckRules';

Expand Down Expand Up @@ -111,7 +112,14 @@ export default function PreprodSettings() {
</Feature>
</Fragment>
)}
{tab === 'snapshots' && <SnapshotStatusChecks />}
{tab === 'snapshots' && (
<Fragment>
<SnapshotStatusChecks />
<Feature features="organizations:preprod-snapshot-pr-comments">
<SnapshotPrCommentsToggle />
</Feature>
</Fragment>
)}
</Stack>
</Feature>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import {Flex, Stack} from '@sentry/scraps/layout';
import {Switch} from '@sentry/scraps/switch';
import {Text} from '@sentry/scraps/text';

import {
addErrorMessage,
addLoadingMessage,
addSuccessMessage,
} from 'sentry/actionCreators/indicator';
import {Panel} from 'sentry/components/panels/panel';
import {PanelBody} from 'sentry/components/panels/panelBody';
import {PanelHeader} from 'sentry/components/panels/panelHeader';
import {t} from 'sentry/locale';
import {useUpdateProject} from 'sentry/utils/project/useUpdateProject';
import {useProjectSettingsOutlet} from 'sentry/views/settings/project/projectSettingsLayout';

const READ_KEY = 'sentry:preprod_snapshot_pr_comments_enabled';
const WRITE_KEY = 'preprodSnapshotPrCommentsEnabled';

export function SnapshotPrCommentsToggle() {
const {project} = useProjectSettingsOutlet();
const {mutate: updateProject} = useUpdateProject(project);

const enabled = (project[WRITE_KEY] ?? project.options?.[READ_KEY]) !== false;

function handleToggle() {
addLoadingMessage(t('Saving...'));
updateProject(
{[WRITE_KEY]: !enabled},
{
onSuccess: () => {
addSuccessMessage(t('PR comment settings updated'));
},
onError: () => {
addErrorMessage(t('Failed to save changes. Please try again.'));
},
}
);
}

return (
<Panel>
<PanelHeader>{t('Snapshots - Pull Request Comments')}</PanelHeader>
<PanelBody>
<Flex align="center" justify="between" padding="xl">
<Stack gap="xs">
<Text size="lg" bold>
{t('Snapshot Pull Request Comments')}
</Text>
<Text size="sm" variant="muted">
{t('Post snapshot comparison results as comments on pull requests.')}
</Text>
</Stack>
<Switch
size="lg"
checked={enabled}
onChange={handleToggle}
aria-label={t('Toggle snapshot PR comments')}
/>
</Flex>
</PanelBody>
</Panel>
);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New toggle component duplicates existing PR comments toggle

Low Severity

SnapshotPrCommentsToggle is a near-exact copy of PrCommentsToggle — both are 64 lines with identical structure, logic, and component tree. The only differences are the READ_KEY/WRITE_KEY constants and five label strings. A single shared component accepting those as props would eliminate the duplication, reducing the risk of the two toggles drifting out of sync if the toggle logic ever needs a bug fix.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 2b881ec. Configure here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm ok either way - extracting most of this to be a shared base or just leaving separate

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to merge as is. We're still not in beta and if we combine the logic then it sets it in stone. If we want to change / add more toggles it makes it trickier.

Loading