Fix: incorrect subscribing event name to navigate in cluster view (#2363)

Co-authored-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
RomanandSebastian Malton authored and GitHub committed 2021-03-23 11:04:31 -04:00
1 parent e718b250cc
commit 62c3501011
6 files changed
+31 -16

No files matched your search

@@ -9,9 +9,10 @@ import { clusterDisconnectHandler } from "../../../common/cluster-ipc";
import { ConfirmDialog } from "../confirm-dialog";
import { Cluster } from "../../../main/cluster";
import { Tooltip } from "../../components//tooltip";
import { IpcRendererNavigationEvents } from "../../navigation/events";
const navigate = (route: string) =>
broadcastMessage("renderer:navigate", route);
broadcastMessage(IpcRendererNavigationEvents.NAVIGATE_IN_APP, route);
/**
* Creates handlers for high-level actions
@@ -10,6 +10,7 @@ import { workspaceStore } from "../../../../common/workspace-store";
import { broadcastMessage, requestMain } from "../../../../common/ipc";
import { clusterDisconnectHandler } from "../../../../common/cluster-ipc";
import { ConfirmDialog } from "../../confirm-dialog";
import { IpcRendererNavigationEvents } from "../../../navigation/events";
const mockBroadcastIpc = broadcastMessage as jest.MockedFunction<typeof broadcastMessage>;
const mockRequestMain = requestMain as jest.MockedFunction<typeof requestMain>;
@@ -76,7 +77,7 @@ describe("<MainLayoutHeader />", () => {
it("navigates to cluster settings", () => {
fireEvent.click(settingsBtn);
expect(mockBroadcastIpc).toBeCalledWith("renderer:navigate", "/cluster/foo/settings");
expect(mockBroadcastIpc).toBeCalledWith(IpcRendererNavigationEvents.NAVIGATE_IN_APP, "/cluster/foo/settings");
});
it("disconnects from cluster", () => {
@@ -86,7 +87,7 @@ describe("<MainLayoutHeader />", () => {
it("opens 'Remove cluster' dialog", async () => {
fireEvent.click(removeBtn);
const dialog = document.querySelector(".ConfirmDialog");
expect(dialog).toBeDefined();
@@ -94,7 +95,7 @@ describe("<MainLayoutHeader />", () => {
const okBtn = dialog.querySelector("button.ok");
expect(okBtn.textContent).toBe("Remove");
expect(okBtn.textContent).toBe("Remove");
});
});
});
+2 -1
View File
@@ -15,6 +15,7 @@ import { CommandContainer } from "./components/command-palette/command-container
import { LensProtocolRouterRenderer, bindProtocolAddRouteHandlers } from "./protocol-handler";
import { registerIpcHandlers } from "./ipc";
import { ipcRenderer } from "electron";
import { IpcRendererNavigationEvents } from "./navigation/events";
@observer
export class LensApp extends React.Component {
@@ -30,7 +31,7 @@ export class LensApp extends React.Component {
});
registerIpcHandlers();
ipcRenderer.send("renderer:loaded");
ipcRenderer.send(IpcRendererNavigationEvents.LOADED);
}
render() {
+12 -4
View File
@@ -4,6 +4,14 @@ import { getMatchedClusterId, navigate } from "./helpers";
import { broadcastMessage, subscribeToBroadcast } from "../../common/ipc";
import logger from "../../main/logger";
export const enum IpcRendererNavigationEvents {
RELOAD_PAGE = "renderer:page-reload",
CLUSTER_VIEW_CURRENT_ID = "renderer:cluster-id-of-active-view",
NAVIGATE_IN_APP = "renderer:navigate",
NAVIGATE_IN_CLUSTER = "renderer:navigate-in-cluster",
LOADED = "renderer:loaded",
}
export function bindEvents() {
if (!ipcRenderer) {
return;
@@ -16,7 +24,7 @@ export function bindEvents() {
}
// Reload dashboard window
subscribeToBroadcast("renderer:reload", () => {
subscribeToBroadcast(IpcRendererNavigationEvents.RELOAD_PAGE, () => {
location.reload();
});
}
@@ -25,13 +33,13 @@ export function bindEvents() {
function bindClusterManagerRouteEvents() {
// Keep track of active cluster-id for handling IPC/menus/etc.
reaction(() => getMatchedClusterId(), clusterId => {
broadcastMessage("cluster-view:current-id", clusterId);
broadcastMessage(IpcRendererNavigationEvents.CLUSTER_VIEW_CURRENT_ID, clusterId);
}, {
fireImmediately: true
});
// Handle navigation via IPC
subscribeToBroadcast("renderer:navigate", (event, url: string) => {
subscribeToBroadcast(IpcRendererNavigationEvents.NAVIGATE_IN_APP, (event, url: string) => {
logger.info(`[IPC]: ${event.type}: ${url}`, { currentLocation: location.href });
navigate(url);
});
@@ -39,7 +47,7 @@ function bindClusterManagerRouteEvents() {
// Handle cluster-view renderer process events within iframes
function bindClusterFrameRouteEvents() {
subscribeToBroadcast("renderer:navigate-cluster-view", (event, url: string) => {
subscribeToBroadcast(IpcRendererNavigationEvents.NAVIGATE_IN_CLUSTER, (event, url: string) => {
logger.info(`[IPC]: ${event.type}: ${url}`, { currentLocation: location.href });
navigate(url);
});