Skip to content

Commit

Permalink
fix(core): fix npe on first project cluster creation (#7673) (#7675)
Browse files Browse the repository at this point in the history
  • Loading branch information
spinnakerbot authored and Travis Tomsu committed Dec 9, 2019
1 parent 137f539 commit 12edf0a
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions app/scripts/modules/core/src/projects/configure/Clusters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ export class Clusters extends React.Component<IClustersProps> implements IWizard
errors.applications = applicationErrors;
}

const areStackAndDetailDisabled = this.areStackAndDetailDisabled(cluster);
errors.stack = areStackAndDetailDisabled && cluster.stack !== '*' && 'Only * is valid for the selected account';
errors.detail =
areStackAndDetailDisabled && cluster.detail !== '*' && 'Only * is valid for the selected account';

return Object.keys(errors).length ? errors : null;
});

Expand All @@ -51,6 +56,9 @@ export class Clusters extends React.Component<IClustersProps> implements IWizard
}

private areStackAndDetailDisabled(cluster: IProjectCluster): boolean {
if (!cluster || !cluster.account) {
return false;
}
const account = this.props.accounts.find(({ name }) => name === cluster.account);
return account.type === 'kubernetes' && account.providerVersion === 'v2';
}
Expand Down Expand Up @@ -92,7 +100,6 @@ export class Clusters extends React.Component<IClustersProps> implements IWizard
{clusters.map((cluster, idx) => {
const clusterPath = `config.clusters[${idx}]`;
const applicationsPath = `${clusterPath}.applications`;
const areStackAndDetailDisabled = this.areStackAndDetailDisabled(cluster);

return (
<tr key={idx}>
Expand Down Expand Up @@ -124,26 +131,14 @@ export class Clusters extends React.Component<IClustersProps> implements IWizard
<td>
<FormikFormField
name={`${clusterPath}.stack`}
input={props => (
<TextInput
{...props}
disabled={areStackAndDetailDisabled}
inputClassName="sp-padding-xs-xaxis"
/>
)}
input={props => <TextInput {...props} inputClassName="sp-padding-xs-xaxis" />}
/>
</td>

<td>
<FormikFormField
name={`${clusterPath}.detail`}
input={props => (
<TextInput
{...props}
disabled={areStackAndDetailDisabled}
inputClassName="sp-padding-xs-xaxis"
/>
)}
input={props => <TextInput {...props} inputClassName="sp-padding-xs-xaxis" />}
/>
</td>

Expand Down

0 comments on commit 12edf0a

Please sign in to comment.