From 072f5caa06405f6fbb553b1a73fbf3d52b5ffade Mon Sep 17 00:00:00 2001 From: StyleZhang Date: Thu, 7 Mar 2024 19:42:46 +0800 Subject: [PATCH] init --- .../workflow/custom-connection-line.tsx | 2 +- web/app/components/workflow/index.tsx | 53 +++++++++++-------- .../nodes/_base/components/next-step/item.tsx | 6 ++- web/app/components/workflow/utils.ts | 5 +- web/i18n/en-US/workflow.ts | 1 + web/i18n/zh-Hans/workflow.ts | 3 +- 6 files changed, 44 insertions(+), 26 deletions(-) diff --git a/web/app/components/workflow/custom-connection-line.tsx b/web/app/components/workflow/custom-connection-line.tsx index f8f15921c9..4d519e930d 100644 --- a/web/app/components/workflow/custom-connection-line.tsx +++ b/web/app/components/workflow/custom-connection-line.tsx @@ -26,7 +26,7 @@ const CustomConnectionLine = ({ fromX, fromY, toX, toY }: ConnectionLineComponen d={edgePath} /> = ({ useStore.setState({ draftUpdatedAt: data.updated_at }) }, [data]) - const startNode = { - id: `${Date.now()}`, - type: 'custom', - data: nodesInitialData.start, - position: { - x: 100, - y: 100, - }, - } + const startNode = useMemo(() => { + return { + id: `${Date.now()}`, + type: 'custom', + data: nodesInitialData.start, + position: { + x: 100, + y: 100, + }, + } + }, [nodesInitialData]) const nodesData = useMemo(() => { if (nodes) @@ -156,7 +158,7 @@ const WorkflowWrap: FC = ({ return data.graph.nodes return [startNode] - }, [data, nodes]) + }, [data, nodes, startNode]) const edgesData = useMemo(() => { if (edges) return edges @@ -165,7 +167,7 @@ const WorkflowWrap: FC = ({ return data.graph.edges return [] - }, [data, nodes]) + }, [data, edges]) const handleFetchCollectionList = async () => { const toolsets = await fetchCollectionList() @@ -183,16 +185,22 @@ const WorkflowWrap: FC = ({ handleFetchCollectionList() }, []) - if (error && appDetail) { - syncWorkflowDraft({ - url: `/apps/${appDetail.id}/workflows/draft`, - params: { - graph: { - nodes: [startNode], - edges: [], - }, - features: {}, - }, + if (error && !error.bodyUsed && appDetail) { + error.json().then((err: any) => { + if (err.code === 'draft_workflow_not_exist') { + syncWorkflowDraft({ + url: `/apps/${appDetail.id}/workflows/draft`, + params: { + graph: { + nodes: [startNode], + edges: [], + }, + features: {}, + }, + }).then((res) => { + useStore.setState({ draftUpdatedAt: res.updated_at }) + }) + } }) } @@ -204,6 +212,9 @@ const WorkflowWrap: FC = ({ ) } + if (!data) + return null + const features = data?.features || {} const initialFeatures: FeaturesData = { opening: { diff --git a/web/app/components/workflow/nodes/_base/components/next-step/item.tsx b/web/app/components/workflow/nodes/_base/components/next-step/item.tsx index f88a9c8c33..3f0a4ec93c 100644 --- a/web/app/components/workflow/nodes/_base/components/next-step/item.tsx +++ b/web/app/components/workflow/nodes/_base/components/next-step/item.tsx @@ -2,6 +2,7 @@ import { memo, useCallback, } from 'react' +import { useTranslation } from 'react-i18next' import type { CommonNodeType, OnSelectBlock, @@ -23,6 +24,7 @@ const Item = ({ branchName, data, }: ItemProps) => { + const { t } = useTranslation() const { handleNodeChange } = useWorkflow() const handleSelect = useCallback((type, toolDefaultValue) => { handleNodeChange(nodeId, type, sourceHandle, toolDefaultValue) @@ -35,10 +37,10 @@ const Item = ({ ${open && '!bg-gray-100 !flex'} `} > - Change + {t('workflow.panel.change')} ) - }, []) + }, [t]) return (
{ export const canRunBySingle = (nodeType: BlockEnum) => { return nodeType === BlockEnum.LLM || nodeType === BlockEnum.KnowledgeRetrieval - || nodeType === BlockEnum.IfElse || nodeType === BlockEnum.Code || nodeType === BlockEnum.TemplateTransform || nodeType === BlockEnum.QuestionClassifier || nodeType === BlockEnum.HttpRequest || nodeType === BlockEnum.Tool } + +export const getVariables = () => { + +} diff --git a/web/i18n/en-US/workflow.ts b/web/i18n/en-US/workflow.ts index f0561288cb..bebb5cac6b 100644 --- a/web/i18n/en-US/workflow.ts +++ b/web/i18n/en-US/workflow.ts @@ -70,6 +70,7 @@ const translation = { checklist: 'Checklist', checklistTip: 'Make sure all issues are resolved before publishing', organizeBlocks: 'Organize blocks', + change: 'Change', }, nodes: { common: { diff --git a/web/i18n/zh-Hans/workflow.ts b/web/i18n/zh-Hans/workflow.ts index 781a6e67fc..4826fe36d5 100644 --- a/web/i18n/zh-Hans/workflow.ts +++ b/web/i18n/zh-Hans/workflow.ts @@ -40,7 +40,7 @@ const translation = { blocks: { 'start': '开始', 'end': '结束', - 'direct-answer': '直接回答', + 'direct-answer': '直接回复', 'llm': 'LLM', 'knowledge-retrieval': '知识检索', 'question-classifier': '问题分类器', @@ -70,6 +70,7 @@ const translation = { checklist: '检查清单', checklistTip: '发布前确保所有问题均已解决', organizeBlocks: '整理节点', + change: '更改', }, nodes: { common: {