Skip to content

Commit 0d33046

Browse files
evanpurkhisersnigdhas
authored andcommitted
fix(crons): Correctly display schedule errors (#47124)
1 parent 0ecda8b commit 0d33046

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

static/app/views/monitors/components/monitorForm.tsx

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ type TransformedData = {
6363
config?: Partial<MonitorConfig>;
6464
};
6565

66+
/**
67+
* Transform config field values into the config object
68+
*/
6669
function transformData(_data: Record<string, any>, model: FormModel) {
6770
return model.fields.toJSON().reduce<TransformedData>((data, [k, v]) => {
6871
// We're only concerned with transforming the config
@@ -95,14 +98,31 @@ function transformData(_data: Record<string, any>, model: FormModel) {
9598
}, {});
9699
}
97100

101+
/**
102+
* Transform config field errors from the error response
103+
*/
104+
function mapFormErrors(responseJson?: any) {
105+
if (responseJson.config === undefined) {
106+
return responseJson;
107+
}
108+
109+
// Bring nested config entries to the top
110+
const {config, ...responseRest} = responseJson;
111+
const configErrors = Object.fromEntries(
112+
Object.entries(config).map(([key, value]) => [`config.${key}`, value])
113+
);
114+
115+
return {...responseRest, ...configErrors};
116+
}
117+
98118
function MonitorForm({
99119
monitor,
100120
submitLabel,
101121
apiEndpoint,
102122
apiMethod,
103123
onSubmitSuccess,
104124
}: Props) {
105-
const form = useRef(new FormModel({transformData}));
125+
const form = useRef(new FormModel({transformData, mapFormErrors}));
106126
const {projects} = useProjects();
107127
const {selection} = usePageFilters();
108128
const [crontabInput, setCrontabInput] = useState(

0 commit comments

Comments
 (0)