mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Make ClusterFrameManager fully injectable (#6590)
* Make ClusterFrameManager fully injectable Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix type errors Signed-off-by: Sebastian Malton <sebastian@malton.name> Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
1 parent
05f17b3cd4
commit
98e42cf25f
11 files changed
+103
-36
No files matched your search
@@ -7,6 +7,7 @@ import clusterStoreInjectable from "../../common/cluster-store/cluster-store.inj
|
||||
import catalogEntityRegistryInjectable from "../catalog/entity-registry.injectable";
|
||||
import clustersThatAreBeingDeletedInjectable from "./are-being-deleted.injectable";
|
||||
import { ClusterManager } from "./manager";
|
||||
import visibleClusterInjectable from "./visible-cluster.injectable";
|
||||
|
||||
const clusterManagerInjectable = getInjectable({
|
||||
id: "cluster-manager",
|
||||
@@ -15,6 +16,7 @@ const clusterManagerInjectable = getInjectable({
|
||||
store: di.inject(clusterStoreInjectable),
|
||||
catalogEntityRegistry: di.inject(catalogEntityRegistryInjectable),
|
||||
clustersThatAreBeingDeleted: di.inject(clustersThatAreBeingDeletedInjectable),
|
||||
visibleCluster: di.inject(visibleClusterInjectable),
|
||||
}),
|
||||
});
|
||||
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
|
||||
import "../../common/ipc/cluster";
|
||||
import type http from "http";
|
||||
import type { ObservableSet } from "mobx";
|
||||
import { action, makeObservable, observable, observe, reaction, toJS } from "mobx";
|
||||
import type { IObservableValue, ObservableSet } from "mobx";
|
||||
import { action, makeObservable, observe, reaction, toJS } from "mobx";
|
||||
import type { Cluster } from "../../common/cluster/cluster";
|
||||
import logger from "../logger";
|
||||
import { apiKubePrefix } from "../../common/vars";
|
||||
@@ -27,11 +27,10 @@ interface Dependencies {
|
||||
readonly store: ClusterStore;
|
||||
readonly catalogEntityRegistry: CatalogEntityRegistry;
|
||||
readonly clustersThatAreBeingDeleted: ObservableSet<ClusterId>;
|
||||
readonly visibleCluster: IObservableValue<ClusterId | null>;
|
||||
}
|
||||
|
||||
export class ClusterManager {
|
||||
@observable visibleCluster: ClusterId | undefined = undefined;
|
||||
|
||||
constructor(private readonly dependencies: Dependencies) {
|
||||
makeObservable(this);
|
||||
}
|
||||
@@ -58,7 +57,7 @@ export class ClusterManager {
|
||||
|
||||
reaction(() => [
|
||||
this.dependencies.catalogEntityRegistry.filterItemsByPredicate(isKubernetesCluster),
|
||||
this.visibleCluster,
|
||||
this.dependencies.visibleCluster.get(),
|
||||
] as const, ([entities, visibleCluster]) => {
|
||||
for (const entity of entities) {
|
||||
if (entity.getId() === visibleCluster) {
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { clusterVisibilityChannel } from "../../common/cluster/visibility-channel";
|
||||
import { getMessageChannelListenerInjectable } from "../../common/utils/channel/message-channel-listener-injection-token";
|
||||
import visibleClusterInjectable from "./visible-cluster.injectable";
|
||||
|
||||
const clusterVisibilityHandlerInjectable = getMessageChannelListenerInjectable({
|
||||
channel: clusterVisibilityChannel,
|
||||
id: "base",
|
||||
handler: (di) => {
|
||||
const visibleCluster = di.inject(visibleClusterInjectable);
|
||||
|
||||
return (clusterId) => visibleCluster.set(clusterId);
|
||||
},
|
||||
});
|
||||
|
||||
export default clusterVisibilityHandlerInjectable;
|
||||
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { observable } from "mobx";
|
||||
import type { ClusterId } from "../../common/cluster-types";
|
||||
|
||||
const visibleClusterInjectable = getInjectable({
|
||||
id: "visible-cluster",
|
||||
instantiate: () => observable.box<ClusterId | null>(null),
|
||||
});
|
||||
|
||||
export default visibleClusterInjectable;
|
||||
-3
@@ -5,7 +5,6 @@
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { setupIpcMainHandlers } from "./setup-ipc-main-handlers";
|
||||
import loggerInjectable from "../../../../common/logger.injectable";
|
||||
import clusterManagerInjectable from "../../../cluster/manager.injectable";
|
||||
import clusterStoreInjectable from "../../../../common/cluster-store/cluster-store.injectable";
|
||||
import { onLoadOfApplicationInjectionToken } from "../../../start-main-application/runnable-tokens/on-load-of-application-injection-token";
|
||||
import operatingSystemThemeInjectable from "../../../theme/operating-system-theme.injectable";
|
||||
@@ -20,7 +19,6 @@ const setupIpcMainHandlersInjectable = getInjectable({
|
||||
|
||||
instantiate: (di) => {
|
||||
const logger = di.inject(loggerInjectable);
|
||||
const clusterManager = di.inject(clusterManagerInjectable);
|
||||
const applicationMenuItemComposite = di.inject(applicationMenuItemCompositeInjectable);
|
||||
const catalogEntityRegistry = di.inject(catalogEntityRegistryInjectable);
|
||||
const clusterStore = di.inject(clusterStoreInjectable);
|
||||
@@ -36,7 +34,6 @@ const setupIpcMainHandlersInjectable = getInjectable({
|
||||
|
||||
setupIpcMainHandlers({
|
||||
applicationMenuItemComposite,
|
||||
clusterManager,
|
||||
catalogEntityRegistry,
|
||||
clusterStore,
|
||||
operatingSystemTheme,
|
||||
|
||||
@@ -5,13 +5,12 @@
|
||||
import type { IpcMainInvokeEvent } from "electron";
|
||||
import { BrowserWindow, Menu } from "electron";
|
||||
import { clusterFrameMap } from "../../../../common/cluster-frames";
|
||||
import { clusterActivateHandler, clusterSetFrameIdHandler, clusterVisibilityHandler, clusterRefreshHandler, clusterDisconnectHandler, clusterKubectlApplyAllHandler, clusterKubectlDeleteAllHandler } from "../../../../common/ipc/cluster";
|
||||
import { clusterActivateHandler, clusterSetFrameIdHandler, clusterRefreshHandler, clusterDisconnectHandler, clusterKubectlApplyAllHandler, clusterKubectlDeleteAllHandler } from "../../../../common/ipc/cluster";
|
||||
import type { ClusterId } from "../../../../common/cluster-types";
|
||||
import { ClusterStore } from "../../../../common/cluster-store/cluster-store";
|
||||
import { broadcastMainChannel, broadcastMessage, ipcMainHandle, ipcMainOn } from "../../../../common/ipc";
|
||||
import type { CatalogEntityRegistry } from "../../../catalog";
|
||||
import { pushCatalogToRenderer } from "../../../catalog-pusher";
|
||||
import type { ClusterManager } from "../../../cluster/manager";
|
||||
import type { IComputedValue } from "mobx";
|
||||
import { windowActionHandleChannel, windowLocationChangedChannel, windowOpenAppMenuAsContextMenuChannel } from "../../../../common/ipc/window";
|
||||
import { handleWindowAction, onLocationChange } from "../../../ipc/window";
|
||||
@@ -28,7 +27,6 @@ import type { CreateResourceApplier } from "../../../resource-applier/create-res
|
||||
|
||||
interface Dependencies {
|
||||
applicationMenuItemComposite: IComputedValue<Composite<ApplicationMenuItemTypes | MenuItemRoot>>;
|
||||
clusterManager: ClusterManager;
|
||||
catalogEntityRegistry: CatalogEntityRegistry;
|
||||
clusterStore: ClusterStore;
|
||||
operatingSystemTheme: IComputedValue<Theme>;
|
||||
@@ -39,7 +37,6 @@ interface Dependencies {
|
||||
|
||||
export const setupIpcMainHandlers = ({
|
||||
applicationMenuItemComposite,
|
||||
clusterManager,
|
||||
catalogEntityRegistry,
|
||||
clusterStore,
|
||||
operatingSystemTheme,
|
||||
@@ -64,10 +61,6 @@ export const setupIpcMainHandlers = ({
|
||||
}
|
||||
});
|
||||
|
||||
ipcMainOn(clusterVisibilityHandler, (event, clusterId?: ClusterId) => {
|
||||
clusterManager.visibleCluster = clusterId;
|
||||
});
|
||||
|
||||
ipcMainHandle(clusterRefreshHandler, (event, clusterId: ClusterId) => {
|
||||
return ClusterStore.getInstance()
|
||||
.getById(clusterId)
|
||||
|
||||
Reference in new issue
Block a user