Skip to content

Commit 2c6fb0e

Browse files
authored
Merge pull request #237 from code0-tech/feat/fixing-null-state-and-dynmaic-parameters
Fixing null state and dynmaic parameters
2 parents b6dd2e7 + 9365928 commit 2c6fb0e

15 files changed

Lines changed: 148 additions & 118 deletions

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"dependencies": {
1717
"@apollo/client": "^4.0.9",
1818
"@code0-tech/pictor": "^0.10.4",
19-
"@code0-tech/triangulum": "^0.25.0",
19+
"@code0-tech/triangulum": "^0.25.2",
2020
"@codemirror/lang-javascript": "^6.2.5",
2121
"@codemirror/lint": "^6.9.5",
2222
"@icons-pack/react-simple-icons": "^13.13.0",

src/packages/ce/src/datatype/components/inputs/DataTypeInputComponent.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ import {
2020
import {Schema} from "@code0-tech/triangulum/dist/util/schema.util";
2121

2222
export interface DataTypeInputComponentProps extends Omit<InputWrapperProps<NodeParameterValue | NodeFunction>, "onChange"> {
23-
schema: (NodeSchema | Schema) & {blocked?: boolean}
23+
schema: (NodeSchema | Schema)
2424
clearable?: boolean
25-
onChange?: (value: ReferenceValue | SubFlowValue | LiteralValue | NodeFunction | undefined) => void
25+
onChange?: (value: ReferenceValue | SubFlowValue | LiteralValue | NodeFunction | null) => void
2626
suggestions?: (NodeFunction | SubFlowValue | ReferenceValue | LiteralValue)[]
2727
onClear?: (event: React.MouseEvent<HTMLButtonElement>) => void
2828
}
@@ -31,11 +31,10 @@ export const DataTypeInputComponent: React.FC<DataTypeInputComponentProps> = (pr
3131

3232
const {schema, ...rest} = props
3333

34-
const suggestions = "schema" in schema ? schema?.schema?.suggestions as (NodeFunction | ReferenceValue | LiteralValue)[] : []
35-
const inputName = "schema" in schema ? (schema?.schema?.input === "generic" ? schema.functionSchema.input : schema?.schema?.input) : schema.input
36-
const blocked = schema?.blocked
34+
const suggestions = "schema" in (schema ?? {}) ? (schema as NodeSchema)?.schema?.suggestions as (NodeFunction | ReferenceValue | LiteralValue)[] : []
35+
const inputName = "schema" in (schema ?? {}) ? ((schema as NodeSchema)?.schema?.input === "generic" ? (schema as NodeSchema).functionSchema.input : (schema as NodeSchema)?.schema?.input) : (schema as Schema).input
3736

38-
if (blocked) {
37+
if ("schema" in (schema ?? {}) && ((schema as NodeSchema).blockedBy?.length ?? 0) > 0) {
3938
return null
4039
}
4140

src/packages/ce/src/datatype/components/inputs/DataTypeInputControlsComponent.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {NodeBadgeComponent} from "@edition/datatype/components/badges/NodeBadgeC
2121

2222
export interface DataTypeInputControlsComponentProps {
2323
suggestions?: (NodeFunction | SubFlowValue | ReferenceValue | LiteralValue)[]
24-
onSelect?: (value: NodeFunction | SubFlowValue | ReferenceValue | LiteralValue | undefined) => void
24+
onSelect?: (value: NodeFunction | SubFlowValue | ReferenceValue | LiteralValue | null) => void
2525
showSuggestions?: boolean
2626
}
2727

@@ -83,7 +83,7 @@ export const DataTypeInputControlsComponent: React.FC<DataTypeInputControlsCompo
8383
</Menu>
8484
) : <></>}
8585
<Button paddingSize={"xxs"} onClick={(event) => {
86-
onSelect?.(undefined)
86+
onSelect?.(null)
8787
event.stopPropagation()
8888
event.preventDefault()
8989
}}>

src/packages/ce/src/datatype/components/inputs/boolean/DataTypeBooleanInputComponent.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ export const DataTypeBooleanInputComponent: React.FC<DataTypeBooleanInputCompone
1111

1212
const {suggestions, initialValue, title, description, formValidation, onChange} = props
1313

14-
const onChangeDebounced = useDebouncedCallback((value: string | LiteralValue | NodeFunction | SubFlowValue | ReferenceValue | undefined) => {
14+
const onChangeDebounced = useDebouncedCallback((value: string | LiteralValue | NodeFunction | SubFlowValue | ReferenceValue | null) => {
1515

1616
if (typeof value === "string") {
17-
const boolValue: LiteralValue | undefined = value && ["true", "false"].includes(value) ? {
17+
const boolValue: LiteralValue | null = value && ["true", "false"].includes(value) ? {
1818
__typename: "LiteralValue",
1919
value: value === "true"
20-
} : undefined
20+
} : null
2121

2222
formValidation?.setValue?.(boolValue)
2323
onChange?.(boolValue)

src/packages/ce/src/datatype/components/inputs/generic/DataTypeGenericInputComponent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const DataTypeGenericInputComponent: React.FC<DataTypeGenericInputCompone
1111

1212
const {title, description, onChange, formValidation} = props
1313

14-
const onChangeDebounced = useDebouncedCallback((value: LiteralValue | NodeFunction | ReferenceValue | undefined) => {
14+
const onChangeDebounced = useDebouncedCallback((value: LiteralValue | NodeFunction | ReferenceValue | null) => {
1515
formValidation?.setValue?.(value)
1616
onChange?.(value)
1717
}, 200)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const DataTypeJSONInputComponent: React.FC<DataTypeJSONInputComponentProp
2828
const [editEntry, setEditEntry] = React.useState<EditableJSONEntry | undefined>(undefined)
2929
const [collapsedState, setCollapsedStateRaw] = React.useState<Record<string, boolean>>({})
3030

31-
const onChangeDebounced = useDebouncedCallback((value: LiteralValue | SubFlowValue | NodeFunction | ReferenceValue | undefined) => {
31+
const onChangeDebounced = useDebouncedCallback((value: LiteralValue | SubFlowValue | NodeFunction | ReferenceValue | null) => {
3232
formValidation?.setValue?.(value)
3333
onChange?.(value)
3434
}, 400)

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ import {
2323
export interface DataTypeJSONInputEditDialogComponentProps {
2424
open: boolean
2525
entry: EditableJSONEntry | undefined
26-
value: LiteralValue | undefined
26+
value: LiteralValue | null
2727
onOpenChange?: (open: boolean) => void
28-
onObjectChange?: (object: LiteralValue | undefined) => void
28+
onObjectChange?: (object: LiteralValue | null) => void
2929
}
3030

31-
function getValueAtPath(obj: LiteralValue | undefined, path: string[]): unknown {
31+
function getValueAtPath(obj: LiteralValue | null, path: string[]): unknown {
3232
if (!obj || !Array.isArray(path) || path.length === 0) return obj?.value
3333
// Traverse .value recursively if nested
3434
let current: any = obj.value
@@ -42,8 +42,8 @@ function getValueAtPath(obj: LiteralValue | undefined, path: string[]): unknown
4242
return current
4343
}
4444

45-
function setValueAtPath(obj: LiteralValue | undefined, path: string[], value: unknown): LiteralValue | undefined {
46-
if (!obj) return undefined
45+
function setValueAtPath(obj: LiteralValue | null, path: string[], value: unknown): LiteralValue | null {
46+
if (!obj) return null
4747
if (path.length === 0) return { ...obj, value }
4848
const [key, ...rest] = path
4949
if (Array.isArray(obj.value)) {
@@ -81,7 +81,7 @@ export const DataTypeJSONInputEditDialogComponent: React.FC<DataTypeJSONInputEdi
8181
const [editOpen, setEditOpen] = React.useState(open)
8282
const [collapsedState, setCollapsedStateRaw] = React.useState<Record<string, boolean>>({})
8383
const [activePath, setActivePath] = React.useState(entry?.path ?? [])
84-
const [editedObject, setEditedObject] = React.useState<LiteralValue | undefined>(value)
84+
const [editedObject, setEditedObject] = React.useState<LiteralValue | null>(value)
8585
const [editorValue, setEditorValue] = React.useState(getValueAtPath(value, entry?.path ?? []))
8686
const clickTimeout = React.useRef<NodeJS.Timeout | null>(null)
8787

src/packages/ce/src/datatype/components/inputs/number/DataTypeNumberInputComponent.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ export const DataTypeNumberInputComponent: React.FC<DataTypeNumberInputComponent
2121
const {formValidation, title, initialValue, description, suggestions, onChange} = props
2222

2323
const defaultValue: NodeParameterValue | NodeFunction | undefined = React.useMemo(() => initialValue ?? undefined, [initialValue])
24-
const onChangeDebounced = useDebouncedCallback((value: string | LiteralValue | SubFlowValue | NodeFunction | ReferenceValue | undefined) => {
24+
const onChangeDebounced = useDebouncedCallback((value: string | LiteralValue | SubFlowValue | NodeFunction | ReferenceValue | null) => {
2525

2626
if (typeof value === "string") {
27-
formValidation?.setValue?.(value ? {__typename: "LiteralValue", value: !Number.isNaN(Number(value)) ? Number(value) : value} : undefined)
28-
onChange?.(value ? {__typename: "LiteralValue", value: !Number.isNaN(Number(value)) ? Number(value) : value} : undefined)
27+
formValidation?.setValue?.(value ? {__typename: "LiteralValue", value: !Number.isNaN(Number(value)) ? Number(value) : value} : null)
28+
onChange?.(value ? {__typename: "LiteralValue", value: !Number.isNaN(Number(value)) ? Number(value) : value} : null)
2929
} else {
3030
formValidation?.setValue?.(value)
3131
onChange?.(value)

src/packages/ce/src/datatype/components/inputs/select/DataTypeSelectInputComponent.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,22 @@ export const DataTypeSelectInputComponent: React.FC<DataTypeSelectInputComponent
3232
return initialValue && lodash.isMatch(initialValue, suggest)
3333
}), [suggestions])!
3434

35-
const onChangeDebounced = useDebouncedCallback((value: string | undefined) => {
36-
formValidation?.setValue?.(suggestions?.[Number(value)] ?? undefined)
37-
onChange?.(suggestions?.[Number(value)] ?? undefined)
35+
const onChangeDebounced = useDebouncedCallback((value: string | null) => {
36+
formValidation?.setValue?.((!!value ? suggestions?.[Number(value)] : null) ?? null)
37+
onChange?.((!!value ? suggestions?.[Number(value)] : null) ?? null)
3838
}, 200)
3939

4040
return React.useMemo(() => <>
4141
<InputLabel>{title}</InputLabel>
4242
<InputDescription>{description}</InputDescription>
43-
<SelectInput defaultValue={defaultValue >= 0 ?defaultValue?.toString() : undefined}
43+
<SelectInput value={defaultValue >= 0 ? defaultValue?.toString() : undefined}
4444
formValidation={{...formValidation, setValue: undefined}}
4545
maw={"100%"}
46-
key={formValidation?.notValidMessage}
46+
key={defaultValue}
4747
onValueChange={onChangeDebounced}
48-
placeholder={"sd"}
4948
right={
5049
<Button color={"primary"} onClick={() => {
51-
onChangeDebounced(undefined)
50+
onChangeDebounced(null)
5251
}} paddingSize={"xxs"}>
5352
<IconX size={13}/>
5453
</Button>

0 commit comments

Comments
 (0)