|
9 | 9 | } from "@edition/datatype/components/inputs/json/DataTypeJSONInputEditDialogComponent"; |
10 | 10 | import {DataTypeInputValueComponent} from "@edition/datatype/components/inputs/DataTypeInputValueComponent"; |
11 | 11 | 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"; |
13 | 13 |
|
14 | 14 | export interface EditableJSONEntry { |
15 | 15 | key: string |
@@ -87,22 +87,23 @@ export const DataTypeJSONInputComponent: React.FC<DataTypeJSONInputComponentProp |
87 | 87 | } |
88 | 88 |
|
89 | 89 |
|
90 | | -//TODO: only if required |
91 | 90 | const generateDefaultDataValue = (schema: DataInput): LiteralValue => { |
92 | 91 | return { |
93 | 92 | __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]} |
102 | 102 | } |
103 | | - return {[key]: null} |
| 103 | + return {[key]: []} |
104 | 104 | } |
105 | | - })) |
106 | | - } |
| 105 | + return {[key]: null} |
| 106 | + } |
| 107 | + })) |
107 | 108 | } |
108 | 109 | } |
0 commit comments