From 33314664b3f4b0435d74ca99d5db3ff22c8a94a3 Mon Sep 17 00:00:00 2001 From: am6737 <1359816810@qq.com> Date: Sat, 5 Oct 2024 02:04:53 +0800 Subject: [PATCH] fix: Set default values for traits in VelaUX - Addressed the issue where default values for traits (including "cpuscaler", "hpa", "resource", "k8s-update-strategy") were not being set properly. Signed-off-by: am6737 <1359816810@qq.com> --- .../src/components/UISchema/index.tsx | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/packages/velaux-ui/src/components/UISchema/index.tsx b/packages/velaux-ui/src/components/UISchema/index.tsx index 0b601c6e..4a8d7dee 100644 --- a/packages/velaux-ui/src/components/UISchema/index.tsx +++ b/packages/velaux-ui/src/components/UISchema/index.tsx @@ -134,6 +134,7 @@ class UISchema extends Component { if (this.props.registerForm) { this.props.registerForm(this.form); } + this.initFormValues(); this.state = { secretKeys: [], advanced: props.advanced || false, @@ -176,6 +177,32 @@ class UISchema extends Component { }); }; + initFormValues = () => { + // Extract default values from the UI schema + const extractDefaultValues = (uiSchema) => { + const initialValues = {}; + + // Loop through the UI schema and extract default values + uiSchema?.forEach((param) => { + if (param.validate?.defaultValue !== undefined) { + initialValues[param.jsonKey] = param.validate.defaultValue; + } + }); + + return initialValues; + }; + + const defaultValues = extractDefaultValues(this.props.uiSchema); + + // Initialize the form with default values + if (defaultValues) { + const { onChange } = this.props; + if (onChange) { + onChange(defaultValues); + } + } + }; + conditionAllowRender = (conditions?: ParamCondition[]) => { if (!conditions || conditions.length == 0) { return true;