diff --git a/client/web/src/cody/CodyChat.tsx b/client/web/src/cody/CodyChat.tsx index 55f1c39be70..e014a36977a 100644 --- a/client/web/src/cody/CodyChat.tsx +++ b/client/web/src/cody/CodyChat.tsx @@ -1,6 +1,6 @@ import { useCallback, useEffect, useRef, useState } from 'react' -import { mdiClose, mdiSend, mdiArrowDown } from '@mdi/js' +import { mdiClose, mdiSend, mdiArrowDown, mdiReload } from '@mdi/js' import classNames from 'classnames' import useResizeObserver from 'use-resize-observer' @@ -9,7 +9,7 @@ import { FileLinkProps } from '@sourcegraph/cody-ui/src/chat/ContextFiles' import { CodyLogo } from '@sourcegraph/cody-ui/src/icons/CodyLogo' import { CODY_TERMS_MARKDOWN } from '@sourcegraph/cody-ui/src/terms' import { useQuery } from '@sourcegraph/http-client' -import { Button, ErrorAlert, Icon, LoadingSpinner, Text, TextArea } from '@sourcegraph/wildcard' +import { Button, ErrorAlert, Icon, LoadingSpinner, Text, TextArea, Tooltip } from '@sourcegraph/wildcard' import { RepoEmbeddingExistsQueryResult, RepoEmbeddingExistsQueryVariables } from '../graphql-operations' import { REPO_EMBEDDING_EXISTS_QUERY } from '../repo/repoRevisionSidebar/cody/backend' @@ -24,7 +24,7 @@ interface CodyChatProps { } export const CodyChat = ({ onClose }: CodyChatProps): JSX.Element => { - const { onSubmit, messageInProgress, transcript, repo } = useChatStoreState() + const { onReset, onSubmit, messageInProgress, transcript, repo } = useChatStoreState() const codySidebarRef = useRef(null) const [formInput, setFormInput] = useState('') @@ -66,10 +66,22 @@ export const CodyChat = ({ onClose }: CodyChatProps): JSX.Element => { variables: { repoName: repo }, }) + const shouldShowResetButton = + !embeddingExistsLoading && !embeddingExistsError && embeddingExistsData?.repository?.embeddingExists + return (
+ {shouldShowResetButton && ( +
+ + + +
+ )}
Ask Cody diff --git a/client/web/src/stores/codyChat.ts b/client/web/src/stores/codyChat.ts index 743ef862998..a799a01d932 100644 --- a/client/web/src/stores/codyChat.ts +++ b/client/web/src/stores/codyChat.ts @@ -10,15 +10,18 @@ import { eventLogger } from '../tracking/eventLogger' interface CodyChatStore { client: Client | null + config: ClientInit['config'] | null messageInProgress: ChatMessage | null transcript: ChatMessage[] repo: string filePath: string setClient: (client: Client | null) => void + setConfig: (config: ClientInit['config']) => void setMessageInProgress: (message: ChatMessage | null) => void setTranscript: (transcript: ChatMessage[]) => void initializeClient: (config: Required) => void onSubmit: (text: string) => void + onReset: () => void } export const useChatStoreState = create((set, get): CodyChatStore => { @@ -34,17 +37,26 @@ export const useChatStoreState = create((set, get): CodyChatStore } } + const onReset = (): void => { + const { initializeClient, config } = get() + if (config) { + initializeClient(config as Required) + } + } + return { client: null, messageInProgress: null, + config: null, transcript: [], filePath: '', repo: '', setClient: client => set({ client }), + setConfig: config => set({ config }), setMessageInProgress: message => set({ messageInProgress: message }), setTranscript: transcript => set({ transcript }), initializeClient: (config: Required): void => { - set({ messageInProgress: null, transcript: [], repo: config.codebase }) + set({ messageInProgress: null, transcript: [], repo: config.codebase, config }) createClient({ config, setMessageInProgress: message => set({ messageInProgress: message }), @@ -60,6 +72,7 @@ export const useChatStoreState = create((set, get): CodyChatStore }, onSubmit, + onReset, } })