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

proper select-all option for NamespaceSelect (#2084)

Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
Roman 2021-02-04 19:24:39 +02:00 committed by GitHub
parent ad6de71826
commit b514e5c833
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 5 deletions

View File

@ -70,6 +70,7 @@ export class KubeWatchApi {
return [];
}
// TODO: optimize - check when all namespaces are selected and then request all in one
if (api.isNamespaced && !this.cluster.isGlobalWatchEnabled) {
return this.namespaces.map(namespace => api.getWatchUrl(namespace));
}

View File

@ -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"
}
};

View File

@ -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));
}