From bf365bba3dbedcfc1724e7c3f2d331a678fa79b3 Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Fri, 3 Mar 2023 16:32:40 -0500 Subject: [PATCH] Fix namespaces not respecting accessible namespace config Signed-off-by: Sebastian Malton --- .../selected-filter-namespaces.injectable.ts | 6 +++--- ...namespace-select-filter-model.injectable.ts | 2 ++ .../namespace-select-filter-model.tsx | 10 +++++----- .../+namespaces/namespace-select.tsx | 18 +++++++++--------- ...load-pods-from-all-namespaces.injectable.ts | 8 ++++---- 5 files changed, 23 insertions(+), 21 deletions(-) diff --git a/packages/core/src/common/k8s-api/selected-filter-namespaces.injectable.ts b/packages/core/src/common/k8s-api/selected-filter-namespaces.injectable.ts index 6c70a665a4..41f664b895 100644 --- a/packages/core/src/common/k8s-api/selected-filter-namespaces.injectable.ts +++ b/packages/core/src/common/k8s-api/selected-filter-namespaces.injectable.ts @@ -4,7 +4,7 @@ */ import { getInjectable } from "@ogre-tools/injectable"; import { computed } from "mobx"; -import namespaceStoreInjectable from "../../renderer/components/+namespaces/store.injectable"; +import clusterFrameContextForNamespacedResourcesInjectable from "../../renderer/cluster-frame-context/for-namespaced-resources.injectable"; import { storesAndApisCanBeCreatedInjectionToken } from "./stores-apis-can-be-created.token"; const selectedFilterNamespacesInjectable = getInjectable({ @@ -15,9 +15,9 @@ const selectedFilterNamespacesInjectable = getInjectable({ return computed(() => []); } - const store = di.inject(namespaceStoreInjectable); + const context = di.inject(clusterFrameContextForNamespacedResourcesInjectable); - return computed(() => [...store.contextNamespaces]); + return computed(() => [...context.contextNamespaces]); }, }); diff --git a/packages/core/src/renderer/components/+namespaces/namespace-select-filter-model/namespace-select-filter-model.injectable.ts b/packages/core/src/renderer/components/+namespaces/namespace-select-filter-model/namespace-select-filter-model.injectable.ts index 5578767cf1..d84292410b 100644 --- a/packages/core/src/renderer/components/+namespaces/namespace-select-filter-model/namespace-select-filter-model.injectable.ts +++ b/packages/core/src/renderer/components/+namespaces/namespace-select-filter-model/namespace-select-filter-model.injectable.ts @@ -6,6 +6,7 @@ import { namespaceSelectFilterModelFor } from "./namespace-select-filter-model"; import { getInjectable } from "@ogre-tools/injectable"; import namespaceStoreInjectable from "../store.injectable"; import isMultiSelectionKeyInjectable from "./is-selection-key.injectable"; +import clusterFrameContextForNamespacedResourcesInjectable from "../../../cluster-frame-context/for-namespaced-resources.injectable"; const namespaceSelectFilterModelInjectable = getInjectable({ id: "namespace-select-filter-model", @@ -13,6 +14,7 @@ const namespaceSelectFilterModelInjectable = getInjectable({ instantiate: (di) => namespaceSelectFilterModelFor({ namespaceStore: di.inject(namespaceStoreInjectable), isMultiSelectionKey: di.inject(isMultiSelectionKeyInjectable), + context: di.inject(clusterFrameContextForNamespacedResourcesInjectable), }), }); diff --git a/packages/core/src/renderer/components/+namespaces/namespace-select-filter-model/namespace-select-filter-model.tsx b/packages/core/src/renderer/components/+namespaces/namespace-select-filter-model/namespace-select-filter-model.tsx index a3d850cdcd..b9396f56a0 100644 --- a/packages/core/src/renderer/components/+namespaces/namespace-select-filter-model/namespace-select-filter-model.tsx +++ b/packages/core/src/renderer/components/+namespaces/namespace-select-filter-model/namespace-select-filter-model.tsx @@ -13,6 +13,7 @@ import { observableCrate } from "../../../utils"; import type { IsMultiSelectionKey } from "./is-selection-key.injectable"; interface Dependencies { + context: NamespaceScopedClusterContext; namespaceStore: NamespaceStore; isMultiSelectionKey: IsMultiSelectionKey; } @@ -44,7 +45,7 @@ enum SelectMenuState { } export function namespaceSelectFilterModelFor(dependencies: Dependencies): NamespaceSelectFilterModel { - const { isMultiSelectionKey, namespaceStore } = dependencies; + const { isMultiSelectionKey, namespaceStore, context } = dependencies; let didToggle = false; let isMultiSelection = false; @@ -56,7 +57,7 @@ export function namespaceSelectFilterModelFor(dependencies: Dependencies): Names didToggle = false; }, }]); - const selectedNames = computed(() => new Set(namespaceStore.contextNamespaces), { + const selectedNames = computed(() => new Set(context.contextNamespaces), { equals: comparer.structural, }); const optionsSortingSelected = observable.set(selectedNames.get()); @@ -78,9 +79,8 @@ export function namespaceSelectFilterModelFor(dependencies: Dependencies): Names label: "All Namespaces", id: "all-namespaces", }, - ...namespaceStore - .items - .map(ns => ns.getName()) + ...context + .allNamespaces .sort(sortNamespacesByIfTheyHaveBeenSelected) .map(namespace => ({ value: namespace, diff --git a/packages/core/src/renderer/components/+namespaces/namespace-select.tsx b/packages/core/src/renderer/components/+namespaces/namespace-select.tsx index 6c50f3f921..baf2ba2d92 100644 --- a/packages/core/src/renderer/components/+namespaces/namespace-select.tsx +++ b/packages/core/src/renderer/components/+namespaces/namespace-select.tsx @@ -12,9 +12,9 @@ import type { SelectProps } from "../select"; import { Select } from "../select"; import { cssNames } from "../../utils"; import { Icon } from "../icon"; -import type { NamespaceStore } from "./store"; import { withInjectables } from "@ogre-tools/injectable-react"; -import namespaceStoreInjectable from "./store.injectable"; +import clusterFrameContextForNamespacedResourcesInjectable from "../../cluster-frame-context/for-namespaced-resources.injectable"; +import type { ClusterContext } from "../../cluster-frame-context/cluster-frame-context"; export type NamespaceSelectSort = (left: string, right: string) => number; @@ -25,12 +25,12 @@ export interface NamespaceSelectProps extends Omit { - const baseOptions = namespaceStore.items.map(ns => ns.getName()); + const baseOptions = context.allNamespaces; if (sort) { baseOptions.sort(sort); @@ -44,16 +44,16 @@ function getOptions(namespaceStore: NamespaceStore, sort: NamespaceSelectSort | } const NonInjectedNamespaceSelect = observer(({ - namespaceStore, + context, showIcons, formatOptionLabel, sort, className, ...selectProps }: Dependencies & NamespaceSelectProps) => { - const [baseOptions, setBaseOptions] = useState(getOptions(namespaceStore, sort)); + const [baseOptions, setBaseOptions] = useState(getOptions(context, sort)); - useEffect(() => setBaseOptions(getOptions(namespaceStore, sort)), [sort]); + useEffect(() => setBaseOptions(getOptions(context, sort)), [sort]); return (