Update packages/features/form-builder/FormBuilder.tsx

Co-authored-by: Omar López <zomars@me.com>
pull/6560/head
Hariom Balhara 2023-02-16 10:49:32 +05:30 committed by GitHub
parent 7316bd4775
commit 10d9886dcc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 19 deletions

View File

@ -542,25 +542,16 @@ export const ComponentForField = ({
const componentConfig = Components[fieldType]; const componentConfig = Components[fieldType];
const isValueOfPropsType = (val: unknown, propsType: typeof componentConfig.propsType) => { const isValueOfPropsType = (val: unknown, propsType: typeof componentConfig.propsType) => {
if (propsType === "text") { const propsTypeConditionMap = {
return typeof val === "string"; boolean: typeof val === "boolean",
} multiselect: val instanceof Array && val.every((v) => typeof v === "string"),
if (propsType === "boolean") { objectiveWithInput: typeof val === "object" && val !== null ? "value" in val : false,
return typeof val === "boolean"; select: typeof val === "string",
} text: typeof val === "string",
if (propsType === "textList") { textList: val instanceof Array && val.every((v) => typeof v === "string"),
return val instanceof Array && val.every((v) => typeof v === "string"); } as const;
} if (!propsTypeConditionMap[propsType]) throw new Error(`Unknown propsType ${propsType}`);
if (propsType === "select") { return propsTypeConditionMap[propsType];
return typeof val === "string";
}
if (propsType === "multiselect") {
return val instanceof Array && val.every((v) => typeof v === "string");
}
if (propsType === "objectiveWithInput") {
return typeof value === "object" && value !== null ? "value" in value : false;
}
throw new Error(`Unknown propsType ${propsType}`);
}; };
// If possible would have wanted `isValueOfPropsType` to narrow the type of `value` and `setValue` accordingly, but can't seem to do it. // If possible would have wanted `isValueOfPropsType` to narrow the type of `value` and `setValue` accordingly, but can't seem to do it.