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

@@ -22,7 +22,7 @@
import { navigate } from "../../navigation";
import { commandRegistry } from "../../../extensions/registries/command-registry";
import { entitySettingsURL } from "../+entity-settings";
import { ClusterStore } from "../../../common/cluster-store";
import { getActiveClusterEntity } from "../../api/catalog-entity-registry";
commandRegistry.add({
id: "cluster.viewCurrentClusterSettings",
@@ -30,7 +30,7 @@ commandRegistry.add({
scope: "global",
action: () => navigate(entitySettingsURL({
params: {
entityId: ClusterStore.getInstance().active.id
entityId: getActiveClusterEntity()?.id,
}
})),
isActive: (context) => !!context.entity
@@ -25,26 +25,13 @@ import { Select, SelectOption } from "../../select/select";
import { Icon } from "../../icon/icon";
import { Button } from "../../button/button";
import { SubTitle } from "../../layout/sub-title";
import type { Cluster } from "../../../../main/cluster";
import { Cluster, ClusterMetricsResourceType } from "../../../../main/cluster";
import { observable, reaction, makeObservable } from "mobx";
interface Props {
cluster: Cluster;
}
export enum ResourceType {
Cluster = "Cluster",
Node = "Node",
Pod = "Pod",
Deployment = "Deployment",
StatefulSet = "StatefulSet",
Container = "Container",
Ingress = "Ingress",
VolumeClaim = "VolumeClaim",
ReplicaSet = "ReplicaSet",
DaemonSet = "DaemonSet",
}
@observer
export class ClusterMetricsSetting extends React.Component<Props> {
@observable hiddenMetrics = observable.set<string>();
@@ -68,7 +55,7 @@ export class ClusterMetricsSetting extends React.Component<Props> {
this.props.cluster.preferences.hiddenMetrics = Array.from(this.hiddenMetrics);
};
onChangeSelect = (values: SelectOption<ResourceType>[]) => {
onChangeSelect = (values: SelectOption<ClusterMetricsResourceType>[]) => {
for (const { value } of values) {
if (this.hiddenMetrics.has(value)) {
this.hiddenMetrics.delete(value);
@@ -80,7 +67,7 @@ export class ClusterMetricsSetting extends React.Component<Props> {
};
onChangeButton = () => {
Object.keys(ResourceType).map(value =>
Object.keys(ClusterMetricsResourceType).map(value =>
this.hiddenMetrics.add(value)
);
this.save();
@@ -91,7 +78,7 @@ export class ClusterMetricsSetting extends React.Component<Props> {
this.save();
};
formatOptionLabel = ({ value: resource }: SelectOption<ResourceType>) => (
formatOptionLabel = ({ value: resource }: SelectOption<ClusterMetricsResourceType>) => (
<div className="flex gaps align-center">
<span>{resource}</span>
{this.hiddenMetrics.has(resource) && <Icon smallest material="check" className="box right" />}
@@ -110,7 +97,7 @@ export class ClusterMetricsSetting extends React.Component<Props> {
onMenuClose={this.save}
closeMenuOnSelect={false}
controlShouldRenderValue={false}
options={Object.values(ResourceType)}
options={Object.values(ClusterMetricsResourceType)}
onChange={this.onChangeSelect}
formatOptionLabel={this.formatOptionLabel}
/>