fix: add keys to ObjectField children and guard relation data in getFieldOptions
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import * as React from 'react';
|
||||||
import { Box, Typography } from '@mui/material';
|
import { Box, Typography } from '@mui/material';
|
||||||
import { FieldComponentProps } from '../../types/overrides';
|
import { FieldComponentProps } from '../../types/overrides';
|
||||||
|
|
||||||
@@ -15,21 +16,26 @@ export default function ObjectField({ name, field, value, onChange, disabled, ba
|
|||||||
</Typography>
|
</Typography>
|
||||||
<Box sx={{ display: 'flex', flexDirection: 'column', gap: 2 }}>
|
<Box sx={{ display: 'flex', flexDirection: 'column', gap: 2 }}>
|
||||||
{Object.entries(field.schema).map(([subKey, subField]) =>
|
{Object.entries(field.schema).map(([subKey, subField]) =>
|
||||||
renderField({
|
React.cloneElement(
|
||||||
name: `${name}.${subKey}`,
|
renderField({
|
||||||
field: subField,
|
name: `${name}.${subKey}`,
|
||||||
value: value?.[subKey],
|
field: subField,
|
||||||
onChange: (newVal: any) => {
|
value: value?.[subKey],
|
||||||
const updated = { ...(value || {}), [subKey]: newVal };
|
onChange: (newVal: any) => {
|
||||||
onChange(updated);
|
const updated = { ...(value || {}), [subKey]: newVal };
|
||||||
},
|
onChange(updated);
|
||||||
disabled,
|
},
|
||||||
baseUrl,
|
disabled,
|
||||||
uploadFile,
|
baseUrl,
|
||||||
uploading,
|
uploadFile,
|
||||||
relationDataMap,
|
uploading,
|
||||||
})
|
relationDataMap,
|
||||||
|
}) as React.ReactElement,
|
||||||
|
{ key: subKey }
|
||||||
|
)
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|
||||||
</Box>
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ export function getFieldOptions(field: ResourceField, relationData?: any[]): Sel
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (field.relation) {
|
if (field.relation) {
|
||||||
const data = relationData ?? [];
|
const data = Array.isArray(relationData) ? relationData : [];
|
||||||
const enumOption = field.enumOption;
|
const enumOption = field.enumOption;
|
||||||
if (!enumOption) {
|
if (!enumOption) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
|
|||||||
Reference in New Issue
Block a user