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 { 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]);
},
});

View File

@ -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),
}),
});

View File

@ -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,

View File

@ -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<IsMulti extends boolean> extends Omit<Sele
}
interface Dependencies {
namespaceStore: NamespaceStore;
context: ClusterContext;
}
function getOptions(namespaceStore: NamespaceStore, sort: NamespaceSelectSort | undefined) {
function getOptions(context: ClusterContext, sort: NamespaceSelectSort | undefined) {
return computed(() => {
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<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 (
<Select
@ -77,7 +77,7 @@ const NonInjectedNamespaceSelect = observer(({
const InjectedNamespaceSelect = withInjectables<Dependencies, NamespaceSelectProps<boolean>>(NonInjectedNamespaceSelect, {
getProps: (di, props) => ({
...props,
namespaceStore: di.inject(namespaceStoreInjectable),
context: di.inject(clusterFrameContextForNamespacedResourcesInjectable),
}),
});

View File

@ -4,7 +4,7 @@
*/
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 podStoreInjectable from "./store.injectable";
@ -12,12 +12,12 @@ const loadPodsFromAllNamespacesInjectable = getInjectable({
id: "load-pods-from-all-namespaces",
instantiate: (di) => {
const podStore = di.inject(podStoreInjectable);
const namespaceStore = di.inject(namespaceStoreInjectable);
const context = di.inject(clusterFrameContextForNamespacedResourcesInjectable);
const showErrorNotification = di.inject(showErrorNotificationInjectable);
return () => {
podStore.loadAll({
namespaces: [...namespaceStore.getItems().map(ns => ns.getName())],
namespaces: context.allNamespaces,
onLoadFailure: error =>
showErrorNotification(`Can not load Pods. ${String(error)}`),
});