From 205e77c47ad5757af17276c6f2af47969eb03108 Mon Sep 17 00:00:00 2001 From: Henry Fontanier Date: Tue, 3 Oct 2023 12:42:06 +0200 Subject: [PATCH] feat: display list of retrived documents when clicking on the chip (#1912) * feat: display list of retrived documents when clicking on the chip * insane div centering * text xs + chevron icons * hide results # on small screen --- .../conversation/RetrievalAction.tsx | 145 ++++++++++++------ 1 file changed, 100 insertions(+), 45 deletions(-) diff --git a/front/components/assistant/conversation/RetrievalAction.tsx b/front/components/assistant/conversation/RetrievalAction.tsx index 8a93b4e0f7a4..cb3bad8d0587 100644 --- a/front/components/assistant/conversation/RetrievalAction.tsx +++ b/front/components/assistant/conversation/RetrievalAction.tsx @@ -1,9 +1,14 @@ import { + ChevronDownIcon, + ChevronRightIcon, Chip, DocumentDuplicateStrokeIcon, + Icon, Spinner, Tooltip, } from "@dust-tt/sparkle"; +import { Transition } from "@headlessui/react"; +import { useState } from "react"; import { classNames } from "@app/lib/utils"; import { @@ -24,65 +29,115 @@ export default function RetrievalAction({ retrievalAction: RetrievalActionType; }) { const { query, relativeTimeFrame } = retrievalAction.params; + const [docListVisible, setDocListVisible] = useState(false); + function shortText(text: string, maxLength = 20) { return text.length > maxLength ? text.substring(0, maxLength) + "..." : text; } + return ( -
-
- Searching for: -
- - - 1 - ? `${relativeTimeFrame.duration} ${relativeTimeFrame.unit}s` - : `${relativeTimeFrame.unit}`) - : "All time" - } - /> - - - - - -
+ <> +
+
Searching for:
+ + + 1 + ? `${relativeTimeFrame.duration} ${relativeTimeFrame.unit}s` + : `${relativeTimeFrame.unit}`) + : "All time" + } + /> + + + + +
- {!retrievalAction.documents ? ( -
-
- Retrieving... -
- +
+
+ {!retrievalAction.documents ? ( +
+
+ Retrieving... +
+ +
+ ) : ( +
+ Retrieved: +
+ )}
- ) : ( -
- Retrieved: - - {retrievalAction.documents.length > 0 - ? RetrievedDocumentsInfo(retrievalAction.documents) - : "No documents found"} - +
+ {retrievalAction.documents && ( +
setDocListVisible(!docListVisible)}> + + {retrievalAction.documents.length > 0 + ? RetrievedDocumentsInfo(retrievalAction.documents) + : "No documents found"} + + +
+ )}
- )} -
+
+ {!!retrievalAction.documents?.length && ( + + + + )} +
+
+ ); } function RetrievedDocumentsInfo(documents: RetrievalDocumentType[]) { const summary = documentsSummary(documents); return ( - <> - {documents.length} results +
+ {documents.length} results {Object.keys(summary).map((k) => { return (
@@ -97,7 +152,7 @@ function RetrievedDocumentsInfo(documents: RetrievalDocumentType[]) {
); })} - +
); }