From ff8f8e8b66e989dac529f789c6c2f2aaf2685d4e Mon Sep 17 00:00:00 2001 From: Janne Savolainen Date: Wed, 16 Nov 2022 13:23:01 +0200 Subject: [PATCH] WIP Co-authored-by: Mikko Aspiala Signed-off-by: Janne Savolainen --- package.json | 1 - .../catalog-entities.injectable.ts | 24 ++++++++++++ .../catalog-entity-for-cluster.injectable.ts | 38 +++++++++++++++++++ .../clusters.injectable.ts | 37 ++++++++++++++++++ src/main/catalog/entity-registry.ts | 26 ++++++++++--- src/renderer/register-features.ts | 12 ++---- yarn.lock | 25 ++++++++++++ 7 files changed, 147 insertions(+), 16 deletions(-) create mode 100644 src/main/catalog/catalog-entities-from-features/catalog-entities.injectable.ts create mode 100644 src/main/catalog/catalog-entities-from-features/catalog-entity-for-cluster.injectable.ts create mode 100644 src/main/catalog/catalog-entities-from-features/clusters.injectable.ts diff --git a/package.json b/package.json index 14b5d8535c..3db7566f25 100644 --- a/package.json +++ b/package.json @@ -296,7 +296,6 @@ "@lensapp/utils": "0.0.1", "@lensapp/composite": "0.0.1", "@lensapp/preferences": "0.0.1", - "@lensapp/test-feature": "0.0.1", "@lensapp/feature-core": "0.0.1" }, "devDependencies": { diff --git a/src/main/catalog/catalog-entities-from-features/catalog-entities.injectable.ts b/src/main/catalog/catalog-entities-from-features/catalog-entities.injectable.ts new file mode 100644 index 0000000000..8d100374ed --- /dev/null +++ b/src/main/catalog/catalog-entities-from-features/catalog-entities.injectable.ts @@ -0,0 +1,24 @@ +/** + * 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 type { ClusterDto } from "./clusters.injectable"; +import clustersInjectable from "./clusters.injectable"; +import catalogEntityForClusterInjectable from "./catalog-entity-for-cluster.injectable"; + +const catalogEntitiesInjectable = getInjectable({ + id: "catalog-entities", + + instantiate: (di) => { + const clusters = di.inject(clustersInjectable); + + const getCatalogEntity = (cluster: ClusterDto) => + di.inject(catalogEntityForClusterInjectable, cluster); + + return computed(() => clusters.get().map(getCatalogEntity)); + }, +}); + +export default catalogEntitiesInjectable; diff --git a/src/main/catalog/catalog-entities-from-features/catalog-entity-for-cluster.injectable.ts b/src/main/catalog/catalog-entities-from-features/catalog-entity-for-cluster.injectable.ts new file mode 100644 index 0000000000..3a43ccf339 --- /dev/null +++ b/src/main/catalog/catalog-entities-from-features/catalog-entity-for-cluster.injectable.ts @@ -0,0 +1,38 @@ +/** + * Copyright (c) OpenLens Authors. All rights reserved. + * Licensed under MIT License. See LICENSE in root directory for more information. + */ +import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable"; +import { KubernetesCluster, LensKubernetesClusterStatus } from "../../../common/catalog-entities"; +import type { ClusterDto } from "./clusters.injectable"; + +const catalogEntityForClusterInjectable = getInjectable({ + id: "catalog-entity-for-cluster", + + instantiate: (di, cluster: ClusterDto) => + new KubernetesCluster({ + metadata: { + uid: cluster.id, + name: cluster.name, + source: cluster.source, + labels: cluster.labels, + distro: cluster.distribution, + kubeVersion: cluster.version, + }, + + spec: { + kubeconfigPath: cluster.kubeconfigPath, + kubeconfigContext: cluster.contextName, + }, + + status: { + phase: LensKubernetesClusterStatus.DISCONNECTED, + }, + }), + + lifecycle: lifecycleEnum.keyedSingleton({ + getInstanceKey: (di, cluster: ClusterDto) => cluster.id, + }), +}); + +export default catalogEntityForClusterInjectable; diff --git a/src/main/catalog/catalog-entities-from-features/clusters.injectable.ts b/src/main/catalog/catalog-entities-from-features/clusters.injectable.ts new file mode 100644 index 0000000000..8f1c59bc6f --- /dev/null +++ b/src/main/catalog/catalog-entities-from-features/clusters.injectable.ts @@ -0,0 +1,37 @@ +/** + * Copyright (c) OpenLens Authors. All rights reserved. + * Licensed under MIT License. See LICENSE in root directory for more information. + */ +import { getInjectable, getInjectionToken } from "@ogre-tools/injectable"; +import { computedInjectManyInjectable } from "@ogre-tools/injectable-extension-for-mobx"; +import { computed } from "mobx"; + +export interface ClusterDto { + id: string; + name: string; + source: string; + labels: Record; + distribution: string; + + kubeconfigPath: string; + contextName: string; + clusterServerUrl: string; + version: string; +} + +export const clusterInjectionToken = getInjectionToken({ + id: "cluster-injection-token", +}); + +const clustersInjectable = getInjectable({ + id: "clusters", + + instantiate: (di) => { + const computedInjectMany = di.inject(computedInjectManyInjectable); + const clusters = computedInjectMany(clusterInjectionToken); + + return computed(() => clusters.get()); + }, +}); + +export default clustersInjectable; diff --git a/src/main/catalog/entity-registry.ts b/src/main/catalog/entity-registry.ts index 972da73132..86893b4af4 100644 --- a/src/main/catalog/entity-registry.ts +++ b/src/main/catalog/entity-registry.ts @@ -6,10 +6,18 @@ import { action, computed, type IComputedValue, type IObservableArray, makeObservable, observable } from "mobx"; import type { CatalogEntity } from "../../common/catalog"; import type { HasCategoryForEntity } from "../../common/catalog/has-category-for-entity.injectable"; -import { iter } from "../../common/utils"; +import { filter, flatMap } from "lodash/fp"; +import { pipeline } from "@ogre-tools/fp"; + +import { + getLegacyGlobalDiForExtensionApi, +} from "../../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api"; + +import catalogEntitiesInjectable from "./catalog-entities-from-features/catalog-entities.injectable"; interface Dependencies { readonly hasCategoryForEntity: HasCategoryForEntity; + readonly decoupledCatalogEntities: IComputedValue; } export class CatalogEntityRegistry { @@ -32,11 +40,17 @@ export class CatalogEntityRegistry { } @computed get items(): CatalogEntity[] { - return Array.from( - iter.filter( - iter.flatMap(this.sources.values(), source => source.get()), - entity => this.dependencies.hasCategoryForEntity(entity), - ), + const di = getLegacyGlobalDiForExtensionApi(); + + const catalogEntities = di.inject(catalogEntitiesInjectable); + + const asd = [...this.sources.values()]; + + return pipeline( + asd, + flatMap(source => source.get()), + x => [...x, ...catalogEntities.get()], + filter(entity => this.dependencies.hasCategoryForEntity(entity)), ); } diff --git a/src/renderer/register-features.ts b/src/renderer/register-features.ts index 3de592271a..2261de4d4f 100644 --- a/src/renderer/register-features.ts +++ b/src/renderer/register-features.ts @@ -3,13 +3,7 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ -import { registerFeature } from "@lensapp/feature-core"; -import type { DiContainer } from "@ogre-tools/injectable"; -import { runInAction } from "mobx"; -import testFeature from "@lensapp/test-feature"; +import { action } from "mobx"; + +export default action(() => {}); -export default (di: DiContainer) => { - runInAction(() => { - registerFeature(di, testFeature); - }); -}; diff --git a/yarn.lock b/yarn.lock index c2fccc0195..240289651c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1101,6 +1101,31 @@ resolved "https://registry.yarnpkg.com/@leichtgewicht/ip-codec/-/ip-codec-2.0.4.tgz#b2ac626d6cb9c8718ab459166d4bb405b8ffa78b" integrity sha512-Hcv+nVC0kZnQ3tD9GVu5xSMR4VVYOteQIr/hwFPVEvPdlXqgGEuRjiheChHgdM+JyqdgNcmzZOX/tnl0JOiI7A== +"@lensapp/composable-responsibilities@0.0.1": + version "0.1.2" + resolved "http://localhost:53093/@lensapp%2fcomposable-responsibilities/-/composable-responsibilities-0.1.2.tgz#93ed9e3d0337cfc64247573708909e7dca4acba7" + integrity sha512-7/lCX/uqn9/h86wV9/j76c1X0oTyp4QTJXwOEWugj8BaM61A6HRMXh3JQzV/g9+OJygp9n8fmy8Zl5exUu0g/g== + +"@lensapp/composite@0.0.1": + version "0.1.2" + resolved "http://localhost:53093/@lensapp%2fcomposite/-/composite-0.1.2.tgz#92d4723213a259caa47e7ea0354f1568442c112c" + integrity sha512-MZH7mG4au4Rd9eWmjijJ6ZcibRId2FMCYo4MzgKNl6EGRikKotVM4yNIGDY/Pjwp4+viYlndjTaj89uDSXmwiQ== + +"@lensapp/feature-core@0.0.1": + version "0.1.2" + resolved "http://localhost:53093/@lensapp%2ffeature-core/-/feature-core-0.1.2.tgz#9b1574ceee3a4d0a686c3c6bc4193a1b4f78a68a" + integrity sha512-O/FiUdT/sI3ocPWpNXlTFOOwZm1nc22NngCQkcFdBlJZODfOFwb/ngzvur1hI24ZBNXqz6sHoIXxz+PhxZlFiQ== + +"@lensapp/preferences@0.0.1": + version "0.1.2" + resolved "http://localhost:53093/@lensapp%2fpreferences/-/preferences-0.1.2.tgz#ab1e16afacfef219bcbece8f0a21ce44d3d3dbcd" + integrity sha512-Sv4GHs/p5IfGa/m5LX91uqJhnGyRGoxWVHSkrXqk98iBVltRIGFCu7R8px5o+C4HZOPCoc2gX2MKMqciAMnHJg== + +"@lensapp/utils@0.0.1": + version "0.1.2" + resolved "http://localhost:53093/@lensapp%2futils/-/utils-0.1.2.tgz#825c58b51ffe41022b3b46d32a175e08f158ec0b" + integrity sha512-Syc3KqKWlaBFhFM/Zww+f/hrTbz8jZI1n02eVFgsXhHo5iJh1+UFglE9JSmry9pPbltNMmAoOq8xiy/0NstdPQ== + "@malept/cross-spawn-promise@^1.1.0": version "1.1.1" resolved "https://registry.yarnpkg.com/@malept/cross-spawn-promise/-/cross-spawn-promise-1.1.1.tgz#504af200af6b98e198bce768bc1730c6936ae01d"