Merge "feat: update creating heat stack"

This commit is contained in:
Zuul 2024-04-17 05:41:09 +00:00 committed by Gerrit Code Review
commit 35f57c4c25
2 changed files with 35 additions and 4 deletions

View File

@ -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') },

View File

@ -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;