Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ describe('HubStatusBar', () => {
expect(mockItem.tooltip).toContain('○ ns2');
expect(mockItem.tooltip).toContain('✓ ns3');
});

it('marks every namespace as selected when the selection is empty', () => {
statusBar.setState('connected', 2);
statusBar.setAvailableAndSelected(['alpha', 'beta'], []);
expect(mockItem.text).toBe('$(cloud) CALM Hub (2)');
expect(mockItem.tooltip).toContain('Namespaces (2 selected / 2 available)');
expect(mockItem.tooltip).toContain('✓ alpha');
expect(mockItem.tooltip).toContain('✓ beta');
});
});

describe('dispose', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as vscode from 'vscode';
import { resolveSelectedNamespaces } from './namespace-selection';

export type ConnectionState = 'disconnected' | 'connecting' | 'connected' | 'error';

Expand Down Expand Up @@ -64,11 +65,13 @@ export class HubStatusBar {
const countLabel = selCount > 0 ? `${selCount}/${availCount}` : `${availCount}`;
this.statusBarItem.text = `$(cloud) CALM Hub (${countLabel})`;

// An empty selection means "all namespaces", so the tooltip resolves it (#3493).
const selected = resolveSelectedNamespaces(this.availableNamespaces, this.selectedNamespaces);
const nsList = this.availableNamespaces.map((ns) =>
this.selectedNamespaces.includes(ns) ? ` ✓ ${ns}` : ` ○ ${ns}`
selected.includes(ns) ? ` ✓ ${ns}` : ` ○ ${ns}`
).join('\n');
this.statusBarItem.tooltip = (this.hubUrl ? `${this.hubUrl}\n\n` : '') +
`Namespaces (${selCount} selected / ${availCount} available):\n` +
`Namespaces (${selected.length} selected / ${availCount} available):\n` +
nsList +
'\n\nClick to manage';
this.statusBarItem.backgroundColor = undefined;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { describe, it, expect } from 'vitest';
import { resolveSelectedNamespaces } from './namespace-selection';

describe('resolveSelectedNamespaces', () => {
const available = ['alpha', 'beta', 'gamma'];

it('treats an empty selection as "all namespaces"', () => {
expect(resolveSelectedNamespaces(available, [])).toEqual(available);
});

it('treats an unset selection as "all namespaces"', () => {
expect(resolveSelectedNamespaces(available, undefined)).toEqual(available);
expect(resolveSelectedNamespaces(available, null)).toEqual(available);
});

it('keeps only the selected namespaces', () => {
expect(resolveSelectedNamespaces(available, ['gamma', 'alpha'])).toEqual(['alpha', 'gamma']);
});

it('drops names that the hub no longer lists', () => {
expect(resolveSelectedNamespaces(available, ['alpha', 'gone'])).toEqual(['alpha']);
});

it('returns nothing when the hub lists no namespaces', () => {
expect(resolveSelectedNamespaces([], [])).toEqual([]);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* Resolve the `calm.hub.selectedNamespaces` setting against the namespaces the
* Hub lists.
*
* CALM Hub has no namespace selection of its own: the filter is this plugin's
* setting. VS Code reports an unset string array as `[]`, so `undefined`, `null`
* and `[]` all mean "every namespace".
*/
Comment thread
rocketstack-matt marked this conversation as resolved.
export function resolveSelectedNamespaces(
available: readonly string[],
selection: readonly string[] | null | undefined
): string[] {
if (!selection || selection.length === 0) {
return [...available];
}
return available.filter((namespace) => selection.includes(namespace));
}
6 changes: 2 additions & 4 deletions calm-plugins/vscode/src/extension/webview/canvas-panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { DiagramExportService } from '../services/diagram-export-service';
import { HubClient, describeHubError } from '../services/hub-client';
import { HubAssetService, type HubNamespace } from '../services/hub-asset-service';
import { ControlAssetService, LOCAL_DOMAIN } from '../services/control-asset-service';
import { resolveSelectedNamespaces } from '../services/namespace-selection';
import { ShaCacheService } from '../services/sha-cache-service';
import { SvgImportService } from '../services/svg-import';
import {
Expand Down Expand Up @@ -346,10 +347,7 @@ export class CanvasPanel {

const allNs = this.hubAssetService?.getNamespaces().map(ns => ns.name) ?? [];
const userSelection = vscode.workspace.getConfiguration('calm.hub').get<string[]>('selectedNamespaces');
// VS Code defaults unset arrays to []. Treat null/undefined/[] as "show all".
const selectedNs = (userSelection && userSelection.length > 0)
? allNs.filter(ns => userSelection.includes(ns))
: allNs;
const selectedNs = resolveSelectedNamespaces(allNs, userSelection);
const hubBlocks = this.hubAssetService?.getAllStandardNodes(selectedNs) ?? [];
const hubPatterns = this.hubAssetService?.getAllPatterns(selectedNs) ?? [];

Expand Down
Loading