Skip to content

Commit ccd69f4

Browse files
committed
fix: default value generation
1 parent ba68653 commit ccd69f4

1 file changed

Lines changed: 14 additions & 13 deletions

File tree

src/packages/ce/src/datatype/components/inputs/json/DataTypeJSONInputComponent.tsx

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
} from "@edition/datatype/components/inputs/json/DataTypeJSONInputEditDialogComponent";
1010
import {DataTypeInputValueComponent} from "@edition/datatype/components/inputs/DataTypeInputValueComponent";
1111
import {useDebouncedCallback} from "use-debounce";
12-
import {DataInput} from "@code0-tech/triangulum/dist/util/schema.util";
12+
import {DataInput, ListInput} from "@code0-tech/triangulum/dist/util/schema.util";
1313

1414
export interface EditableJSONEntry {
1515
key: string
@@ -87,22 +87,23 @@ export const DataTypeJSONInputComponent: React.FC<DataTypeJSONInputComponentProp
8787
}
8888

8989

90-
//TODO: only if required
9190
const generateDefaultDataValue = (schema: DataInput): LiteralValue => {
9291
return {
9392
__typename: "LiteralValue",
94-
value: {
95-
...(Object.entries(schema.properties ?? {})?.map(([key, propSchema]) => {
96-
if (!Array.isArray(propSchema)) {
97-
if (propSchema.input === "data") {
98-
return {[key]: generateDefaultDataValue(propSchema).value}
99-
}
100-
if (propSchema.input === "list") {
101-
return {[key]: []}
93+
value: Object.assign({}, ...Object.entries(schema.properties ?? {}).map(([key, propSchema]) => {
94+
if (!Array.isArray(propSchema)) {
95+
if (propSchema.input === "data") {
96+
return {[key]: generateDefaultDataValue(propSchema).value}
97+
}
98+
if (propSchema.input === "list") {
99+
const itemSchema = (propSchema as ListInput).items?.[0]
100+
if (itemSchema && !Array.isArray(itemSchema) && itemSchema.input === "data") {
101+
return {[key]: [generateDefaultDataValue(itemSchema as DataInput).value]}
102102
}
103-
return {[key]: null}
103+
return {[key]: []}
104104
}
105-
}))
106-
}
105+
return {[key]: null}
106+
}
107+
}))
107108
}
108109
}

0 commit comments

Comments
 (0)