mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Catch YAML parse errors, show spinner while debouncing
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
bac2d6e2ac
commit
a711200b27
@ -23,13 +23,14 @@ import path from "path";
|
|||||||
|
|
||||||
export class ExecValidationNotFoundError extends Error {
|
export class ExecValidationNotFoundError extends Error {
|
||||||
constructor(execPath: string) {
|
constructor(execPath: string) {
|
||||||
super(`User Exec command "${execPath}" not found on host.`);
|
|
||||||
let message = `User Exec command "${execPath}" not found on host.`;
|
let message = `User Exec command "${execPath}" not found on host.`;
|
||||||
|
|
||||||
if (!path.isAbsolute(execPath)) {
|
if (!path.isAbsolute(execPath)) {
|
||||||
message += ` Please ensure binary is found in PATH or use absolute path to binary in Kubeconfig`;
|
message += ` Please ensure binary is found in PATH or use absolute path to binary in Kubeconfig`;
|
||||||
}
|
}
|
||||||
this.message = message;
|
|
||||||
|
super(message);
|
||||||
|
|
||||||
this.name = this.constructor.name;
|
this.name = this.constructor.name;
|
||||||
Error.captureStackTrace(this, this.constructor);
|
Error.captureStackTrace(this, this.constructor);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -50,4 +50,11 @@
|
|||||||
display: block;
|
display: block;
|
||||||
padding-top: 6px;
|
padding-top: 6px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.actions-panel {
|
||||||
|
.Spinner {
|
||||||
|
vertical-align: middle;
|
||||||
|
margin-left: $spacing;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,7 +24,7 @@ import "./add-cluster.scss";
|
|||||||
import type { KubeConfig } from "@kubernetes/client-node";
|
import type { KubeConfig } from "@kubernetes/client-node";
|
||||||
import fse from "fs-extra";
|
import fse from "fs-extra";
|
||||||
import { debounce } from "lodash";
|
import { debounce } from "lodash";
|
||||||
import { action, computed, observable, makeObservable } from "mobx";
|
import { action, computed, observable, makeObservable, runInAction } from "mobx";
|
||||||
import { observer } from "mobx-react";
|
import { observer } from "mobx-react";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
@ -41,6 +41,7 @@ import { SettingLayout } from "../layout/setting-layout";
|
|||||||
import MonacoEditor from "react-monaco-editor";
|
import MonacoEditor from "react-monaco-editor";
|
||||||
import { ThemeStore } from "../../theme.store";
|
import { ThemeStore } from "../../theme.store";
|
||||||
import { UserStore } from "../../../common/user-store";
|
import { UserStore } from "../../../common/user-store";
|
||||||
|
import { Spinner } from "../spinner";
|
||||||
|
|
||||||
interface Option {
|
interface Option {
|
||||||
config: KubeConfig;
|
config: KubeConfig;
|
||||||
@ -62,6 +63,7 @@ export class AddCluster extends React.Component {
|
|||||||
@observable kubeContexts = observable.map<string, Option>();
|
@observable kubeContexts = observable.map<string, Option>();
|
||||||
@observable customConfig = "";
|
@observable customConfig = "";
|
||||||
@observable isWaiting = false;
|
@observable isWaiting = false;
|
||||||
|
@observable isCheckingInput = false;
|
||||||
@observable errorText: string;
|
@observable errorText: string;
|
||||||
|
|
||||||
constructor(props: {}) {
|
constructor(props: {}) {
|
||||||
@ -80,14 +82,35 @@ export class AddCluster extends React.Component {
|
|||||||
].filter(Boolean);
|
].filter(Boolean);
|
||||||
}
|
}
|
||||||
|
|
||||||
@action
|
_refreshContexts = debounce(() => {
|
||||||
refreshContexts = debounce(() => {
|
runInAction(() => {
|
||||||
const { config, error } = loadConfigFromString(this.customConfig.trim() || "{}");
|
try {
|
||||||
|
const text = this.customConfig.trim();
|
||||||
|
|
||||||
this.kubeContexts.replace(getContexts(config));
|
if (!text) {
|
||||||
this.errorText = error?.toString();
|
return this.kubeContexts.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
const { config, error } = loadConfigFromString(text);
|
||||||
|
|
||||||
|
this.kubeContexts.replace(getContexts(config));
|
||||||
|
this.errorText = error?.toString();
|
||||||
|
} catch (error) {
|
||||||
|
this.kubeContexts.clear();
|
||||||
|
this.errorText = error?.toString() || "An error occured";
|
||||||
|
} finally {
|
||||||
|
this.isCheckingInput = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
}, 500);
|
}, 500);
|
||||||
|
|
||||||
|
refreshContexts = () => {
|
||||||
|
// Clear the kubeContexts immediately
|
||||||
|
this.isCheckingInput = true;
|
||||||
|
this.kubeContexts.clear();
|
||||||
|
this._refreshContexts();
|
||||||
|
};
|
||||||
|
|
||||||
@action
|
@action
|
||||||
addClusters = async () => {
|
addClusters = async () => {
|
||||||
this.isWaiting = true;
|
this.isWaiting = true;
|
||||||
@ -145,6 +168,7 @@ export class AddCluster extends React.Component {
|
|||||||
tooltip={this.kubeContexts.size === 0 || "Paste in at least one cluster to add."}
|
tooltip={this.kubeContexts.size === 0 || "Paste in at least one cluster to add."}
|
||||||
tooltipOverrideDisabled
|
tooltipOverrideDisabled
|
||||||
/>
|
/>
|
||||||
|
{this.isCheckingInput && <Spinner />}
|
||||||
</div>
|
</div>
|
||||||
</SettingLayout>
|
</SettingLayout>
|
||||||
);
|
);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user