diff --git a/src/api/application.ts b/src/api/application.ts index f06e0ce59..0b09aa470 100644 --- a/src/api/application.ts +++ b/src/api/application.ts @@ -134,7 +134,7 @@ export function createApplicationEnv(params: { appName?: string }) { return post(gurl, params).then((res) => res); } -export function updateApplicationEnv(params: { appName?: string, name: string }) { +export function updateApplicationEnv(params: { appName?: string; name: string }) { const gurl = isMock ? `${updateApplicationEnv_mock}` : `${application}/${params.appName}/envs/${name}`; diff --git a/src/api/devLink.ts b/src/api/devLink.ts index 3fcdf0034..7908b9854 100644 --- a/src/api/devLink.ts +++ b/src/api/devLink.ts @@ -37,4 +37,4 @@ export const getTrait_mock = '/mock/getTrait.json'; export const listWorkFlowDefintion_mock = '/mock/listWorkFlowDefintion.json'; export const listWorkFlowDetailsDefintion_mock = '/mock/listWorkFlowDetailsDefintion.json'; -export const updateApplicationEnv_mock = `/mock/api/v1/applications/name/envs/envName` +export const updateApplicationEnv_mock = `/mock/api/v1/applications/name/envs/envName`; diff --git a/src/components/UISchema/index.tsx b/src/components/UISchema/index.tsx index 8af4bf3bc..28b9cf3b4 100644 --- a/src/components/UISchema/index.tsx +++ b/src/components/UISchema/index.tsx @@ -249,7 +249,15 @@ class UISchema extends Component { description={{param.description || ''}} title={{param.label || ''}} closed={true} - key={param.jsonKey} + required={param.validate && param.validate.required} + field={this.form} + jsonKey={param.jsonKey || ''} + propertyValue={this.props.value} + onChange={(values) => { + if (this.props.onChange) { + this.props.onChange(values); + } + }} > { description={{param.description || ''}} title={{param.label || ''}} closed={true} - key={param.jsonKey} + required={param.validate && param.validate.required} + field={this.form} + jsonKey={param.jsonKey || ''} + propertyValue={this.props.value} + onChange={(values) => { + if (this.props.onChange) { + this.props.onChange(values); + } + }} > { title={{param.label || ''}} closed={true} required={param.validate && param.validate.required} + field={this.form} + jsonKey={param.jsonKey || ''} + propertyValue={this.props.value} + onChange={(values) => { + if (this.props.onChange) { + this.props.onChange(values); + } + }} > { description={{param.description || ''}} title={{param.label || ''}} closed={true} + required={param.validate && param.validate.required} + field={this.form} + jsonKey={param.jsonKey || ''} + propertyValue={this.props.value} + onChange={(values) => { + if (this.props.onChange) { + this.props.onChange(values); + } + }} > void; }; type State = { closed: boolean | undefined; enable?: boolean; + checked: boolean; }; class Group extends React.Component { @@ -28,6 +34,7 @@ class Group extends React.Component { this.state = { closed: props.closed, enable: props.required, + checked: false, }; } @@ -37,9 +44,34 @@ class Group extends React.Component { closed: !closed, }); }; + + componentDidMount() { + this.initSwitchState(); + } + + initSwitchState = () => { + const { jsonKey = '', propertyValue = {} } = this.props; + const findKey = Object.keys(propertyValue).find((item) => item === jsonKey); + if (findKey) { + this.setState({ enable: true, closed: false, checked: true }); + } else { + this.setState({ enable: false, closed: false, checked: false }); + } + }; + + removeJsonKeyValue() { + const { jsonKey = '', onChange } = this.props; + const field: Field | undefined = this.props.field; + if (field && onChange) { + field.remove(jsonKey); + const values = field.getValues(); + onChange(values); + } + } + render() { const { title, description, children, hasToggleIcon, loading, required } = this.props; - const { closed, enable } = this.state; + const { closed, enable, checked } = this.state; return (
@@ -53,8 +85,27 @@ class Group extends React.Component { { - this.setState({ enable: event, closed: false }); + if (event === true) { + this.setState({ enable: event, closed: false, checked: true }); + } else if (event === false) { + Dialog.confirm({ + type: 'confirm', + content: ( + + If Swtich is turned off, The configuration will be reset. Are you sure + you want to do this? + + ), + onOk: () => { + this.setState({ enable: event, closed: false, checked: false }); + this.removeJsonKeyValue(); + }, + locale: locale.Dialog, + }); + } }} /> diff --git a/src/locals/Zh/zh.json b/src/locals/Zh/zh.json index fa56a9229..b480ea95f 100644 --- a/src/locals/Zh/zh.json +++ b/src/locals/Zh/zh.json @@ -37,7 +37,7 @@ "Reset": "重置", "Please enter": "请输入", "Project Screening": "所属项目筛选", - "Target Screening":"交付目标筛选", + "Target Screening": "交付目标筛选", "Application name, description and search": "名称、描述模糊搜索", "App Name": "应用名称", "App Name-": "应用名称-", @@ -181,4 +181,4 @@ "Please select the action you want to perform": "请选择您期望的动作执行?", "Continue": "继续", "Termination": "终止" -} \ No newline at end of file +}