mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-14 19:15:41 +00:00
Extract specific field definition
This commit is contained in:
@ -39,12 +39,25 @@ function ApiFormField({
|
||||
field: ApiFormFieldType;
|
||||
definitions: ApiFormFieldType[];
|
||||
}) {
|
||||
useEffect(() => {
|
||||
console.log('field:', field);
|
||||
console.log('definitions:', definitions);
|
||||
}, []);
|
||||
// Extract field definition from provided data
|
||||
// Where user has provided specific data, override the API definition
|
||||
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>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user