1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Cluster commands disappeared from Command Palette, close #2760

Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
Roman 2021-05-27 15:01:55 +03:00
parent bfcb6c7e36
commit ad97dd65d3
6 changed files with 22 additions and 35 deletions

View File

@ -22,7 +22,6 @@
// Extensions API -> Commands // Extensions API -> Commands
import { BaseRegistry } from "./base-registry"; import { BaseRegistry } from "./base-registry";
import { makeObservable, observable } from "mobx";
import type { LensExtension } from "../lens-extension"; import type { LensExtension } from "../lens-extension";
import type { CatalogEntity } from "../../common/catalog"; import type { CatalogEntity } from "../../common/catalog";
@ -39,14 +38,6 @@ export interface CommandRegistration {
} }
export class CommandRegistry extends BaseRegistry<CommandRegistration> { export class CommandRegistry extends BaseRegistry<CommandRegistration> {
@observable.ref activeEntity: CatalogEntity;
constructor() {
super();
makeObservable(this);
}
add(items: CommandRegistration | CommandRegistration[], extension?: LensExtension) { add(items: CommandRegistration | CommandRegistration[], extension?: LensExtension) {
const itemArray = [items].flat(); const itemArray = [items].flat();

View File

@ -20,8 +20,8 @@
*/ */
import { navigate } from "../navigation"; 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 { CatalogCategory, CatalogEntity } from "../../common/catalog";
export type { export type {
@ -37,6 +37,6 @@ export type {
export const catalogEntityRunContext = { export const catalogEntityRunContext = {
navigate: (url: string) => navigate(url), navigate: (url: string) => navigate(url),
setCommandPaletteContext: (entity?: CatalogEntity) => { setCommandPaletteContext: (entity?: CatalogEntity) => {
commandRegistry.activeEntity = entity; catalogEntityRegistry.activeEntity = entity;
} }
}; };

View File

@ -35,6 +35,8 @@ import { catalogURL } from "../+catalog/catalog.route";
@observer @observer
export class ClusterView extends React.Component { export class ClusterView extends React.Component {
private store = ClusterStore.getInstance();
constructor(props: {}) { constructor(props: {}) {
super(props); super(props);
makeObservable(this); makeObservable(this);
@ -45,7 +47,7 @@ export class ClusterView extends React.Component {
} }
@computed get cluster(): Cluster | undefined { @computed get cluster(): Cluster | undefined {
return ClusterStore.getInstance().getById(this.clusterId); return this.store.getById(this.clusterId);
} }
@computed get isReady(): boolean { @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 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 requestMain(clusterActivateHandler, clusterId, false); // activate and fetch cluster's state from main
catalogEntityRegistry.activeEntity = catalogEntityRegistry.getById(clusterId); catalogEntityRegistry.activeEntity = catalogEntityRegistry.getById(clusterId);
this.store.setActive(clusterId);
}, { }, {
fireImmediately: true, fireImmediately: true,
}), }),

View File

@ -30,6 +30,7 @@ import { subscribeToBroadcast } from "../../../common/ipc";
import { CommandDialog } from "./command-dialog"; import { CommandDialog } from "./command-dialog";
import { CommandRegistration, commandRegistry } from "../../../extensions/registries/command-registry"; import { CommandRegistration, commandRegistry } from "../../../extensions/registries/command-registry";
import type { ClusterId } from "../../../common/cluster-store"; import type { ClusterId } from "../../../common/cluster-store";
import { catalogEntityRegistry } from "../../api/catalog-entity-registry";
export type CommandDialogEvent = { export type CommandDialogEvent = {
component: React.ReactElement component: React.ReactElement
@ -78,7 +79,7 @@ export class CommandContainer extends React.Component<CommandContainerProps> {
private runCommand(command: CommandRegistration) { private runCommand(command: CommandRegistration) {
command.action({ command.action({
entity: commandRegistry.activeEntity entity: catalogEntityRegistry.activeEntity
}); });
} }

View File

@ -30,6 +30,8 @@ import { CommandOverlay } from "./command-container";
import { broadcastMessage } from "../../../common/ipc"; import { broadcastMessage } from "../../../common/ipc";
import { navigate } from "../../navigation"; import { navigate } from "../../navigation";
import { clusterViewURL } from "../cluster-manager/cluster-view.route"; import { clusterViewURL } from "../cluster-manager/cluster-view.route";
import { catalogEntityRegistry } from "../../api/catalog-entity-registry";
import type { CatalogEntity } from "../../../common/catalog";
@observer @observer
export class CommandDialog extends React.Component { export class CommandDialog extends React.Component {
@ -39,10 +41,14 @@ export class CommandDialog extends React.Component {
super(props); super(props);
makeObservable(this); makeObservable(this);
} }
@computed get activeEntity(): CatalogEntity | undefined {
return catalogEntityRegistry.activeEntity;
}
@computed get options() { @computed get options() {
const context = { const context = {
entity: commandRegistry.activeEntity entity: this.activeEntity
}; };
return commandRegistry.getItems().filter((command) => { return commandRegistry.getItems().filter((command) => {
@ -78,15 +84,15 @@ export class CommandDialog extends React.Component {
if (command.scope === "global") { if (command.scope === "global") {
command.action({ command.action({
entity: commandRegistry.activeEntity entity: this.activeEntity
}); });
} else if(commandRegistry.activeEntity) { } else if(this.activeEntity) {
navigate(clusterViewURL({ navigate(clusterViewURL({
params: { 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) { } catch(error) {
console.error("[COMMAND-DIALOG] failed to execute command", command.id, error); console.error("[COMMAND-DIALOG] failed to execute command", command.id, error);

View File

@ -31,13 +31,11 @@ import { ConfirmDialog } from "./components/confirm-dialog";
import { ExtensionLoader } from "../extensions/extension-loader"; import { ExtensionLoader } from "../extensions/extension-loader";
import { broadcastMessage } from "../common/ipc"; import { broadcastMessage } from "../common/ipc";
import { CommandContainer } from "./components/command-palette/command-container"; 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 { registerIpcHandlers } from "./ipc";
import { ipcRenderer } from "electron"; import { ipcRenderer } from "electron";
import { IpcRendererNavigationEvents } from "./navigation/events"; import { IpcRendererNavigationEvents } from "./navigation/events";
import { catalogEntityRegistry } from "./api/catalog-entity-registry"; import { catalogEntityRegistry } from "./api/catalog-entity-registry";
import { commandRegistry } from "../extensions/registries";
import { reaction } from "mobx";
@observer @observer
export class LensApp extends React.Component { export class LensApp extends React.Component {
@ -54,18 +52,6 @@ export class LensApp extends React.Component {
ipcRenderer.send(IpcRendererNavigationEvents.LOADED); ipcRenderer.send(IpcRendererNavigationEvents.LOADED);
} }
componentDidMount() {
reaction(() => catalogEntityRegistry.items, (items) => {
if (!commandRegistry.activeEntity) {
return;
}
if (!items.includes(commandRegistry.activeEntity)) {
commandRegistry.activeEntity = null;
}
});
}
render() { render() {
return ( return (
<Router history={history}> <Router history={history}>