From 952543f5aedd07ddd5f1fe7d985c65267a785db7 Mon Sep 17 00:00:00 2001 From: zhangjingwei Date: Wed, 17 Apr 2024 11:08:47 +0800 Subject: [PATCH] feat: update creating heat stack When the parameters in the second step are changed, the contents of the environment variables in the first step are updated simultaneously. Change-Id: I619ec9ada74c5040bdb234f375651c8b053db79b --- .../Stack/actions/Create/Parameter.jsx | 19 ++++++++++++++++++ src/resources/heat/stack.js | 20 +++++++++++++++---- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/src/pages/heat/containers/Stack/actions/Create/Parameter.jsx b/src/pages/heat/containers/Stack/actions/Create/Parameter.jsx index a52a0d13..0044b328 100644 --- a/src/pages/heat/containers/Stack/actions/Create/Parameter.jsx +++ b/src/pages/heat/containers/Stack/actions/Create/Parameter.jsx @@ -20,7 +20,9 @@ import { getFormDefaultValues, getTemplate, rollbackTip, + getParamsFromContent, } from 'resources/heat/stack'; +import { getValue } from 'utils/yaml'; export class Parameter extends Base { get isStep() { @@ -71,6 +73,23 @@ export class Parameter extends Base { return getFormItems(this.template); } + updateParamsInContext = (key, value) => { + const { params = '' } = this.props.context || {}; + const newParams = !params ? { parameters: {} } : getYaml(params); + newParams.parameters[key] = value; + this.updateContext({ params: getValue(newParams) }); + }; + + onValuesChange = (changedFields) => { + const params = getParamsFromContent(this.template); + const keys = Object.keys(params); + Object.keys(changedFields).forEach((key) => { + if (keys.includes(key)) { + this.updateParamsInContext(key, changedFields[key]); + } + }); + }; + get rollbackOptions() { return [ { value: true, label: t('Enable') }, diff --git a/src/resources/heat/stack.js b/src/resources/heat/stack.js index 85a44b8a..210af26d 100644 --- a/src/resources/heat/stack.js +++ b/src/resources/heat/stack.js @@ -13,7 +13,7 @@ // limitations under the License. import yaml from 'js-yaml'; -import { has, isObject } from 'lodash'; +import { has, isEmpty, isObject } from 'lodash'; import { yesNoOptions } from 'utils/constants'; export const stackStatus = { @@ -114,14 +114,26 @@ export const getFormItemType = (type) => { } }; -export const getFormItems = (contentYaml) => { - const formItems = []; +export const getParamsFromContent = (contentYaml) => { try { const content = yaml.load(contentYaml); if (!isObject(content)) { - return formItems; + return {}; } const params = content.parameters; + return params || {}; + } catch { + return {}; + } +}; + +export const getFormItems = (contentYaml) => { + const formItems = []; + try { + const params = getParamsFromContent(contentYaml); + if (isEmpty(params)) { + return formItems; + } Object.keys(params).forEach((key) => { const value = params[key]; const { type = 'string', description = '', label, hidden } = value;