From 4d4d3bb965abe6d1b20355d960a23b53c6230517 Mon Sep 17 00:00:00 2001 From: Joel Date: Tue, 27 Feb 2024 10:34:13 +0800 Subject: [PATCH] feat: add default values and utils and fix ts --- web/app/(commonLayout)/workflow/nodes/page.tsx | 4 ++-- web/app/components/workflow/nodes/constants.ts | 2 +- web/app/components/workflow/nodes/if-else/node.tsx | 6 +++--- .../workflow/nodes/variable-assigner/default.ts | 14 ++++++++++++++ .../workflow/nodes/variable-assigner/utils.ts | 5 +++++ web/app/components/workflow/types.ts | 6 ++++++ 6 files changed, 31 insertions(+), 6 deletions(-) create mode 100644 web/app/components/workflow/nodes/variable-assigner/default.ts create mode 100644 web/app/components/workflow/nodes/variable-assigner/utils.ts diff --git a/web/app/(commonLayout)/workflow/nodes/page.tsx b/web/app/(commonLayout)/workflow/nodes/page.tsx index a13fd8c802..117e9b4cf7 100644 --- a/web/app/(commonLayout)/workflow/nodes/page.tsx +++ b/web/app/(commonLayout)/workflow/nodes/page.tsx @@ -5,9 +5,9 @@ import { memo } from 'react' import Workflow from '@/app/components/workflow' import { BlockEnum } from '@/app/components/workflow/types' const nodes = [ - BlockEnum.VariableAssigner/* 11 */, BlockEnum.Start/* 1 */, BlockEnum.DirectAnswer/* 2 */, BlockEnum.LLM/* 3 */, BlockEnum.KnowledgeRetrieval/* 4 */, BlockEnum.QuestionClassifier/* 5 */, + BlockEnum.Start/* 1 */, BlockEnum.DirectAnswer/* 2 */, BlockEnum.LLM/* 3 */, BlockEnum.KnowledgeRetrieval/* 4 */, BlockEnum.QuestionClassifier/* 5 */, BlockEnum.IfElse/* 6 */, BlockEnum.Code/* 7 */, BlockEnum.TemplateTransform/* 8 */, BlockEnum.HttpRequest/* 9 */, BlockEnum.Tool/* 10 */, - BlockEnum.End/* 12 */, + BlockEnum.VariableAssigner/* 11 */, BlockEnum.End/* 12 */, ].map((item, i) => ({ id: `${i + 1}`, type: 'custom', diff --git a/web/app/components/workflow/nodes/constants.ts b/web/app/components/workflow/nodes/constants.ts index ec63909c32..2c6eebcea0 100644 --- a/web/app/components/workflow/nodes/constants.ts +++ b/web/app/components/workflow/nodes/constants.ts @@ -25,7 +25,7 @@ import ToolPanel from './tool/panel' import VariableAssignerNode from './variable-assigner/node' import VariableAssignerPanel from './variable-assigner/panel' -export const NodeComponentMap: Record = { +export const NodeComponentMap: Record> = { [BlockEnum.Start]: StartNode, [BlockEnum.End]: EndNode, [BlockEnum.DirectAnswer]: DirectAnswerNode, diff --git a/web/app/components/workflow/nodes/if-else/node.tsx b/web/app/components/workflow/nodes/if-else/node.tsx index 65fb7448f3..3e4267819c 100644 --- a/web/app/components/workflow/nodes/if-else/node.tsx +++ b/web/app/components/workflow/nodes/if-else/node.tsx @@ -1,4 +1,4 @@ -import { memo } from 'react' +import type { FC } from 'react' import { useTranslation } from 'react-i18next' import type { NodeProps } from 'reactflow' import { NodeSourceHandle } from '../_base/components/node-handle' @@ -14,7 +14,7 @@ const notTranslateKey = [ ComparisonOperator.lessThan, ComparisonOperator.lessThanOrEqual, ] -const Node = (props: Pick) => { +const IfElseNode: FC> = (props) => { const { t } = useTranslation() const { conditions, logical_operator } = mockData @@ -56,4 +56,4 @@ const Node = (props: Pick) => { ) } -export default memo(Node) +export default IfElseNode diff --git a/web/app/components/workflow/nodes/variable-assigner/default.ts b/web/app/components/workflow/nodes/variable-assigner/default.ts new file mode 100644 index 0000000000..1439774ac5 --- /dev/null +++ b/web/app/components/workflow/nodes/variable-assigner/default.ts @@ -0,0 +1,14 @@ +import type { NodeDefault } from '../../types' +import type { VariableAssignerNodeType } from './types' + +const nodeDefault: NodeDefault = { + defaultValue: {}, + getAvailablePrevNodes() { + return [] + }, + getAvailableNextNodes() { + return [] + }, +} + +export default nodeDefault diff --git a/web/app/components/workflow/nodes/variable-assigner/utils.ts b/web/app/components/workflow/nodes/variable-assigner/utils.ts new file mode 100644 index 0000000000..4cc83bf211 --- /dev/null +++ b/web/app/components/workflow/nodes/variable-assigner/utils.ts @@ -0,0 +1,5 @@ +import type { VariableAssignerNodeType } from './types' + +export const checkNodeValid = (node: VariableAssignerNodeType) => { + return true +} diff --git a/web/app/components/workflow/types.ts b/web/app/components/workflow/types.ts index 62a368c5f6..500ffc8803 100644 --- a/web/app/components/workflow/types.ts +++ b/web/app/components/workflow/types.ts @@ -101,3 +101,9 @@ export type Block = { title: string description?: string } + +export type NodeDefault = { + defaultValue: Partial + getAvailablePrevNodes: () => BlockEnum[] + getAvailableNextNodes: () => BlockEnum[] +}