-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
Copy pathDocsSection.tsx
78 lines (70 loc) · 2.62 KB
/
DocsSection.tsx
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
68
69
70
71
72
73
74
75
76
77
78
import { parseConfigYaml } from "@continuedev/config-yaml";
import { IndexingStatus } from "core";
import { useMemo } from "react";
import { useDispatch } from "react-redux";
import { useAuth } from "../../../../../context/Auth";
import { useAppSelector } from "../../../../../redux/hooks";
import { ExploreBlocksButton } from "../ExploreBlocksButton";
import DocsIndexingStatus from "./DocsIndexingStatus";
function DocsIndexingStatuses() {
const dispatch = useDispatch();
const config = useAppSelector((store) => store.config.config);
const indexingStatuses = useAppSelector(
(store) => store.indexing.indexing.statuses,
);
const { selectedProfile } = useAuth();
const mergedDocs = useMemo(() => {
const parsed = selectedProfile?.rawYaml
? parseConfigYaml(selectedProfile?.rawYaml ?? "")
: undefined;
return (config.docs ?? []).map((doc, index) => ({
doc,
docFromYaml: parsed?.docs?.[index],
}));
}, [config.docs, selectedProfile?.rawYaml]);
const sortedConfigDocs = useMemo(() => {
const sorter = (status: IndexingStatus["status"]) => {
if (status === "complete") return 0;
if (status === "indexing" || status === "paused") return 1;
if (status === "failed") return 2;
if (status === "aborted" || status === "pending") return 3;
return 4;
};
const docs = [...mergedDocs];
docs.sort((a, b) => {
const statusA = indexingStatuses[a.doc.startUrl]?.status ?? "pending";
const statusB = indexingStatuses[b.doc.startUrl]?.status ?? "pending";
// First, compare by status
const statusCompare = sorter(statusA) - sorter(statusB);
if (statusCompare !== 0) return statusCompare;
// If status is the same, sort by presence of icon
const hasIconA = !!a.doc.faviconUrl;
const hasIconB = !!b.doc.faviconUrl;
return hasIconB === hasIconA ? 0 : hasIconB ? 1 : -1;
});
return docs;
}, [mergedDocs, indexingStatuses]);
return (
<div className="flex flex-col gap-1">
<div className="flex flex-col gap-1 overflow-y-auto overflow-x-hidden pr-2">
{sortedConfigDocs.map((docConfig) => {
return (
<div
key={docConfig.doc.startUrl}
className="flex items-center gap-2"
>
<div className="flex-grow">
<DocsIndexingStatus
docFromYaml={docConfig.docFromYaml}
docConfig={docConfig.doc}
/>
</div>
</div>
);
})}
</div>
<ExploreBlocksButton blockType="docs" />
</div>
);
}
export default DocsIndexingStatuses;