From cffaf307604d3ff69d0bfbe950a2bc6a1fea0680 Mon Sep 17 00:00:00 2001 From: Joel Date: Wed, 21 Feb 2024 16:34:38 +0800 Subject: [PATCH] feat: if types --- .../(commonLayout)/workflow/nodes/page.tsx | 4 +- .../components/workflow/nodes/if-else/mock.ts | 23 ++++++++++++ .../workflow/nodes/if-else/types.ts | 37 +++++++++++++++++++ 3 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 web/app/components/workflow/nodes/if-else/mock.ts create mode 100644 web/app/components/workflow/nodes/if-else/types.ts diff --git a/web/app/(commonLayout)/workflow/nodes/page.tsx b/web/app/(commonLayout)/workflow/nodes/page.tsx index cc41ff378a..e7402d9670 100644 --- a/web/app/(commonLayout)/workflow/nodes/page.tsx +++ b/web/app/(commonLayout)/workflow/nodes/page.tsx @@ -46,9 +46,9 @@ const Page: FC = () => { /* * TODO: for debug. * 2 directAnswer 3: llm 5: questionClassifier - * 7 Code, 8 TemplateTransform 9 http + * 6 if else 7 Code, 8 TemplateTransform 9 http */ - selectedNodeId='9' + selectedNodeId='6' /> ) diff --git a/web/app/components/workflow/nodes/if-else/mock.ts b/web/app/components/workflow/nodes/if-else/mock.ts new file mode 100644 index 0000000000..4c719c5df1 --- /dev/null +++ b/web/app/components/workflow/nodes/if-else/mock.ts @@ -0,0 +1,23 @@ +import type { IfElseType } from './types' +import { ComparisonOperator, LogicalOperator } from './types' + +export const mockData: IfElseType = { + title: 'Test', + desc: 'Test', + type: 'Test', + logical_operator: LogicalOperator.and, + conditions: [ + { + id: '1', + variable_selector: ['aaa', 'name'], + comparison_operator: ComparisonOperator.contains, + value: '22', + }, + { + id: '2', + variable_selector: ['bbb', 'b', 'c'], + comparison_operator: ComparisonOperator.equal, + value: 'b', + }, + ], +} diff --git a/web/app/components/workflow/nodes/if-else/types.ts b/web/app/components/workflow/nodes/if-else/types.ts new file mode 100644 index 0000000000..7746faf931 --- /dev/null +++ b/web/app/components/workflow/nodes/if-else/types.ts @@ -0,0 +1,37 @@ +import type { CommonNodeType, ValueSelector } from '@/app/components/workflow/types' + +export enum LogicalOperator { + and = 'and', + or = 'or', +} + +export enum ComparisonOperator { + contains = 'contains', + notContains = 'not contains', + startWith = 'start with', + endWith = 'end with', + is = 'is', + isNot = 'is not', + empty = 'empty', + notEmpty = 'not empty', + equal = '=', + notEqual = '≠', + largerThan = '>', + lessThan = '<', + largerThanOrEqual = '≥', + lessThanOrEqual = '≤', + isNull = 'is null', + isNotNull = 'is not null', +} + +export type Condition = { + id: string + variable_selector: ValueSelector + comparison_operator: ComparisonOperator + value: string +} + +export type IfElseType = CommonNodeType & { + logical_operator: LogicalOperator + conditions: Condition[] +}