Skip to content

Commit 7e8168a

Browse files
committed
annotations displaying improvement
1 parent 4cbd858 commit 7e8168a

File tree

3 files changed

+49
-16
lines changed

3 files changed

+49
-16
lines changed

src/client/components/ChatV2/Annotations.tsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { Box, Typography, Chip } from '@mui/material'
1+
import { Box, Typography, Chip, IconButton } from '@mui/material'
2+
import { Close } from '@mui/icons-material'
23
import { FileSearchCompletedData, FileSearchResultData } from '../../../shared/types'
34
import { useTranslation } from 'react-i18next'
45
import { useFileSearchResults } from './api'
@@ -83,17 +84,24 @@ const Queries = ({ queries }: { queries: string[] }) => {
8384
</Box>)
8485
}
8586

86-
const Annotations = ({ fileSearchResult }: { fileSearchResult: FileSearchCompletedData }) => {
87+
const Annotations = ({ fileSearchResult, setShowAnnotations }: { fileSearchResult: FileSearchCompletedData; setShowAnnotations: (show: boolean) => void }) => {
8788
const { data: results, isSuccess: isResultsSuccess } = useFileSearchResults(fileSearchResult.id)
8889
const arrayResults = Array.isArray(results) ? results : []
8990
const { t } = useTranslation()
9091

91-
9292
return (
9393
<Box>
94-
<Typography variant="h6" fontWeight={'bold'} sx={{ mb: 2.5 }}>
95-
{t('chat:sources')}
96-
</Typography>
94+
<Box sx={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', mb: 4 }}>
95+
<Typography variant="h6" fontWeight={'bold'}>
96+
{t('chat:sources')}
97+
</Typography>
98+
<IconButton
99+
id="close-annotations"
100+
onClick={() => setShowAnnotations(false)}
101+
>
102+
<Close />
103+
</IconButton>
104+
</Box>
97105
<Queries queries={fileSearchResult.queries} />
98106
{isResultsSuccess ?
99107
<Box sx={{ display: 'flex', flexDirection: 'column', gap: '1.5rem', minHeight: 400 }}>

src/client/components/ChatV2/ChatV2.tsx

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ export const ChatV2 = () => {
6161

6262
const [messages, setMessages] = useLocalStorageState(`${localStoragePrefix}-chat-messages`, [] as Message[])
6363
const [prevResponse, setPrevResponse] = useLocalStorageState(`${localStoragePrefix}-prev-response`, { id: '' })
64-
const [fileSearch, setFileSearch] = useLocalStorageState<FileSearchCompletedData>(`${localStoragePrefix}-last-file-search`)
6564

6665
// App States
6766
const [settingsModalOpen, setSettingsModalOpen] = useState<boolean>(false)
@@ -70,6 +69,7 @@ export const ChatV2 = () => {
7069
const [tokenUsageAlertOpen, setTokenUsageAlertOpen] = useState<boolean>(false)
7170
const [allowedModels, setAllowedModels] = useState<string[]>([])
7271
const [saveConsent, setSaveConsent] = useState<boolean>(false)
72+
const [showAnnotations, setShowAnnotations] = useState<boolean>(false)
7373

7474
// RAG states
7575
const [ragIndexId, setRagIndexId] = useState<number | undefined>()
@@ -103,8 +103,8 @@ export const ChatV2 = () => {
103103
handleCompletionStreamError(error, fileName)
104104
},
105105
onFileSearchComplete: (fileSearch) => {
106-
setFileSearch(fileSearch) // possibly deprecating this
107106
setActiveFileSearchResult(fileSearch)
107+
setShowAnnotations(true)
108108
},
109109
})
110110

@@ -133,7 +133,6 @@ export const ChatV2 = () => {
133133
fileInputRef.current.value = ''
134134
}
135135
setFileName('')
136-
setFileSearch(undefined)
137136
setRetryTimeout(() => {
138137
if (streamController) {
139138
streamController.abort()
@@ -182,12 +181,12 @@ export const ChatV2 = () => {
182181
const handleReset = () => {
183182
if (window.confirm('Are you sure you want to empty this conversation?')) {
184183
setMessages([])
184+
setShowAnnotations(false)
185185
setPrevResponse({ id: '' })
186186
if (fileInputRef.current) {
187187
fileInputRef.current.value = ''
188188
}
189189
setFileName('')
190-
setFileSearch(undefined)
191190
setTokenUsageWarning('')
192191
setTokenUsageAlertOpen(false)
193192
setRetryTimeout(() => {
@@ -405,6 +404,7 @@ export const ChatV2 = () => {
405404
completion={completion}
406405
isCompletionDone={!isStreaming}
407406
setActiveFileSearchResult={setActiveFileSearchResult}
407+
setShowAnnotations={setShowAnnotations}
408408
/>
409409
</Box>
410410

@@ -461,10 +461,21 @@ export const ChatV2 = () => {
461461
flex: 1,
462462
minWidth: 300,
463463
position: 'relative',
464-
borderLeft: activeFileSearchResult ? '1px solid rgba(0, 0, 0, 0.12)' : 'none',
464+
transition: 'border 300ms',
465+
borderLeft: '1px solid',
466+
borderColor: showAnnotations ? 'rgba(0,0,0,0.12)' : 'rgba(0,0,0,0)'
465467
}}
466468
>
467-
<Box sx={{ position: 'sticky', top: 65, padding: '2rem' }}>{activeFileSearchResult && <Annotations fileSearchResult={activeFileSearchResult} />}</Box>
469+
<Box
470+
sx={{
471+
position: 'sticky',
472+
top: 65,
473+
padding: '2rem',
474+
transition: 'transform 250ms ease-in-out',
475+
transform: showAnnotations ? 'translateX(0%)' : 'translate(100%)'
476+
}}>
477+
{activeFileSearchResult && <Annotations fileSearchResult={activeFileSearchResult} setShowAnnotations={setShowAnnotations} />}
478+
</Box>
468479
</Box>
469480

470481
{/* Modals --------------------------------------*/}

src/client/components/ChatV2/Conversation.tsx

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,16 @@ const AssistantMessage = ({
7575
isLastAssistantNode,
7676
expandedNodeHeight,
7777
fileSearchResult,
78-
setActiveFileSearchResult
78+
setActiveFileSearchResult,
79+
setShowAnnotations
7980
}: {
8081
content: string
8182
error?: string
8283
isLastAssistantNode: boolean
8384
expandedNodeHeight: number
8485
fileSearchResult?: FileSearchCompletedData
8586
setActiveFileSearchResult: (data: FileSearchCompletedData) => void
87+
setShowAnnotations: (show: boolean) => void
8688
}) => {
8789
const processedContent = preprocessMath(content)
8890
const katexOptions = {
@@ -125,6 +127,11 @@ const AssistantMessage = ({
125127
}
126128
let codeCount = 0
127129

130+
const handleAnnotations = (fileSearchResult: FileSearchCompletedData) => {
131+
setActiveFileSearchResult(fileSearchResult)
132+
setShowAnnotations(true)
133+
}
134+
128135
return (
129136
<Box className={`message-role-assistant`} data-testid="assistant-message" sx={{ minHeight: isLastAssistantNode ? expandedNodeHeight : 'auto' }}>
130137
<Box
@@ -209,7 +216,7 @@ const AssistantMessage = ({
209216
</Box>
210217
)}
211218
{fileSearchResult?.status === "completed" &&
212-
<OutlineButtonBlack sx={{ mt: 3 }} startIcon={<FormatQuoteIcon />} onClick={() => setActiveFileSearchResult(fileSearchResult)}>
219+
<OutlineButtonBlack sx={{ mt: 3 }} startIcon={<FormatQuoteIcon />} onClick={() => handleAnnotations(fileSearchResult)}>
213220
<Typography variant='body2'>{`${t('chat:displaySources')}: `}<em>{fileSearchResult?.searchedFiles?.join(', ')}</em></Typography>
214221
</OutlineButtonBlack>
215222
}
@@ -222,12 +229,14 @@ const MessageItem = ({
222229
message,
223230
isLastAssistantNode,
224231
expandedNodeHeight,
225-
setActiveFileSearchResult
232+
setActiveFileSearchResult,
233+
setShowAnnotations
226234
}: {
227235
message: Message
228236
isLastAssistantNode: boolean
229237
expandedNodeHeight: number
230238
setActiveFileSearchResult: (data: FileSearchCompletedData) => void
239+
setShowAnnotations: (show: boolean) => void
231240
}) => {
232241

233242
if (message.role === 'assistant') {
@@ -239,6 +248,7 @@ const MessageItem = ({
239248
expandedNodeHeight={expandedNodeHeight}
240249
fileSearchResult={message.fileSearchResult}
241250
setActiveFileSearchResult={setActiveFileSearchResult}
251+
setShowAnnotations={setShowAnnotations}
242252
/>
243253
)
244254
} else {
@@ -261,7 +271,8 @@ export const Conversation = ({
261271
messages,
262272
completion,
263273
isCompletionDone,
264-
setActiveFileSearchResult
274+
setActiveFileSearchResult,
275+
setShowAnnotations
265276
}: {
266277
courseName?: string
267278
courseDate?: ActivityPeriod
@@ -271,6 +282,7 @@ export const Conversation = ({
271282
completion: string
272283
isCompletionDone: boolean
273284
setActiveFileSearchResult: (data: FileSearchCompletedData) => void
285+
setShowAnnotations: (show: boolean) => void
274286
}) => (
275287
<Box
276288
style={{
@@ -293,6 +305,7 @@ export const Conversation = ({
293305
isLastAssistantNode={isLastAssistantNode}
294306
expandedNodeHeight={expandedNodeHeight}
295307
setActiveFileSearchResult={setActiveFileSearchResult}
308+
setShowAnnotations={setShowAnnotations}
296309
/>
297310
)
298311
})}
@@ -304,6 +317,7 @@ export const Conversation = ({
304317
isLastAssistantNode={true}
305318
expandedNodeHeight={expandedNodeHeight}
306319
setActiveFileSearchResult={setActiveFileSearchResult}
320+
setShowAnnotations={setShowAnnotations}
307321
/>
308322
) : (
309323
<LoadingMessage expandedNodeHeight={expandedNodeHeight} />

0 commit comments

Comments
 (0)