Skip to content

Commit 2eb0868

Browse files
committed
feat: enhance validation handling and display in FunctionFileTriggerComponent for improved user feedback
1 parent 76c2085 commit 2eb0868

1 file changed

Lines changed: 34 additions & 13 deletions

File tree

src/packages/ce/src/function/components/files/FunctionFileTriggerComponent.tsx

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from "react";
2-
import {Flex, InputSyntaxSegment, useForm, useService, useStore} from "@code0-tech/pictor";
2+
import {Alert, InputSyntaxSegment, Spacing, Text, useForm, useService, useStore} from "@code0-tech/pictor";
33
import {Flow, LiteralValue} from "@code0-tech/sagittarius-graphql-types";
44
import {FlowTypeService} from "@edition/flowtype/services/FlowType.service";
55
import {FlowService} from "@edition/flow/services/Flow.service";
@@ -8,7 +8,6 @@ import {DataTypeInputComponent} from "@edition/datatype/components/inputs/DataTy
88
import {getTypesFromFunction} from "@code0-tech/triangulum";
99
import {DataTypeTypeInputComponent} from "@edition/datatype/components/inputs/datatype/DataTypeTypeInputComponent";
1010
import {
11-
FALLBACK_FLOW_TYPE_DESCRIPTION,
1211
FALLBACK_FLOW_TYPE_SETTING_DESCRIPTION,
1312
FALLBACK_FLOW_TYPE_SETTING_NAME
1413
} from "@core/util/fallback-translations";
@@ -47,7 +46,12 @@ export const FunctionFileTriggerComponent: React.FC<FunctionFileTriggerComponent
4746
return values
4847
}, [definition, instance])
4948

50-
const validations = React.useMemo(() => {
49+
const triggerValidation = React.useMemo(
50+
() => validation?.find(v => v.nodeId === null && v.parameterIndex === null),
51+
[validation]
52+
)
53+
54+
const settingsValidations = React.useMemo(() => {
5155
const values: Record<string, any> = {}
5256
definition?.flowTypeSettings?.forEach((setting, index) => {
5357
values[setting!.id!] = (_: any) => {
@@ -87,7 +91,7 @@ export const FunctionFileTriggerComponent: React.FC<FunctionFileTriggerComponent
8791

8892
const [inputs, validate] = useForm<Record<string | "inputType", InputSyntaxSegment[]>>({
8993
initialValues: initialValues,
90-
validate: validations,
94+
validate: settingsValidations,
9195
truthyValidationBeforeSubmit: false,
9296
useInitialValidation: true,
9397
onSubmit: onSubmit
@@ -97,18 +101,34 @@ export const FunctionFileTriggerComponent: React.FC<FunctionFileTriggerComponent
97101
validate()
98102
}, [validation])
99103

100-
return <Flex style={{gap: ".7rem", flexDirection: "column"}}>
104+
return <>
105+
<Text size={"md"}>{definition?.names?.[0].content}</Text>
106+
<Spacing spacing={"xs"}/>
107+
<Text hierarchy={"tertiary"}>{definition?.descriptions?.[0].content}</Text>
108+
{
109+
triggerValidation && <>
110+
<Spacing spacing={"xl"}/>
111+
<Alert color={"error"}>
112+
{triggerValidation?.message?.[0]?.content as string}
113+
</Alert>
114+
</>
115+
}
116+
<Spacing spacing={"xl"}/>
117+
<Text size={"md"}>Settings</Text>
118+
<Spacing spacing={"xs"}/>
101119
{
102120

103-
(flowInputType && flowInputType != "void") && (flowTypeInputType && flowTypeInputType != "void") ? <DataTypeTypeInputComponent
104-
flowId={instance.id}
105-
title={"Input type"}
106-
description={"The type of the input that will be provided to the flow when it is triggered."}
107-
onChange={() => validate()}
108-
{...inputs.getInputProps("inputType")}
109-
/> : null
121+
(flowInputType && flowInputType != "void") && (flowTypeInputType && flowTypeInputType != "void") ?
122+
<DataTypeTypeInputComponent
123+
flowId={instance.id}
124+
title={"Input type"}
125+
description={"The type of the input that will be provided to the flow when it is triggered."}
126+
onChange={() => validate()}
127+
{...inputs.getInputProps("inputType")}
128+
/> : null
110129

111130
}
131+
<Spacing spacing={"xl"}/>
112132
{definition?.flowTypeSettings?.map((settingDefinition, index) => {
113133

114134
if (!settingDefinition) return null
@@ -131,8 +151,9 @@ export const FunctionFileTriggerComponent: React.FC<FunctionFileTriggerComponent
131151
}}
132152
{...inputs.getInputProps(settingDefinition.id!)}
133153
/>
154+
<Spacing spacing={"xl"}/>
134155
</div>
135156

136157
})}
137-
</Flex>
158+
</>
138159
}

0 commit comments

Comments
 (0)