Skip to content

Commit 1c450f1

Browse files
author
Nico Sammito
authored
Merge pull request #617 from code0-tech/feat/object-list-input
Object list input
2 parents b015f08 + 06ac3f0 commit 1c450f1

29 files changed

Lines changed: 895 additions & 27341 deletions

package-lock.json

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

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"@ariakit/react": "^0.4.17",
2121
"@babel/plugin-proposal-decorators": "^7.29.0",
2222
"@babel/plugin-transform-class-properties": "^7.28.6",
23-
"@code0-tech/sagittarius-graphql-types": "^0.0.0-703d578a55a3f0f20be3cb6892418f9e04d25716",
23+
"@code0-tech/sagittarius-graphql-types": "0.0.0-experimental-2342308809-931efb40b4bf3245999c53abbdd9164cea82e82d",
2424
"@codemirror/autocomplete": "^6.20.0",
2525
"@codemirror/lang-json": "^6.0.2",
2626
"@codemirror/language": "^6.12.1",
@@ -111,7 +111,7 @@
111111
"types": "dist/index.d.ts",
112112
"peerDependencies": {
113113
"@ariakit/react": "^0.4.17",
114-
"@code0-tech/sagittarius-graphql-types": "0.0.0-703d578a55a3f0f20be3cb6892418f9e04d25716",
114+
"@code0-tech/sagittarius-graphql-types": "0.0.0-experimental-2342308809-931efb40b4bf3245999c53abbdd9164cea82e82d",
115115
"@codemirror/autocomplete": "^6.20.0",
116116
"@codemirror/lang-json": "^6.0.2",
117117
"@codemirror/language": "^6.12.1",

src/components/d-flow-data-type/DFlowDataType.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export abstract class DFlowDataTypeReactiveService extends ReactiveArrayService<
6868

6969
}
7070

71-
getValueFromType(dataTypeIdentifier: DataTypeIdentifier, flow?: Flow, dependencies?: DFlowDataTypeDependencies): NodeParameterValue | undefined {
71+
getValueFromType(dataTypeIdentifier: DataTypeIdentifier, flow?: Flow, dependencies?: DFlowDataTypeDependencies): LiteralValue | undefined {
7272
const type = this.getDataType(dataTypeIdentifier, dependencies)
7373
if (!type) return undefined
7474

src/components/d-flow-data-type/rules/DFlowDataTypeContainsKeyRule.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export class DFlowDataTypeContainsKeyRule {
3333
//use generic given type for checking against value
3434
if (config?.dataTypeIdentifier?.genericKey && genericMapper && genericTypes) {
3535
const checkAllTypes: boolean[] = genericTypes.map(genericType => {
36-
return useValueValidation((value as LiteralValue).value[(config?.key ?? "")], dataTypeService?.getDataType(genericType)!!, dataTypeService!!, flow, ((genericType.genericType)!!.genericMappers as GenericMapper[]))
36+
return useValueValidation({__typename: "LiteralValue", value: (value as LiteralValue).value[(config?.key ?? "")]}, dataTypeService?.getDataType(genericType)!!, dataTypeService!!, flow, ((genericType.genericType)!!.genericMappers as GenericMapper[]))
3737
})
3838

3939
const combination = checkAllTypes.length > 1 ? checkAllTypes.reduce((previousValue, currentValue, currentIndex) => {
@@ -49,9 +49,9 @@ export class DFlowDataTypeContainsKeyRule {
4949

5050
//normal datatype link
5151
if (config?.dataTypeIdentifier?.dataType) {
52-
return ((config?.key ?? "") in value) && useValueValidation((value as LiteralValue).value[(config?.key ?? "")], dataTypeService?.getDataType(config.dataTypeIdentifier)!!, dataTypeService!!)
52+
return ((config?.key ?? "") in (value as LiteralValue).value) && useValueValidation({__typename: "LiteralValue", value: (value as LiteralValue).value[(config?.key ?? "")]}, dataTypeService?.getDataType(config.dataTypeIdentifier)!!, dataTypeService!!)
5353
}
5454

55-
return ((config?.key ?? "") in value) && useValueValidation((value as LiteralValue).value[(config?.key ?? "")], dataTypeService?.getDataType(config.dataTypeIdentifier!!)!!, dataTypeService!!, flow, genericMapping(config?.dataTypeIdentifier?.genericType?.genericMappers!!, generics))
55+
return ((config?.key ?? "") in (value as LiteralValue).value) && useValueValidation({__typename: "LiteralValue", value: (value as LiteralValue).value[(config?.key ?? "")]}, dataTypeService?.getDataType(config.dataTypeIdentifier!!)!!, dataTypeService!!, flow, genericMapping(config?.dataTypeIdentifier?.genericType?.genericMappers!!, generics))
5656
}
5757
}

src/components/d-flow-data-type/rules/DFlowDataTypeContainsTypeRule.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ export class DFlowDataTypeContainsTypeRule {
5959

6060
//normal datatype link
6161
if (config?.dataTypeIdentifier?.dataType) {
62-
return (value as LiteralValue).value.every((value1: any) => useValueValidation(value1, dataTypeService?.getDataType(config.dataTypeIdentifier!!)!!, dataTypeService!!))
62+
return (value as LiteralValue).value.every((value1: any) => useValueValidation({__typename: "LiteralValue", value: value1}, dataTypeService?.getDataType(config.dataTypeIdentifier!!)!!, dataTypeService!!))
6363
}
6464

65-
return (value as LiteralValue).value.every((value1: any) => useValueValidation(value1, dataTypeService?.getDataType(config.dataTypeIdentifier!!)!!, dataTypeService!!, flow, genericMapping((config.dataTypeIdentifier?.genericType as GenericType).genericMappers!!, generics)))
65+
return (value as LiteralValue).value.every((value1: any) => useValueValidation({__typename: "LiteralValue", value: value1}, dataTypeService?.getDataType(config.dataTypeIdentifier!!)!!, dataTypeService!!, flow, genericMapping((config.dataTypeIdentifier?.genericType as GenericType).genericMappers!!, generics)))
6666

6767
}
6868
}

src/components/d-flow-file/DFlowTabDefault.tsx

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ import {
1212
ReferenceValue,
1313
Scalars
1414
} from "@code0-tech/sagittarius-graphql-types";
15-
import {InputSyntaxSegment} from "../form/Input.syntax.hook";
15+
import {InputSyntaxSegment} from "../form";
1616
import {useNodeValidation} from "../d-flow-validation/DNodeValidation.hook";
1717
import {FileTabsService} from "../file-tabs/FileTabs.service";
18-
import {DFlowInputDefault} from "../d-flow-input/DFlowInputDefault";
18+
import {DFlowInput} from "../d-flow-input/DFlowInput";
1919

2020
export interface DFlowTabDefaultProps {
2121
node: NodeFunction
@@ -55,7 +55,7 @@ export const DFlowTabDefault: React.FC<DFlowTabDefaultProps> = (props) => {
5555
const initialValues = React.useMemo(() => {
5656
const values: Record<string, any> = {}
5757
sortedParameters.forEach(parameter => {
58-
values[parameter?.id!!] = parameter?.value?.__typename === "LiteralValue" ? (typeof parameter.value?.value === "object" && parameter.value?.value != null ? JSON.stringify(parameter.value?.value) : parameter.value.value) : parameter?.value != null ? JSON.stringify(parameter?.value) : parameter?.value
58+
values[parameter?.id!!] = parameter?.value?.__typename === "LiteralValue" ? (typeof parameter.value?.value === "object" && parameter.value?.value != null ? JSON.stringify(parameter.value?.value) : parameter.value.value) : parameter?.value != null ? JSON.stringify(parameter?.value) : parameter?.value
5959
})
6060
return values
6161
}, [sortedParameters])
@@ -80,7 +80,7 @@ export const DFlowTabDefault: React.FC<DFlowTabDefaultProps> = (props) => {
8080
if (!changedParameters.current.has(paramDefinitions1?.id!!)) continue;
8181
const syntaxSegment = values[paramDefinitions1?.id!]
8282
const previousValue = paramDefinitions1?.value as NodeParameterValue
83-
const syntaxValue = syntaxSegment?.[0]?.value as NodeFunction | LiteralValue | ReferenceValue
83+
const syntaxValue = syntaxSegment?.[0]?.value ?? syntaxSegment?.value ?? syntaxSegment as NodeFunction | LiteralValue | ReferenceValue
8484

8585
if (previousValue && previousValue.__typename === "NodeFunctionIdWrapper" && previousValue.id) {
8686
const linkedNodes = flowService.getLinkedNodesById(flowId, previousValue.id)
@@ -94,8 +94,8 @@ export const DFlowTabDefault: React.FC<DFlowTabDefaultProps> = (props) => {
9494
}
9595

9696
try {
97-
const parsedSyntaxValue = Number.isNaN(Number(syntaxValue)) ? JSON.parse(String(syntaxValue)) : String(syntaxValue)
98-
if (!syntaxValue?.__typename) {
97+
const parsedSyntaxValue = Number.isNaN(Number(syntaxValue)) ? JSON.parse(syntaxValue) : syntaxValue
98+
if (!parsedSyntaxValue?.__typename) {
9999
await flowService.setParameterValue(flowId, node.id!!, paramDefinitions1!!.id!!, syntaxValue ? {
100100
__typename: "LiteralValue",
101101
value: parsedSyntaxValue === null || parsedSyntaxValue === undefined ? String(parsedSyntaxValue) : parsedSyntaxValue
@@ -112,7 +112,9 @@ export const DFlowTabDefault: React.FC<DFlowTabDefaultProps> = (props) => {
112112
}
113113
}
114114

115-
await flowService.setParameterValue(flowId, node.id!!, paramDefinitions1!!.id!!, syntaxValue.__typename === "LiteralValue" ? (!!syntaxValue.value ? syntaxValue : undefined) : syntaxValue);
115+
const parsedSyntaxValue = typeof syntaxValue === "object" ? syntaxValue : JSON.parse(syntaxValue)
116+
117+
await flowService.setParameterValue(flowId, node.id!!, paramDefinitions1!!.id!!, parsedSyntaxValue.__typename === "LiteralValue" ? (!!parsedSyntaxValue.value ? parsedSyntaxValue : undefined) : parsedSyntaxValue);
116118
}
117119
changedParameters.current.clear()
118120
})
@@ -136,17 +138,17 @@ export const DFlowTabDefault: React.FC<DFlowTabDefaultProps> = (props) => {
136138

137139
return <div>
138140
{/*@ts-ignore*/}
139-
<DFlowInputDefault flowId={flowId}
140-
nodeId={node.id}
141-
parameterId={parameter.id}
142-
title={title}
143-
description={description}
144-
clearable
145-
onChange={() => {
146-
changedParameters.current.add(parameter.id!!)
147-
validate()
148-
}}
149-
{...inputs.getInputProps(parameter.id!!)}
141+
<DFlowInput flowId={flowId}
142+
nodeId={node.id}
143+
parameterId={parameter.id}
144+
title={title}
145+
description={description}
146+
clearable
147+
onChange={() => {
148+
changedParameters.current.add(parameter.id!!)
149+
validate()
150+
}}
151+
{...inputs.getInputProps(parameter.id!!)}
150152
/>
151153
</div>
152154
})}

src/components/d-flow-file/DFlowTabTrigger.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export const DFlowTabTrigger: React.FC<DFlowTabTriggerProps> = (props) => {
5959

6060
return <Flex style={{gap: ".7rem", flexDirection: "column"}}>
6161
{definition?.inputType ? <DFlowInputDataType
62-
initialValue={testDataType}
62+
initialValue={testDataType || undefined}
6363
label={"Test Data Type"}
6464
description={"Data type used for testing"}
6565
onChange={(dataTypeIdentifier) => console.log(dataTypeIdentifier)}/> : null}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import {Flow, NodeFunction, NodeParameter} from "@code0-tech/sagittarius-graphql-types";
2+
import React from "react";
3+
import {InputProps} from "../form";
4+
import {DFlowInputDefault} from "./DFlowInputDefault";
5+
import {useService, useStore} from "../../utils";
6+
import {DFlowReactiveService} from "../d-flow";
7+
import {DFlowDataTypeReactiveService} from "../d-flow-data-type";
8+
import {DFlowFunctionReactiveService} from "../d-flow-function";
9+
import {DFlowInputObject} from "./DFlowInputObject";
10+
11+
export interface DFlowInputProps extends Omit<InputProps<any | null>, "wrapperComponent" | "type"> {
12+
flowId: Flow['id']
13+
nodeId: NodeFunction['id']
14+
parameterId: NodeParameter['id']
15+
clearable?: boolean
16+
onClear?: (event: React.MouseEvent<HTMLButtonElement>) => void
17+
}
18+
19+
export const DFlowInput: React.FC<DFlowInputProps> = (props) => {
20+
21+
const {flowId, nodeId, parameterId, ...rest} = props
22+
23+
const flowService = useService(DFlowReactiveService)
24+
const flowStore = useStore(DFlowReactiveService)
25+
const dataTypeService = useService(DFlowDataTypeReactiveService)
26+
const dataTypeStore = useStore(DFlowDataTypeReactiveService)
27+
const functionService = useService(DFlowFunctionReactiveService)
28+
const functionStore = useStore(DFlowFunctionReactiveService)
29+
30+
const node = React.useMemo(
31+
() => flowService.getNodeById(flowId, nodeId),
32+
[flowStore, flowId, nodeId]
33+
)
34+
35+
const parameter = React.useMemo(
36+
() => node?.parameters?.nodes?.find(p => p?.id === parameterId),
37+
[node, parameterId]
38+
)
39+
40+
const functionDefinition = React.useMemo(
41+
() => functionService.getById(node?.functionDefinition?.id!),
42+
[functionStore, node]
43+
)
44+
45+
const parameterDefinition = React.useMemo(
46+
() => functionDefinition?.parameterDefinitions?.find(pd => pd.id === parameter?.parameterDefinition?.id),
47+
[functionDefinition, parameter]
48+
)
49+
50+
const dataType = React.useMemo(
51+
() => dataTypeService.getDataType(parameterDefinition?.dataTypeIdentifier!),
52+
[dataTypeStore, parameterDefinition]
53+
)
54+
55+
switch (dataType?.variant) {
56+
case "ARRAY":
57+
case "OBJECT":
58+
return <DFlowInputObject
59+
flowId={flowId}
60+
nodeId={nodeId}
61+
parameterId={parameterId}
62+
{...rest}
63+
/>
64+
default:
65+
return <DFlowInputDefault
66+
flowId={flowId}
67+
nodeId={nodeId}
68+
parameterId={parameterId}
69+
{...rest}
70+
/>
71+
}
72+
}

src/components/d-flow-input/DFlowInputDataType.style.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ ul {
1818
li {
1919
position: relative;
2020
padding-inline-start: variables.$xs;
21+
list-style: none;
2122

2223
&:before {
2324
content: '';

src/components/d-flow-input/DFlowInputDefault.tsx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import React from "react";
2-
import {TextInput, TextInputProps} from "../form";
3-
import {Flow, NodeFunction, NodeParameter, ReferenceValue} from "@code0-tech/sagittarius-graphql-types";
2+
import {TextInput} from "../form";
3+
import {ReferenceValue} from "@code0-tech/sagittarius-graphql-types";
44
import {MenuItem} from "../menu/Menu";
55
import {Text} from "../text/Text";
66
import {DFlowSuggestionMenuFooter} from "../d-flow-suggestion/DFlowSuggestionMenuFooter";
77
import {toInputSuggestions} from "../d-flow-suggestion/DFlowSuggestionMenu.util";
8-
import {InputSyntaxSegment} from "../form/Input.syntax.hook";
8+
import {InputSyntaxSegment} from "../form";
99
import {useService} from "../../utils";
1010
import {DFlowFunctionReactiveService} from "../d-flow-function";
1111
import {DFlowReactiveService} from "../d-flow";
@@ -14,12 +14,9 @@ import {DFlowSuggestion} from "../d-flow-suggestion";
1414
import {DFlowInputNodeBadge} from "./DFlowInputNodeBadge";
1515
import {DFlowInputReferenceBadge} from "./DFlowInputReferenceBadge";
1616
import {DFlowTypeReactiveService} from "../d-flow-type";
17+
import {DFlowInputProps} from "./DFlowInput";
1718

18-
export interface DFlowInputDefaultProps extends TextInputProps {
19-
flowId: Flow['id']
20-
nodeId: NodeFunction['id']
21-
parameterId: NodeParameter['id']
22-
}
19+
export type DFlowInputDefaultProps = DFlowInputProps
2320

2421
export const splitTextAndObjects = (input: string) => {
2522
const result: (string | Record<string, any>)[] = []

0 commit comments

Comments
 (0)