Skip to content

Commit e5b017b

Browse files
committed
fix(amazonq): check if tab is already open before exporting from history
1 parent 7bdf822 commit e5b017b

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

packages/core/src/codewhispererChat/controllers/chat/tabBarController.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,21 @@ export class TabBarController {
2626
constructor(messenger: Messenger) {
2727
this.messenger = messenger
2828
}
29-
processActionClickMessage(msg: DetailedListActionClickMessage) {
29+
async processActionClickMessage(msg: DetailedListActionClickMessage) {
3030
if (msg.listType === 'history') {
3131
if (msg.action.text === 'Delete') {
3232
this.chatHistoryDb.deleteHistory(msg.action.id)
3333
this.messenger.sendUpdateDetailedListMessage('history', { list: this.generateHistoryList() })
3434
} else if (msg.action.text === 'Export') {
35-
const selectedTab = this.chatHistoryDb.getTab(msg.action.id)
36-
this.restoreTab(selectedTab, true)
35+
// If conversation is already open, export it
36+
const openTabId = this.chatHistoryDb.getOpenTabId(msg.action.id)
37+
if (openTabId) {
38+
await this.exportChatButtonClicked({ tabID: openTabId, buttonId: 'export_chat' })
39+
} // If conversation is not open, restore it before exporting
40+
else {
41+
const selectedTab = this.chatHistoryDb.getTab(msg.action.id)
42+
this.restoreTab(selectedTab, true)
43+
}
3744
}
3845
}
3946
}
@@ -58,13 +65,14 @@ export class TabBarController {
5865
}
5966
}
6067

68+
// If selected is conversation is already open, select that tab. Else, open new tab with conversation.
6169
processItemSelectMessage(msg: DetailedListItemSelectMessage) {
6270
if (msg.listType === 'history') {
6371
const historyID = msg.item.id
6472
if (historyID) {
65-
const selectedTab = this.chatHistoryDb.getTab(historyID)
66-
const openTabID = this.chatHistoryDb.getTabId(historyID)
67-
if (!selectedTab?.isOpen || !openTabID) {
73+
const openTabID = this.chatHistoryDb.getOpenTabId(historyID)
74+
if (!openTabID) {
75+
const selectedTab = this.chatHistoryDb.getTab(historyID)
6876
this.restoreTab(selectedTab)
6977
} else {
7078
this.messenger.sendSelectTabMessage(openTabID, historyID)

packages/core/src/shared/db/chatDb/chatDb.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,14 @@ export class Database {
119119
}
120120
}
121121

122-
getTabId(historyId: string) {
123-
for (const [tabId, id] of this.historyIdMapping) {
124-
if (id === historyId) {
125-
return tabId
122+
// If conversation is open, return its tabId, else return undefined
123+
getOpenTabId(historyId: string) {
124+
const selectedTab = this.getTab(historyId)
125+
if (selectedTab?.isOpen) {
126+
for (const [tabId, id] of this.historyIdMapping) {
127+
if (id === historyId) {
128+
return tabId
129+
}
126130
}
127131
}
128132
return undefined
@@ -214,7 +218,7 @@ export class Database {
214218
if (this.initialized) {
215219
const tabCollection = this.db.getCollection<Tab>(TabCollection)
216220
tabCollection.findAndRemove({ historyId })
217-
const tabId = this.getTabId(historyId)
221+
const tabId = this.getOpenTabId(historyId)
218222
if (tabId) {
219223
this.historyIdMapping.delete(tabId)
220224
}

0 commit comments

Comments
 (0)