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 { clusterActivateHandler } from "../../../common/cluster-ipc";
import { catalogEntityRegistry } from "../../api/catalog-entity-registry";
import { getMatchedClusterId, navigate } from "../../navigation";
import { navigate } from "../../navigation";
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
export class ClusterView extends React.Component {
export class ClusterView extends React.Component<Props> {
private store = ClusterStore.getInstance();
constructor(props: {}) {
constructor(props: Props) {
super(props);
makeObservable(this);
}
get clusterId() {
return getMatchedClusterId();
@computed get clusterId() {
return this.props.match.params.clusterId;
}
@computed get cluster(): Cluster | undefined {
@ -71,14 +77,13 @@ export class ClusterView extends React.Component {
fireImmediately: true,
}),
reaction(() => this.isReady, (ready) => {
if (ready) {
refreshViews(this.clusterId); // show cluster's view (iframe)
} else if (hasLoadedView(this.clusterId)) {
reaction(() => [this.cluster?.ready, this.cluster?.disconnected], (values) => {
const disconnected = values[1];
if (hasLoadedView(this.clusterId) && disconnected) {
refreshViews();
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;
if (cluster && !isReady) {
return <ClusterStatus clusterId={clusterId} className="box center"/>;
return <ClusterStatus key={clusterId} clusterId={clusterId} className="box center"/>;
}
return null;

View File

@ -56,9 +56,14 @@ export async function initView(clusterId: ClusterId) {
parentElem.appendChild(iframe);
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);
}
}
export async function autoCleanOnRemove(clusterId: ClusterId, iframe: HTMLIFrameElement) {
await when(() => {