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