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