Skip to content

Commit

Permalink
feat: Replace index by messageId in Sources key
Browse files Browse the repository at this point in the history
  • Loading branch information
JF-Cozy committed Oct 24, 2024
1 parent 4bb0679 commit 01559af
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/assistant/Conversations/ChatAssistantItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import AssistantIcon from 'assets/images/icon-assistant.png'
import Sources from './Sources/Sources'
import ChatItem from './ChatItem'

const ChatAssistantItem = ({ className, label, sources, ...props }) => {
const ChatAssistantItem = ({ className, id, label, sources, ...props }) => {
const { t } = useI18n()
// need memo to avoid rendering it everytime
const icon = useMemo(() => <Icon icon={AssistantIcon} size={32} />, [])
Expand All @@ -22,7 +22,7 @@ const ChatAssistantItem = ({ className, label, sources, ...props }) => {
name={t('assistant.name')}
label={label}
/>
{sources?.length > 0 && <Sources sources={sources} />}
{sources?.length > 0 && <Sources messageId={id} sources={sources} />}
</>
)
}
Expand Down
2 changes: 2 additions & 0 deletions src/assistant/Conversations/ChatConversation.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const ChatConversation = ({ conversation, myself }) => {
<ChatAssistantItem
key={conversation._id + '--' + idx}
className="u-mt-1-half"
id={message.id}
label={message.content}
sources={message.sources}
/>
Expand All @@ -56,6 +57,7 @@ const ChatConversation = ({ conversation, myself }) => {
<ChatAssistantItem
key={conversation._id + '--' + idx}
className="u-mt-1-half"
id={message.id}
label={message.content}
sources={message.sources}
/>
Expand Down
10 changes: 5 additions & 5 deletions src/assistant/Conversations/Sources/Sources.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Grow from 'cozy-ui/transpiled/react/Grow'
import { buildFilesByIds } from 'assistant/queries'
import SourcesItem from './SourcesItem'

const Sources = ({ files }) => {
const Sources = ({ messageId, files }) => {
const [showSources, setShowSources] = useState(false)
const { t } = useI18n()
const ref = useRef()
Expand Down Expand Up @@ -58,16 +58,16 @@ const Sources = ({ files }) => {
unmountOnExit={true}
>
<div>
{files.map((file, index) => (
<SourcesItem key={`${file._id}-${index}`} file={file} />
{files.map(file => (
<SourcesItem key={`${messageId}-${file._id}`} file={file} />
))}
</div>
</Grow>
</Box>
)
}

const SourcesWithFilesQuery = ({ sources }) => {
const SourcesWithFilesQuery = ({ messageId, sources }) => {
const fileIds = sources.map(source => source.id)

const filesByIds = buildFilesByIds(fileIds)
Expand All @@ -80,7 +80,7 @@ const SourcesWithFilesQuery = ({ sources }) => {

if (isLoading || files.length === 0) return null

return <Sources files={files} />
return <Sources messageId={messageId} files={files} />
}

export default SourcesWithFilesQuery

0 comments on commit 01559af

Please sign in to comment.