2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-15 11:35:41 +00:00

Extract specific field definition

This commit is contained in:
Oliver Walters
2023-07-27 15:09:29 +10:00
parent 256ef5792c
commit 62caf6aaf2

View File

@ -39,12 +39,25 @@ function ApiFormField({
field: ApiFormFieldType; field: ApiFormFieldType;
definitions: ApiFormFieldType[]; definitions: ApiFormFieldType[];
}) { }) {
useEffect(() => { // Extract field definition from provided data
console.log('field:', field); // Where user has provided specific data, override the API definition
console.log('definitions:', definitions); const definition: ApiFormFieldType = useMemo(() => {
}, []); let def = definitions.find((def) => def.name == field.name) || field;
return <Text>{field.name}</Text>; return {
...def,
...field
};
}, [field, definitions]);
switch (definition.type) {
default:
return (
<Alert color="red" title="Error">
Unknown field type for field '{definition.name}': {definition.type}
</Alert>
);
}
} }
/** /**