Skip to content

Commit 22f69f7

Browse files
authored
Merge pull request #4 from rohit-ganguly/mergemain3
Merge from upstream: collapsible references
2 parents e769da6 + acac218 commit 22f69f7

File tree

1 file changed

+27
-16
lines changed

1 file changed

+27
-16
lines changed

src/frontend/src/components/Answer/Answer.tsx

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useMemo } from "react";
1+
import { useMemo, useState } from "react";
22
import { Stack, IconButton } from "@fluentui/react";
33
import DOMPurify from "dompurify";
44

@@ -29,6 +29,7 @@ export const Answer = ({
2929
onFollowupQuestionClicked,
3030
showFollowupQuestions
3131
}: Props) => {
32+
const [isReferencesCollapsed, setIsReferencesCollapsed] = useState(true);
3233
const followupQuestions = answer.context.followup_questions;
3334
const messageContent = answer.message.content;
3435
const parsedAnswer = useMemo(() => parseAnswerToHtml(messageContent, isStreaming, onCitationClicked), [answer]);
@@ -60,23 +61,33 @@ export const Answer = ({
6061
{!!parsedAnswer.citations.length && (
6162
<Stack.Item>
6263
<Stack horizontal wrap tokens={{ childrenGap: 5 }}>
63-
<span className={styles.citationLearnMore}>References:</span>
64+
<Stack horizontal verticalAlign="center" tokens={{ childrenGap: 5 }}>
65+
<IconButton
66+
iconProps={{ iconName: isReferencesCollapsed ? "ChevronDown" : "ChevronUp" }}
67+
title={isReferencesCollapsed ? "Expand references" : "Collapse references"}
68+
ariaLabel={isReferencesCollapsed ? "Expand references" : "Collapse references"}
69+
onClick={() => setIsReferencesCollapsed(!isReferencesCollapsed)}
70+
/>
71+
<span className={styles.citationLearnMore}>References:</span>
72+
</Stack>
73+
</Stack>
74+
{!isReferencesCollapsed && (
6475
<ol>
65-
{parsedAnswer.citations.map((rowId, ind) => {
66-
const citation = answer.context.data_points[rowId];
67-
if (!citation) return null;
68-
return (
69-
<li key={rowId}>
70-
<h4>{citation.name}</h4>
71-
<p className={styles.referenceMetadata}>Location: {citation.location}</p>
72-
<p className={styles.referenceMetadata}>Price level: {citation.price_level}</p>
73-
<p className={styles.referenceMetadata}>Rating: {citation.rating}</p>
74-
<p>{citation.description}</p>
75-
</li>
76-
);
77-
})}
76+
{parsedAnswer.citations.map((rowId, ind) => {
77+
const citation = answer.context.data_points[rowId];
78+
if (!citation) return null;
79+
return (
80+
<li key={rowId}>
81+
<h4>{citation.name}</h4>
82+
<p className={styles.referenceMetadata}>Location: {citation.location}</p>
83+
<p className={styles.referenceMetadata}>Price level: {citation.price_level}</p>
84+
<p className={styles.referenceMetadata}>Rating: {citation.rating}</p>
85+
<p>{citation.description}</p>
86+
</li>
87+
);
88+
})}
7889
</ol>
79-
</Stack>
90+
)}
8091
</Stack.Item>
8192
)}
8293

0 commit comments

Comments
 (0)