|
1 | | -import {Flow, NodeFunction} from "@code0-tech/sagittarius-graphql-types"; |
2 | 1 | import React from "react"; |
3 | 2 | import {DataTypeTextInputComponent} from "./text/DataTypeTextInputComponent"; |
4 | | -import {InputProps, useService, useStore} from "@code0-tech/pictor"; |
5 | | -import {FlowService} from "@edition/flow/services/Flow.service"; |
6 | | -import {DatatypeService} from "@edition/datatype/services/Datatype.service"; |
7 | | -import {FunctionService} from "@edition/function/services/Function.service"; |
8 | | -import {DataTypeVariant, getTypesFromFunction, getTypeVariant} from "@code0-tech/triangulum"; |
9 | | -import {DataTypeJSONInputComponent} from "@edition/datatype/components/inputs/json/DataTypeJSONInputComponent"; |
10 | | - |
11 | | -export interface DataTypeInputComponentProps extends Omit<InputProps<any | null>, "wrapperComponent" | "type"> { |
12 | | - flowId: Flow['id'] |
13 | | - nodeId?: NodeFunction['id'] //TODO if undefined we need to get infos from trigger |
14 | | - parameterIndex: number |
| 3 | +import {NodeSchema} from "@code0-tech/triangulum"; |
| 4 | +import {LiteralValue, NodeFunction, NodeParameterValue, ReferenceValue} from "@code0-tech/sagittarius-graphql-types"; |
| 5 | +import {DataTypeBooleanInputComponent} from "@edition/datatype/components/inputs/boolean/DataTypeBooleanInputComponent"; |
| 6 | +import {DataTypeSelectInputComponent} from "@edition/datatype/components/inputs/select/DataTypeSelectInputComponent"; |
| 7 | +import {InputWrapperProps} from "@code0-tech/pictor/dist/components/form/InputWrapper"; |
| 8 | +import {DataTypeNumberInputComponent} from "@edition/datatype/components/inputs/number/DataTypeNumberInputComponent"; |
| 9 | + |
| 10 | +export interface DataTypeInputComponentProps extends Omit<InputWrapperProps<NodeParameterValue | NodeFunction>, "wrapperComponent" | "onChange"> { |
| 11 | + schema: NodeSchema |
15 | 12 | clearable?: boolean |
| 13 | + onChange?: (value: ReferenceValue | LiteralValue | NodeFunction | undefined) => void |
| 14 | + suggestions?: (NodeFunction | ReferenceValue | LiteralValue)[] |
16 | 15 | onClear?: (event: React.MouseEvent<HTMLButtonElement>) => void |
17 | 16 | } |
18 | 17 |
|
19 | 18 | export const DataTypeInputComponent: React.FC<DataTypeInputComponentProps> = (props) => { |
20 | 19 |
|
21 | | - const {flowId, nodeId, parameterIndex, ...rest} = props |
22 | | - |
23 | | - const flowService = useService(FlowService) |
24 | | - const flowStore = useStore(FlowService) |
25 | | - const dataTypeStore = useStore(DatatypeService) |
26 | | - const dataTypeService = useService(DatatypeService) |
27 | | - const functionStore = useStore(FunctionService) |
28 | | - const functionService = useService(FunctionService) |
29 | | - |
30 | | - const flow = React.useMemo( |
31 | | - () => flowId ? flowService.getById(flowId) : undefined, |
32 | | - [flowStore, flowId] |
33 | | - ) |
34 | | - |
35 | | - const node = React.useMemo( |
36 | | - () => nodeId && flowId ? flowService.getNodeById(flowId, nodeId) : undefined, |
37 | | - [flowStore, flowId, nodeId] |
38 | | - ) |
39 | | - |
40 | | - const functionDefinition = React.useMemo( |
41 | | - () => node ? functionService.getById(node?.functionDefinition?.id) : undefined, |
42 | | - [functionStore, node] |
43 | | - ) |
44 | | - |
45 | | - const types = React.useMemo( |
46 | | - () => nodeId ? getTypesFromFunction(functionDefinition!) : undefined, |
47 | | - [functionDefinition, nodeId] |
48 | | - ) |
| 20 | + const {schema, ...rest} = props |
49 | 21 |
|
50 | | - const dataTypeVariant = React.useMemo( |
51 | | - () => types ? getTypeVariant(types.parameters[parameterIndex], dataTypeService.values())[0].variant : undefined, |
52 | | - [dataTypeStore, types] |
53 | | - ) |
| 22 | + const suggestions = schema?.schema?.suggestions as (NodeFunction | ReferenceValue | LiteralValue)[] |
54 | 23 |
|
55 | | - switch (dataTypeVariant) { |
56 | | - case DataTypeVariant.ARRAY: |
57 | | - case DataTypeVariant.OBJECT: |
58 | | - return <DataTypeJSONInputComponent |
59 | | - flowId={flowId} |
60 | | - nodeId={nodeId} |
61 | | - parameterIndex={parameterIndex} |
| 24 | + switch (schema?.schema?.input) { |
| 25 | + case "boolean": |
| 26 | + return <DataTypeBooleanInputComponent |
| 27 | + schema={schema} |
| 28 | + suggestions={suggestions} |
62 | 29 | {...rest} |
63 | 30 | /> |
| 31 | + case "select": |
| 32 | + return <DataTypeSelectInputComponent |
| 33 | + schema={schema} |
| 34 | + suggestions={suggestions} |
| 35 | + {...rest}/> |
| 36 | + case "number": |
| 37 | + return <DataTypeNumberInputComponent |
| 38 | + schema={schema} |
| 39 | + suggestions={suggestions} |
| 40 | + {...rest}/> |
64 | 41 | default: |
65 | 42 | return <DataTypeTextInputComponent |
66 | | - flowId={flowId} |
67 | | - nodeId={nodeId} |
68 | | - parameterIndex={parameterIndex} |
| 43 | + suggestions={suggestions} |
| 44 | + schema={schema} |
69 | 45 | {...rest} |
70 | 46 | /> |
71 | 47 | } |
|
0 commit comments