mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
fix: navigating to cluster-view from common-view
Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
parent
0e19f3e250
commit
51312a8ddd
@ -13,7 +13,7 @@ import { AddCluster, addClusterRoute } from "../+add-cluster";
|
|||||||
import { ClusterView } from "./cluster-view";
|
import { ClusterView } from "./cluster-view";
|
||||||
import { clusterViewRoute, clusterViewURL, getMatchedCluster, getMatchedClusterId } from "./cluster-view.route";
|
import { clusterViewRoute, clusterViewURL, getMatchedCluster, getMatchedClusterId } from "./cluster-view.route";
|
||||||
import { clusterStore } from "../../../common/cluster-store";
|
import { clusterStore } from "../../../common/cluster-store";
|
||||||
import { initView, lensViews, refreshViews } from "./lens-views";
|
import { hasLoadedView, initView, lensViews, refreshViews } from "./lens-views";
|
||||||
|
|
||||||
@observer
|
@observer
|
||||||
export class ClusterManager extends React.Component {
|
export class ClusterManager extends React.Component {
|
||||||
@ -23,7 +23,7 @@ export class ClusterManager extends React.Component {
|
|||||||
fireImmediately: true
|
fireImmediately: true
|
||||||
}),
|
}),
|
||||||
reaction(() => [
|
reaction(() => [
|
||||||
getMatchedClusterId(),
|
hasLoadedView(getMatchedClusterId()), // refresh when cluster's webview loaded
|
||||||
getMatchedCluster()?.available, // refresh on disconnect active-cluster
|
getMatchedCluster()?.available, // refresh on disconnect active-cluster
|
||||||
], refreshViews, {
|
], refreshViews, {
|
||||||
fireImmediately: true
|
fireImmediately: true
|
||||||
|
|||||||
@ -49,8 +49,7 @@ export class ClustersMenu extends React.Component<Props> {
|
|||||||
menu.append(new MenuItem({
|
menu.append(new MenuItem({
|
||||||
label: _i18n._(t`Settings`),
|
label: _i18n._(t`Settings`),
|
||||||
click: () => {
|
click: () => {
|
||||||
clusterStore.setActive(cluster.id);
|
navigateInClusterView(clusterSettingsURL(), cluster.id)
|
||||||
navigateInClusterView(clusterSettingsURL())
|
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
if (cluster.online) {
|
if (cluster.online) {
|
||||||
|
|||||||
@ -1,9 +1,10 @@
|
|||||||
import { ipcRenderer, WebviewTag } from "electron";
|
import { ipcRenderer, WebviewTag } from "electron";
|
||||||
import { observable } from "mobx";
|
import { observable, when } from "mobx";
|
||||||
import { ClusterId } from "../../../common/cluster-store";
|
import { ClusterId, clusterStore } from "../../../common/cluster-store";
|
||||||
import { clusterIpc } from "../../../common/cluster-ipc";
|
import { clusterIpc } from "../../../common/cluster-ipc";
|
||||||
|
import { clusterViewURL, getMatchedCluster, getMatchedClusterId } from "./cluster-view.route"
|
||||||
|
import { navigate } from "../../navigation";
|
||||||
import logger from "../../../main/logger";
|
import logger from "../../../main/logger";
|
||||||
import { getMatchedCluster, getMatchedClusterId } from "./cluster-view.route";
|
|
||||||
|
|
||||||
export interface LensView {
|
export interface LensView {
|
||||||
isLoaded?: boolean
|
isLoaded?: boolean
|
||||||
@ -13,11 +14,15 @@ export interface LensView {
|
|||||||
|
|
||||||
export const lensViews = observable.map<ClusterId, LensView>();
|
export const lensViews = observable.map<ClusterId, LensView>();
|
||||||
|
|
||||||
export function navigateInClusterView(path: string, clusterId: ClusterId = getMatchedClusterId()) {
|
export async function navigateInClusterView(path: string, clusterId: ClusterId) {
|
||||||
const viewId = getViewId(clusterId);
|
// select active cluster in common view
|
||||||
if (viewId) {
|
if (clusterId !== getMatchedClusterId()) {
|
||||||
ipcRenderer.sendTo(viewId, "menu:navigate", path)
|
clusterStore.setActive(clusterId);
|
||||||
|
navigate(clusterViewURL({ params: { clusterId } }));
|
||||||
}
|
}
|
||||||
|
// navigate in cluster-view when ready
|
||||||
|
await when(() => hasLoadedView(clusterId))
|
||||||
|
ipcRenderer.sendTo(getViewId(clusterId), "menu:navigate", path);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function hasLoadedView(clusterId: ClusterId): boolean {
|
export function hasLoadedView(clusterId: ClusterId): boolean {
|
||||||
@ -46,7 +51,6 @@ export function initView(clusterId: ClusterId) {
|
|||||||
logger.info(`[CLUSTER-VIEW]: loaded, clusterId=${clusterId}`)
|
logger.info(`[CLUSTER-VIEW]: loaded, clusterId=${clusterId}`)
|
||||||
clusterIpc.init.invokeFromRenderer(clusterId); // push cluster-state to webview and init render
|
clusterIpc.init.invokeFromRenderer(clusterId); // push cluster-state to webview and init render
|
||||||
lensViews.get(clusterId).isLoaded = true;
|
lensViews.get(clusterId).isLoaded = true;
|
||||||
refreshViews();
|
|
||||||
});
|
});
|
||||||
webview.addEventListener("did-fail-load", (event) => {
|
webview.addEventListener("did-fail-load", (event) => {
|
||||||
logger.error(`[CLUSTER-VIEW]: failed to load, clusterId=${clusterId}`, event)
|
logger.error(`[CLUSTER-VIEW]: failed to load, clusterId=${clusterId}`, event)
|
||||||
@ -56,9 +60,9 @@ export function initView(clusterId: ClusterId) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function refreshViews() {
|
export function refreshViews() {
|
||||||
const visibleCluster = getMatchedCluster();
|
const cluster = getMatchedCluster();
|
||||||
lensViews.forEach(({ clusterId, view, isLoaded }) => {
|
lensViews.forEach(({ clusterId, view, isLoaded }) => {
|
||||||
const isVisible = visibleCluster && visibleCluster.available && visibleCluster.id === clusterId;
|
const isVisible = cluster && cluster.available && cluster.id === clusterId;
|
||||||
view.style.display = isLoaded && isVisible ? "flex" : "none"
|
view.style.display = isLoaded && isVisible ? "flex" : "none"
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user