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

- fix: don't reset selected "all namespaces" on page reload (#2185)

- fix: don't reload namespaces on every page visit / NamespaceSelect.render()

Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
Roman 2021-02-22 14:44:21 +02:00 committed by Jari Kolehmainen
parent 4ea04c1ffd
commit 136dac4a8f
3 changed files with 8 additions and 7 deletions

View File

@ -56,7 +56,7 @@ export class NamespaceSelectFilter extends React.Component {
if (namespace) { if (namespace) {
namespaceStore.toggleContext(namespace); namespaceStore.toggleContext(namespace);
} else { } else {
namespaceStore.resetContext(); // "All namespaces" clicked, empty list considered as "all" namespaceStore.toggleAll(false); // "All namespaces" clicked
} }
} }

View File

@ -29,6 +29,7 @@ export class NamespaceSelect extends React.Component<Props> {
disposeOnUnmount(this, [ disposeOnUnmount(this, [
kubeWatchApi.subscribeStores([namespaceStore], { kubeWatchApi.subscribeStores([namespaceStore], {
preload: true, preload: true,
loadOnce: true, // skip reloading namespaces on every render / page visit
}) })
]); ]);
} }

View File

@ -5,7 +5,7 @@ import { Namespace, namespacesApi } from "../../api/endpoints/namespaces.api";
import { createPageParam } from "../../navigation"; import { createPageParam } from "../../navigation";
import { apiManager } from "../../api/api-manager"; import { apiManager } from "../../api/api-manager";
const storage = createStorage<string[]>("context_namespaces", []); const storage = createStorage<string[]>("context_namespaces");
export const namespaceUrlParam = createPageParam<string[]>({ export const namespaceUrlParam = createPageParam<string[]>({
name: "namespaces", name: "namespaces",
@ -74,11 +74,11 @@ export class NamespaceStore extends KubeObjectStore<Namespace> {
@computed @computed
private get initialNamespaces(): string[] { private get initialNamespaces(): string[] {
const namespaces = new Set(this.allowedNamespaces); const namespaces = new Set(this.allowedNamespaces);
const prevSelected = storage.get().filter(namespace => namespaces.has(namespace)); const prevSelectedNamespaces = storage.get();
// return previously saved namespaces from local-storage // return previously saved namespaces from local-storage (if any)
if (prevSelected.length > 0) { if (prevSelectedNamespaces) {
return prevSelected; return prevSelectedNamespaces.filter(namespace => namespaces.has(namespace));
} }
// otherwise select "default" or first allowed namespace // otherwise select "default" or first allowed namespace
@ -166,7 +166,7 @@ export class NamespaceStore extends KubeObjectStore<Namespace> {
if (showAll) { if (showAll) {
this.setContext(this.allowedNamespaces); this.setContext(this.allowedNamespaces);
} else { } else {
this.contextNs.clear(); this.resetContext(); // empty context considered as "All namespaces"
} }
} else { } else {
this.toggleAll(!this.hasAllContexts); this.toggleAll(!this.hasAllContexts);