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

Fix ClusterView bugs (#2928)

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
Jari Kolehmainen 2021-06-01 16:32:42 +03:00 committed by GitHub
parent e1be10b74d
commit 06612409ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 14 deletions

View File

@ -30,20 +30,26 @@ import { ClusterStore } from "../../../common/cluster-store";
import { requestMain } from "../../../common/ipc"; import { requestMain } from "../../../common/ipc";
import { clusterActivateHandler } from "../../../common/cluster-ipc"; import { clusterActivateHandler } from "../../../common/cluster-ipc";
import { catalogEntityRegistry } from "../../api/catalog-entity-registry"; import { catalogEntityRegistry } from "../../api/catalog-entity-registry";
import { getMatchedClusterId, navigate } from "../../navigation"; import { navigate } from "../../navigation";
import { catalogURL } from "../+catalog/catalog.route"; import { catalogURL } from "../+catalog/catalog.route";
import type { RouteComponentProps } from "react-router-dom";
import type { IClusterViewRouteParams } from "./cluster-view.route";
interface Props extends RouteComponentProps<IClusterViewRouteParams> {
}
@observer @observer
export class ClusterView extends React.Component { export class ClusterView extends React.Component<Props> {
private store = ClusterStore.getInstance(); private store = ClusterStore.getInstance();
constructor(props: {}) { constructor(props: Props) {
super(props); super(props);
makeObservable(this); makeObservable(this);
} }
get clusterId() { @computed get clusterId() {
return getMatchedClusterId(); return this.props.match.params.clusterId;
} }
@computed get cluster(): Cluster | undefined { @computed get cluster(): Cluster | undefined {
@ -71,14 +77,13 @@ export class ClusterView extends React.Component {
fireImmediately: true, fireImmediately: true,
}), }),
reaction(() => this.isReady, (ready) => { reaction(() => [this.cluster?.ready, this.cluster?.disconnected], (values) => {
if (ready) { const disconnected = values[1];
refreshViews(this.clusterId); // show cluster's view (iframe)
} else if (hasLoadedView(this.clusterId)) { if (hasLoadedView(this.clusterId) && disconnected) {
refreshViews();
navigate(catalogURL()); // redirect to catalog when active cluster get disconnected/not available navigate(catalogURL()); // redirect to catalog when active cluster get disconnected/not available
} }
}, {
fireImmediately: true,
}), }),
]); ]);
} }
@ -87,7 +92,7 @@ export class ClusterView extends React.Component {
const { clusterId, cluster, isReady } = this; const { clusterId, cluster, isReady } = this;
if (cluster && !isReady) { if (cluster && !isReady) {
return <ClusterStatus clusterId={clusterId} className="box center"/>; return <ClusterStatus key={clusterId} clusterId={clusterId} className="box center"/>;
} }
return null; return null;

View File

@ -56,8 +56,13 @@ export async function initView(clusterId: ClusterId) {
parentElem.appendChild(iframe); parentElem.appendChild(iframe);
logger.info(`[LENS-VIEW]: waiting cluster to be ready, clusterId=${clusterId}`); logger.info(`[LENS-VIEW]: waiting cluster to be ready, clusterId=${clusterId}`);
await cluster.whenReady;
try {
await when(() => cluster.ready, { timeout: 5_000 }); // we cannot wait forever because cleanup would be blocked for broken cluster connections
logger.info(`[LENS-VIEW]: cluster is ready, clusterId=${clusterId}`);
} finally {
await autoCleanOnRemove(clusterId, iframe); await autoCleanOnRemove(clusterId, iframe);
}
} }
export async function autoCleanOnRemove(clusterId: ClusterId, iframe: HTMLIFrameElement) { export async function autoCleanOnRemove(clusterId: ClusterId, iframe: HTMLIFrameElement) {