Skip to content

Make references collapsible, collapse by default #213

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 12, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 26 additions & 15 deletions src/frontend/src/components/Answer/Answer.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useMemo } from "react";
import { useMemo, useState } from "react";
import { Stack, IconButton } from "@fluentui/react";
import DOMPurify from "dompurify";

Expand Down Expand Up @@ -29,6 +29,7 @@ export const Answer = ({
onFollowupQuestionClicked,
showFollowupQuestions
}: Props) => {
const [isReferencesCollapsed, setIsReferencesCollapsed] = useState(true);
const followupQuestions = answer.context.followup_questions;
const messageContent = answer.message.content;
const parsedAnswer = useMemo(() => parseAnswerToHtml(messageContent, isStreaming, onCitationClicked), [answer]);
Expand Down Expand Up @@ -60,22 +61,32 @@ export const Answer = ({
{!!parsedAnswer.citations.length && (
<Stack.Item>
<Stack horizontal wrap tokens={{ childrenGap: 5 }}>
<span className={styles.citationLearnMore}>References:</span>
<Stack horizontal verticalAlign="center" tokens={{ childrenGap: 5 }}>
<IconButton
iconProps={{ iconName: isReferencesCollapsed ? "ChevronDown" : "ChevronUp" }}
title={isReferencesCollapsed ? "Expand references" : "Collapse references"}
ariaLabel={isReferencesCollapsed ? "Expand references" : "Collapse references"}
onClick={() => setIsReferencesCollapsed(!isReferencesCollapsed)}
/>
<span className={styles.citationLearnMore}>References:</span>
</Stack>
</Stack>
{!isReferencesCollapsed && (
<ol>
{parsedAnswer.citations.map((rowId, ind) => {
const citation = answer.context.data_points[rowId];
if (!citation) return null;
return (
<li key={rowId}>
<h4>{citation.name}</h4>
<p className={styles.referenceMetadata}>Brand: {citation.brand}</p>
<p className={styles.referenceMetadata}>Price: {citation.price}</p>
<p>{citation.description}</p>
</li>
);
})}
{parsedAnswer.citations.map((rowId, ind) => {
const citation = answer.context.data_points[rowId];
if (!citation) return null;
return (
<li key={rowId}>
<h4>{citation.name}</h4>
<p className={styles.referenceMetadata}>Brand: {citation.brand}</p>
<p className={styles.referenceMetadata}>Price: {citation.price}</p>
<p>{citation.description}</p>
</li>
);
})}
</ol>
</Stack>
)}
</Stack.Item>
)}

Expand Down
Loading