diff --git a/src/common/cluster-store/allowed-resources-injection-token.ts b/src/common/cluster-store/allowed-resources-injection-token.ts new file mode 100644 index 0000000000..ad387d26a2 --- /dev/null +++ b/src/common/cluster-store/allowed-resources-injection-token.ts @@ -0,0 +1,13 @@ +/** + * Copyright (c) OpenLens Authors. All rights reserved. + * Licensed under MIT License. See LICENSE in root directory for more information. + */ + +import { getInjectionToken } from "@ogre-tools/injectable"; +import type { IComputedValue } from "mobx"; + +export const allowedResourcesInjectionToken = getInjectionToken< + IComputedValue> +>({ + id: "allowed-resources", +}); diff --git a/src/common/utils/is-allowed-resource.injectable.ts b/src/common/utils/is-allowed-resource.injectable.ts index 67050a7f02..8841a8f0cc 100644 --- a/src/common/utils/is-allowed-resource.injectable.ts +++ b/src/common/utils/is-allowed-resource.injectable.ts @@ -4,8 +4,8 @@ */ import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable"; import { computed } from "mobx"; -import allowedResourcesInjectable from "../cluster-store/allowed-resources.injectable"; import type { KubeResource } from "../rbac"; +import { allowedResourcesInjectionToken } from "../cluster-store/allowed-resources-injection-token"; export type IsAllowedResource = (resource: KubeResource) => boolean; @@ -13,7 +13,7 @@ const isAllowedResourceInjectable = getInjectable({ id: "is-allowed-resource", instantiate: (di, resourceName: string) => { - const allowedResources = di.inject(allowedResourcesInjectable); + const allowedResources = di.inject(allowedResourcesInjectionToken); return computed(() => allowedResources.get().has(resourceName)); }, diff --git a/src/main/create-cluster/allowed-resources.injectable.ts b/src/main/create-cluster/allowed-resources.injectable.ts new file mode 100644 index 0000000000..d614ca3d17 --- /dev/null +++ b/src/main/create-cluster/allowed-resources.injectable.ts @@ -0,0 +1,16 @@ +/** + * 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 { computed } from "mobx"; +import { allowedResourcesInjectionToken } from "../../common/cluster-store/allowed-resources-injection-token"; + +// TODO: Figure out implementation for this later. +const allowedResourcesInjectable = getInjectable({ + id: "allowed-resources", + instantiate: () => computed(() => new Set()), + injectionToken: allowedResourcesInjectionToken, +}); + +export default allowedResourcesInjectable; diff --git a/src/renderer/api/create-terminal-api.injectable.ts b/src/renderer/api/create-terminal-api.injectable.ts index f9f151dace..255fa396f3 100644 --- a/src/renderer/api/create-terminal-api.injectable.ts +++ b/src/renderer/api/create-terminal-api.injectable.ts @@ -4,7 +4,7 @@ */ import { getInjectable } from "@ogre-tools/injectable"; import assert from "assert"; -import hostedClusterIdInjectable from "../../common/cluster-store/hosted-cluster-id.injectable"; +import hostedClusterIdInjectable from "../cluster-frame-context/hosted-cluster-id.injectable"; import type { TerminalApiQuery } from "./terminal-api"; import { TerminalApi } from "./terminal-api"; diff --git a/src/common/cluster-store/allowed-resources.injectable.ts b/src/renderer/cluster-frame-context/allowed-resources.injectable.ts similarity index 82% rename from src/common/cluster-store/allowed-resources.injectable.ts rename to src/renderer/cluster-frame-context/allowed-resources.injectable.ts index 27ce2d510f..646d931367 100644 --- a/src/common/cluster-store/allowed-resources.injectable.ts +++ b/src/renderer/cluster-frame-context/allowed-resources.injectable.ts @@ -5,6 +5,7 @@ import { getInjectable } from "@ogre-tools/injectable"; import { comparer, computed } from "mobx"; import hostedClusterInjectable from "./hosted-cluster.injectable"; +import { allowedResourcesInjectionToken } from "../../common/cluster-store/allowed-resources-injection-token"; const allowedResourcesInjectable = getInjectable({ id: "allowed-resources", @@ -17,6 +18,8 @@ const allowedResourcesInjectable = getInjectable({ equals: (cur, prev) => comparer.structural(cur, prev), }); }, + + injectionToken: allowedResourcesInjectionToken, }); export default allowedResourcesInjectable; diff --git a/src/renderer/cluster-frame-context/cluster-frame-context.injectable.ts b/src/renderer/cluster-frame-context/cluster-frame-context.injectable.ts index 08a921a87e..a353a30b40 100644 --- a/src/renderer/cluster-frame-context/cluster-frame-context.injectable.ts +++ b/src/renderer/cluster-frame-context/cluster-frame-context.injectable.ts @@ -5,7 +5,7 @@ import { getInjectable } from "@ogre-tools/injectable"; import { ClusterFrameContext } from "./cluster-frame-context"; import namespaceStoreInjectable from "../components/+namespaces/store.injectable"; -import hostedClusterInjectable from "../../common/cluster-store/hosted-cluster.injectable"; +import hostedClusterInjectable from "./hosted-cluster.injectable"; import assert from "assert"; const clusterFrameContextInjectable = getInjectable({ diff --git a/src/common/cluster-store/hosted-cluster-id.injectable.ts b/src/renderer/cluster-frame-context/hosted-cluster-id.injectable.ts similarity index 87% rename from src/common/cluster-store/hosted-cluster-id.injectable.ts rename to src/renderer/cluster-frame-context/hosted-cluster-id.injectable.ts index 5a5c99c580..854e004796 100644 --- a/src/common/cluster-store/hosted-cluster-id.injectable.ts +++ b/src/renderer/cluster-frame-context/hosted-cluster-id.injectable.ts @@ -3,7 +3,7 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { getInjectable } from "@ogre-tools/injectable"; -import { getClusterIdFromHost } from "../utils"; +import { getClusterIdFromHost } from "../../common/utils"; const hostedClusterIdInjectable = getInjectable({ id: "hosted-cluster-id", diff --git a/src/common/cluster-store/hosted-cluster.injectable.ts b/src/renderer/cluster-frame-context/hosted-cluster.injectable.ts similarity index 86% rename from src/common/cluster-store/hosted-cluster.injectable.ts rename to src/renderer/cluster-frame-context/hosted-cluster.injectable.ts index fa49cbca48..a466984952 100644 --- a/src/common/cluster-store/hosted-cluster.injectable.ts +++ b/src/renderer/cluster-frame-context/hosted-cluster.injectable.ts @@ -4,7 +4,7 @@ */ import { getInjectable } from "@ogre-tools/injectable"; import hostedClusterIdInjectable from "./hosted-cluster-id.injectable"; -import clusterStoreInjectable from "./cluster-store.injectable"; +import clusterStoreInjectable from "../../common/cluster-store/cluster-store.injectable"; const hostedClusterInjectable = getInjectable({ id: "hosted-cluster", diff --git a/src/renderer/components/+cluster/cluster-no-metrics.tsx b/src/renderer/components/+cluster/cluster-no-metrics.tsx index 5c981008be..ec039835fc 100644 --- a/src/renderer/components/+cluster/cluster-no-metrics.tsx +++ b/src/renderer/components/+cluster/cluster-no-metrics.tsx @@ -11,7 +11,7 @@ import { cssNames } from "../../utils"; import type { NavigateToEntitySettings } from "../../../common/front-end-routing/routes/entity-settings/navigate-to-entity-settings.injectable"; import { withInjectables } from "@ogre-tools/injectable-react"; import navigateToEntitySettingsInjectable from "../../../common/front-end-routing/routes/entity-settings/navigate-to-entity-settings.injectable"; -import hostedClusterInjectable from "../../../common/cluster-store/hosted-cluster.injectable"; +import hostedClusterInjectable from "../../cluster-frame-context/hosted-cluster.injectable"; export interface ClusterNoMetricsProps { className: string; diff --git a/src/renderer/components/+cluster/cluster-overview.tsx b/src/renderer/components/+cluster/cluster-overview.tsx index f17579e843..1ba8df8401 100644 --- a/src/renderer/components/+cluster/cluster-overview.tsx +++ b/src/renderer/components/+cluster/cluster-overview.tsx @@ -24,7 +24,7 @@ import { withInjectables } from "@ogre-tools/injectable-react"; import clusterOverviewStoreInjectable from "./cluster-overview-store/cluster-overview-store.injectable"; import type { SubscribeStores } from "../../kube-watch-api/kube-watch-api"; import type { Cluster } from "../../../common/cluster/cluster"; -import hostedClusterInjectable from "../../../common/cluster-store/hosted-cluster.injectable"; +import hostedClusterInjectable from "../../cluster-frame-context/hosted-cluster.injectable"; import assert from "assert"; import subscribeStoresInjectable from "../../kube-watch-api/subscribe-stores.injectable"; import podStoreInjectable from "../+workloads-pods/store.injectable"; diff --git a/src/renderer/components/command-palette/command-container.tsx b/src/renderer/components/command-palette/command-container.tsx index 3154917842..759e41e312 100644 --- a/src/renderer/components/command-palette/command-container.tsx +++ b/src/renderer/components/command-palette/command-container.tsx @@ -21,7 +21,7 @@ import windowAddEventListenerInjectable from "../../window/event-listener.inject import type { IComputedValue } from "mobx"; import matchedClusterIdInjectable from "../../navigation/matched-cluster-id.injectable"; import catalogEntityRegistryInjectable from "../../api/catalog/entity/registry.injectable"; -import hostedClusterIdInjectable from "../../../common/cluster-store/hosted-cluster-id.injectable"; +import hostedClusterIdInjectable from "../../cluster-frame-context/hosted-cluster-id.injectable"; interface Dependencies { addWindowEventListener: (type: K, listener: (this: Window, ev: WindowEventMap[K]) => any, options?: boolean | AddEventListenerOptions) => Disposer; diff --git a/src/renderer/components/dock/__test__/dock-store.test.ts b/src/renderer/components/dock/__test__/dock-store.test.ts index c9191c4928..1fd7e102e8 100644 --- a/src/renderer/components/dock/__test__/dock-store.test.ts +++ b/src/renderer/components/dock/__test__/dock-store.test.ts @@ -4,7 +4,7 @@ */ import directoryForUserDataInjectable from "../../../../common/app-paths/directory-for-user-data/directory-for-user-data.injectable"; -import hostedClusterIdInjectable from "../../../../common/cluster-store/hosted-cluster-id.injectable"; +import hostedClusterIdInjectable from "../../../cluster-frame-context/hosted-cluster-id.injectable"; import { getDiForUnitTesting } from "../../../getDiForUnitTesting"; import type { DockStore, DockTab } from "../dock/store"; import { TabKind } from "../dock/store"; diff --git a/src/renderer/components/dock/__test__/dock-tabs.test.tsx b/src/renderer/components/dock/__test__/dock-tabs.test.tsx index aa4f755943..8c834061d8 100644 --- a/src/renderer/components/dock/__test__/dock-tabs.test.tsx +++ b/src/renderer/components/dock/__test__/dock-tabs.test.tsx @@ -19,7 +19,7 @@ import directoryForUserDataInjectable from "../../../../common/app-paths/directo import getConfigurationFileModelInjectable from "../../../../common/get-configuration-file-model/get-configuration-file-model.injectable"; import appVersionInjectable from "../../../../common/get-configuration-file-model/app-version/app-version.injectable"; import assert from "assert"; -import hostedClusterIdInjectable from "../../../../common/cluster-store/hosted-cluster-id.injectable"; +import hostedClusterIdInjectable from "../../../cluster-frame-context/hosted-cluster-id.injectable"; jest.mock("electron", () => ({ app: { diff --git a/src/renderer/components/test-utils/get-application-builder.tsx b/src/renderer/components/test-utils/get-application-builder.tsx index e9fc09f7fe..9154299b38 100644 --- a/src/renderer/components/test-utils/get-application-builder.tsx +++ b/src/renderer/components/test-utils/get-application-builder.tsx @@ -13,7 +13,7 @@ import React from "react"; import { Router } from "react-router"; import { Observer } from "mobx-react"; import subscribeStoresInjectable from "../../kube-watch-api/subscribe-stores.injectable"; -import allowedResourcesInjectable from "../../../common/cluster-store/allowed-resources.injectable"; +import allowedResourcesInjectable from "../../cluster-frame-context/allowed-resources.injectable"; import type { RenderResult } from "@testing-library/react"; import { getByText, fireEvent } from "@testing-library/react"; import type { KubeResource } from "../../../common/rbac"; @@ -32,7 +32,7 @@ import applicationMenuItemsInjectable from "../../../main/menu/application-menu- import type { MenuItemConstructorOptions, MenuItem } from "electron"; import storesAndApisCanBeCreatedInjectable from "../../stores-apis-can-be-created.injectable"; import navigateToHelmChartsInjectable from "../../../common/front-end-routing/routes/cluster/helm/charts/navigate-to-helm-charts.injectable"; -import hostedClusterInjectable from "../../../common/cluster-store/hosted-cluster.injectable"; +import hostedClusterInjectable from "../../cluster-frame-context/hosted-cluster.injectable"; import { ClusterFrameContext } from "../../cluster-frame-context/cluster-frame-context"; import type { Cluster } from "../../../common/cluster/cluster"; import { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; diff --git a/src/renderer/frames/cluster-frame/init-cluster-frame/init-cluster-frame.injectable.ts b/src/renderer/frames/cluster-frame/init-cluster-frame/init-cluster-frame.injectable.ts index c80fa760a5..9dd4f59702 100644 --- a/src/renderer/frames/cluster-frame/init-cluster-frame/init-cluster-frame.injectable.ts +++ b/src/renderer/frames/cluster-frame/init-cluster-frame/init-cluster-frame.injectable.ts @@ -7,7 +7,7 @@ import { initClusterFrame } from "./init-cluster-frame"; import extensionLoaderInjectable from "../../../../extensions/extension-loader/extension-loader.injectable"; import catalogEntityRegistryInjectable from "../../../api/catalog/entity/registry.injectable"; import frameRoutingIdInjectable from "./frame-routing-id/frame-routing-id.injectable"; -import hostedClusterInjectable from "../../../../common/cluster-store/hosted-cluster.injectable"; +import hostedClusterInjectable from "../../../cluster-frame-context/hosted-cluster.injectable"; import appEventBusInjectable from "../../../../common/app-event-bus/app-event-bus.injectable"; import clusterFrameContextInjectable from "../../../cluster-frame-context/cluster-frame-context.injectable"; import assert from "assert"; diff --git a/src/renderer/getDiForUnitTesting.tsx b/src/renderer/getDiForUnitTesting.tsx index 3c25ee96aa..6deb96df64 100644 --- a/src/renderer/getDiForUnitTesting.tsx +++ b/src/renderer/getDiForUnitTesting.tsx @@ -32,7 +32,7 @@ import joinPathsInjectable from "../common/path/join-paths.injectable"; import { joinPathsFake } from "../common/test-utils/join-paths-fake"; import hotbarStoreInjectable from "../common/hotbars/store.injectable"; import terminalSpawningPoolInjectable from "./components/dock/terminal/terminal-spawning-pool.injectable"; -import hostedClusterIdInjectable from "../common/cluster-store/hosted-cluster-id.injectable"; +import hostedClusterIdInjectable from "./cluster-frame-context/hosted-cluster-id.injectable"; import historyInjectable from "./navigation/history.injectable"; import { ApiManager } from "../common/k8s-api/api-manager"; import lensResourcesDirInjectable from "../common/vars/lens-resources-dir.injectable"; diff --git a/src/renderer/port-forward/about-port-forwarding.injectable.ts b/src/renderer/port-forward/about-port-forwarding.injectable.ts index 29dba28962..e04fc6a18c 100644 --- a/src/renderer/port-forward/about-port-forwarding.injectable.ts +++ b/src/renderer/port-forward/about-port-forwarding.injectable.ts @@ -5,7 +5,7 @@ import { getInjectable } from "@ogre-tools/injectable"; import { aboutPortForwarding } from "./port-forward-notify"; import navigateToPortForwardsInjectable from "../../common/front-end-routing/routes/cluster/network/port-forwards/navigate-to-port-forwards.injectable"; -import hostedClusterIdInjectable from "../../common/cluster-store/hosted-cluster-id.injectable"; +import hostedClusterIdInjectable from "../cluster-frame-context/hosted-cluster-id.injectable"; import assert from "assert"; import notificationsStoreInjectable from "../components/notifications/notifications-store.injectable"; diff --git a/src/renderer/port-forward/notify-error-port-forwarding.injectable.ts b/src/renderer/port-forward/notify-error-port-forwarding.injectable.ts index a0f1ed714f..9ef9daf805 100644 --- a/src/renderer/port-forward/notify-error-port-forwarding.injectable.ts +++ b/src/renderer/port-forward/notify-error-port-forwarding.injectable.ts @@ -5,7 +5,7 @@ import { getInjectable } from "@ogre-tools/injectable"; import { notifyErrorPortForwarding } from "./port-forward-notify"; import navigateToPortForwardsInjectable from "../../common/front-end-routing/routes/cluster/network/port-forwards/navigate-to-port-forwards.injectable"; -import hostedClusterIdInjectable from "../../common/cluster-store/hosted-cluster-id.injectable"; +import hostedClusterIdInjectable from "../cluster-frame-context/hosted-cluster-id.injectable"; import assert from "assert"; import notificationsStoreInjectable from "../components/notifications/notifications-store.injectable"; diff --git a/src/renderer/utils/create-storage/create-storage.injectable.ts b/src/renderer/utils/create-storage/create-storage.injectable.ts index 798e763dff..f0bc54cd53 100644 --- a/src/renderer/utils/create-storage/create-storage.injectable.ts +++ b/src/renderer/utils/create-storage/create-storage.injectable.ts @@ -10,7 +10,7 @@ import writeJsonFileInjectable from "../../../common/fs/write-json-file.injectab import { observable } from "mobx"; import loggerInjectable from "../../../common/logger.injectable"; import getAbsolutePathInjectable from "../../../common/path/get-absolute-path.injectable"; -import hostedClusterIdInjectable from "../../../common/cluster-store/hosted-cluster-id.injectable"; +import hostedClusterIdInjectable from "../../cluster-frame-context/hosted-cluster-id.injectable"; const createStorageInjectable = getInjectable({ id: "create-storage",