From 9cfd521d678f490fd2990f6f7c04b08070226aae Mon Sep 17 00:00:00 2001 From: balibabu Date: Mon, 19 Aug 2024 16:07:04 +0800 Subject: [PATCH] feat: Add complex dynamic form to SwitchForm #1739 (#2001) ### What problem does this PR solve? feat: Add complex dynamic form to SwitchForm #1739 ### Type of change - [x] New Feature (non-breaking change which adds functionality) --- web/src/locales/en.ts | 1 + web/src/locales/zh-traditional.ts | 1 + web/src/locales/zh.ts | 1 + web/src/pages/flow/constant.tsx | 2 +- web/src/pages/flow/switch-form/index.tsx | 141 ++++++++++++++++++++++- 5 files changed, 143 insertions(+), 3 deletions(-) diff --git a/web/src/locales/en.ts b/web/src/locales/en.ts index f98480a46..ec07adddf 100644 --- a/web/src/locales/en.ts +++ b/web/src/locales/en.ts @@ -807,6 +807,7 @@ The above is the content you need to summarize.`, port: 'Port', password: 'Password', switch: 'Switch', + logicalOperator: 'Logical operator', }, footer: { profile: 'All rights reserved @ React', diff --git a/web/src/locales/zh-traditional.ts b/web/src/locales/zh-traditional.ts index 32864728c..85428d85e 100644 --- a/web/src/locales/zh-traditional.ts +++ b/web/src/locales/zh-traditional.ts @@ -765,6 +765,7 @@ export default { port: '端口', password: '密碼', switch: '條件', + logicalOperator: '操作符', }, footer: { profile: '“保留所有權利 @ react”', diff --git a/web/src/locales/zh.ts b/web/src/locales/zh.ts index a398b54a0..3be6fe802 100644 --- a/web/src/locales/zh.ts +++ b/web/src/locales/zh.ts @@ -783,6 +783,7 @@ export default { port: '端口', password: '密码', switch: '条件', + logicalOperator: '操作符', }, footer: { profile: 'All rights reserved @ React', diff --git a/web/src/pages/flow/constant.tsx b/web/src/pages/flow/constant.tsx index 91cb89098..ec652fe43 100644 --- a/web/src/pages/flow/constant.tsx +++ b/web/src/pages/flow/constant.tsx @@ -388,7 +388,7 @@ export const initialExeSqlValues = { top_n: 30, }; -export const initialSwitchValues = {}; +export const initialSwitchValues = { conditions: [{}] }; export const CategorizeAnchorPointPositions = [ { top: 1, right: 34 }, diff --git a/web/src/pages/flow/switch-form/index.tsx b/web/src/pages/flow/switch-form/index.tsx index 1be6a7ad9..f9564a7cb 100644 --- a/web/src/pages/flow/switch-form/index.tsx +++ b/web/src/pages/flow/switch-form/index.tsx @@ -1,5 +1,142 @@ -const SwitchForm = () => { - return
Switch
; +import { CloseOutlined } from '@ant-design/icons'; +import { Button, Card, Form, Input, Typography } from 'antd'; +import React from 'react'; +import { useTranslation } from 'react-i18next'; +import { IOperatorForm } from '../interface'; + +const subLabelCol = { + span: 7, +}; + +const subWrapperCol = { + span: 17, +}; + +const SwitchForm: React.FC = ({ form, onValuesChange }: IOperatorForm) => { + const { t } = useTranslation(); + + return ( +
+ + + + + + + + {(fields, { add, remove }) => ( +
+ {fields.map((field) => ( + { + remove(field.name); + }} + /> + } + > + + + + + + + + {/* Nest Form.List */} + + + {(subFields, subOpt) => ( +
+ {subFields.map((subField) => ( + { + subOpt.remove(subField.name); + }} + /> + } + > + + + + + + + + + + + ))} + +
+ )} +
+
+
+ ))} + + +
+ )} +
+ + + {() => ( + +
{JSON.stringify(form?.getFieldsValue(), null, 2)}
+
+ )} +
+
+ ); }; export default SwitchForm;