From a579612a8550beeb9a584063096089fa8de1e9e6 Mon Sep 17 00:00:00 2001 From: broisnees Date: Sun, 15 Nov 2026 18:34:31 +0000 Subject: [PATCH] NoSQL: a tab per collection, like table tabs MongoDB, CouchDB, Elasticsearch/OpenSearch, Firestore and Cassandra had one Browse tab whose collection the sidebar swapped. Each collection now opens its own tab, named after it; an open one is focused, and the blank Browse tab a connection starts on takes the first pick. Every docs tab keeps its own browser mounted, so switching back keeps its page, filters and scroll. Co-Authored-By: Claude Opus 5.5 --- src/lib/components/StudioShell.svelte | 87 +++++++++++++++++---------- src/lib/studio-tabs.js | 2 + 2 files changed, 58 insertions(+), 31 deletions(-) diff --git a/src/lib/components/StudioShell.svelte b/src/lib/components/StudioShell.svelte index 7aacbdc9..2a1f3841 100644 --- a/src/lib/components/StudioShell.svelte +++ b/src/lib/components/StudioShell.svelte @@ -1007,7 +1007,8 @@ let dynamoEverOpened = $state(false) let docsEverOpened = $state(false) /** The collection/table the Browse page shows: the sidebar's selection. */ - let docCollection = $state('') + /** The open document tab's collection (each docs tab keeps its own). */ + const docCollection = $derived(activeTab?.kind === 'docs' ? (/** @type {any} */ (activeTab).collection ?? '') : '') /** The DynamoDB table the DynamoDB page shows. */ let dynamoTable = $state('') /** Engines whose sidebar schema is part of the collection's name (db.coll, keyspace.table). */ @@ -4514,13 +4515,34 @@ let rowSearch = $state('') clearTableEditor() } - /** The document browser: the main page of a CouchDB / Cassandra / Firestore connection. */ - function openDocsTab() { - const existing = findDocsTab(tabs) - if (existing) { void activateTab(existing.id); return } + /** + * The document browser (MongoDB, CouchDB, Elasticsearch, Firestore, + * Cassandra...), one tab per collection like table tabs. A collection + * already open is focused; the blank Browse tab a connection opens on takes + * the first collection picked; any other pick opens its own tab. No + * collection: back to the docs tab used last, or a blank one. + * @param {string} [collection] + */ + function openDocsTab(collection) { + const docs = tabs.filter((t) => t.kind === 'docs') + if (collection === undefined) { + const last = docs.find((t) => t.id === activeTabId) ?? docs.at(-1) + if (last) { void activateTab(last.id); return } + collection = '' + } + const name = /** @type {string} */ (collection) + const same = docs.find((t) => (/** @type {any} */ (t).collection ?? '') === name) + if (same) { void activateTab(same.id); return } + const title = name ? name.slice(name.lastIndexOf('.') + 1) : 'Browse' + const blank = name ? docs.find((t) => !(/** @type {any} */ (t).collection)) : null + if (blank) { + tabs = tabs.map((t) => (t.id === blank.id ? /** @type {any} */ ({ ...t, collection: name, title }) : t)) + void activateTab(blank.id) + return + } saveActiveTabState() dropWelcomeTabs() - const tab = createDocsTab() + const tab = /** @type {any} */ ({ ...createDocsTab(), collection: name, title }) tabs = [...tabs, tab] activeTabId = tab.id clearTableEditor() @@ -7667,10 +7689,9 @@ let rowSearch = $state('') const connIsDynamo = fam === 'dynamodb' const connIsDoc = fam === 'couchdb' || fam === 'cassandra' || fam === 'firestore' || fam === 'mongodb' || fam === 'elasticsearch' || fam === 'opensearch' const connIsRedis = fam === 'redis' - docCollection = '' dynamoTable = '' if (connIsDoc) { - openDocsTab() + openDocsTab('') } else if (connIsDynamo) { openDynamoTab() } else if (connIsRedis) { @@ -8036,8 +8057,7 @@ let rowSearch = $state('') if (aiMode) exitAiMode() // NoSQL: the sidebar picks what the engine's own page shows. if (isDoc) { - docCollection = docQualified && activeSchema ? `${activeSchema}.${name}` : name - openDocsTab() + openDocsTab(docQualified && activeSchema ? `${activeSchema}.${name}` : name) return } if (isDynamo) { @@ -10293,28 +10313,33 @@ let rowSearch = $state('') {/if} - + {#if docsEverOpened && docAdapter} -
- - {#await import('./DocBrowser.svelte')}{:then { default: DocBrowser }} - {#key dbType} - { if (aiMode) exitAiMode(); openSqlTabWith(text, coll ? `${docAdapter.consoleLabel} · ${coll}` : docAdapter.consoleLabel) }} - /> - {/key} - {/await} - -
+ {#each tabs.filter((t) => t.kind === 'docs') as dt (dt.id)} + {@const on = activeTab?.id === dt.id} +
+ + {#await import('./DocBrowser.svelte')}{:then { default: DocBrowser }} + {#key dbType} + { if (aiMode) exitAiMode(); openSqlTabWith(text, coll ? `${docAdapter.consoleLabel} · ${coll}` : docAdapter.consoleLabel) }} + /> + {/key} + {/await} + +
+ {/each} {/if} diff --git a/src/lib/studio-tabs.js b/src/lib/studio-tabs.js index 97a27c34..312cb946 100644 --- a/src/lib/studio-tabs.js +++ b/src/lib/studio-tabs.js @@ -375,6 +375,8 @@ export function tabDisplayTitle(tab) { if (tab.kind === 'terminal') return tab.title || 'Terminal' if (tab.kind === 'sql') return tab.title || 'Query Editor' if (tab.kind === 'notebook') return tab.title || 'Untitled Notebook' + // A document tab is named after its collection. + if (tab.kind === 'docs') return tab.title || 'Browse' if (tab.kind === 'extension-detail') return tab.title || tab.state?.extensionId || 'Extension' return SINGLETON_TAB_TITLES[tab.kind] ?? tab.title }