diff --git a/web/components/flow/add-flow-variable.tsx b/web/components/flow/add-flow-variable.tsx new file mode 100644 index 000000000..808fd50f4 --- /dev/null +++ b/web/components/flow/add-flow-variable.tsx @@ -0,0 +1,151 @@ +import { apiInterceptors, getFlowNodes } from '@/client/api'; +import { IFlowNode } from '@/types/flow'; +import { FLOW_NODES_KEY } from '@/utils'; +import { MinusCircleOutlined, PlusOutlined } from '@ant-design/icons'; +import { Button, Form, Input, Modal } from 'antd'; +import React, { useEffect, useState } from 'react'; +import { useTranslation } from 'react-i18next'; + +type GroupType = { category: string; categoryLabel: string; nodes: IFlowNode[] }; + +const AddFlowVariable: React.FC = () => { + const { t } = useTranslation(); + const [operators, setOperators] = useState>([]); + const [resources, setResources] = useState>([]); + const [operatorsGroup, setOperatorsGroup] = useState([]); + const [resourcesGroup, setResourcesGroup] = useState([]); + const [isModalOpen, setIsModalOpen] = useState(false); + + const showModal = () => { + setIsModalOpen(true); + }; + + useEffect(() => { + getNodes(); + }, []); + + async function getNodes() { + const [_, data] = await apiInterceptors(getFlowNodes()); + if (data && data.length > 0) { + localStorage.setItem(FLOW_NODES_KEY, JSON.stringify(data)); + const operatorNodes = data.filter(node => node.flow_type === 'operator'); + const resourceNodes = data.filter(node => node.flow_type === 'resource'); + setOperators(operatorNodes); + setResources(resourceNodes); + setOperatorsGroup(groupNodes(operatorNodes)); + setResourcesGroup(groupNodes(resourceNodes)); + } + } + + function groupNodes(data: IFlowNode[]) { + const groups: GroupType[] = []; + const categoryMap: Record = {}; + data.forEach(item => { + const { category, category_label } = item; + if (!categoryMap[category]) { + categoryMap[category] = { category, categoryLabel: category_label, nodes: [] }; + groups.push(categoryMap[category]); + } + categoryMap[category].nodes.push(item); + }); + return groups; + } + + const formItemLayout = { + labelCol: { + xs: { span: 24 }, + sm: { span: 4 }, + }, + wrapperCol: { + xs: { span: 24 }, + sm: { span: 20 }, + }, + }; + + const formItemLayoutWithOutLabel = { + wrapperCol: { + xs: { span: 24, offset: 0 }, + sm: { span: 20, offset: 2 }, + }, + }; + + const onFinish = (values: any) => { + console.log('Received values of form:', values); + }; + + return ( + <> + + + + + + )} + + + + + + + + + ); +}; + +export default AddFlowVariable; diff --git a/web/locales/en/flow.ts b/web/locales/en/flow.ts index fffe4a6a3..396e6d5ee 100644 --- a/web/locales/en/flow.ts +++ b/web/locales/en/flow.ts @@ -17,4 +17,5 @@ export const FlowEn = { Yes: 'Yes', No: 'No', Please_Add_Nodes_First: 'Please add nodes first', + Add_Global_Variable_of_Flow: 'Add global variable of flow', }; diff --git a/web/locales/zh/flow.ts b/web/locales/zh/flow.ts index 9ce76d733..338c6df50 100644 --- a/web/locales/zh/flow.ts +++ b/web/locales/zh/flow.ts @@ -17,4 +17,5 @@ export const FlowZn = { Yes: '是', No: '否', Please_Add_Nodes_First: '请先添加节点', + Add_Global_Variable_of_Flow: '添加 Flow 全局变量', }; diff --git a/web/new-components/layout/Construct.tsx b/web/new-components/layout/Construct.tsx index 8d76e62fd..f68ef3ccf 100644 --- a/web/new-components/layout/Construct.tsx +++ b/web/new-components/layout/Construct.tsx @@ -12,6 +12,7 @@ import { t } from 'i18next'; import { useRouter } from 'next/router'; import React from 'react'; import './style.css'; + function ConstructLayout({ children }: { children: React.ReactNode }) { const items = [ { @@ -19,6 +20,15 @@ function ConstructLayout({ children }: { children: React.ReactNode }) { name: t('App'), path: '/app', icon: , + // operations: ( + // + // ), }, { key: 'flow', @@ -102,6 +112,15 @@ function ConstructLayout({ children }: { children: React.ReactNode }) { onTabClick={key => { router.push(`/construct/${key}`); }} + // tabBarExtraContent={ + // + // } /> diff --git a/web/pages/construct/flow/canvas/index.tsx b/web/pages/construct/flow/canvas/index.tsx index 5e5676c66..5957074ea 100644 --- a/web/pages/construct/flow/canvas/index.tsx +++ b/web/pages/construct/flow/canvas/index.tsx @@ -17,6 +17,7 @@ import ReactFlow, { useReactFlow, } from 'reactflow'; // import AddNodes from '@/components/flow/add-nodes'; +import AddFlowVariable from '@/components/flow/add-flow-variable'; import AddNodesSider from '@/components/flow/add-nodes-sider'; import ButtonEdge from '@/components/flow/button-edge'; import { ExportFlowModal, ImportFlowModal, SaveFlowModal } from '@/components/flow/canvas-modal'; @@ -249,7 +250,9 @@ const Canvas: React.FC = () => { > + {/* */} +