From e3a7ca1c4222328a0a4044ab232a720209754a19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E7=94=9C?= <759644414@qq.com> Date: Thu, 12 Dec 2024 10:16:40 +0800 Subject: [PATCH] improve: update zone topo from in cluster new --- ui/src/pages/Cluster/New/Topo.tsx | 741 +++++++++++++++--------------- 1 file changed, 359 insertions(+), 382 deletions(-) diff --git a/ui/src/pages/Cluster/New/Topo.tsx b/ui/src/pages/Cluster/New/Topo.tsx index 136f01c0..c2e29688 100644 --- a/ui/src/pages/Cluster/New/Topo.tsx +++ b/ui/src/pages/Cluster/New/Topo.tsx @@ -9,11 +9,9 @@ import { Button, Card, Col, - Dropdown, Form, Input, InputNumber, - Menu, Popconfirm, Row, Select, @@ -23,20 +21,216 @@ import { import { RULER_ZONE } from '@/constants/rules'; import { useState } from 'react'; -export default function Topo() { - // const { getFieldValue } = form; - - const [topologyConfiguration, setTopologyConfiguration] = - useState(''); +export default function Topo({ form }) { const [showTopology, setShowTopology] = useState(false); + const [formsubIndex, setFromSubIndex] = useState({}); + + const basicFrom = (topologyConfiguration, name) => ( + <> + + + + + + + + + ) : ( + + + + + remove(name)} /> + + + ))} + + + + + )} + + + ); - // const getNowNodeSelector = (zoneIdx: number) => { - // return () => { - // const topologyData = getFieldValue('topology'); - // const { nodeSelector } = topologyData[zoneIdx]; - // return nodeSelector; - // }; - // }; + const TolerationFrom: React.FC = ({ fieldName }) => ( + + + {(tolerationfields, { add, remove }) => ( + <> + {tolerationfields.map(({ key, name }) => ( +
+ + {basicFrom('Toleration', name)} + + + - - - {/* - - */} - - - - - - - - - - - {fields.length > 1 && ( - - { - remove(index); - }} - okText={intl.formatMessage({ - id: 'OBDashboard.Cluster.New.Topo.Delete', - defaultMessage: '删除', - })} - cancelText={intl.formatMessage({ - id: 'OBDashboard.Cluster.New.Topo.Cancel', - defaultMessage: '取消', - })} - okButtonProps={{ - danger: true, - ghost: true, - }} - > - - - - )} - - { - setShowTopology(!showTopology); - }} - > - {showTopology ? : } - Topology - - - {/* - TOdo - 表单存在两个问题: - 1 点击新增 Topology 按钮,多个card 会同时展示下拉标志 - 2 点击新增 Topology 按钮,原有选择nodeselector 时,后选择pod affinity 时,pod affinity 会覆盖 nodeselector 的选择的UI - */} - {showTopology && ( - <> -
- {topologyConfiguration} -
- - - {(subFields, subOpt) => ( -
- {subFields.map((subField) => ( -
- - {topologyConfiguration === - 'Pod Affinity' && ( - - - - - - )} - - - - - - - - - ) : ( - + + + + + + + + + + {() => { + const { topology } = form.getFieldsValue(); - {topologyConfiguration === - 'Toleration' && ( - - - - - - )} + const content = + topology?.length > 0 ? topology[field.name] : null; - { - subOpt.remove(subField.name); - }} - /> - -
- ))} + const { nodeSelector, affinities, tolerations } = + content || {}; - { - setTopologyConfiguration(key); - subOpt.add(); - }} - > - - nodeSelector - - - Pod Affinity - - - Toleration - - - } - > - - -
+ return ( +
+ {!!nodeSelector || + !!affinities || + !!tolerations ? ( + <> +
+ {!!nodeSelector && '- nodeSelector'} +
+
{!!affinities && '- affinities'}
+
{!!tolerations && '- tolerations'}
+ + ) : ( + '-' )} - - - +
+ ); + }} +
+ + + {fields.length > 1 && ( + } + style={{ marginBottom: 0 }} + name={[field.name, ' ']} + > + { + remove(field.name); + }} + okText={intl.formatMessage({ + id: 'OBDashboard.Cluster.New.Topo.Delete', + defaultMessage: '删除', + })} + cancelText={intl.formatMessage({ + id: 'OBDashboard.Cluster.New.Topo.Cancel', + defaultMessage: '取消', + })} + okButtonProps={{ + danger: true, + ghost: true, + }} + > + + + )} + + + { + setShowTopology(!showTopology); + setFromSubIndex({ + ...formsubIndex, + [field.index]: !showTopology, + }); + }} + > + {formsubIndex[field.index] ? ( + + ) : ( + + )} + Topology + + {formsubIndex[field.index] && ( +
+ + +
- - ))} - - - - - - - - - ); - }} + )} + + ))} + + + + + + + +
+ )}