From 7244aaf36aaeb9a98fba6508e5ef7089d16a9e51 Mon Sep 17 00:00:00 2001 From: Boris Tyshkevich Date: Fri, 24 Jul 2026 08:01:19 +0200 Subject: [PATCH] Fix workspace route navigation --- src/ui/app-header.ts | 9 ++++++--- tests/unit/app.test.ts | 10 +++++++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/ui/app-header.ts b/src/ui/app-header.ts index 9704d4d..1b9421a 100644 --- a/src/ui/app-header.ts +++ b/src/ui/app-header.ts @@ -25,17 +25,20 @@ export function routeButton( } function surfaceSwitch(app: App): HTMLElement { - const key = app.currentWorkspace?.key ?? app.state.workspaceKey; const dashboard = app.sqlRoute.surface === 'dashboard'; + // The header stays mounted when File → New workspace swaps the active + // aggregate. Resolve at click time so its route never retains the workspace + // key from the header's original render. + const workspaceKey = (): string => app.currentWorkspace?.key ?? app.state.workspaceKey; return h('div', { class: 'editor-mode-switch app-surface-switch', role: 'group', 'aria-label': 'Application surface', }, routeButton('SQL Browser', !dashboard, () => { - void app.navigateSqlRoute({ surface: 'workspace', workspaceKey: key }, 'push'); + void app.navigateSqlRoute({ surface: 'workspace', workspaceKey: workspaceKey() }, 'push'); }), routeButton('Dashboard', dashboard, () => { - void app.navigateSqlRoute({ surface: 'dashboard', workspaceKey: key, mode: 'edit' }, 'push'); + void app.navigateSqlRoute({ surface: 'dashboard', workspaceKey: workspaceKey(), mode: 'edit' }, 'push'); })); } diff --git a/tests/unit/app.test.ts b/tests/unit/app.test.ts index ddbf8a6..044c2bd 100644 --- a/tests/unit/app.test.ts +++ b/tests/unit/app.test.ts @@ -972,10 +972,18 @@ describe('renderApp shell', () => { .toEqual(['SQL Browser', 'Dashboard']); expect(qs(app.root, '.dashboard-mode-switch')).toBeNull(); app.navigateSqlRoute = vi.fn(async () => {}); + // File → New workspace replaces the active aggregate without rebuilding + // this header. Its surface controls must route to the replacement, not + // the key captured when the header first mounted. + app.currentWorkspace = { + storageVersion: 2, id: 'new-workspace', key: 'sql_library_7', + name: 'SQL Library', queries: [], dashboard: null, + }; + app.state.workspaceKey = 'sql_library_7'; qsa(app.root, '.app-surface-switch .editor-mode-btn') .find((button) => button.textContent === 'Dashboard')!.click(); expect(app.navigateSqlRoute).toHaveBeenCalledWith({ - surface: 'dashboard', workspaceKey: app.state.workspaceKey, mode: 'edit', + surface: 'dashboard', workspaceKey: 'sql_library_7', mode: 'edit', }, 'push'); expect(qs(app.root, '.sidebar')).not.toBeNull(); expect(qs(app.root, '.cm-editor')).not.toBeNull();