1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Fix namespaces not respecting accessible namespace config

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2023-03-03 16:32:40 -05:00
parent 0d625ccea7
commit bf365bba3d
5 changed files with 23 additions and 21 deletions

View File

@ -4,7 +4,7 @@
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import { computed } from "mobx"; 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"; import { storesAndApisCanBeCreatedInjectionToken } from "./stores-apis-can-be-created.token";
const selectedFilterNamespacesInjectable = getInjectable({ const selectedFilterNamespacesInjectable = getInjectable({
@ -15,9 +15,9 @@ const selectedFilterNamespacesInjectable = getInjectable({
return computed(() => []); return computed(() => []);
} }
const store = di.inject(namespaceStoreInjectable); const context = di.inject(clusterFrameContextForNamespacedResourcesInjectable);
return computed(() => [...store.contextNamespaces]); return computed(() => [...context.contextNamespaces]);
}, },
}); });

View File

@ -6,6 +6,7 @@ import { namespaceSelectFilterModelFor } from "./namespace-select-filter-model";
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import namespaceStoreInjectable from "../store.injectable"; import namespaceStoreInjectable from "../store.injectable";
import isMultiSelectionKeyInjectable from "./is-selection-key.injectable"; import isMultiSelectionKeyInjectable from "./is-selection-key.injectable";
import clusterFrameContextForNamespacedResourcesInjectable from "../../../cluster-frame-context/for-namespaced-resources.injectable";
const namespaceSelectFilterModelInjectable = getInjectable({ const namespaceSelectFilterModelInjectable = getInjectable({
id: "namespace-select-filter-model", id: "namespace-select-filter-model",
@ -13,6 +14,7 @@ const namespaceSelectFilterModelInjectable = getInjectable({
instantiate: (di) => namespaceSelectFilterModelFor({ instantiate: (di) => namespaceSelectFilterModelFor({
namespaceStore: di.inject(namespaceStoreInjectable), namespaceStore: di.inject(namespaceStoreInjectable),
isMultiSelectionKey: di.inject(isMultiSelectionKeyInjectable), isMultiSelectionKey: di.inject(isMultiSelectionKeyInjectable),
context: di.inject(clusterFrameContextForNamespacedResourcesInjectable),
}), }),
}); });

View File

@ -13,6 +13,7 @@ import { observableCrate } from "../../../utils";
import type { IsMultiSelectionKey } from "./is-selection-key.injectable"; import type { IsMultiSelectionKey } from "./is-selection-key.injectable";
interface Dependencies { interface Dependencies {
context: NamespaceScopedClusterContext;
namespaceStore: NamespaceStore; namespaceStore: NamespaceStore;
isMultiSelectionKey: IsMultiSelectionKey; isMultiSelectionKey: IsMultiSelectionKey;
} }
@ -44,7 +45,7 @@ enum SelectMenuState {
} }
export function namespaceSelectFilterModelFor(dependencies: Dependencies): NamespaceSelectFilterModel { export function namespaceSelectFilterModelFor(dependencies: Dependencies): NamespaceSelectFilterModel {
const { isMultiSelectionKey, namespaceStore } = dependencies; const { isMultiSelectionKey, namespaceStore, context } = dependencies;
let didToggle = false; let didToggle = false;
let isMultiSelection = false; let isMultiSelection = false;
@ -56,7 +57,7 @@ export function namespaceSelectFilterModelFor(dependencies: Dependencies): Names
didToggle = false; didToggle = false;
}, },
}]); }]);
const selectedNames = computed(() => new Set(namespaceStore.contextNamespaces), { const selectedNames = computed(() => new Set(context.contextNamespaces), {
equals: comparer.structural, equals: comparer.structural,
}); });
const optionsSortingSelected = observable.set(selectedNames.get()); const optionsSortingSelected = observable.set(selectedNames.get());
@ -78,9 +79,8 @@ export function namespaceSelectFilterModelFor(dependencies: Dependencies): Names
label: "All Namespaces", label: "All Namespaces",
id: "all-namespaces", id: "all-namespaces",
}, },
...namespaceStore ...context
.items .allNamespaces
.map(ns => ns.getName())
.sort(sortNamespacesByIfTheyHaveBeenSelected) .sort(sortNamespacesByIfTheyHaveBeenSelected)
.map(namespace => ({ .map(namespace => ({
value: namespace, value: namespace,

View File

@ -12,9 +12,9 @@ import type { SelectProps } from "../select";
import { Select } from "../select"; import { Select } from "../select";
import { cssNames } from "../../utils"; import { cssNames } from "../../utils";
import { Icon } from "../icon"; import { Icon } from "../icon";
import type { NamespaceStore } from "./store";
import { withInjectables } from "@ogre-tools/injectable-react"; 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; export type NamespaceSelectSort = (left: string, right: string) => number;
@ -25,12 +25,12 @@ export interface NamespaceSelectProps<IsMulti extends boolean> extends Omit<Sele
} }
interface Dependencies { interface Dependencies {
namespaceStore: NamespaceStore; context: ClusterContext;
} }
function getOptions(namespaceStore: NamespaceStore, sort: NamespaceSelectSort | undefined) { function getOptions(context: ClusterContext, sort: NamespaceSelectSort | undefined) {
return computed(() => { return computed(() => {
const baseOptions = namespaceStore.items.map(ns => ns.getName()); const baseOptions = context.allNamespaces;
if (sort) { if (sort) {
baseOptions.sort(sort); baseOptions.sort(sort);
@ -44,16 +44,16 @@ function getOptions(namespaceStore: NamespaceStore, sort: NamespaceSelectSort |
} }
const NonInjectedNamespaceSelect = observer(({ const NonInjectedNamespaceSelect = observer(({
namespaceStore, context,
showIcons, showIcons,
formatOptionLabel, formatOptionLabel,
sort, sort,
className, className,
...selectProps ...selectProps
}: Dependencies & NamespaceSelectProps<boolean>) => { }: Dependencies & NamespaceSelectProps<boolean>) => {
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 ( return (
<Select <Select
@ -77,7 +77,7 @@ const NonInjectedNamespaceSelect = observer(({
const InjectedNamespaceSelect = withInjectables<Dependencies, NamespaceSelectProps<boolean>>(NonInjectedNamespaceSelect, { const InjectedNamespaceSelect = withInjectables<Dependencies, NamespaceSelectProps<boolean>>(NonInjectedNamespaceSelect, {
getProps: (di, props) => ({ getProps: (di, props) => ({
...props, ...props,
namespaceStore: di.inject(namespaceStoreInjectable), context: di.inject(clusterFrameContextForNamespacedResourcesInjectable),
}), }),
}); });

View File

@ -4,7 +4,7 @@
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import namespaceStoreInjectable from "../+namespaces/store.injectable"; import clusterFrameContextForNamespacedResourcesInjectable from "../../cluster-frame-context/for-namespaced-resources.injectable";
import showErrorNotificationInjectable from "../notifications/show-error-notification.injectable"; import showErrorNotificationInjectable from "../notifications/show-error-notification.injectable";
import podStoreInjectable from "./store.injectable"; import podStoreInjectable from "./store.injectable";
@ -12,12 +12,12 @@ const loadPodsFromAllNamespacesInjectable = getInjectable({
id: "load-pods-from-all-namespaces", id: "load-pods-from-all-namespaces",
instantiate: (di) => { instantiate: (di) => {
const podStore = di.inject(podStoreInjectable); const podStore = di.inject(podStoreInjectable);
const namespaceStore = di.inject(namespaceStoreInjectable); const context = di.inject(clusterFrameContextForNamespacedResourcesInjectable);
const showErrorNotification = di.inject(showErrorNotificationInjectable); const showErrorNotification = di.inject(showErrorNotificationInjectable);
return () => { return () => {
podStore.loadAll({ podStore.loadAll({
namespaces: [...namespaceStore.getItems().map(ns => ns.getName())], namespaces: context.allNamespaces,
onLoadFailure: error => onLoadFailure: error =>
showErrorNotification(`Can not load Pods. ${String(error)}`), showErrorNotification(`Can not load Pods. ${String(error)}`),
}); });