Fix: cluster commands disappeared from Command Palette (#2886)

* Cluster commands disappeared from Command Palette, close #2760

Signed-off-by: Roman <ixrock@gmail.com>

* refactoring: get rid of ClusterStore.active && ClusterStore.activeCluster (managed via catalog's entity)

Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
Roman authored and GitHub committed 2021-05-28 14:06:18 +03:00
1 parent d0dbb8744c
commit 643b0d861f
23 files changed
+99 -155

No files matched your search

@@ -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
});
}
@@ -25,11 +25,12 @@ import { computed, makeObservable, observable } from "mobx";
import { observer } from "mobx-react";
import React from "react";
import { commandRegistry } from "../../../extensions/registries/command-registry";
import { ClusterStore } from "../../../common/cluster-store";
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,14 +40,18 @@ 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) => {
if (command.scope === "entity" && !ClusterStore.getInstance().active) {
if (command.scope === "entity" && !this.activeEntity) {
return false;
}
@@ -78,15 +83,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);