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 <[email protected]>
  • Loading branch information
am6737 committed Oct 10, 2024
1 parent 5704854 commit a7dc707
Showing 1 changed file with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class AddClusterDialog extends React.Component<Props, State> {
});
}
};

onClose = () => {
this.props.onClose();
this.resetField();
Expand All @@ -69,13 +69,13 @@ class AddClusterDialog extends React.Component<Props, State> {
}
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(<Translation>cluster update success</Translation>);
Expand Down Expand Up @@ -140,7 +140,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 +170,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 +187,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 +204,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 +223,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 +252,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 a7dc707

Please sign in to comment.