From 9e2ee009742461da414adda2a0c10f8768fdf20f Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Fri, 29 Oct 2021 08:45:02 -0400 Subject: [PATCH] Clear up some NamespaceStore.toggleAll and NamespaceStore.hasAllContexts (#4167) --- .../+namespaces/namespace-select-filter.tsx | 5 +-- .../components/+namespaces/namespace.store.ts | 31 ++++++++++++------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/renderer/components/+namespaces/namespace-select-filter.tsx b/src/renderer/components/+namespaces/namespace-select-filter.tsx index 9ad0c60a4c..4bcc280cc6 100644 --- a/src/renderer/components/+namespaces/namespace-select-filter.tsx +++ b/src/renderer/components/+namespaces/namespace-select-filter.tsx @@ -121,10 +121,7 @@ export class NamespaceSelectFilter extends React.Component { namespaceStore.toggleSingle(namespace); } } else { - /** - * WARNING: only ever call this method with `false` as an argument - */ - namespaceStore.toggleAll(false); + namespaceStore.selectAll(); } }; diff --git a/src/renderer/components/+namespaces/namespace.store.ts b/src/renderer/components/+namespaces/namespace.store.ts index 54f98702fc..e2a6b5ebf1 100644 --- a/src/renderer/components/+namespaces/namespace.store.ts +++ b/src/renderer/components/+namespaces/namespace.store.ts @@ -148,8 +148,11 @@ export class NamespaceStore extends KubeObjectStore { .every(namespace => this.selectedNamespaces.includes(namespace)); } + /** + * Is `true` if all available namespaces are selected, otherwise `false` + */ @computed get hasAllContexts(): boolean { - return this.selectedNamespaces.length === this.allowedNamespaces.length; + return this.contextNamespaces.length === this.allowedNamespaces.length; } @action @@ -167,17 +170,21 @@ export class NamespaceStore extends KubeObjectStore { this.selectNamespaces(namespace); } - @action - toggleAll(showAll?: boolean) { - if (typeof showAll === "boolean") { - if (showAll) { - this.selectNamespaces(this.allowedNamespaces); - } else { - this.selectNamespaces([]); // empty context considered as "All namespaces" - } - } else { - this.toggleAll(!this.hasAllContexts); - } + /** + * Selects all available namespaces. + * + * Note: If new namespaces appear in the future those will be selected too + */ + selectAll() { + this.selectNamespaces([]); + } + + /** + * @deprecated Use `NamespaceStore.selectAll` instead + */ + toggleAll(selectAll?: boolean) { + void selectAll; + this.selectAll(); } @action