Skip to content

Commit

Permalink
Chat: Shows welcome message on empty chat only (#3341)
Browse files Browse the repository at this point in the history
  • Loading branch information
abeatrix authored and steveyegge committed Mar 13, 2024
1 parent 79edf88 commit 587823d
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
2 changes: 2 additions & 0 deletions vscode/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ This is a log of all notable changes to Cody for VS Code. [Unreleased] changes a

### Changed

- Chat: Welcome message is only shown on new chat panel. [pull/3341](https://github.com/sourcegraph/cody/pull/3341)

## [1.8.1]

### Added
Expand Down
2 changes: 1 addition & 1 deletion vscode/test/e2e/command-menu.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ test('Start a new chat from Cody Command Menu', async ({ page, sidebar }) => {

// the question should show up in the chat panel on submit
const chatPanel = page.frameLocator('iframe.webview').last().frameLocator('iframe')
await chatPanel.getByText('new chat submitted from command menu').click()
await chatPanel.getByText('hello from the assistant').hover()

const expectedEvents = [
'CodyVSCodeExtension:menu:command:default:clicked',
Expand Down
3 changes: 2 additions & 1 deletion vscode/test/e2e/update-notice.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,11 @@ test('existing installs should show the update toast when the last dismissed ver
await page.locator('*[aria-label="Tab actions"] *[aria-label~="Close"]').click()

// Reopen the chat; the update notice should be visible.
// Welcome message is removed.
await chatHistoryEntry.click()
chatFrame = page.frameLocator('iframe.webview').last().frameLocator('iframe')
const introChat = chatFrame.getByText(greetingChatText)
await expect(introChat).toBeVisible()
await expect(introChat).not.toBeVisible()
const chatNotice = chatFrame.getByText(updateToastText)
await expect(chatNotice).toBeVisible()

Expand Down
3 changes: 2 additions & 1 deletion vscode/webviews/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,8 @@ export const Chat: React.FunctionComponent<React.PropsWithChildren<ChatboxProps>
<div className={classNames(styles.innerContainer)}>
{
<Transcript
transcript={transcriptWithWelcome}
// Remove welcome message after the first message is submitted
transcript={transcript.length ? transcript : transcriptWithWelcome}
messageInProgress={messageInProgress}
messageBeingEdited={messageBeingEdited}
setMessageBeingEdited={setEditMessageState}
Expand Down
8 changes: 2 additions & 6 deletions vscode/webviews/chat/Transcript.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,20 +155,16 @@ export const Transcript: React.FunctionComponent<
if (!message?.displayText && !message.error) {
return null
}
// The key index includes the Cody welcome message added to the transcript in the webview
// as it is not included in the transcript returned from the server, the key index is
// offset by 1 to account for this.
const offsetIndex = index + offset === earlierMessages.length
const keyIndex = index + offset
const transcriptIndex = keyIndex - 1

const isItemBeingEdited = messageBeingEdited === transcriptIndex
const isItemBeingEdited = messageBeingEdited === keyIndex

return (
<div key={index}>
{isItemBeingEdited && <div ref={itemBeingEditedRef} />}
<TranscriptItem
index={transcriptIndex}
index={keyIndex}
key={keyIndex}
message={message}
inProgress={
Expand Down

0 comments on commit 587823d

Please sign in to comment.