Skip to content

Commit

Permalink
fix: Prevent crashes when accessing cluster details
Browse files Browse the repository at this point in the history
- 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>
  • Loading branch information
am6737 committed Oct 4, 2024
1 parent 5704854 commit 5703b22
Showing 1 changed file with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,27 +55,28 @@ class AddClusterDialog extends React.Component<Props, State> {
});
}
};

onClose = () => {
this.props.onClose();
this.resetField();
};

onOk = () => {
const { editMode, cluster } = this.state;
const { editClusterName } = this.props;
this.field.validate((error: any, values: any) => {
if (error) {
return;
}
if (editMode) {
updateCluster({
name: cluster.name,
name: cluster?.name || editClusterName,
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(<Translation>cluster update success</Translation>);
Expand Down Expand Up @@ -140,7 +141,7 @@ class AddClusterDialog extends React.Component<Props, State> {
};
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 (
<Dialog
locale={locale().Dialog}
Expand Down Expand Up @@ -170,7 +171,7 @@ class AddClusterDialog extends React.Component<Props, State> {
name="name"
disabled={editMode}
{...init('name', {
initValue: cluster.name,
initValue: cluster?.name || editClusterName,
rules: [
{
required: true,
Expand All @@ -187,7 +188,7 @@ class AddClusterDialog extends React.Component<Props, State> {
<Input
name="alias"
{...init('alias', {
initValue: cluster.alias,
initValue: cluster?.alias,
rules: [
{
minLength: 2,
Expand All @@ -204,10 +205,10 @@ class AddClusterDialog extends React.Component<Props, State> {
<Col span={12} style={{ padding: '0 8px' }}>
<FormItem label={<Translation>Description</Translation>}>
<Input
defaultValue={cluster.description}
defaultValue={cluster?.description}
name="description"
{...init('description', {
initValue: cluster.description,
initValue: cluster?.description,
rules: [
{
maxLength: 256,
Expand All @@ -223,7 +224,7 @@ class AddClusterDialog extends React.Component<Props, State> {
<Input
name="dashboardURL"
{...init('dashboardURL', {
initValue: cluster.dashboardURL,
initValue: cluster?.dashboardURL,
rules: [
{
required: false,
Expand Down Expand Up @@ -252,7 +253,7 @@ class AddClusterDialog extends React.Component<Props, State> {
language={'yaml'}
readOnly={false}
{...init('kubeConfig', {
initValue: cluster.kubeConfig,
initValue: cluster?.kubeConfig,
rules: [
{
required: true,
Expand Down

0 comments on commit 5703b22

Please sign in to comment.