From 744af1334e64f2d044eaa79962ed401527a368dc Mon Sep 17 00:00:00 2001 From: am6737 <1359816810@qq.com> Date: Sat, 5 Oct 2024 14:28:39 +0800 Subject: [PATCH] fix: Set default values for traits in VelaUX Added `setDefaultProperties` to ensure default values are correctly set for traits like "cpuscaler", "hpa", "resource", and "k8s-update-strategy". Signed-off-by: am6737 <1359816810@qq.com> --- .../components/TraitDialog/index.tsx | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/packages/velaux-ui/src/pages/ApplicationConfig/components/TraitDialog/index.tsx b/packages/velaux-ui/src/pages/ApplicationConfig/components/TraitDialog/index.tsx index cb19bfd28..92977630f 100644 --- a/packages/velaux-ui/src/pages/ApplicationConfig/components/TraitDialog/index.tsx +++ b/packages/velaux-ui/src/pages/ApplicationConfig/components/TraitDialog/index.tsx @@ -195,14 +195,28 @@ class TraitDialog extends React.Component { .then((re) => { if (re) { this.setState({ definitionDetail: re, definitionLoading: false }); - if (callback) { - callback(); - } + this.setDefaultProperties(re) + if (callback) { + callback(); + } } }) .catch(() => this.setState({ definitionLoading: false })); }; + setDefaultProperties = (definitionDetail: DefinitionDetail) => { + const properties = definitionDetail.schema?.properties; + if (properties) { + const defaultValues = {}; + for (const key in properties) { + if (properties[key].default !== undefined) { + defaultValues[key] = properties[key].default; + } + } + this.field.setValues({ properties: defaultValues }); + } + }; + handleTypeChange = (value: string) => { this.removeProperties(); this.field.setValues({ type: value });