From b560693565db6d84ac46baae3553b94e52045cab Mon Sep 17 00:00:00 2001 From: Aralhi Date: Thu, 1 Feb 2024 01:02:11 +0800 Subject: [PATCH] feat: add description --- web/app/i18n.ts | 4 ++++ web/components/flow/flow-card.tsx | 3 ++- web/pages/flow/canvas/index.tsx | 26 +++++++++++++++++++++++--- web/types/flow.ts | 3 +++ 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/web/app/i18n.ts b/web/app/i18n.ts index 359857800..11e392a23 100644 --- a/web/app/i18n.ts +++ b/web/app/i18n.ts @@ -189,7 +189,9 @@ const en = { connect_warning: 'Nodes cannot be connected', flow_modal_title: 'Save Flow', flow_name: 'Flow Name', + flow_description: 'Flow Description', flow_name_required: 'Please enter the flow name', + flow_description_required: 'Please enter the flow description', save_flow_success: 'Save flow success', delete_flow_confirm: 'Are you sure you want to delete this flow?', related_nodes: 'Related Nodes', @@ -388,7 +390,9 @@ const zh: Resources['translation'] = { connect_warning: '节点无法连接', flow_modal_title: '保存工作流', flow_name: '工作流名称', + flow_description: '工作流描述', flow_name_required: '请输入工作流名称', + flow_description_required: '请输入工作流描述', save_flow_success: '保存工作流成功', delete_flow_confirm: '确定删除该工作流吗?', related_nodes: '关联节点', diff --git a/web/components/flow/flow-card.tsx b/web/components/flow/flow-card.tsx index c31428a71..24387b940 100644 --- a/web/components/flow/flow-card.tsx +++ b/web/components/flow/flow-card.tsx @@ -23,10 +23,11 @@ const FlowCard: React.FC = ({ flow, deleteCallback }) => { return ( <> -
+

{flow.name}

+

{flow.description}

= () => { const reactFlowWrapper = useRef(null); const [isModalVisible, setIsModalVisible] = useState(false); const [name, setName] = useState(''); + const [description, setDescription] = useState(''); async function getFlowData() { setLoading(true); @@ -39,6 +43,7 @@ const Canvas: React.FC = () => { if (data) { const flowData = mapUnderlineToHump(data.flow_data); setName(data.name); + setDescription(data.description); setNodes(flowData.nodes.map((node) => ({ ...node, type: 'customNode' }))); setEdges(flowData.edges.map((edge) => ({ ...edge, type: 'buttonedge' }))); } @@ -134,7 +139,7 @@ const Canvas: React.FC = () => { async function handleSaveFlow() { const reactFlowObject = mapHumpToUnderline(reactFlow.toObject() as IFlowData); if (id) { - const [, , res] = await apiInterceptors(updateFlowById(id, { name, uid: id, flow_data: reactFlowObject })); + const [, , res] = await apiInterceptors(updateFlowById(id, { name, description, uid: id, flow_data: reactFlowObject })); if (res?.success) { messageApi.success(t('save_flow_success')); } else if (res?.err_msg) { @@ -143,8 +148,10 @@ const Canvas: React.FC = () => { } else { if (!name) { return messageApi.warning(t('flow_name_required')); + } else if (!description) { + return messageApi.warning(t('flow_description_required')); } - const [_, res] = await apiInterceptors(addFlow({ name, flow_data: reactFlowObject })); + const [_, res] = await apiInterceptors(addFlow({ name, description, flow_data: reactFlowObject })); if (res?.uid) { messageApi.success(t('save_flow_success')); const history = window.history; @@ -193,12 +200,25 @@ const Canvas: React.FC = () => { }} > <> -

{t('flow_name')}

+

+ {t('flow_name')} + +

{ setName(e.target.value); }} /> +

+ {t('flow_description')} + +

+