fix: resource label value validation

This commit is contained in:
jialin
2024-09-14 19:49:22 +08:00
parent 0adca93d5c
commit 1fe42a6eda
6 changed files with 34 additions and 4 deletions
+1 -1
View File
@@ -46,7 +46,7 @@ export default {
'common.button.disabled': 'Disabled', 'common.button.disabled': 'Disabled',
'common.button.upgrade': 'Upgrade', 'common.button.upgrade': 'Upgrade',
'common.input.holder': 'Please enter', 'common.input.holder': 'Please enter',
'common.validate.value': 'value is required', 'common.validate.value': '{name} value is required',
'common.button.edit': 'Edit', 'common.button.edit': 'Edit',
'common.button.authorize': 'Role Authorization', 'common.button.authorize': 'Role Authorization',
'common.button.confirm': 'Confirm', 'common.button.confirm': 'Confirm',
+1
View File
@@ -8,6 +8,7 @@ export default {
'resources.table.labels': 'Labels', 'resources.table.labels': 'Labels',
'resources.table.hostname': 'Hostname', 'resources.table.hostname': 'Hostname',
'resources.table.key.tips': 'The same key exists.', 'resources.table.key.tips': 'The same key exists.',
'resources.form.label': 'Label',
'resources.form.advanced': 'Advanced', 'resources.form.advanced': 'Advanced',
'resources.form.enablePartialOffload': 'Allow CPU Offloading', 'resources.form.enablePartialOffload': 'Allow CPU Offloading',
'resources.form.placementStrategy': 'Placement Strategy', 'resources.form.placementStrategy': 'Placement Strategy',
+1 -1
View File
@@ -109,7 +109,7 @@ export default {
'common.ws.reconnect': '重新连接', 'common.ws.reconnect': '重新连接',
'common.input.key': '键', 'common.input.key': '键',
'common.input.value': '值', 'common.input.value': '值',
'common.validate.value': '值必填', 'common.validate.value': '{name}值必填',
'common.input.type': '类型', 'common.input.type': '类型',
'common.input.visible': '是否可见', 'common.input.visible': '是否可见',
'common.input.description': '描述', 'common.input.description': '描述',
+1
View File
@@ -7,6 +7,7 @@ export default {
'resources.nodes': '节点', 'resources.nodes': '节点',
'resources.table.hostname': '主机名', 'resources.table.hostname': '主机名',
'resources.table.key.tips': '存在相同的 key.', 'resources.table.key.tips': '存在相同的 key.',
'resources.form.label': '标签',
'resources.table.labels': '标签', 'resources.table.labels': '标签',
'resources.form.advanced': '高级', 'resources.form.advanced': '高级',
'resources.form.enablePartialOffload': '允许 CPU 卸载', 'resources.form.enablePartialOffload': '允许 CPU 卸载',
@@ -146,7 +146,9 @@ const AdvanceConfig: React.FC<AdvanceConfigProps> = (props) => {
id: 'common.validate.value' id: 'common.validate.value'
}, },
{ {
name: 'models.form.selector' name: intl.formatMessage({
id: 'models.form.selector'
})
} }
) )
); );
@@ -3,6 +3,7 @@ import ModalFooter from '@/components/modal-footer';
import SealInput from '@/components/seal-form/seal-input'; import SealInput from '@/components/seal-form/seal-input';
import { useIntl } from '@umijs/max'; import { useIntl } from '@umijs/max';
import { Form, Modal } from 'antd'; import { Form, Modal } from 'antd';
import _ from 'lodash';
import React from 'react'; import React from 'react';
import SimpleBar from 'simplebar-react'; import SimpleBar from 'simplebar-react';
import 'simplebar-react/dist/simplebar.min.css'; import 'simplebar-react/dist/simplebar.min.css';
@@ -93,7 +94,32 @@ const UpdateLabels: React.FC<ViewModalProps> = (props) => {
disabled disabled
/> />
</Form.Item> </Form.Item>
<Form.Item<FormData> name="labels"> <Form.Item<FormData>
name="labels"
rules={[
() => ({
validator(rule, value) {
if (_.keys(value).length > 0) {
if (_.some(_.keys(value), (k: string) => !value[k])) {
return Promise.reject(
intl.formatMessage(
{
id: 'common.validate.value'
},
{
name: intl.formatMessage({
id: 'resources.form.label'
})
}
)
);
}
}
return Promise.resolve();
}
})
]}
>
<LabelSelector <LabelSelector
label={intl.formatMessage({ label={intl.formatMessage({
id: 'resources.table.labels' id: 'resources.table.labels'