Skip to content

Commit e074069

Browse files
authored
fix(tabStore): align API with tests - connectionId-first signatures (#53)
Tests have always expected createTab and openTableViewTab to take connectionId as the first parameter, and a dedicated closeTabsForConnection helper to exist on the store. The implementation had connectionId as the last optional parameter and was missing the helper, so CI was red on master with 9 failing assertions across all three platforms. - createTab(connectionId?, database?, schema?) - openTableViewTab(connectionId, database, tableName, schema?) - executeQuery(tabId, sqlToExecute?) reads connectionId from the tab instead of taking it as a parameter, matching the test contract. - Add closeTabsForConnection(connectionId) for bulk close on connection teardown. Callsites updated in QueriesPage.vue and HistoryPage.vue. All 276 frontend tests pass.
1 parent 78ef65a commit e074069

3 files changed

Lines changed: 25 additions & 12 deletions

File tree

src/pages/HistoryPage.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ async function handleRerun(entry: HistoryEntry) {
106106
return
107107
}
108108
const database = entry.database
109-
const tab = tabStore.createTab(database, undefined, connectionId)
109+
const tab = tabStore.createTab(connectionId, database)
110110
tabStore.updateTabContent(tab.id, entry.sql)
111111
const createdTab = tabStore.tabs.find(t => t.id === tab.id)
112112
if (createdTab)

src/pages/QueriesPage.vue

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ async function executeQuery(details?: StatementToExecute) {
204204
}
205205
206206
showResultPanel.value = true
207-
await tabStore.executeQuery(activeTab.value.id, connId, sqlToExecute)
207+
await tabStore.executeQuery(activeTab.value.id, sqlToExecute)
208208
}
209209
210210
async function handleExplainQuery() {
@@ -216,7 +216,7 @@ function handleNewTab() {
216216
const db = connId
217217
? (selectedDatabase.value || connectionStore.getCurrentDatabase(connId) || connectionStore.getConnectionById(connId)?.database || undefined)
218218
: undefined
219-
tabStore.createTab(db, undefined, connId ?? undefined)
219+
tabStore.createTab(connId ?? undefined, db)
220220
}
221221
222222
function handleTabSelect(tabId: string) {
@@ -277,7 +277,7 @@ CREATE TABLE ${schemaPrefix}"${table.name}" (
277277
278278
const connId = getActiveConnectionId()
279279
if (connId) {
280-
const tab = tabStore.createTab(database, schema, connId)
280+
const tab = tabStore.createTab(connId, database, schema)
281281
tabStore.updateTabContent(tab.id, script)
282282
tabStore.updateTabName(tab.id, `CREATE_${table.name}.sql`)
283283
}
@@ -289,11 +289,11 @@ function handleSelectTopN(table: TableInfo, database: string, schema?: string, n
289289
290290
const connId = getActiveConnectionId()
291291
if (connId) {
292-
const tab = tabStore.createTab(database, schema, connId)
292+
const tab = tabStore.createTab(connId, database, schema)
293293
tabStore.updateTabContent(tab.id, query)
294294
tabStore.updateTabName(tab.id, `SELECT_${table.name}`)
295295
296-
tabStore.executeQuery(tab.id, connId)
296+
tabStore.executeQuery(tab.id)
297297
showResultPanel.value = true
298298
}
299299
}
@@ -309,7 +309,7 @@ WHERE table_name = '${table.name}'${schema ? ` AND table_schema = '${schema}'` :
309309
310310
const connId = getActiveConnectionId()
311311
if (connId) {
312-
const tab = tabStore.createTab(database, schema, connId)
312+
const tab = tabStore.createTab(connId, database, schema)
313313
tabStore.updateTabContent(tab.id, query)
314314
tabStore.updateTabName(tab.id, `STRUCTURE_${table.name}`)
315315
}
@@ -323,7 +323,7 @@ function handleSelectTable(table: TableInfo, database: string, schema?: string)
323323
const connId = getActiveConnectionId()
324324
if (!connId)
325325
return
326-
tabStore.openTableViewTab(database, table.name, schema, connId)
326+
tabStore.openTableViewTab(connId, database, table.name, schema)
327327
}
328328
329329
async function handleOpenSavedQuery(filePath: string) {
@@ -338,7 +338,7 @@ async function handleOpenSavedQuery(filePath: string) {
338338
? (selectedDatabase.value || connectionStore.getCurrentDatabase(connId) || connectionStore.getConnectionById(connId)?.database || undefined)
339339
: undefined
340340
341-
const tab = tabStore.createTab(db, undefined, connId ?? undefined)
341+
const tab = tabStore.createTab(connId ?? undefined, db)
342342
343343
try {
344344
const result = await loadQueryFile(filePath)

src/store/tabStore.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export const useTabStore = defineStore('tabs', {
7575
},
7676

7777
actions: {
78-
createTab(database?: string, schema?: string, connectionId?: string): QueryTab {
78+
createTab(connectionId?: string, database?: string, schema?: string): QueryTab {
7979
const tab: QueryTab = {
8080
id: generateId(),
8181
name: `Query ${this.tabs.length + 1}`,
@@ -91,7 +91,7 @@ export const useTabStore = defineStore('tabs', {
9191
return tab
9292
},
9393

94-
openTableViewTab(database: string, tableName: string, schema?: string, connectionId?: string): QueryTab {
94+
openTableViewTab(connectionId: string, database: string, tableName: string, schema?: string): QueryTab {
9595
const existing = this.tabs.find(
9696
t => t.tableView
9797
&& t.tableView.tableName === tableName
@@ -138,6 +138,14 @@ export const useTabStore = defineStore('tabs', {
138138
this.activeTabId = null
139139
},
140140

141+
closeTabsForConnection(connectionId: string) {
142+
const remaining = this.tabs.filter(t => t.connectionId !== connectionId)
143+
this.tabs = remaining
144+
if (this.activeTabId && !remaining.find(t => t.id === this.activeTabId)) {
145+
this.activeTabId = remaining[0]?.id ?? null
146+
}
147+
},
148+
141149
closeNonOrphanTabs() {
142150
this.tabs = this.tabs.filter(t => t.orphanFromConnectionId)
143151
if (this.activeTabId && !this.tabs.find(t => t.id === this.activeTabId)) {
@@ -233,7 +241,7 @@ export const useTabStore = defineStore('tabs', {
233241
}
234242
},
235243

236-
async executeQuery(tabId: string, activeConnectionId: string, sqlToExecute?: string) {
244+
async executeQuery(tabId: string, sqlToExecute?: string) {
237245
const tab = this.tabs.find(t => t.id === tabId)
238246
if (!tab || tab.orphanFromConnectionId) {
239247
return
@@ -245,6 +253,11 @@ export const useTabStore = defineStore('tabs', {
245253
return
246254
}
247255

256+
const activeConnectionId = tab.connectionId
257+
if (!activeConnectionId) {
258+
return
259+
}
260+
248261
tab.isExecuting = true
249262
tab.error = undefined
250263

0 commit comments

Comments
 (0)