fix: Set correct default for added Resource Mapper boolean fields (#12344)

This commit is contained in:
Charlie Kolb 2024-12-23 13:03:24 +01:00 committed by GitHub
parent fe7fb41ad8
commit b4c77f27b6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -493,14 +493,20 @@ function addField(name: string): void {
if (name === 'removeAllFields') { if (name === 'removeAllFields') {
return removeAllFields(); return removeAllFields();
} }
const schema = state.paramValue.schema;
const field = schema.find((f) => f.id === name);
state.paramValue.value = { state.paramValue.value = {
...state.paramValue.value, ...state.paramValue.value,
[name]: null, // We only supply boolean defaults since it's a switch that cannot be null in `Fixed` mode
// Other defaults may break backwards compatibility as we'd remove the implicit passthrough
// mode you get when the field exists, but is empty in `Fixed` mode.
[name]: field?.type === 'boolean' ? false : null,
}; };
const field = state.paramValue.schema.find((f) => f.id === name);
if (field) { if (field) {
field.removed = false; field.removed = false;
state.paramValue.schema.splice(state.paramValue.schema.indexOf(field), 1, field); schema.splice(schema.indexOf(field), 1, field);
} }
emitValueChanged(); emitValueChanged();
} }