Skip to content

Commit

Permalink
reviewcomments
Browse files Browse the repository at this point in the history
  • Loading branch information
gtarpenning committed Nov 15, 2024
1 parent 5799b6a commit ac3a466
Showing 1 changed file with 40 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,15 @@ const NestedForm: React.FC<{
config: Record<string, any>;
setConfig: (config: Record<string, any>) => void;
path: string[];
}> = ({keyName, fieldSchema, config, setConfig, path}) => {
hideLabel?: boolean;
}> = ({keyName, fieldSchema, config, setConfig, path, hideLabel}) => {
const currentPath = [...path, keyName];
const currentValue = getNestedValue(config, currentPath);

const unwrappedSchema = unwrapSchema(fieldSchema);

console.log(typeof fieldSchema, fieldSchema);

if (unwrappedSchema instanceof z.ZodDiscriminatedUnion) {
return (
<DiscriminatedUnionField
Expand All @@ -180,7 +183,7 @@ const NestedForm: React.FC<{
<FormControl
fullWidth
style={{marginBottom: GAP_BETWEEN_ITEMS_PX + 'px'}}>
<Label label={keyName} />
{!hideLabel && <Label label={keyName} />}
<Box ml={2}>
<ZSForm
configSchema={unwrappedSchema as z.ZodObject<any>}
Expand Down Expand Up @@ -286,7 +289,7 @@ const NestedForm: React.FC<{

return (
<TextFieldWithLabel
label={keyName}
label={!hideLabel ? keyName : undefined}
type={fieldType}
value={currentValue ?? ''}
onChange={value => updateConfig(currentPath, value, config, setConfig)}
Expand Down Expand Up @@ -344,35 +347,40 @@ const ArrayField: React.FC<{
display="flex"
flexDirection="column"
alignItems="flex-start"
mb={2}
sx={{
borderBottom: '1px solid',
p: 2,
style={{
width: '100%',
gap: 4,
alignItems: 'center',
height: '35px',
marginBottom: '4px',
}}>
<Box flexGrow={1} width="100%">
<NestedForm
keyName={`${index}`}
fieldSchema={elementSchema}
config={{[`${index}`]: item}}
setConfig={newItemConfig => {
const newArray = [...arrayValue];
newArray[index] = newItemConfig[`${index}`];
updateConfig(targetPath, newArray, config, setConfig);
}}
path={[]}
/>
</Box>
<Box mt={1}>
<Button
size="small"
variant="ghost"
icon="delete"
tooltip="Remove this key"
disabled={arrayValue.length <= minItems}
onClick={() =>
removeArrayItem(targetPath, index, config, setConfig)
}
/>
<Box flexGrow={1} width="100%" display="flex" alignItems="center">
<Box flexGrow={1}>
<NestedForm
keyName={`${index}`}
fieldSchema={elementSchema}
config={{[`${index}`]: item}}
setConfig={newItemConfig => {
const newArray = [...arrayValue];
newArray[index] = newItemConfig[`${index}`];
updateConfig(targetPath, newArray, config, setConfig);
}}
path={[]}
hideLabel
/>
</Box>
<Box mb={2} ml={1}>
<Button
size="small"
variant="ghost"
icon="delete"
tooltip="Remove this entry"
disabled={arrayValue.length <= minItems}
onClick={() =>
removeArrayItem(targetPath, index, config, setConfig)
}
/>
</Box>
</Box>
</Box>
))}
Expand All @@ -381,7 +389,7 @@ const ArrayField: React.FC<{
onClick={() =>
addArrayItem(targetPath, elementSchema, config, setConfig)
}>
Add Item
Add item
</Button>
</FormControl>
);
Expand Down

0 comments on commit ac3a466

Please sign in to comment.