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

Reconnecting selected cluster

Signed-off-by: alexfront <alex.andreev.email@gmail.com>
This commit is contained in:
alexfront 2020-08-13 15:56:24 +03:00
parent 93616763df
commit 76ef892a3a
5 changed files with 31 additions and 33 deletions

View File

@ -84,7 +84,7 @@ export class ClusterStore extends BaseStore<ClusterStoreModel> {
} }
isActive(id: ClusterId) { isActive(id: ClusterId) {
return this.activeCluster.id === id; return this.activeClusterId === id;
} }
setActive(id: ClusterId) { setActive(id: ClusterId) {

View File

@ -16,6 +16,7 @@ import { getMatchedCluster } from "../cluster-manager/cluster-view.route";
export class ClusterSettings extends React.Component { export class ClusterSettings extends React.Component {
render() { render() {
const cluster = getMatchedCluster(); const cluster = getMatchedCluster();
if (!cluster) return null;
const header = ( const header = (
<> <>
<ClusterIcon <ClusterIcon

View File

@ -13,7 +13,6 @@ interface Props {
export class AppInit extends React.Component<Props> { export class AppInit extends React.Component<Props> {
static async start(rootElem: HTMLElement) { static async start(rootElem: HTMLElement) {
render(<AppInit/>, rootElem); // show loading indicator asap render(<AppInit/>, rootElem); // show loading indicator asap
await AppInit.readyStateCheck(rootElem); // wait while all good to run await AppInit.readyStateCheck(rootElem); // wait while all good to run
} }

View File

@ -11,6 +11,7 @@ import { Button } from "../button";
import { cssNames, IClassName } from "../../utils"; import { cssNames, IClassName } from "../../utils";
import { Cluster } from "../../../main/cluster"; import { Cluster } from "../../../main/cluster";
import { ClusterId, clusterStore } from "../../../common/cluster-store"; import { ClusterId, clusterStore } from "../../../common/cluster-store";
import { CubeSpinner } from "../spinner";
interface Props { interface Props {
className?: IClassName; className?: IClassName;
@ -31,17 +32,13 @@ export class ClusterStatus extends React.Component<Props> {
} }
async componentDidMount() { async componentDidMount() {
if (this.cluster.disconnected) {
return;
}
this.authOutput = [{ data: "Connecting..." }];
ipcRenderer.on(`kube-auth:${this.cluster.id}`, (evt, res: KubeAuthProxyLog) => { ipcRenderer.on(`kube-auth:${this.cluster.id}`, (evt, res: KubeAuthProxyLog) => {
this.authOutput.push({ this.authOutput.push({
data: res.data.trimRight(), data: res.data.trimRight(),
error: res.error, error: res.error,
}); });
}) })
if (!this.cluster.initialized) { if (!this.cluster.initialized || this.cluster.disconnected) {
await this.refreshCluster(); await this.refreshCluster();
} }
} }
@ -55,7 +52,6 @@ export class ClusterStatus extends React.Component<Props> {
} }
reconnect = async () => { reconnect = async () => {
this.authOutput = [{ data: "Reconnecting..." }];
this.isReconnecting = true; this.isReconnecting = true;
await this.refreshCluster(); await this.refreshCluster();
this.isReconnecting = false; this.isReconnecting = false;
@ -63,39 +59,41 @@ export class ClusterStatus extends React.Component<Props> {
render() { render() {
const { authOutput, cluster, hasErrors } = this; const { authOutput, cluster, hasErrors } = this;
const isDisconnected = !!cluster.disconnected;
const failureReason = cluster.failureReason; const failureReason = cluster.failureReason;
const isError = hasErrors || isDisconnected; if (!hasErrors || this.isReconnecting) {
return ( return (
<div className={cssNames("ClusterStatus flex column gaps box center", this.props.className)}> <div className="ClusterStatus flex column align-center justify-center">
{isError && ( <CubeSpinner />
<Icon
material="cloud_off"
className={cssNames({ error: hasErrors })}
/>
)}
<h2>
{cluster.preferences.clusterName}
</h2>
{!isDisconnected && (
<pre className="kube-auth-out"> <pre className="kube-auth-out">
<p>{this.isReconnecting ? "Reconnecting..." : "Connecting..."}</p>
{authOutput.map(({ data, error }, index) => { {authOutput.map(({ data, error }, index) => {
return <p key={index} className={cssNames({ error })}>{data}</p> return <p key={index} className={cssNames({ error })}>{data}</p>
})} })}
</pre> </pre>
)} </div>
);
}
return (
<div className={cssNames("ClusterStatus flex column gaps box center", this.props.className)}>
<Icon material="cloud_off" className="error" />
<h2>
{cluster.preferences.clusterName}
</h2>
<pre className="kube-auth-out">
{authOutput.map(({ data, error }, index) => {
return <p key={index} className={cssNames({ error })}>{data}</p>
})}
</pre>
{failureReason && ( {failureReason && (
<div className="failure-reason error">{failureReason}</div> <div className="failure-reason error">{failureReason}</div>
)} )}
{isError && ( <Button
<Button primary
primary label="Reconnect"
label="Reconnect" className="box center"
className="box center" onClick={this.reconnect}
onClick={this.reconnect} waiting={this.isReconnecting}
waiting={this.isReconnecting} />
/>
)}
</div> </div>
) )
} }

View File

@ -34,7 +34,7 @@ export class ClustersMenu extends React.Component<Props> {
showCluster = (clusterId: ClusterId) => { showCluster = (clusterId: ClusterId) => {
clusterStore.setActive(clusterId); clusterStore.setActive(clusterId);
navigate(clusterViewURL({ params: { clusterId } })) navigate(clusterViewURL({ params: { clusterId } }));
} }
addCluster = () => { addCluster = () => {