Skip to content
Merged
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
22 changes: 21 additions & 1 deletion static/app/views/monitors/components/monitorForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ type TransformedData = {
config?: Partial<MonitorConfig>;
};

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

/**
* Transform config field errors from the error response
*/
function mapFormErrors(responseJson?: any) {
if (responseJson.config === undefined) {
return responseJson;
}

// Bring nested config entries to the top
const {config, ...responseRest} = responseJson;
const configErrors = Object.fromEntries(
Object.entries(config).map(([key, value]) => [`config.${key}`, value])
);

return {...responseRest, ...configErrors};
}

function MonitorForm({
monitor,
submitLabel,
apiEndpoint,
apiMethod,
onSubmitSuccess,
}: Props) {
const form = useRef(new FormModel({transformData}));
const form = useRef(new FormModel({transformData, mapFormErrors}));
const {projects} = useProjects();
const {selection} = usePageFilters();
const [crontabInput, setCrontabInput] = useState(
Expand Down