diff --git a/src/locales/en.json b/src/locales/en.json index 9a71b2e3..63fdb564 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -1394,6 +1394,7 @@ "Placement service:": "Placement service:", "Platform Info": "Platform Info", "Please confirm your password!": "Please confirm your password!", + "Please enter JSON in the correct format!": "Please enter JSON in the correct format!", "Please enter a memory page size, such as: 1024, 1024MB": "Please enter a memory page size, such as: 1024, 1024MB", "Please enter a valid ASCII code": "Please enter a valid ASCII code", "Please enter a valid Email Address!": "Please enter a valid Email Address!", @@ -2100,7 +2101,6 @@ "Virtual LANs": "Virtual LANs", "Virtual Resource Num": "Virtual Resource Num", "Virtual Resource Overview": "Virtual Resource Overview", - "Virtual Size": "Virtual Size", "VirtualAdapter Mac": "VirtualAdapter Mac", "Visibility": "Visibility", "Visualization Compute Optimized Type with GPU": "Visualization Compute Optimized Type with GPU", diff --git a/src/locales/zh.json b/src/locales/zh.json index 615eed53..d570bf97 100644 --- a/src/locales/zh.json +++ b/src/locales/zh.json @@ -1394,6 +1394,7 @@ "Placement service:": "放置服务(placement):", "Platform Info": "平台概况", "Please confirm your password!": "请确认您的密码", + "Please enter JSON in the correct format!": "请输入正确格式的JSON!", "Please enter a memory page size, such as: 1024, 1024MB": "请输入内存页大小,如:1024, 1024MB", "Please enter a valid ASCII code": "请输入有效的ASCII码", "Please enter a valid Email Address!": "请输入一个有效的邮箱地址", @@ -2100,7 +2101,6 @@ "Virtual LANs": "块虚拟网卡", "Virtual Resource Num": "虚拟资源用量", "Virtual Resource Overview": "虚拟资源总览", - "Virtual Size": "虚拟大小", "VirtualAdapter Mac": "虚拟网卡的MAC", "Visibility": "可见性", "Visualization Compute Optimized Type with GPU": "GPU虚拟化型", diff --git a/src/pages/configuration/containers/Setting/actions/Edit.jsx b/src/pages/configuration/containers/Setting/actions/Edit.jsx index 087078b8..a011ecae 100644 --- a/src/pages/configuration/containers/Setting/actions/Edit.jsx +++ b/src/pages/configuration/containers/Setting/actions/Edit.jsx @@ -18,9 +18,7 @@ import globalSettingStore from 'stores/skyline/setting'; import CodeEditor from 'components/CodeEditor'; import { inject, observer } from 'mobx-react'; -@inject('rootStore') -@observer -export default class Edit extends ModalAction { +export class Edit extends ModalAction { get id() { return 'edit'; } @@ -39,6 +37,7 @@ export default class Edit extends ModalAction { init() { this.state.value = this.item.value; + this.state.inputValue = JSON.stringify(this.item.value); } get defaultValue() { @@ -57,6 +56,7 @@ export default class Edit extends ModalAction { } this.setState({ value: realValue, + inputValue: value, }); }; @@ -83,6 +83,17 @@ export default class Edit extends ModalAction { }; } + checkKeyValues = () => { + const { inputValue } = this.state; + try { + JSON.parse(inputValue); + return true; + } catch (e) { + console.log(inputValue, e); + return false; + } + }; + get formItems() { return [ { @@ -95,6 +106,14 @@ export default class Edit extends ModalAction { type: 'other', label: t('Value'), content: this.renderContent(), + validator: () => { + if (!this.checkKeyValues()) { + return Promise.reject( + t('Please enter JSON in the correct format!') + ); + } + return Promise.resolve(); + }, }, ]; } @@ -109,3 +128,5 @@ export default class Edit extends ModalAction { return globalSettingStore.update(body); }; } + +export default inject('rootStore')(observer(Edit)); diff --git a/src/pages/configuration/containers/Setting/actions/View.jsx b/src/pages/configuration/containers/Setting/actions/View.jsx index 48641511..fe2fe83a 100644 --- a/src/pages/configuration/containers/Setting/actions/View.jsx +++ b/src/pages/configuration/containers/Setting/actions/View.jsx @@ -18,9 +18,7 @@ import { inject, observer } from 'mobx-react'; import { onlyAdminCanReadPolicy } from 'resources/policy'; import CodeEditor from 'components/CodeEditor'; -@inject('rootStore') -@observer -export default class View extends ModalAction { +export class View extends ModalAction { get id() { return 'view'; } @@ -97,3 +95,5 @@ export default class View extends ModalAction { onSubmit = null; } + +export default inject('rootStore')(observer(View)); diff --git a/src/pages/configuration/containers/Setting/index.jsx b/src/pages/configuration/containers/Setting/index.jsx index 1639a79f..d9b81b8a 100644 --- a/src/pages/configuration/containers/Setting/index.jsx +++ b/src/pages/configuration/containers/Setting/index.jsx @@ -18,9 +18,7 @@ import globalSettingStore from 'stores/skyline/setting'; import { onlyAdminCanReadPolicy } from 'resources/policy'; import actionConfigs from './actions'; -@inject('rootStore') -@observer -export default class Setting extends Base { +export class Setting extends Base { init() { this.store = globalSettingStore; } @@ -63,3 +61,5 @@ export default class Setting extends Base { return []; } } + +export default inject('rootStore')(observer(Setting));