Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ac4b0a6

Browse files
Collapse references by default (#213)
1 parent 425fb2a commit ac4b0a6

File tree

1 file changed

+26
-15
lines changed

1 file changed

+26
-15
lines changed

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

Lines changed: 26 additions & 15 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,22 +61,32 @@ 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}>Brand: {citation.brand}</p>
72-
<p className={styles.referenceMetadata}>Price: {citation.price}</p>
73-
<p>{citation.description}</p>
74-
</li>
75-
);
76-
})}
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}>Brand: {citation.brand}</p>
83+
<p className={styles.referenceMetadata}>Price: {citation.price}</p>
84+
<p>{citation.description}</p>
85+
</li>
86+
);
87+
})}
7788
</ol>
78-
</Stack>
89+
)}
7990
</Stack.Item>
8091
)}
8192

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /