1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Add error message for no contexts in add cluster page (#3868)

This commit is contained in:
Sebastian Malton 2021-09-22 07:25:48 -07:00 committed by GitHub
parent 49e8b9cc0a
commit 3fc5b83461
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -62,7 +62,7 @@ export class AddCluster extends React.Component {
@observable kubeContexts = observable.map<string, Option>();
@observable customConfig = "";
@observable isWaiting = false;
@observable errorText: string;
@observable errors: string[] = [];
constructor(props: {}) {
super(props);
@ -75,7 +75,7 @@ export class AddCluster extends React.Component {
@computed get allErrors(): string[] {
return [
this.errorText,
...this.errors,
...iter.map(this.kubeContexts.values(), ({ error }) => error)
].filter(Boolean);
}
@ -85,7 +85,14 @@ export class AddCluster extends React.Component {
const { config, error } = loadConfigFromString(this.customConfig.trim() || "{}");
this.kubeContexts.replace(getContexts(config));
this.errorText = error?.toString();
if (error) {
this.errors.push(error.toString());
}
if (config.contexts.length === 0) {
this.errors.push('No contexts defined, either missing the "contexts" field, or it is empty.');
}
}, 500);
@action
@ -124,7 +131,7 @@ export class AddCluster extends React.Component {
value={this.customConfig}
onChange={value => {
this.customConfig = value;
this.errorText = "";
this.errors.length = 0;
this.refreshContexts();
}}
/>