mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
fix: handle navigation from global menu
Signed-off-by: Roman <ixrock@gmail.com> Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com>
This commit is contained in:
1 parent
6f6680be98
commit
4ef26bec58
6 files changed
+55
-25
No files matched your search
@@ -35,7 +35,7 @@ function initView(clusterId: ClusterId) {
|
||||
return;
|
||||
}
|
||||
logger.info(`[CLUSTER-VIEW]: init dashboard, clusterId=${clusterId}`)
|
||||
const lensViewsHolder = document.getElementById("lens-views"); // defined in cluster-manager's css-grid
|
||||
const parentElem = document.getElementById("lens-views"); // defined in cluster-manager's css-grid
|
||||
const webview = document.createElement("webview");
|
||||
webview.setAttribute("src", `//${clusterId}.${location.host}`)
|
||||
webview.setAttribute("nodeintegration", "true")
|
||||
@@ -50,7 +50,7 @@ function initView(clusterId: ClusterId) {
|
||||
logger.error(`[CLUSTER-VIEW]: failed to load, clusterId=${clusterId}`, event)
|
||||
});
|
||||
lensViews.set(clusterId, { clusterId, view: webview });
|
||||
lensViewsHolder.appendChild(webview); // add to dom and init cluster-page loading
|
||||
parentElem.appendChild(webview); // add to dom and init cluster-page loading
|
||||
}
|
||||
|
||||
function refreshViews() {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { reaction } from "mobx";
|
||||
import { ipcRenderer } from "electron";
|
||||
import { matchPath, RouteProps } from "react-router";
|
||||
import { buildURL, navigation } from "../../navigation";
|
||||
import { clusterStore } from "../../../common/cluster-store";
|
||||
import { clusterStore, getHostedClusterId } from "../../../common/cluster-store";
|
||||
|
||||
export interface IClusterViewRouteParams {
|
||||
clusterId: string;
|
||||
@@ -25,3 +27,15 @@ export function getMatchedClusterId(): string {
|
||||
export function getMatchedCluster() {
|
||||
return clusterStore.getById(getMatchedClusterId())
|
||||
}
|
||||
|
||||
// Refresh global menu depending on active route's type (common/cluster view)
|
||||
if (ipcRenderer) {
|
||||
const isMainView = !getHostedClusterId();
|
||||
if (isMainView) {
|
||||
reaction(() => getMatchedClusterId(), clusterId => {
|
||||
ipcRenderer.send("menu:refresh", clusterId);
|
||||
}, {
|
||||
fireImmediately: true
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,23 @@
|
||||
// Navigation helpers
|
||||
|
||||
import { ipcRenderer } from "electron";
|
||||
import { compile } from "path-to-regexp"
|
||||
import { createBrowserHistory, createMemoryHistory, Location, LocationDescriptor } from "history";
|
||||
import { createObservableHistory } from "mobx-observable-history";
|
||||
import { getHostedClusterId } from "../common/cluster-store";
|
||||
|
||||
export const history = typeof window !== "undefined" ? createBrowserHistory() : createMemoryHistory();
|
||||
export const navigation = createObservableHistory(history);
|
||||
|
||||
// handle navigation from global menu
|
||||
if (ipcRenderer) {
|
||||
const clusterId = getHostedClusterId();
|
||||
const channel = "menu:navigate" + (clusterId ? `:${clusterId}` : "");
|
||||
ipcRenderer.on(channel, (event, path: string) => {
|
||||
navigate(path);
|
||||
})
|
||||
}
|
||||
|
||||
export function navigate(location: LocationDescriptor) {
|
||||
navigation.location = location as Location;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user