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

Clear up some NamespaceStore methods

- Deprecate toggleAll in favour of selectAll because the other was
  dangerous, mostly broken, and didn't toggle

- Fix hasAllContexts to be true in the [] case

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2021-10-28 08:28:51 -04:00
parent 079976d703
commit 956a579bee
2 changed files with 20 additions and 16 deletions

View File

@ -121,10 +121,7 @@ export class NamespaceSelectFilter extends React.Component<SelectProps> {
namespaceStore.toggleSingle(namespace); namespaceStore.toggleSingle(namespace);
} }
} else { } else {
/** namespaceStore.selectAll();
* WARNING: only ever call this method with `false` as an argument
*/
namespaceStore.toggleAll(false);
} }
}; };

View File

@ -148,8 +148,11 @@ export class NamespaceStore extends KubeObjectStore<Namespace> {
.every(namespace => this.selectedNamespaces.includes(namespace)); .every(namespace => this.selectedNamespaces.includes(namespace));
} }
/**
* Is `true` if all available namespaces are selected, otherwise `false`
*/
@computed get hasAllContexts(): boolean { @computed get hasAllContexts(): boolean {
return this.selectedNamespaces.length === this.allowedNamespaces.length; return this.contextNamespaces.length === this.allowedNamespaces.length;
} }
@action @action
@ -167,17 +170,21 @@ export class NamespaceStore extends KubeObjectStore<Namespace> {
this.selectNamespaces(namespace); this.selectNamespaces(namespace);
} }
@action /**
toggleAll(showAll?: boolean) { * Selects all available namespaces.
if (typeof showAll === "boolean") { *
if (showAll) { * Note: If new namespaces appear in the future those will be selected too
this.selectNamespaces(this.allowedNamespaces); */
} else { selectAll() {
this.selectNamespaces([]); // empty context considered as "All namespaces" this.selectNamespaces([]);
} }
} else {
this.toggleAll(!this.hasAllContexts); /**
} * @deprecated Use `NamespaceStore.selectAll` instead
*/
toggleAll(selectAll?: boolean) {
void selectAll;
this.selectAll();
} }
@action @action