mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Move parts of clusterFrameContextForNamespacedResources to separate injectables
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
57ce050e11
commit
b97c8f7746
@ -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);
|
||||
const namespaceStore = di.inject(namespaceStoreInjectable);
|
||||
|
||||
assert(cluster, "This can only be injected within a cluster frame");
|
||||
|
||||
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;
|
||||
@ -0,0 +1,32 @@
|
||||
/**
|
||||
* 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 allNamespacesInjectable from "./all-namespaces.injectable";
|
||||
import hostedClusterInjectable from "./hosted-cluster.injectable";
|
||||
import selectedNamespacesForFilteringInjectable from "./selected-namespaces.injectable";
|
||||
|
||||
const areAllNamespacesSelectedInjectable = getInjectable({
|
||||
id: "are-all-namespaces-selected",
|
||||
instantiate: (di) => {
|
||||
const cluster = di.inject(hostedClusterInjectable);
|
||||
|
||||
assert(cluster, "This can only be injected within a cluster frame");
|
||||
|
||||
const allNamespaces = di.inject(allNamespacesInjectable);
|
||||
const contextNamespaces = di.inject(selectedNamespacesForFilteringInjectable);
|
||||
|
||||
return computed(() => {
|
||||
const namespaces = new Set(contextNamespaces.get());
|
||||
|
||||
return allNamespaces.get().length > 1
|
||||
&& cluster.accessibleNamespaces.length === 0
|
||||
&& allNamespaces.get().every(ns => namespaces.has(ns));
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
export default areAllNamespacesSelectedInjectable;
|
||||
@ -4,58 +4,24 @@
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { ClusterContext } from "./cluster-frame-context";
|
||||
import namespaceStoreInjectable from "../components/+namespaces/store.injectable";
|
||||
import hostedClusterInjectable from "./hosted-cluster.injectable";
|
||||
import assert from "assert";
|
||||
import { computed } from "mobx";
|
||||
import selectedNamespacesStorageInjectable from "../../features/namespace-filtering/renderer/storage.injectable";
|
||||
import allNamespacesInjectable from "./all-namespaces.injectable";
|
||||
import selectedNamespacesForFilteringInjectable from "./selected-namespaces.injectable";
|
||||
import areAllNamespacesSelectedInjectable from "./are-all-namespaces-selected.injectable";
|
||||
import isNamespaceListSufficientToLoadFromAllNamespacesInjectable from "./is-loading-all.injectable";
|
||||
import globalWatchEnabledInjectable from "./global-watch-enabled.injectable";
|
||||
|
||||
const clusterFrameContextForNamespacedResourcesInjectable = getInjectable({
|
||||
id: "cluster-frame-context-for-namespaced-resources",
|
||||
|
||||
instantiate: (di): ClusterContext => {
|
||||
const cluster = di.inject(hostedClusterInjectable);
|
||||
const namespaceStore = di.inject(namespaceStoreInjectable);
|
||||
const selectedNamespacesStorage = di.inject(selectedNamespacesStorageInjectable);
|
||||
|
||||
assert(cluster, "This can only be injected within a cluster frame");
|
||||
|
||||
const allNamespaces = 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();
|
||||
});
|
||||
const contextNamespaces = computed(() => {
|
||||
const selectedNamespaces = selectedNamespacesStorage.get();
|
||||
|
||||
return selectedNamespaces.length > 0
|
||||
? selectedNamespaces
|
||||
: allNamespaces.get();
|
||||
});
|
||||
const hasSelectedAll = computed(() => {
|
||||
const namespaces = new Set(contextNamespaces.get());
|
||||
|
||||
return allNamespaces.get().length > 1
|
||||
&& cluster.accessibleNamespaces.length === 0
|
||||
&& allNamespaces.get().every(ns => namespaces.has(ns));
|
||||
});
|
||||
const allNamespaces = di.inject(allNamespacesInjectable);
|
||||
const contextNamespaces = di.inject(selectedNamespacesForFilteringInjectable);
|
||||
const areAllNamespacesSelected = di.inject(areAllNamespacesSelectedInjectable);
|
||||
const globalWatchEnabled = di.inject(globalWatchEnabledInjectable);
|
||||
|
||||
return {
|
||||
isLoadingAll: (namespaces) => (
|
||||
allNamespaces.get().length > 1
|
||||
&& cluster.accessibleNamespaces.length === 0
|
||||
&& allNamespaces.get().every(ns => namespaces.includes(ns))
|
||||
),
|
||||
isGlobalWatchEnabled: () => cluster.isGlobalWatchEnabled,
|
||||
isLoadingAll: di.inject(isNamespaceListSufficientToLoadFromAllNamespacesInjectable),
|
||||
isGlobalWatchEnabled: () => globalWatchEnabled.get(),
|
||||
get allNamespaces() {
|
||||
return allNamespaces.get();
|
||||
},
|
||||
@ -63,7 +29,7 @@ const clusterFrameContextForNamespacedResourcesInjectable = getInjectable({
|
||||
return contextNamespaces.get();
|
||||
},
|
||||
get hasSelectedAll() {
|
||||
return hasSelectedAll.get();
|
||||
return areAllNamespacesSelected.get();
|
||||
},
|
||||
};
|
||||
},
|
||||
|
||||
@ -0,0 +1,21 @@
|
||||
/**
|
||||
* 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 hostedClusterInjectable from "./hosted-cluster.injectable";
|
||||
|
||||
const globalWatchEnabledInjectable = getInjectable({
|
||||
id: "global-watch-enabled",
|
||||
instantiate: (di) => {
|
||||
const cluster = di.inject(hostedClusterInjectable);
|
||||
|
||||
assert(cluster, "This can only be injected within a cluster frame");
|
||||
|
||||
return computed(() => cluster.isGlobalWatchEnabled);
|
||||
},
|
||||
});
|
||||
|
||||
export default globalWatchEnabledInjectable;
|
||||
@ -0,0 +1,29 @@
|
||||
/**
|
||||
* 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 allNamespacesInjectable from "./all-namespaces.injectable";
|
||||
import hostedClusterInjectable from "./hosted-cluster.injectable";
|
||||
|
||||
export type IsNamespaceListSufficientToLoadFromAllNamespaces = (namespace: string[]) => boolean;
|
||||
|
||||
const isNamespaceListSufficientToLoadFromAllNamespacesInjectable = getInjectable({
|
||||
id: "is-namespace-list-sufficient-to-load-from-all-namespaces",
|
||||
instantiate: (di): IsNamespaceListSufficientToLoadFromAllNamespaces => {
|
||||
const cluster = di.inject(hostedClusterInjectable);
|
||||
|
||||
assert(cluster, "This can only be injected within a cluster frame");
|
||||
|
||||
const allNamespaces = di.inject(allNamespacesInjectable);
|
||||
|
||||
return (namespaces) => (
|
||||
allNamespaces.get().length > 1
|
||||
&& cluster.accessibleNamespaces.length === 0
|
||||
&& allNamespaces.get().every(ns => namespaces.includes(ns))
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
export default isNamespaceListSufficientToLoadFromAllNamespacesInjectable;
|
||||
@ -0,0 +1,26 @@
|
||||
/**
|
||||
* 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 selectedNamespacesStorageInjectable from "../../features/namespace-filtering/renderer/storage.injectable";
|
||||
import allNamespacesInjectable from "./all-namespaces.injectable";
|
||||
|
||||
const selectedNamespacesForFilteringInjectable = getInjectable({
|
||||
id: "selected-namespaces-for-filtering",
|
||||
instantiate: (di) => {
|
||||
const selectedNamespacesStorage = di.inject(selectedNamespacesStorageInjectable);
|
||||
const allNamespaces = di.inject(allNamespacesInjectable);
|
||||
|
||||
return computed(() => {
|
||||
const selectedNamespaces = selectedNamespacesStorage.get();
|
||||
|
||||
return selectedNamespaces.length > 0
|
||||
? selectedNamespaces
|
||||
: allNamespaces.get();
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
export default selectedNamespacesForFilteringInjectable;
|
||||
Loading…
Reference in New Issue
Block a user