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:
parent
bfcb6c7e36
commit
ad97dd65d3
@ -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<CommandRegistration> {
|
||||
@observable.ref activeEntity: CatalogEntity;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
makeObservable(this);
|
||||
}
|
||||
|
||||
add(items: CommandRegistration | CommandRegistration[], extension?: LensExtension) {
|
||||
const itemArray = [items].flat();
|
||||
|
||||
|
||||
@ -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;
|
||||
}
|
||||
};
|
||||
|
||||
@ -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,
|
||||
}),
|
||||
|
||||
@ -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<CommandContainerProps> {
|
||||
|
||||
private runCommand(command: CommandRegistration) {
|
||||
command.action({
|
||||
entity: commandRegistry.activeEntity
|
||||
entity: catalogEntityRegistry.activeEntity
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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 (
|
||||
<Router history={history}>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user