mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix circular dependency
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
c28b56e1c1
commit
6bbbd17400
@ -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 } from "@ogre-tools/injectable";
|
||||||
|
import assert from "assert";
|
||||||
|
import { computed } from "mobx";
|
||||||
|
import namespaceStoreInjectable from "../components/+namespaces/store.injectable";
|
||||||
|
import hostedClusterInjectable from "./hosted-cluster.injectable";
|
||||||
|
|
||||||
|
const allNamespacesInjectable = getInjectable({
|
||||||
|
id: "all-namespaces",
|
||||||
|
instantiate: (di) => {
|
||||||
|
const cluster = di.inject(hostedClusterInjectable);
|
||||||
|
|
||||||
|
assert(cluster, "This can only be injected within a cluster frame");
|
||||||
|
|
||||||
|
const namespaceStore = di.inject(namespaceStoreInjectable);
|
||||||
|
|
||||||
|
return computed(() => {
|
||||||
|
// user given list of namespaces
|
||||||
|
if (cluster.accessibleNamespaces.length) {
|
||||||
|
return cluster.accessibleNamespaces.slice();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (namespaceStore.items.length > 0) {
|
||||||
|
// namespaces from kubernetes api
|
||||||
|
return namespaceStore.items.map((namespace) => namespace.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
// fallback to cluster resolved namespaces because we could not load list
|
||||||
|
return cluster.allowedNamespaces.slice();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default allNamespacesInjectable;
|
||||||
@ -4,37 +4,23 @@
|
|||||||
*/
|
*/
|
||||||
import { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
import type { NamespaceScopedClusterContext } from "./cluster-frame-context";
|
import type { NamespaceScopedClusterContext } from "./cluster-frame-context";
|
||||||
import namespaceStoreInjectable from "../components/+namespaces/store.injectable";
|
|
||||||
import hostedClusterInjectable from "./hosted-cluster.injectable";
|
import hostedClusterInjectable from "./hosted-cluster.injectable";
|
||||||
import assert from "assert";
|
import assert from "assert";
|
||||||
import { computed } from "mobx";
|
import { computed } from "mobx";
|
||||||
import selectedNamespaceStorageInjectable from "../components/+namespaces/namespace-storage.injectable";
|
import selectedNamespaceStorageInjectable from "../components/+namespaces/namespace-storage.injectable";
|
||||||
import { toggle } from "../utils";
|
import { toggle } from "../utils";
|
||||||
|
import allNamespacesInjectable from "./all-namespaces.injectable";
|
||||||
|
|
||||||
const clusterFrameContextForNamespacedResourcesInjectable = getInjectable({
|
const clusterFrameContextForNamespacedResourcesInjectable = getInjectable({
|
||||||
id: "cluster-frame-context-for-namespaced-resources",
|
id: "cluster-frame-context-for-namespaced-resources",
|
||||||
|
|
||||||
instantiate: (di): NamespaceScopedClusterContext => {
|
instantiate: (di): NamespaceScopedClusterContext => {
|
||||||
const cluster = di.inject(hostedClusterInjectable);
|
const cluster = di.inject(hostedClusterInjectable);
|
||||||
const namespaceStore = di.inject(namespaceStoreInjectable);
|
|
||||||
const selectedNamespaceStorage = di.inject(selectedNamespaceStorageInjectable);
|
const selectedNamespaceStorage = di.inject(selectedNamespaceStorageInjectable);
|
||||||
|
|
||||||
assert(cluster, "This can only be injected within a cluster frame");
|
assert(cluster, "This can only be injected within a cluster frame");
|
||||||
|
|
||||||
const allNamespaces = computed(() => {
|
const allNamespaces = di.inject(allNamespacesInjectable);
|
||||||
// user given list of namespaces
|
|
||||||
if (cluster.accessibleNamespaces.length) {
|
|
||||||
return cluster.accessibleNamespaces.slice();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (namespaceStore.items.length > 0) {
|
|
||||||
// namespaces from kubernetes api
|
|
||||||
return namespaceStore.items.map((namespace) => namespace.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
// fallback to cluster resolved namespaces because we could not load list
|
|
||||||
return cluster.allowedNamespaces.slice();
|
|
||||||
});
|
|
||||||
const contextNamespaces = computed(() => {
|
const contextNamespaces = computed(() => {
|
||||||
const storedState = selectedNamespaceStorage.get();
|
const storedState = selectedNamespaceStorage.get();
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
*/
|
*/
|
||||||
import { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
import clusterFrameContextForNamespacedResourcesInjectable from "../../cluster-frame-context/for-namespaced-resources.injectable";
|
import allNamespacesInjectable from "../../cluster-frame-context/all-namespaces.injectable";
|
||||||
import { isDefined } from "../../utils";
|
import { isDefined } from "../../utils";
|
||||||
import createStorageInjectable from "../../utils/create-storage/create-storage.injectable";
|
import createStorageInjectable from "../../utils/create-storage/create-storage.injectable";
|
||||||
|
|
||||||
@ -11,10 +11,10 @@ const selectedNamespaceStorageInjectable = getInjectable({
|
|||||||
id: "selected-namespace-storage",
|
id: "selected-namespace-storage",
|
||||||
instantiate: (di) => {
|
instantiate: (di) => {
|
||||||
const createStorage = di.inject(createStorageInjectable);
|
const createStorage = di.inject(createStorageInjectable);
|
||||||
const context = di.inject(clusterFrameContextForNamespacedResourcesInjectable);
|
const allNamespaces = di.inject(allNamespacesInjectable);
|
||||||
const defaultSelectedNamespaces = context.allNamespaces.includes("default")
|
const defaultSelectedNamespaces = allNamespaces.get().includes("default")
|
||||||
? ["default"]
|
? ["default"]
|
||||||
: [context.allNamespaces[0]].filter(isDefined);
|
: [allNamespaces.get()[0]].filter(isDefined);
|
||||||
|
|
||||||
return createStorage("selected_namespaces", defaultSelectedNamespaces);
|
return createStorage("selected_namespaces", defaultSelectedNamespaces);
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user