Skip to content

Commit

Permalink
fix: Set default values for traits in VelaUX
Browse files Browse the repository at this point in the history
- 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>
  • Loading branch information
am6737 committed Oct 5, 2024
1 parent 5704854 commit 04e4916
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions packages/velaux-ui/src/components/UISchema/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ class UISchema extends Component<Props, State> {
if (this.props.registerForm) {
this.props.registerForm(this.form);
}
this.initFormValues();
this.state = {
secretKeys: [],
advanced: props.advanced || false,
Expand Down Expand Up @@ -176,6 +177,32 @@ class UISchema extends Component<Props, State> {
});
};

initFormValues = () => {
// Extract default values from the UI schema
const extractDefaultValues = (uiSchema: UIParam[]) => {
const initialValues: Record<string, any> = {};

// Loop through the UI schema and extract default values
uiSchema?.forEach((param: UIParam) => {
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;
Expand Down

0 comments on commit 04e4916

Please sign in to comment.