99} from "@edition/datatype/components/inputs/json/DataTypeJSONInputEditDialogComponent" ;
1010import { DataTypeInputValueComponent } from "@edition/datatype/components/inputs/DataTypeInputValueComponent" ;
1111import { 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
1414export interface EditableJSONEntry {
1515 key : string
@@ -19,7 +19,6 @@ export interface EditableJSONEntry {
1919
2020export type DataTypeJSONInputComponentProps = DataTypeInputComponentProps
2121
22- //TODO render fallback value if undefined based on schema
2322export const DataTypeJSONInputComponent : React . FC < DataTypeJSONInputComponentProps > = ( props ) => {
2423
2524 const { schema, title, description, suggestions, formValidation, initialValue, onChange} = props
@@ -87,22 +86,23 @@ export const DataTypeJSONInputComponent: React.FC<DataTypeJSONInputComponentProp
8786}
8887
8988
90- //TODO: only if required
9189const generateDefaultDataValue = ( schema : DataInput ) : LiteralValue => {
9290 return {
9391 __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 ] : [ ] }
92+ value : Object . assign ( { } , ...Object . entries ( schema . properties ?? { } ) . map ( ( [ key , propSchema ] ) => {
93+ if ( ! Array . isArray ( propSchema ) ) {
94+ if ( propSchema . input === "data" ) {
95+ return { [ key ] : generateDefaultDataValue ( propSchema ) . value }
96+ }
97+ if ( propSchema . input === "list" ) {
98+ const itemSchema = ( propSchema as ListInput ) . items ?. [ 0 ]
99+ if ( itemSchema && ! Array . isArray ( itemSchema ) && itemSchema . input === "data" ) {
100+ return { [ key ] : [ generateDefaultDataValue ( itemSchema as DataInput ) . value ] }
102101 }
103- return { [ key ] : null }
102+ return { [ key ] : [ ] }
104103 }
105- } ) )
106- }
104+ return { [ key ] : null }
105+ }
106+ } ) )
107107 }
108108}
0 commit comments