mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
WIP
Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
1 parent
34d36d20e2
commit
ff8f8e8b66
7 files changed
+147
-16
No files matched your search
@@ -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;
|
||||
+38
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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)),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
};
|
||||
Reference in new issue
Block a user