Skip to content

Commit d22a9cd

Browse files
malwilleygeorge-sentry
authored andcommitted
feat(aci): Add issue preview to cron monitor form (#112237)
1 parent 1a9bdde commit d22a9cd

File tree

3 files changed

+63
-5
lines changed

3 files changed

+63
-5
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import {t} from 'sentry/locale';
2+
import {DetectorIssuePreview} from 'sentry/views/detectors/components/forms/common/detectorIssuePreview';
3+
import {IssuePreviewSection} from 'sentry/views/detectors/components/forms/common/issuePreviewSection';
4+
import {ownerToActor} from 'sentry/views/detectors/components/forms/common/ownerToActor';
5+
import {useDetectorFormContext} from 'sentry/views/detectors/components/forms/context';
6+
import {useCronDetectorFormField} from 'sentry/views/detectors/components/forms/cron/fields';
7+
8+
const FALLBACK_ISSUE_TITLE = t('Cron failure: …');
9+
const SUBTITLE = t('Your monitor is failing: A missed check-in was detected');
10+
11+
function useCronIssueTitle() {
12+
const name = useCronDetectorFormField('name');
13+
14+
if (!name) {
15+
return FALLBACK_ISSUE_TITLE;
16+
}
17+
18+
return t('Cron failure: %s', name);
19+
}
20+
21+
export function CronIssuePreview({step}: {step?: number}) {
22+
const owner = useCronDetectorFormField('owner');
23+
const issueTitle = useCronIssueTitle();
24+
const assignee = ownerToActor(owner);
25+
const {project} = useDetectorFormContext();
26+
27+
return (
28+
<IssuePreviewSection step={step}>
29+
<DetectorIssuePreview
30+
issueTitle={issueTitle}
31+
subtitle={SUBTITLE}
32+
assignee={assignee}
33+
project={project}
34+
/>
35+
</IssuePreviewSection>
36+
);
37+
}

static/app/views/detectors/components/forms/cron/index.spec.tsx

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {OrganizationFixture} from 'sentry-fixture/organization';
22
import {ProjectFixture} from 'sentry-fixture/project';
33

4-
import {render, screen} from 'sentry-test/reactTestingLibrary';
4+
import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
55

66
import {OrganizationStore} from 'sentry/stores/organizationStore';
77
import {ProjectsStore} from 'sentry/stores/projectsStore';
@@ -58,7 +58,7 @@ describe('NewCronDetectorForm', () => {
5858

5959
// Form sections should be visible
6060
expect(await screen.findByText(/Detect/)).toBeInTheDocument();
61-
expect(screen.getByText(/Assign/)).toBeInTheDocument();
61+
expect(screen.getByText(/\d\. Assign/)).toBeInTheDocument();
6262
expect(screen.getByText(/Description/)).toBeInTheDocument();
6363

6464
// Create Monitor button should be present and enabled
@@ -80,15 +80,34 @@ describe('NewCronDetectorForm', () => {
8080

8181
// Form sections should be hidden
8282
expect(screen.queryByText(/Detect/)).not.toBeInTheDocument();
83-
expect(screen.queryByText(/Assign/)).not.toBeInTheDocument();
84-
expect(screen.queryByText(/Description/)).not.toBeInTheDocument();
8583

8684
// Create Monitor button should be present but disabled
8785
const createButton = screen.getByRole('button', {name: 'Create Monitor'});
8886
expect(createButton).toBeInTheDocument();
8987
expect(createButton).toBeDisabled();
9088
});
9189

90+
it('renders issue preview and updates title when name changes', async () => {
91+
renderForm();
92+
93+
// Issue preview section should render with fallback title
94+
expect(await screen.findByTestId('issue-preview-section')).toBeInTheDocument();
95+
expect(screen.getByText('Cron failure: …')).toBeInTheDocument();
96+
expect(
97+
screen.getByText('Your monitor is failing: A missed check-in was detected')
98+
).toBeInTheDocument();
99+
100+
// Edit the monitor name
101+
const title = screen.getByText('New Monitor');
102+
await userEvent.click(title);
103+
const nameInput = screen.getByRole('textbox', {name: 'Monitor Name'});
104+
await userEvent.clear(nameInput);
105+
await userEvent.type(nameInput, 'My Cron Job{Enter}');
106+
107+
// Issue preview updates with the new name
108+
expect(await screen.findByText('Cron failure: My Cron Job')).toBeInTheDocument();
109+
});
110+
92111
it('shows form sections and enabled button when guide is set to "manual"', async () => {
93112
renderForm({
94113
location: {
@@ -99,7 +118,7 @@ describe('NewCronDetectorForm', () => {
99118

100119
// Form sections should be visible even with platform set, because guide is "manual"
101120
expect(await screen.findByText(/Detect/)).toBeInTheDocument();
102-
expect(screen.getByText(/Assign/)).toBeInTheDocument();
121+
expect(screen.getByText(/\d\. Assign/)).toBeInTheDocument();
103122
expect(screen.getByText(/Description/)).toBeInTheDocument();
104123

105124
// Create Monitor button should be present and enabled

static/app/views/detectors/components/forms/cron/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {EditDetectorLayout} from 'sentry/views/detectors/components/forms/editDe
2222
import {NewDetectorLayout} from 'sentry/views/detectors/components/forms/newDetectorLayout';
2323
import {useCronsUpsertGuideState} from 'sentry/views/insights/crons/components/useCronsUpsertGuideState';
2424

25+
import {CronIssuePreview} from './cronIssuePreview';
2526
import {PreviewSection} from './previewSection';
2627

2728
function useIsShowingPlatformGuide() {
@@ -35,6 +36,7 @@ const FORM_SECTIONS = [
3536
CronDetectorFormResolveSection,
3637
AssignSection,
3738
DescribeSection,
39+
CronIssuePreview,
3840
AutomateSection,
3941
];
4042

0 commit comments

Comments
 (0)