diff --git a/src/renderer/api/kube-watch-api.ts b/src/renderer/api/kube-watch-api.ts index d3b2b4512a..06cab9c06c 100644 --- a/src/renderer/api/kube-watch-api.ts +++ b/src/renderer/api/kube-watch-api.ts @@ -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)); } diff --git a/src/renderer/components/+namespaces/namespace-select.tsx b/src/renderer/components/+namespaces/namespace-select.tsx index 5bcf07e1cf..c3d26ba192 100644 --- a/src/renderer/components/+namespaces/namespace-select.tsx +++ b/src/renderer/components/+namespaces/namespace-select.tsx @@ -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" } }; diff --git a/src/renderer/components/+namespaces/namespace.store.ts b/src/renderer/components/+namespaces/namespace.store.ts index c56043766a..51f7606e8b 100644 --- a/src/renderer/components/+namespaces/namespace.store.ts +++ b/src/renderer/components/+namespaces/namespace.store.ts @@ -103,8 +103,20 @@ export class NamespaceStore extends KubeObjectStore { 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 { this.contextNs.replace(namespaces); } + @action + resetContext() { + this.contextNs.clear(); + } + hasContext(namespaces: string | string[]) { return [namespaces].flat().every(namespace => this.contextNs.has(namespace)); }