proper select-all option for NamespaceSelect (#2084)

Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
Roman authored and GitHub committed 2021-02-04 19:24:39 +02:00
1 parent ad6de71826
commit b514e5c833
3 files changed
+22 -5

No files matched your search

@@ -85,10 +85,9 @@ export class NamespaceSelectFilter extends React.Component {
const namespaces = namespaceStore.getContextNamespaces();
switch (namespaces.length) {
case 0:
case namespaceStore.allowedNamespaces.length:
return <>All namespaces</>;
case 0:
return <>Select a namespace</>;
case 1:
return <>Namespace: {namespaces[0]}</>;
default:
@@ -116,7 +115,7 @@ export class NamespaceSelectFilter extends React.Component {
if (namespace) {
namespaceStore.toggleContext(namespace);
} else {
namespaceStore.toggleAll(); // "All namespaces" option clicked
namespaceStore.resetContext(); // "All namespaces" clicked, empty list considered as "all"
}
};
@@ -103,8 +103,20 @@ export class NamespaceStore extends KubeObjectStore<Namespace> {
return [];
}
public getContextNamespaces(): string[] {
return Array.from(this.contextNs);
getContextNamespaces(): string[] {
const namespaces = Array.from(this.contextNs);
// show all namespaces when nothing selected
if (!namespaces.length) {
// return actual namespaces list since "allowedNamespaces" updating every 30s in cluster and thus might be stale
if (this.isLoaded) {
return this.items.map(namespace => namespace.getName());
}
return this.allowedNamespaces;
}
return namespaces;
}
getSubscribeApis() {
@@ -139,6 +151,11 @@ export class NamespaceStore extends KubeObjectStore<Namespace> {
this.contextNs.replace(namespaces);
}
@action
resetContext() {
this.contextNs.clear();
}
hasContext(namespaces: string | string[]) {
return [namespaces].flat().every(namespace => this.contextNs.has(namespace));
}