diff --git a/react-ui/src/pages/AutoML/components/CreateForm/TrialConfig.tsx b/react-ui/src/pages/AutoML/components/CreateForm/TrialConfig.tsx
index 0d8008fb..6a965e9a 100644
--- a/react-ui/src/pages/AutoML/components/CreateForm/TrialConfig.tsx
+++ b/react-ui/src/pages/AutoML/components/CreateForm/TrialConfig.tsx
@@ -1,6 +1,6 @@
import SubAreaTitle from '@/components/SubAreaTitle';
import { AutoMLTaskType } from '@/enums';
-import { modalConfirm } from '@/utils/ui';
+import { removeFormListItem } from '@/utils/ui';
import { MinusCircleOutlined, PlusCircleOutlined } from '@ant-design/icons';
import { Button, Col, Flex, Form, Input, InputNumber, Radio, Row, Select } from 'antd';
import { classificationMetrics, regressionMetrics } from './ExecuteConfig';
@@ -72,12 +72,14 @@ function TrialConfig() {
type="text"
icon={}
onClick={() => {
- modalConfirm({
- title: '确定要删除该指标权重吗?',
- onOk: () => {
- remove(name);
- },
- });
+ removeFormListItem(
+ form,
+ 'metrics',
+ name,
+ remove,
+ ['name', 'value'],
+ '删除后,该该指标权重将不可恢复',
+ );
}}
>
{index === fields.length - 1 && (
diff --git a/react-ui/src/pages/HyperParameter/components/CreateForm/ExecuteConfig.tsx b/react-ui/src/pages/HyperParameter/components/CreateForm/ExecuteConfig.tsx
index 976b6467..cbd97448 100644
--- a/react-ui/src/pages/HyperParameter/components/CreateForm/ExecuteConfig.tsx
+++ b/react-ui/src/pages/HyperParameter/components/CreateForm/ExecuteConfig.tsx
@@ -8,7 +8,7 @@ import SubAreaTitle from '@/components/SubAreaTitle';
import { hyperParameterOptimizedModeOptions } from '@/enums';
import { useComputingResource } from '@/hooks/resource';
import { isEmpty } from '@/utils';
-import { modalConfirm } from '@/utils/ui';
+import { modalConfirm, removeFormListItem } from '@/utils/ui';
import { MinusCircleOutlined, PlusCircleOutlined, QuestionCircleOutlined } from '@ant-design/icons';
import {
Button,
@@ -396,12 +396,14 @@ function ExecuteConfig() {
size="middle"
icon={}
onClick={() => {
- modalConfirm({
- title: '确定要删除该参数吗?',
- onOk: () => {
- remove(name);
- },
- });
+ removeFormListItem(
+ form,
+ 'parameters',
+ name,
+ remove,
+ ['name', 'type'],
+ '删除后,该参数将不可恢复',
+ );
}}
>
{index === fields.length - 1 && (
@@ -460,7 +462,7 @@ function ExecuteConfig() {
);
if (arr.length > 0 && arr.length < runParameters.length) {
return Promise.reject(
- new Error(`手动运行超参数 ${name} 必须全部填写或者都不填写`),
+ new Error(`手动运行超参数 "${name}" 必须全部填写或者都不填写`),
);
}
}
@@ -518,7 +520,8 @@ function ExecuteConfig() {
icon={}
onClick={() => {
modalConfirm({
- title: '确定要删除该运行参数吗?',
+ title: '删除后,该运行参数将不可恢复',
+ content: '是否确认删除?',
onOk: () => {
remove(name);
},
diff --git a/react-ui/src/pages/HyperParameter/components/CreateForm/ParameterRange/index.tsx b/react-ui/src/pages/HyperParameter/components/CreateForm/ParameterRange/index.tsx
index 43cd25f2..d33fcf13 100644
--- a/react-ui/src/pages/HyperParameter/components/CreateForm/ParameterRange/index.tsx
+++ b/react-ui/src/pages/HyperParameter/components/CreateForm/ParameterRange/index.tsx
@@ -68,7 +68,7 @@ function ParameterRange({ type, value, onConfirm }: ParameterRangeProps) {
(
-
+
- =
+ =
-
+
}
disabled={disabled}
onClick={() => {
- modalConfirm({
- title: '确定要删除该环境变量吗?',
- onOk: () => {
- remove(name);
- },
- });
+ removeFormListItem(
+ form,
+ 'env_variables',
+ name,
+ remove,
+ ['key', 'value'],
+ '删除后,该环境变量将不可恢复',
+ );
}}
>
{index === fields.length - 1 && (
diff --git a/react-ui/src/pages/Pipeline/components/GlobalParamsDrawer/index.tsx b/react-ui/src/pages/Pipeline/components/GlobalParamsDrawer/index.tsx
index e54894ea..f1aa57c9 100644
--- a/react-ui/src/pages/Pipeline/components/GlobalParamsDrawer/index.tsx
+++ b/react-ui/src/pages/Pipeline/components/GlobalParamsDrawer/index.tsx
@@ -40,7 +40,8 @@ const GlobalParamsDrawer = forwardRef(
const removeParameter = (name: number, remove: (param: number) => void) => {
modalConfirm({
- title: '确认删除该参数吗?',
+ title: '删除后,该全局参数将不可恢复',
+ content: '是否确认删除?',
onOk: () => {
remove(name);
},
diff --git a/react-ui/src/utils/ui.tsx b/react-ui/src/utils/ui.tsx
index a3a214ec..d9953a3e 100644
--- a/react-ui/src/utils/ui.tsx
+++ b/react-ui/src/utils/ui.tsx
@@ -8,7 +8,16 @@ import { removeAllPageCacheState } from '@/hooks/pageCacheState';
import themes from '@/styles/theme.less';
import { type ClientInfo } from '@/types';
import { history } from '@umijs/max';
-import { Modal, Upload, message, type ModalFuncProps, type UploadFile } from 'antd';
+import {
+ Modal,
+ Upload,
+ message,
+ type FormInstance,
+ type ModalFuncProps,
+ type UploadFile,
+} from 'antd';
+import { NamePath } from 'antd/es/form/interface';
+import { isEmpty } from './index';
import { closeAllModals } from './modal';
import SessionStorage from './sessionStorage';
@@ -143,16 +152,38 @@ export const limitUploadFileType = (type: string) => {
};
/**
- * 滚动到底部
- *
- * @param {boolean} smooth - Determines if the scroll should be smooth
+ * 删除 FormList 表单项,如果表单项没有值,则直接删除,否则弹出确认框
+ * @param form From实例
+ * @param listName FormList 的 name
+ * @param name FormList 的其中一项
+ * @param remove FormList 的删除方法
+ * @param fieldNames FormList 的子项名称数组
+ * @param confirmTitle 弹出确认框的标题
*/
-export const scrollToBottom = (element: HTMLElement | null, smooth: boolean = true) => {
- if (element) {
- const optons: ScrollToOptions = {
- top: element.scrollHeight,
- behavior: smooth ? 'smooth' : 'instant',
- };
- element.scrollTo(optons);
+export const removeFormListItem = (
+ form: FormInstance,
+ listName: NamePath,
+ name: number,
+ remove: (name: number) => void,
+ fieldNames: NamePath[],
+ confirmTitle: string,
+) => {
+ const fields = fieldNames.map((item) => [listName, name, item].flat());
+ const isEmptyField = fields.every((item) => {
+ const value = form.getFieldValue(item);
+ return isEmpty(value);
+ });
+
+ if (isEmptyField) {
+ remove(name);
+ return;
}
+
+ modalConfirm({
+ title: confirmTitle,
+ content: '是否确认删除?',
+ onOk: () => {
+ remove(name);
+ },
+ });
};