mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
debugging cluster-view error -- part 1
Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
parent
6ee2385d3c
commit
995e032be4
@ -8,6 +8,8 @@ import logger from "../main/logger";
|
|||||||
import { broadcastMessage, subscribeToBroadcast, unsubscribeFromBroadcast } from "./ipc";
|
import { broadcastMessage, subscribeToBroadcast, unsubscribeFromBroadcast } from "./ipc";
|
||||||
import isEqual from "lodash/isEqual";
|
import isEqual from "lodash/isEqual";
|
||||||
|
|
||||||
|
// FIXME: sync/saving doesn't work
|
||||||
|
|
||||||
export interface BaseStoreParams<T = any> extends ConfOptions<T> {
|
export interface BaseStoreParams<T = any> extends ConfOptions<T> {
|
||||||
autoLoad?: boolean;
|
autoLoad?: boolean;
|
||||||
syncEnabled?: boolean;
|
syncEnabled?: boolean;
|
||||||
|
|||||||
@ -143,6 +143,8 @@ export class ClusterStore extends BaseStore<ClusterStoreModel> {
|
|||||||
logger.info("[CLUSTER-STORE] requesting initial state sync");
|
logger.info("[CLUSTER-STORE] requesting initial state sync");
|
||||||
const clusterStates: clusterStateSync[] = await requestMain(ClusterStore.stateRequestChannel);
|
const clusterStates: clusterStateSync[] = await requestMain(ClusterStore.stateRequestChannel);
|
||||||
|
|
||||||
|
console.log(`CLUSTERS (${document.URL})`, clusterStates);
|
||||||
|
|
||||||
clusterStates.forEach((clusterState) => {
|
clusterStates.forEach((clusterState) => {
|
||||||
const cluster = this.getById(clusterState.id);
|
const cluster = this.getById(clusterState.id);
|
||||||
|
|
||||||
@ -152,16 +154,20 @@ export class ClusterStore extends BaseStore<ClusterStoreModel> {
|
|||||||
});
|
});
|
||||||
} else if (ipcMain) {
|
} else if (ipcMain) {
|
||||||
handleRequest(ClusterStore.stateRequestChannel, (): clusterStateSync[] => {
|
handleRequest(ClusterStore.stateRequestChannel, (): clusterStateSync[] => {
|
||||||
const states: clusterStateSync[] = [];
|
const clusterStates: clusterStateSync[] = [];
|
||||||
|
|
||||||
this.clustersList.forEach((cluster) => {
|
this.clustersList.forEach((cluster) => {
|
||||||
states.push({
|
clusterStates.push({
|
||||||
state: cluster.getState(),
|
state: cluster.getState(),
|
||||||
id: cluster.id
|
id: cluster.id
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
return states;
|
console.log('CLUSTERS', {
|
||||||
|
clusterStates
|
||||||
|
});
|
||||||
|
|
||||||
|
return clusterStates;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,77 +1,67 @@
|
|||||||
import "./cluster-view.scss";
|
import "./cluster-view.scss";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { reaction } from "mobx";
|
import { comparer, computed, makeObservable, reaction } from "mobx";
|
||||||
import { disposeOnUnmount, observer } from "mobx-react";
|
import { disposeOnUnmount, observer } from "mobx-react";
|
||||||
import { RouteComponentProps } from "react-router";
|
|
||||||
import { IClusterViewRouteParams } from "./cluster-view.route";
|
|
||||||
import { ClusterStatus } from "./cluster-status";
|
import { ClusterStatus } from "./cluster-status";
|
||||||
import { hasLoadedView, initView, lensViews, refreshViews } from "./lens-views";
|
import { hasLoadedView, initView, refreshViews } from "./lens-views";
|
||||||
import { Cluster } from "../../../main/cluster";
|
import { Cluster } from "../../../main/cluster";
|
||||||
import { ClusterStore } from "../../../common/cluster-store";
|
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 { catalogURL } from "../+catalog";
|
import { getMatchedClusterId } from "../../navigation";
|
||||||
import { navigate } from "../../navigation";
|
|
||||||
|
|
||||||
interface Props extends RouteComponentProps<IClusterViewRouteParams> {
|
|
||||||
}
|
|
||||||
|
|
||||||
@observer
|
@observer
|
||||||
export class ClusterView extends React.Component<Props> {
|
export class ClusterView extends React.Component {
|
||||||
get clusterId() {
|
constructor(props: {}) {
|
||||||
return this.props.match.params.clusterId;
|
super(props);
|
||||||
|
|
||||||
|
makeObservable(this);
|
||||||
|
this.bindEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
get cluster(): Cluster {
|
get clusterId() {
|
||||||
|
return getMatchedClusterId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@computed get cluster(): Cluster {
|
||||||
return ClusterStore.getInstance().getById(this.clusterId);
|
return ClusterStore.getInstance().getById(this.clusterId);
|
||||||
}
|
}
|
||||||
|
|
||||||
async componentDidMount() {
|
private bindEvents() {
|
||||||
disposeOnUnmount(this, [
|
disposeOnUnmount(this, [
|
||||||
reaction(() => this.clusterId, (clusterId) => {
|
reaction(() => [
|
||||||
this.showCluster(clusterId);
|
// refresh views when on of the following changes:
|
||||||
}, { fireImmediately: true}
|
hasLoadedView(this.clusterId),
|
||||||
),
|
this.cluster?.available,
|
||||||
reaction(() => this.cluster?.ready, (ready) => {
|
this.cluster?.ready,
|
||||||
const clusterView = lensViews.get(this.clusterId);
|
], changes => {
|
||||||
|
console.log('CHANGES', changes)
|
||||||
if (clusterView && clusterView.isLoaded && !ready) {
|
this.refreshViews(this.clusterId);
|
||||||
navigate(catalogURL());
|
}, {
|
||||||
}
|
fireImmediately: true,
|
||||||
})
|
equals: comparer.shallow,
|
||||||
|
}),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
/**
|
||||||
this.hideCluster();
|
* Refresh cluster-views visibility and catalog's active entity.
|
||||||
}
|
* @param visibleClusterId Currently viewing cluster's iframe
|
||||||
|
*/
|
||||||
|
refreshViews = async (visibleClusterId: string) => {
|
||||||
|
await initView(visibleClusterId);
|
||||||
|
await requestMain(clusterActivateHandler, visibleClusterId, false);
|
||||||
|
refreshViews(visibleClusterId);
|
||||||
|
|
||||||
showCluster(clusterId: string) {
|
const activeEntity = catalogEntityRegistry.getById(visibleClusterId);
|
||||||
initView(clusterId);
|
catalogEntityRegistry.activeEntity = activeEntity;
|
||||||
requestMain(clusterActivateHandler, this.clusterId, false);
|
|
||||||
|
|
||||||
const entity = catalogEntityRegistry.getById(this.clusterId);
|
|
||||||
|
|
||||||
if (entity) {
|
|
||||||
catalogEntityRegistry.activeEntity = entity;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
hideCluster() {
|
|
||||||
refreshViews();
|
|
||||||
|
|
||||||
if (catalogEntityRegistry.activeEntity?.metadata?.uid === this.clusterId) {
|
|
||||||
catalogEntityRegistry.activeEntity = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { cluster } = this;
|
const { cluster } = this;
|
||||||
const showStatus = cluster && (!cluster.available || !hasLoadedView(cluster.id) || !cluster.ready);
|
const showStatus = cluster && (!cluster.available || !hasLoadedView(cluster.id) || !cluster.ready);
|
||||||
|
|
||||||
refreshViews(cluster.id);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="ClusterView flex align-center">
|
<div className="ClusterView flex align-center">
|
||||||
{showStatus && (
|
{showStatus && (
|
||||||
|
|||||||
@ -15,8 +15,6 @@ export function hasLoadedView(clusterId: ClusterId): boolean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function initView(clusterId: ClusterId) {
|
export async function initView(clusterId: ClusterId) {
|
||||||
refreshViews(clusterId);
|
|
||||||
|
|
||||||
if (!clusterId || lensViews.has(clusterId)) {
|
if (!clusterId || lensViews.has(clusterId)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -63,7 +61,8 @@ export async function autoCleanOnRemove(clusterId: ClusterId, iframe: HTMLIFrame
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function refreshViews(visibleClusterId?: string) {
|
export function refreshViews(visibleClusterId?: string) {
|
||||||
const cluster = !visibleClusterId ? null : ClusterStore.getInstance().getById(visibleClusterId);
|
logger.info(`[LENS-VIEW]: refreshing iframe views, visible cluster id=${visibleClusterId}`);
|
||||||
|
const cluster = ClusterStore.getInstance().getById(visibleClusterId);
|
||||||
|
|
||||||
lensViews.forEach(({ clusterId, view, isLoaded }) => {
|
lensViews.forEach(({ clusterId, view, isLoaded }) => {
|
||||||
const isCurrent = clusterId === cluster?.id;
|
const isCurrent = clusterId === cluster?.id;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user