diff --git a/src/extensions/registries/command-registry.ts b/src/extensions/registries/command-registry.ts index b7b822d473..8f91dace10 100644 --- a/src/extensions/registries/command-registry.ts +++ b/src/extensions/registries/command-registry.ts @@ -22,7 +22,6 @@ // Extensions API -> Commands import { BaseRegistry } from "./base-registry"; -import { makeObservable, observable } from "mobx"; import type { LensExtension } from "../lens-extension"; import type { CatalogEntity } from "../../common/catalog"; @@ -39,14 +38,6 @@ export interface CommandRegistration { } export class CommandRegistry extends BaseRegistry { - @observable.ref activeEntity: CatalogEntity; - - constructor() { - super(); - - makeObservable(this); - } - add(items: CommandRegistration | CommandRegistration[], extension?: LensExtension) { const itemArray = [items].flat(); diff --git a/src/renderer/api/catalog-entity.ts b/src/renderer/api/catalog-entity.ts index 63a5ce62eb..212c64464b 100644 --- a/src/renderer/api/catalog-entity.ts +++ b/src/renderer/api/catalog-entity.ts @@ -20,8 +20,8 @@ */ import { navigate } from "../navigation"; -import { commandRegistry } from "../../extensions/registries"; -import type { CatalogEntity } from "../../common/catalog"; +import type { CatalogEntity } from "../../common/catalog"; +import { catalogEntityRegistry } from "./catalog-entity-registry"; export { CatalogCategory, CatalogEntity } from "../../common/catalog"; export type { @@ -37,6 +37,6 @@ export type { export const catalogEntityRunContext = { navigate: (url: string) => navigate(url), setCommandPaletteContext: (entity?: CatalogEntity) => { - commandRegistry.activeEntity = entity; + catalogEntityRegistry.activeEntity = entity; } }; diff --git a/src/renderer/components/cluster-manager/cluster-view.tsx b/src/renderer/components/cluster-manager/cluster-view.tsx index ed4cbe2718..4fe3a51594 100644 --- a/src/renderer/components/cluster-manager/cluster-view.tsx +++ b/src/renderer/components/cluster-manager/cluster-view.tsx @@ -35,6 +35,8 @@ import { catalogURL } from "../+catalog/catalog.route"; @observer export class ClusterView extends React.Component { + private store = ClusterStore.getInstance(); + constructor(props: {}) { super(props); makeObservable(this); @@ -45,7 +47,7 @@ export class ClusterView extends React.Component { } @computed get cluster(): Cluster | undefined { - return ClusterStore.getInstance().getById(this.clusterId); + return this.store.getById(this.clusterId); } @computed get isReady(): boolean { @@ -65,6 +67,7 @@ export class ClusterView extends React.Component { initView(clusterId); // init cluster-view (iframe), requires parent container #lens-views to be in DOM requestMain(clusterActivateHandler, clusterId, false); // activate and fetch cluster's state from main catalogEntityRegistry.activeEntity = catalogEntityRegistry.getById(clusterId); + this.store.setActive(clusterId); }, { fireImmediately: true, }), diff --git a/src/renderer/components/command-palette/command-container.tsx b/src/renderer/components/command-palette/command-container.tsx index 50e79bde12..120c570c77 100644 --- a/src/renderer/components/command-palette/command-container.tsx +++ b/src/renderer/components/command-palette/command-container.tsx @@ -30,6 +30,7 @@ import { subscribeToBroadcast } from "../../../common/ipc"; import { CommandDialog } from "./command-dialog"; import { CommandRegistration, commandRegistry } from "../../../extensions/registries/command-registry"; import type { ClusterId } from "../../../common/cluster-store"; +import { catalogEntityRegistry } from "../../api/catalog-entity-registry"; export type CommandDialogEvent = { component: React.ReactElement @@ -78,7 +79,7 @@ export class CommandContainer extends React.Component { private runCommand(command: CommandRegistration) { command.action({ - entity: commandRegistry.activeEntity + entity: catalogEntityRegistry.activeEntity }); } diff --git a/src/renderer/components/command-palette/command-dialog.tsx b/src/renderer/components/command-palette/command-dialog.tsx index 16c375d666..d908bbfd0d 100644 --- a/src/renderer/components/command-palette/command-dialog.tsx +++ b/src/renderer/components/command-palette/command-dialog.tsx @@ -30,6 +30,8 @@ import { CommandOverlay } from "./command-container"; import { broadcastMessage } from "../../../common/ipc"; import { navigate } from "../../navigation"; import { clusterViewURL } from "../cluster-manager/cluster-view.route"; +import { catalogEntityRegistry } from "../../api/catalog-entity-registry"; +import type { CatalogEntity } from "../../../common/catalog"; @observer export class CommandDialog extends React.Component { @@ -39,10 +41,14 @@ export class CommandDialog extends React.Component { super(props); makeObservable(this); } - + + @computed get activeEntity(): CatalogEntity | undefined { + return catalogEntityRegistry.activeEntity; + } + @computed get options() { const context = { - entity: commandRegistry.activeEntity + entity: this.activeEntity }; return commandRegistry.getItems().filter((command) => { @@ -78,15 +84,15 @@ export class CommandDialog extends React.Component { if (command.scope === "global") { command.action({ - entity: commandRegistry.activeEntity + entity: this.activeEntity }); - } else if(commandRegistry.activeEntity) { + } else if(this.activeEntity) { navigate(clusterViewURL({ params: { - clusterId: commandRegistry.activeEntity.metadata.uid + clusterId: this.activeEntity.metadata.uid } })); - broadcastMessage(`command-palette:run-action:${commandRegistry.activeEntity.metadata.uid}`, command.id); + broadcastMessage(`command-palette:run-action:${this.activeEntity.metadata.uid}`, command.id); } } catch(error) { console.error("[COMMAND-DIALOG] failed to execute command", command.id, error); diff --git a/src/renderer/lens-app.tsx b/src/renderer/lens-app.tsx index 9043819761..c58845fe23 100644 --- a/src/renderer/lens-app.tsx +++ b/src/renderer/lens-app.tsx @@ -31,13 +31,11 @@ import { ConfirmDialog } from "./components/confirm-dialog"; import { ExtensionLoader } from "../extensions/extension-loader"; import { broadcastMessage } from "../common/ipc"; import { CommandContainer } from "./components/command-palette/command-container"; -import { LensProtocolRouterRenderer, bindProtocolAddRouteHandlers } from "./protocol-handler"; +import { bindProtocolAddRouteHandlers, LensProtocolRouterRenderer } from "./protocol-handler"; import { registerIpcHandlers } from "./ipc"; import { ipcRenderer } from "electron"; import { IpcRendererNavigationEvents } from "./navigation/events"; import { catalogEntityRegistry } from "./api/catalog-entity-registry"; -import { commandRegistry } from "../extensions/registries"; -import { reaction } from "mobx"; @observer export class LensApp extends React.Component { @@ -54,18 +52,6 @@ export class LensApp extends React.Component { ipcRenderer.send(IpcRendererNavigationEvents.LOADED); } - componentDidMount() { - reaction(() => catalogEntityRegistry.items, (items) => { - if (!commandRegistry.activeEntity) { - return; - } - - if (!items.includes(commandRegistry.activeEntity)) { - commandRegistry.activeEntity = null; - } - }); - } - render() { return (