Skip to content

Commit 394c845

Browse files
author
Nico Sammito
authored
Merge pull request #108 from code0-tech/feat/#103
Fallback to FunctionParameterDefinition and ReferenceValue input and parameter input fields check is wrong
2 parents 31eb740 + 782d105 commit 394c845

11 files changed

Lines changed: 164 additions & 99 deletions

File tree

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ import {FunctionService} from "@edition/function/services/Function.service";
1010
export interface DataTypeInputComponentProps extends Omit<InputProps<any | null>, "wrapperComponent" | "type"> {
1111
flowId: Flow['id']
1212
nodeId: NodeFunction['id']
13-
parameterId: NodeParameter['id']
13+
parameterIndex: number
1414
clearable?: boolean
1515
onClear?: (event: React.MouseEvent<HTMLButtonElement>) => void
1616
}
1717

1818
export const DataTypeInputComponent: React.FC<DataTypeInputComponentProps> = (props) => {
1919

20-
const {flowId, nodeId, parameterId, ...rest} = props
20+
const {flowId, nodeId, parameterIndex, ...rest} = props
2121

2222
const flowService = useService(FlowService)
2323
const flowStore = useStore(FlowService)
@@ -32,8 +32,8 @@ export const DataTypeInputComponent: React.FC<DataTypeInputComponentProps> = (pr
3232
)
3333

3434
const parameter = React.useMemo(
35-
() => node?.parameters?.nodes?.find(p => p?.id === parameterId),
36-
[node, parameterId]
35+
() => node?.parameters?.nodes?.[parameterIndex],
36+
[node, parameterIndex]
3737
)
3838

3939
const functionDefinition = React.useMemo(
@@ -57,14 +57,14 @@ export const DataTypeInputComponent: React.FC<DataTypeInputComponentProps> = (pr
5757
return <DataTypeJSONInputComponent
5858
flowId={flowId}
5959
nodeId={nodeId}
60-
parameterId={parameterId}
60+
parameterIndex={parameterIndex}
6161
{...rest}
6262
/>
6363
default:
6464
return <DataTypeTextInputComponent
6565
flowId={flowId}
6666
nodeId={nodeId}
67-
parameterId={parameterId}
67+
parameterIndex={parameterIndex}
6868
{...rest}
6969
/>
7070
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export type DataTypeJSONInputComponentProps = DataTypeInputComponentProps
3636
export const DataTypeJSONInputComponent: React.FC<DataTypeJSONInputComponentProps> = (props) => {
3737

3838

39-
const {flowId, nodeId, parameterId, title, description, formValidation, onChange} = props
39+
const {flowId, nodeId, parameterIndex, title, description, formValidation, onChange} = props
4040

4141
const flowService = useService(FlowService)
4242
const flowStore = useStore(FlowService)
@@ -51,8 +51,8 @@ export const DataTypeJSONInputComponent: React.FC<DataTypeJSONInputComponentProp
5151
)
5252

5353
const parameter = React.useMemo(
54-
() => node?.parameters?.nodes?.find(p => p?.id === parameterId),
55-
[node, parameterId]
54+
() => node?.parameters?.nodes?.[parameterIndex],
55+
[node, parameterIndex]
5656
)
5757

5858
const functionDefinition = React.useMemo(
@@ -73,7 +73,7 @@ export const DataTypeJSONInputComponent: React.FC<DataTypeJSONInputComponentProp
7373
}, [parameter, parameterDefinition, dataTypeStore])
7474

7575

76-
const suggestions = useSuggestions(flowId, nodeId, parameterId)
76+
const suggestions = useSuggestions(flowId, nodeId, parameterIndex)
7777

7878
const [value, setValue] = React.useState<NodeParameterValue | NodeFunction | undefined>(initialValue)
7979
const [editDialogOpen, setEditDialogOpen] = React.useState(false)

src/packages/ce/src/datatype/components/inputs/text/DataTypeTextInputComponent.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export const splitTextAndObjects = (input: string) => {
9595

9696
export const DataTypeTextInputComponent: React.FC<DataTypeTextInputComponentProps> = (props) => {
9797

98-
const {flowId, nodeId, parameterId, ...rest} = props
98+
const {flowId, nodeId, parameterIndex, ...rest} = props
9999

100100
const functionService = useService(FunctionService)
101101
const flowService = useService(FlowService)
@@ -105,7 +105,7 @@ export const DataTypeTextInputComponent: React.FC<DataTypeTextInputComponentProp
105105
return flowService.getById(flowId)
106106
}, [flowService, flowId])
107107

108-
const suggestions = rest.suggestions || useSuggestions(flowId, nodeId, parameterId)
108+
const suggestions = rest.suggestions || useSuggestions(flowId, nodeId, parameterIndex)
109109

110110
const transformSyntax = React.useCallback((value: string | null): InputSyntaxSegment[] => {
111111

src/packages/ce/src/flow/hooks/Flow.edges.hook.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export const useEdges = (flowId: Flow['id'], namespaceId?: Namespace['id'], proj
8787
}
8888
}
8989

90-
node.parameters?.nodes?.forEach((param) => {
90+
node.parameters?.nodes?.forEach((param, index) => {
9191
const parameterValue = param?.value;
9292
const parameterDefinition = functionService.getById(node.functionDefinition?.id!!)?.parameterDefinitions?.find(p => p.id === param?.parameterDefinition?.id);
9393
const parameterDataTypeIdentifier = parameterDefinition?.dataTypeIdentifier;
@@ -101,13 +101,13 @@ export const useEdges = (flowId: Flow['id'], namespaceId?: Namespace['id'], proj
101101
const groupId = `${node.id}-group-${idCounter++}`;
102102

103103
edges.push({
104-
id: `${node.id}-${groupId}-param-${param.id}`,
104+
id: `${node.id}-${groupId}-param-${index}`,
105105
source: node.id!,
106106
target: groupId,
107107
deletable: false,
108108
selectable: false,
109109
animated: true,
110-
label: parameterDefinition?.names!![0]?.content ?? param.id,
110+
label: parameterDefinition?.names!![0]?.content ?? index,
111111
data: {
112112
color: hashToColor(parameterValue?.id || ""),
113113
type: 'group',
@@ -132,10 +132,10 @@ export const useEdges = (flowId: Flow['id'], namespaceId?: Namespace['id'], proj
132132
);
133133

134134
edges.push({
135-
id: `${subFnId}-${node.id}-param-${param.id}`,
135+
id: `${subFnId}-${node.id}-param-${index}`,
136136
source: subFnId,
137137
target: node.id!,
138-
targetHandle: `param-${param.id}`,
138+
targetHandle: `param-${index}`,
139139
animated: true,
140140
deletable: false,
141141
selectable: false,

src/packages/ce/src/flow/hooks/NodeValidation.hook.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,16 @@ import {
1616
resolveGenericKeys
1717
} from "@edition/flow/utils/generics";
1818
import {
19-
InspectionSeverity,
2019
useService,
21-
useStore,
22-
ValidationResult
20+
useStore
2321
} from "@code0-tech/pictor";
2422
import {useReturnType} from "@edition/function/hooks/Function.return.hook";
2523
import {getReferenceType} from "@edition/function/hooks/FunctionNodeReference.return.hook";
2624
import {FunctionService} from "@edition/function/services/Function.service";
2725
import {FlowService} from "@edition/flow/services/Flow.service";
2826
import {FlowTypeService} from "@edition/flowtype/services/FlowType.service";
2927
import {DatatypeService} from "@edition/datatype/services/Datatype.service";
28+
import {InspectionSeverity, ValidationResult} from "@core/util/inspection";
3029

3130
const isReference = (value: NodeParameterValue) =>
3231
value.__typename === "ReferenceValue"
@@ -43,11 +42,11 @@ const resolveDataTypeWithGenerics = (
4342
)
4443

4544
const errorResult = (
46-
parameterId: NodeParameter['id'],
45+
parameterIndex: number,
4746
expected?: DataTypeView,
4847
actual?: DataTypeView
4948
): ValidationResult => ({
50-
parameterId,
49+
parameterIndex: parameterIndex,
5150
type: InspectionSeverity.ERROR,
5251
message: [{
5352
code: "en-US",
@@ -106,7 +105,6 @@ export const useNodeValidation = (
106105
for (let i = 0; i < parameters.length; i++) {
107106
const parameter = parameters[i]
108107
const value = values[i]
109-
const nodeParameter = node?.parameters?.nodes?.find(p => p?.parameterDefinition?.id === parameter.id)
110108
if (!value) continue
111109

112110
const expectedType = parameter.dataTypeIdentifier
@@ -116,7 +114,7 @@ export const useNodeValidation = (
116114
const valueDT = dataTypeService.getDataType(valueType!!)
117115

118116
if (!expectedDT || !valueDT) {
119-
errors.push(errorResult(nodeParameter?.id, expectedDT, valueDT))
117+
errors.push(errorResult(i, expectedDT, valueDT))
120118
continue
121119
}
122120

@@ -150,7 +148,7 @@ export const useNodeValidation = (
150148
}
151149

152150
if (!isValid) {
153-
errors.push(errorResult(nodeParameter?.id, expectedDT, valueDT))
151+
errors.push(errorResult(i, expectedDT, valueDT))
154152
}
155153
}
156154

src/packages/ce/src/flow/services/Flow.service.ts

Lines changed: 54 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import {
44
FlowSetting,
55
LiteralValue,
66
Maybe,
7-
Mutation, Namespace, NamespaceProject,
7+
Mutation,
8+
Namespace,
9+
NamespaceProject,
810
NamespacesProjectsFlowsCreateInput,
911
NamespacesProjectsFlowsCreatePayload,
1012
NamespacesProjectsFlowsDeleteInput,
@@ -14,7 +16,7 @@ import {
1416
NodeFunction,
1517
NodeFunctionIdWrapper,
1618
NodeParameter,
17-
NodeParameterValueInput,
19+
NodeParameterValueInput, ParameterDefinition,
1820
Query,
1921
ReferencePathInput,
2022
ReferenceValue,
@@ -177,10 +179,11 @@ export class FlowService extends ReactiveArrayService<FlowView, FlowDependencies
177179

178180
case "ReferenceValue": {
179181
const v = parameter.value as ReferenceValue
182+
console.log(v)
180183
value = {
181184
referenceValue: {
182185
...(v.nodeFunctionId ? {nodeFunctionId: v.nodeFunctionId} : {}),
183-
...(v.parameterIndex && v.inputIndex ?
186+
...("parameterIndex" in v && "inputIndex" in v ?
184187
{
185188
parameterIndex: v.parameterIndex,
186189
inputIndex: v.inputIndex
@@ -304,31 +307,62 @@ export class FlowService extends ReactiveArrayService<FlowView, FlowDependencies
304307
await this.syncFlow(flowId)
305308
}
306309

307-
async setParameterValue(flowId: FlowView['id'], nodeId: NodeFunction['id'], parameterId: NodeParameter['id'], value?: LiteralValue | ReferenceValue | NodeFunction): Promise<void> {
310+
async setParameterValue(flowId: FlowView['id'], nodeId: NodeFunction['id'], parameterIndex: number, value?: LiteralValue | ReferenceValue | NodeFunction, parameterDefinitionId?: ParameterDefinition['id']): Promise<void> {
308311
const flow = this.getById(flowId)
309312
const index = this.values().findIndex(f => f.id === flowId)
310313
if (!flow) return
311314
const node = this.getNodeById(flowId, nodeId)
312315
if (!node) return
313-
const parameter = node.parameters?.nodes?.find(p => p?.id === parameterId)
314-
if (!parameter) return
315-
this.removeParameterNode(flow, parameter)
316-
if (value?.__typename === "NodeFunction") {
317-
const nextNodeIndex: number = Math.max(0, ...flow.nodes?.nodes?.map(node => Number(node?.id?.match(/NodeFunction\/(\d+)$/)?.[1] ?? 0)) ?? [0])
318-
const addingIdValue: NodeFunction = {
319-
...value,
320-
id: `gid://sagittarius/NodeFunction/${nextNodeIndex + 1}`
316+
const parameter = node.parameters?.nodes?.[parameterIndex]
317+
if (!parameter && parameterDefinitionId) {
318+
//TODO: needs a parameterDefinitionId
319+
const localParameter: NodeParameter = {
320+
__typename: "NodeParameter",
321+
parameterDefinition: {
322+
__typename: "ParameterDefinition",
323+
id: parameterDefinitionId
324+
},
325+
value: null
321326
}
322-
flow.nodes?.nodes?.push(addingIdValue)
323-
parameter.value = {
324-
id: `gid://sagittarius/NodeFunction/${nextNodeIndex + 1}`,
325-
__typename: "NodeFunctionIdWrapper"
326-
} as NodeFunctionIdWrapper
327-
} else {
328-
parameter.value = value as LiteralValue | ReferenceValue
327+
328+
if (value?.__typename === "NodeFunction") {
329+
const nextNodeIndex: number = Math.max(0, ...flow.nodes?.nodes?.map(node => Number(node?.id?.match(/NodeFunction\/(\d+)$/)?.[1] ?? 0)) ?? [0])
330+
const addingIdValue: NodeFunction = {
331+
...value,
332+
id: `gid://sagittarius/NodeFunction/${nextNodeIndex + 1}`
333+
}
334+
flow.nodes?.nodes?.push(addingIdValue)
335+
localParameter.value = {
336+
id: `gid://sagittarius/NodeFunction/${nextNodeIndex + 1}`,
337+
__typename: "NodeFunctionIdWrapper"
338+
} as NodeFunctionIdWrapper
339+
} else {
340+
localParameter.value = value as LiteralValue | ReferenceValue
341+
}
342+
343+
flow.editedAt = new Date().toISOString()
344+
345+
node.parameters?.nodes?.push(localParameter)
346+
} else if (parameter) {
347+
this.removeParameterNode(flow, parameter)
348+
if (value?.__typename === "NodeFunction") {
349+
const nextNodeIndex: number = Math.max(0, ...flow.nodes?.nodes?.map(node => Number(node?.id?.match(/NodeFunction\/(\d+)$/)?.[1] ?? 0)) ?? [0])
350+
const addingIdValue: NodeFunction = {
351+
...value,
352+
id: `gid://sagittarius/NodeFunction/${nextNodeIndex + 1}`
353+
}
354+
flow.nodes?.nodes?.push(addingIdValue)
355+
parameter.value = {
356+
id: `gid://sagittarius/NodeFunction/${nextNodeIndex + 1}`,
357+
__typename: "NodeFunctionIdWrapper"
358+
} as NodeFunctionIdWrapper
359+
} else {
360+
parameter.value = value as LiteralValue | ReferenceValue
361+
}
362+
363+
flow.editedAt = new Date().toISOString()
329364
}
330365

331-
flow.editedAt = new Date().toISOString()
332366

333367
this.set(index, new View(flow))
334368
await this.syncFlow(flowId)

0 commit comments

Comments
 (0)