Skip to content

Commit bc20a04

Browse files
authored
fix(chat-client): disable click event for empty history list item (#973)
1 parent 1e31ef2 commit bc20a04

File tree

4 files changed

+36
-5
lines changed

4 files changed

+36
-5
lines changed

chat-client/src/client/features/history.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ export class ChatHistoryList {
6565
if (!item.id) {
6666
throw new Error('Conversation id is not defined')
6767
}
68+
69+
if (item.id === 'empty') {
70+
return
71+
}
72+
6873
this.messager.onConversationClick(item.id)
6974
}
7075

server/aws-lsp-codewhisperer/src/language-server/agenticChat/tabBarController.test.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { TestFeatures } from '@aws/language-server-runtimes/testing'
77
import sinon from 'ts-sinon'
88
import * as assert from 'assert'
99
import { TabBarController } from './tabBarController'
10-
import { ChatDatabase } from './tools/chatDb/chatDb'
10+
import { ChatDatabase, EMPTY_CONVERSATION_LIST_ID } from './tools/chatDb/chatDb'
1111
import { Tab } from './tools/chatDb/util'
1212
import { ConversationItemGroup, OpenTabParams, OpenTabResult } from '@aws/language-server-runtimes-types'
1313
import { InitializeParams } from '@aws/language-server-runtimes/protocol'
@@ -244,6 +244,23 @@ describe('TabBarController', () => {
244244
sinon.assert.calledWith(chatHistoryDb.deleteHistory as sinon.SinonStub, historyId)
245245
assert.strictEqual(result.success, true)
246246
})
247+
248+
it('should not perform actions when item with `empty` historyId is clicked', async () => {
249+
const historyId = EMPTY_CONVERSATION_LIST_ID
250+
const openTabId = 'tab1'
251+
;(chatHistoryDb.getOpenTabId as sinon.SinonStub).withArgs(historyId).returns(openTabId)
252+
253+
const openTabStub = sinon.stub<[OpenTabParams], Promise<OpenTabResult>>()
254+
testFeatures.chat.openTab = openTabStub
255+
256+
const result = await tabBarController.onConversationClick({ id: historyId })
257+
258+
sinon.assert.notCalled(openTabStub)
259+
assert.deepStrictEqual(result, {
260+
id: EMPTY_CONVERSATION_LIST_ID,
261+
success: true,
262+
})
263+
})
247264
})
248265

249266
describe('export conversation', () => {

server/aws-lsp-codewhisperer/src/language-server/agenticChat/tabBarController.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
import { ChatDatabase } from './tools/chatDb/chatDb'
6+
import { ChatDatabase, EMPTY_CONVERSATION_LIST_ID } from './tools/chatDb/chatDb'
77
import { Conversation, messageToChatMessage, Tab } from './tools/chatDb/util'
88
import { Features } from '@aws/language-server-runtimes/server-interface/server'
99
import {
@@ -58,7 +58,9 @@ export class TabBarController {
5858
const items =
5959
group.items?.map(item => ({
6060
...item,
61-
...(item.id !== 'empty' ? { actions: this.getConversationActions(item.id) } : {}),
61+
...(item.id !== EMPTY_CONVERSATION_LIST_ID
62+
? { actions: this.getConversationActions(item.id) }
63+
: {}),
6264
})) || []
6365

6466
return {
@@ -128,6 +130,11 @@ export class TabBarController {
128130
async onConversationClick(params: ConversationClickParams): Promise<ConversationClickResult> {
129131
const historyID = params.id
130132

133+
if (historyID === EMPTY_CONVERSATION_LIST_ID) {
134+
this.#features.logging.debug('Empty conversation history list item clicked')
135+
return { ...params, success: true }
136+
}
137+
131138
// Handle user click on conversation in history
132139
if (!params.action) {
133140
const openTabID = this.#chatHistoryDb.getOpenTabId(historyID)

server/aws-lsp-codewhisperer/src/language-server/agenticChat/tools/chatDb/chatDb.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import { Features } from '@aws/language-server-runtimes/server-interface/server'
2020
import { ConversationItemGroup } from '@aws/language-server-runtimes/protocol'
2121
import { getUserHomeDir } from '@aws/lsp-core/out/util/path'
2222

23+
export const EMPTY_CONVERSATION_LIST_ID = 'empty'
24+
2325
/**
2426
* A singleton database class that manages chat history persistence using LokiJS.
2527
* This class handles storage and retrieval of chat conversations, messages, and tab states
@@ -212,7 +214,7 @@ export class ChatDatabase {
212214
}
213215
if (searchResults.length === 0) {
214216
this.#features.logging.log(`No matches found`)
215-
searchResults = [{ items: [{ id: 'empty', description: 'No matches found' }] }]
217+
searchResults = [{ items: [{ id: EMPTY_CONVERSATION_LIST_ID, description: 'No matches found' }] }]
216218
}
217219
return searchResults
218220
}
@@ -253,7 +255,7 @@ export class ChatDatabase {
253255
let groupedTabs = groupTabsByDate(tabs)
254256
this.#features.logging.log(`Found ${tabs.length} conversations from history`)
255257
if (groupedTabs.length === 0) {
256-
return [{ items: [{ id: 'empty', description: 'No chat history found' }] }]
258+
return [{ items: [{ id: EMPTY_CONVERSATION_LIST_ID, description: 'No chat history found' }] }]
257259
} else {
258260
return groupedTabs
259261
}

0 commit comments

Comments
 (0)