From a7dc707c36ca3ec73daf005a798352672e279f9c Mon Sep 17 00:00:00 2001 From: am6737 <1359816810@qq.com> Date: Fri, 4 Oct 2024 18:04:27 +0800 Subject: [PATCH] fix: Prevent crashes when accessing cluster details - Added optional chaining to safely access cluster details in `AddClusterDialog`. This fix addresses the issue where the page crashes when trying to load details for an inaccessible cluster. Signed-off-by: am6737 <1359816810@qq.com> --- .../components/AddClusterDialog/index.tsx | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/velaux-ui/src/pages/Cluster/components/AddClusterDialog/index.tsx b/packages/velaux-ui/src/pages/Cluster/components/AddClusterDialog/index.tsx index 50f54acbd..d32a78cf2 100644 --- a/packages/velaux-ui/src/pages/Cluster/components/AddClusterDialog/index.tsx +++ b/packages/velaux-ui/src/pages/Cluster/components/AddClusterDialog/index.tsx @@ -55,7 +55,7 @@ class AddClusterDialog extends React.Component { }); } }; - + onClose = () => { this.props.onClose(); this.resetField(); @@ -69,13 +69,13 @@ class AddClusterDialog extends React.Component { } if (editMode) { updateCluster({ - name: cluster.name, + name: cluster?.name, alias: values.alias, - icon: cluster.icon, + icon: cluster?.icon, description: values.description, dashboardURL: values.dashboardURL, kubeConfig: values.kubeConfig, - labels: cluster.labels, + labels: cluster?.labels, }).then((re: any) => { if (re) { Message.success(cluster update success); @@ -140,7 +140,7 @@ class AddClusterDialog extends React.Component { }; const init = this.field.init; const values: { kubeConfig: string } = this.field.getValues(); - const valueInfo = cluster.kubeConfig || values.kubeConfig || ''; + const valueInfo = cluster?.kubeConfig || values.kubeConfig || ''; return ( { name="name" disabled={editMode} {...init('name', { - initValue: cluster.name, + initValue: cluster?.name || editClusterName, rules: [ { required: true, @@ -187,7 +187,7 @@ class AddClusterDialog extends React.Component { { Description}> { { language={'yaml'} readOnly={false} {...init('kubeConfig', { - initValue: cluster.kubeConfig, + initValue: cluster?.kubeConfig, rules: [ { required: true,