Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from "@edition/datatype/components/inputs/json/DataTypeJSONInputEditDialogComponent";
import {DataTypeInputValueComponent} from "@edition/datatype/components/inputs/DataTypeInputValueComponent";
import {useDebouncedCallback} from "use-debounce";
import {DataInput} from "@code0-tech/triangulum/dist/util/schema.util";
import {DataInput, ListInput} from "@code0-tech/triangulum/dist/util/schema.util";

export interface EditableJSONEntry {
key: string
Expand All @@ -19,7 +19,6 @@ export interface EditableJSONEntry {

export type DataTypeJSONInputComponentProps = DataTypeInputComponentProps

//TODO render fallback value if undefined based on schema
export const DataTypeJSONInputComponent: React.FC<DataTypeJSONInputComponentProps> = (props) => {

const {schema, title, description, suggestions, formValidation, initialValue, onChange} = props
Expand Down Expand Up @@ -87,22 +86,23 @@ export const DataTypeJSONInputComponent: React.FC<DataTypeJSONInputComponentProp
}


//TODO: only if required
const generateDefaultDataValue = (schema: DataInput): LiteralValue => {
return {
__typename: "LiteralValue",
value: {
...(Object.entries(schema.properties ?? {})?.map(([key, propSchema]) => {
if (!Array.isArray(propSchema)) {
if (propSchema.input === "data") {
return {[key]: generateDefaultDataValue(propSchema).value}
}
if (propSchema.input === "list") {
return {[key]: []}
value: Object.assign({}, ...Object.entries(schema.properties ?? {}).map(([key, propSchema]) => {
if (!Array.isArray(propSchema)) {
if (propSchema.input === "data") {
return {[key]: generateDefaultDataValue(propSchema).value}
}
if (propSchema.input === "list") {
const itemSchema = (propSchema as ListInput).items?.[0]
if (itemSchema && !Array.isArray(itemSchema) && itemSchema.input === "data") {
return {[key]: [generateDefaultDataValue(itemSchema as DataInput).value]}
}
return {[key]: null}
return {[key]: []}
}
}))
}
return {[key]: null}
}
}))
}
}