Elffuss BraidHub

kikocis/continue public

e31fcddb0dec · 2.6 KiBRawPermalink
1import { parseConfigYaml } from "@continuedev/config-yaml";
2import { IndexingStatus } from "core";
3import { useMemo } from "react";
4import { useAuth } from "../../../../context/Auth";
5import { useAppSelector } from "../../../../redux/hooks";
6import { EmptyState } from "../../../../components/ui";
7import DocsIndexingStatus from "./DocsIndexingStatus";
8
9function DocsIndexingStatuses() {
10 const config = useAppSelector((store) => store.config.config);
11 const indexingStatuses = useAppSelector(
12 (store) => store.indexing.indexing.statuses,
13 );
14 const { selectedProfile } = useAuth();
15 const mergedDocs = useMemo(() => {
16 const parsed = selectedProfile?.rawYaml
17 ? parseConfigYaml(selectedProfile?.rawYaml ?? "")
18 : undefined;
19 return (config.docs ?? []).map((doc, index) => ({
20 doc,
21 docFromYaml: parsed?.docs?.[index],
22 }));
23 }, [config.docs, selectedProfile?.rawYaml]);
24
25 const sortedConfigDocs = useMemo(() => {
26 const sorter = (status: IndexingStatus["status"]) => {
27 if (status === "complete") return 0;
28 if (status === "indexing" || status === "paused") return 1;
29 if (status === "failed") return 2;
30 if (status === "aborted" || status === "pending") return 3;
31 return 4;
32 };
33
34 const docs = [...mergedDocs];
35 docs.sort((a, b) => {
36 const statusA = indexingStatuses[a.doc.startUrl]?.status ?? "pending";
37 const statusB = indexingStatuses[b.doc.startUrl]?.status ?? "pending";
38
39 // First, compare by status
40 const statusCompare = sorter(statusA) - sorter(statusB);
41 if (statusCompare !== 0) return statusCompare;
42
43 // If status is the same, sort by presence of icon
44 const hasIconA = !!a.doc.faviconUrl;
45 const hasIconB = !!b.doc.faviconUrl;
46 return hasIconB === hasIconA ? 0 : hasIconB ? 1 : -1;
47 });
48 return docs;
49 }, [mergedDocs, indexingStatuses]);
50
51 if (sortedConfigDocs.length === 0) {
52 return (
53 <EmptyState message="No documentation sources configured. Click the + button to add your first docs." />
54 );
55 }
56
57 return (
58 <div className="flex flex-col gap-1">
59 <div className="flex flex-col overflow-y-auto overflow-x-hidden pr-2">
60 {sortedConfigDocs.map((docConfig) => {
61 return (
62 <div
63 key={docConfig.doc.startUrl}
64 className="flex items-center gap-2"
65 >
66 <div className="flex-grow">
67 <DocsIndexingStatus
68 docFromYaml={docConfig.docFromYaml}
69 docConfig={docConfig.doc}
70 />
71 </div>
72 </div>
73 );
74 })}
75 </div>
76 </div>
77 );
78}
79
80export default DocsIndexingStatuses;