From 0ee5c80a374269b61f4186515ddc5338a96d1d8f 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..84ca7bcf8 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: any) => { + const properties = definitionDetail.schema?.properties; + if (properties) { + const defaultValues: Record = {}; + 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 });