Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | 2x 20x 20x 10x 20x 20x 10x 10x 10x | import { SkeletonLines } from "@/components/detail";
import {
budgetHoldUntil,
Knowledge,
KnowledgeDocument,
} from "@/objects/Knowledge";
import { documentsKey } from "./figures";
import { useApiHandler } from "@/services/useApiHandler";
import { useQuery } from "@tanstack/react-query";
import { FileText } from "lucide-react";
import React from "react";
/**
* A knowledge base's documents as a plain, read-only list — for a source the
* reader can look into but not open in the knowledge editor: the CHAIN-R
* User Guide, on CHAINR Bot's page and on the guide repository's page.
*/
const SourceDocumentList: React.FC<{ knowledge: Knowledge }> = ({
knowledge,
}) => {
const { getApiHandler } = useApiHandler();
const { data, isLoading } = useQuery<KnowledgeDocument[]>({
queryKey: documentsKey(knowledge.id),
queryFn: async () =>
(await getApiHandler().knowledge_router.listDocuments(knowledge.id)) ??
[],
});
// Bound to a typed const: the pinned TypeScript cannot infer react-query's
// return type, so `data` arrives as `any`.
const documents: KnowledgeDocument[] = data ?? [];
if (isLoading) return <SkeletonLines count={3} />;
Iif (!documents.length) {
return (
<p className="text-xs text-gray-400 dark:text-gray-500">
The guide is being prepared. It will be cited once it has been
indexed.
</p>
);
}
return (
<ul className="grid grid-cols-1 sm:grid-cols-2 gap-x-6 gap-y-1.5">
{documents.map((doc) => (
<li
key={doc.id}
className="flex items-center gap-2 text-xs text-gray-600 dark:text-gray-300 min-w-0"
>
<FileText className="size-3.5 shrink-0 text-gray-400 dark:text-gray-500" />
<span className="truncate">
{doc.document_metadata?.original_filename ?? doc.source_id}
</span>
{doc.document_metadata?.index_status &&
doc.document_metadata.index_status !== "indexed" && (
<span className="shrink-0 text-[10px] text-amber-600 dark:text-amber-400">
{budgetHoldUntil(doc) !== undefined
? "waiting for budget"
: doc.document_metadata.index_status}
</span>
)}
</li>
))}
</ul>
);
};
export default SourceDocumentList;
|