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
9 changes: 6 additions & 3 deletions src/ui/app-header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}));
}

Expand Down
10 changes: 9 additions & 1 deletion tests/unit/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<HTMLButtonElement>(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();
Expand Down
Loading