From 93eddae58aea25283e24da6774caacf515788df1 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Sun, 17 Nov 2024 23:10:01 -0800 Subject: [PATCH] docs UI working --- core/indexing/docs/DocsService.ts | 21 +++--- gui/src/components/dialogs/AddDocsDialog.tsx | 69 ++++++++++++++++++- gui/src/components/dialogs/index.tsx | 2 +- .../components/indexing/ChatIndexingPeeks.tsx | 10 +-- .../components/indexing/IndexingStatus.tsx | 10 +-- .../components/indexing/IndexingStatuses.tsx | 11 ++- gui/src/pages/gui/Chat.tsx | 8 ++- 7 files changed, 101 insertions(+), 30 deletions(-) diff --git a/core/indexing/docs/DocsService.ts b/core/indexing/docs/DocsService.ts index cc75c3835..ffb251c64 100644 --- a/core/indexing/docs/DocsService.ts +++ b/core/indexing/docs/DocsService.ts @@ -376,24 +376,15 @@ export default class DocsService { progress: 0, }); - // NOTE - during "indexing" phase, check if aborted before each status update - const articles: Article[] = []; let processedPages = 0; - let estimatedProgress = 0; // progress heuristic = sum series 1/(3*2^n) from n=0 to pages. Alternative e.g. sum 1/(2^n) + let estimatedProgress = 0; // progress heuristic = sum series 1/(2^n) from n=1 to pages + 1. Alternative e.g. sum 1/(2^n) // Crawl pages and retrieve info as articles for await (const page of this.docsCrawler.crawl(new URL(startUrl))) { - estimatedProgress += 1 / (3 * 2 ** processedPages); - - const article = pageToArticle(page); - - if (!article) { - continue; - } - - articles.push(article); + estimatedProgress += 1 / 2 ** (processedPages + 1); + // NOTE - during "indexing" phase, check if aborted before each status update if (this.isAborted(startUrl)) { return; } @@ -404,6 +395,12 @@ export default class DocsService { progress: 0.4 * estimatedProgress, // 0% -> 40%, a heuristic approach for progress calculation }); + const article = pageToArticle(page); + if (!article) { + continue; + } + articles.push(article); + processedPages++; await new Promise((resolve) => setTimeout(resolve, 50)); // Locks down GUI if no sleeping } diff --git a/gui/src/components/dialogs/AddDocsDialog.tsx b/gui/src/components/dialogs/AddDocsDialog.tsx index 3c97e09e6..f373f4bc0 100644 --- a/gui/src/components/dialogs/AddDocsDialog.tsx +++ b/gui/src/components/dialogs/AddDocsDialog.tsx @@ -1,11 +1,17 @@ -import { ChevronDownIcon, ChevronUpIcon } from "@heroicons/react/24/outline"; +import { + CheckCircleIcon, + ChevronDownIcon, + ChevronUpIcon, +} from "@heroicons/react/24/outline"; import { SiteIndexingConfig } from "core"; import { usePostHog } from "posthog-js/react"; import { useContext, useLayoutEffect, useRef, useState } from "react"; -import { useDispatch } from "react-redux"; +import { useDispatch, useSelector } from "react-redux"; import { Button, HelperText, Input, lightGray } from ".."; import { IdeMessengerContext } from "../../context/IdeMessenger"; import { setShowDialog } from "../../redux/slices/uiStateSlice"; +import { RootState } from "../../redux/store"; +import IndexingStatusViewer from "../indexing/IndexingStatus"; function AddDocsDialog() { const posthog = usePostHog(); @@ -18,7 +24,12 @@ function AddDocsDialog() { const [faviconUrl, setFaviconUrl] = useState(""); const [isOpen, setIsOpen] = useState(false); + const [submittedConfig, setSubmittedConfig] = useState(); + const ideMessenger = useContext(IdeMessengerContext); + const indexingStatuses = useSelector( + (store: RootState) => store.state.indexingStatuses, + ); const isFormValid = startUrl && title; @@ -41,15 +52,67 @@ function AddDocsDialog() { ideMessenger.post("context/addDocs", siteIndexingConfig); + setSubmittedConfig(siteIndexingConfig); setTitle(""); setStartUrl(""); setFaviconUrl(""); - dispatch(setShowDialog(false)); + // dispatch(setShowDialog(false)); posthog.capture("add_docs_gui", { url: startUrl }); } + if (submittedConfig) { + const status = indexingStatuses[submittedConfig.startUrl]; + return ( +
+
+ +

{`Docs added`}

+
+
+

Title: {submittedConfig.title}

+

Start URL: {submittedConfig.startUrl}

+ {submittedConfig.rootUrl && ( +

Root URL: {submittedConfig.rootUrl}

+ )} + {submittedConfig.maxDepth && ( +

Max depth: {submittedConfig.maxDepth}

+ )} + {submittedConfig.faviconUrl && ( +

Favicon URL: {submittedConfig.faviconUrl}

+ )} +
+ {!!status && ( +
+

{`Type "@docs" and select ${submittedConfig.title} to reference these docs once indexing is complete. Check indexing status from the "More" page.`}

+
+ +
+
+ )} +
+ + +
+
+ ); + } + return (
diff --git a/gui/src/components/dialogs/index.tsx b/gui/src/components/dialogs/index.tsx index 33214fdfb..7685109ba 100644 --- a/gui/src/components/dialogs/index.tsx +++ b/gui/src/components/dialogs/index.tsx @@ -34,7 +34,6 @@ const DialogContainer = styled.div` top: 50%; left: 50%; transform: translate(-50%, -50%); - width: 75%; `; const Dialog = styled.div` @@ -72,6 +71,7 @@ const TextDialog = (props: TextDialogProps) => { return (
- +
+ +
); }