1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com>

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
Janne Savolainen 2022-11-16 13:23:01 +02:00 committed by Iku-turso
parent 34d36d20e2
commit ff8f8e8b66
7 changed files with 147 additions and 16 deletions

View File

@ -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": {

View File

@ -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;

View File

@ -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;

View File

@ -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<string, string>;
distribution: string;
kubeconfigPath: string;
contextName: string;
clusterServerUrl: string;
version: string;
}
export const clusterInjectionToken = getInjectionToken<ClusterDto>({
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;

View File

@ -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<CatalogEntity[]>;
}
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)),
);
}

View File

@ -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);
});
};

View File

@ -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"