From 28aad1a668a50a1e17feb471806f6d1a48c0531d Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Mon, 9 Dec 2024 00:16:14 -0800 Subject: [PATCH] docs UI updates + delete docs --- core/core.ts | 2 +- core/index.d.ts | 9 +-- core/indexing/docs/DocsService.ts | 61 ++++++++----------- gui/src/components/dialogs/AddDocsDialog.tsx | 14 ++++- .../indexing/DocsIndexingStatus.tsx | 43 ++++++++++--- .../indexing/DocsIndexingStatuses.tsx | 26 ++++---- gui/src/components/indexing/utils.ts | 16 ----- 7 files changed, 88 insertions(+), 83 deletions(-) delete mode 100644 gui/src/components/indexing/utils.ts diff --git a/core/core.ts b/core/core.ts index ddfacf5b9..d28d2e25c 100644 --- a/core/core.ts +++ b/core/core.ts @@ -735,7 +735,7 @@ export class Core { }); on("indexing/setPaused", async (msg) => { if (msg.data.type === "docs") { - this.docsService.setPaused(msg.data.id, msg.data.paused); + // this.docsService.setPaused(msg.data.id, msg.data.paused); } }); on("docs/getSuggestedDocs", async (msg) => { diff --git a/core/index.d.ts b/core/index.d.ts index cd3518c36..aac57bdf5 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -59,14 +59,7 @@ export interface IndexingStatus { type: "docs"; progress: number; description: string; - status: - | "indexing" - | "complete" - | "paused" - | "failed" - | "aborted" - | "deleted" - | "pending"; + status: "indexing" | "complete" | "paused" | "failed" | "aborted" | "pending"; embeddingsProviderId: string; isReindexing?: boolean; debugInfo?: string; diff --git a/core/indexing/docs/DocsService.ts b/core/indexing/docs/DocsService.ts index b52577a5f..994cb6aa2 100644 --- a/core/indexing/docs/DocsService.ts +++ b/core/indexing/docs/DocsService.ts @@ -37,12 +37,6 @@ import { } from "./preIndexed"; import preIndexedDocs from "./preIndexedDocs"; -// Progress heuristic values -// subpages -> embeddings -> delete from db -> add to db -const PROGRESS_AT_EMBEDDING = 0.5; -const PROGRESS_AT_DELETE_OPERATIONS = 0.7; -const PROGRESS_AT_ADD_OPERATIONS = 0.8; - // Purposefully lowercase because lancedb converts export interface LanceDbDocsRow { title: string; @@ -206,19 +200,19 @@ export default class DocsService { } // NOTE Pausing not supported for docs yet - setPaused(startUrl: string, pause: boolean) { - const status = this.statuses.get(startUrl); - if (status) { - this.handleStatusUpdate({ - ...status, - status: pause ? "paused" : "indexing", - }); - } - } + // setPaused(startUrl: string, pause: boolean) { + // const status = this.statuses.get(startUrl); + // if (status) { + // this.handleStatusUpdate({ + // ...status, + // status: pause ? "paused" : "indexing", + // }); + // } + // } - isPaused(startUrl: string) { - return this.statuses.get(startUrl)?.status === "paused"; - } + // isPaused(startUrl: string) { + // return this.statuses.get(startUrl)?.status === "paused"; + // } /* * Currently, we generate and host embeddings for pre-indexed docs using transformers. @@ -383,16 +377,9 @@ export default class DocsService { const indexExists = await this.hasMetadata(startUrl); // Build status update - most of it is fixed values - const fixedStatus: Pick< + const fixedStatus: Omit< IndexingStatus, - | "type" - | "id" - | "embeddingsProviderId" - | "isReindexing" - | "debugInfo" - | "icon" - | "url" - | "title" + "progress" | "description" | "status" > = { type: "docs", id: siteIndexingConfig.startUrl, @@ -405,7 +392,6 @@ export default class DocsService { }; // Clear current indexes if reIndexing - // if (indexExists) { if (reIndex) { await this.deleteIndexes(startUrl); @@ -452,9 +438,9 @@ export default class DocsService { description: `Finding subpages (${page.path})`, status: "indexing", progress: - 0.3 * estimatedProgress + - Math.min(0.2, (0.2 * processedPages) / 500), - // For the first 50%, 30% is sum of series 1/(2^n) and the other 20% is based on number of files/ 500 max + 0.15 * estimatedProgress + + Math.min(0.35, (0.35 * processedPages) / 500), + // For the first 50%, 15% is sum of series 1/(2^n) and the other 35% is based on number of files/ 500 max }); const article = pageToArticle(page); @@ -464,7 +450,11 @@ export default class DocsService { articles.push(article); processedPages++; - await new Promise((resolve) => setTimeout(resolve, 100)); // Locks down GUI if no sleeping + + // Locks down GUI if no sleeping + // Wait proportional to how many docs are indexing + const toWait = 100 * this.docsIndexingQueue.size + 50; + await new Promise((resolve) => setTimeout(resolve, toWait)); } void Telemetry.capture("docs_pages_crawled", { @@ -1017,13 +1007,10 @@ export default class DocsService { } async delete(startUrl: string) { + this.docsIndexingQueue.delete(startUrl); + this.abort(startUrl); await this.deleteIndexes(startUrl); this.deleteFromConfig(startUrl); - - const status = this.statuses.get(startUrl); - if (status) { - this.handleStatusUpdate({ ...status, status: "deleted" }); - } this.messenger?.send("refreshSubmenuItems", undefined); } diff --git a/gui/src/components/dialogs/AddDocsDialog.tsx b/gui/src/components/dialogs/AddDocsDialog.tsx index 51d11498d..0bcd40fd9 100644 --- a/gui/src/components/dialogs/AddDocsDialog.tsx +++ b/gui/src/components/dialogs/AddDocsDialog.tsx @@ -215,13 +215,23 @@ function AddDocsDialog() { {/*
*/} -

+

{ + e.stopPropagation(); + ideMessenger.post("openUrl", details.docsLink); + }} + > {details.docsLink}

)} -
+
{ + e.stopPropagation(); + }} + > = { paused: PauseCircleIcon, complete: CheckCircleIcon, aborted: null, - deleted: null, pending: null, - failed: XMarkIcon, // Since we show an erorr message below + failed: XMarkIcon, // Since we show an error message below }; function DocsIndexingStatus({ docConfig }: IndexingStatusViewerProps) { const ideMessenger = useContext(IdeMessengerContext); - const dispatch = useDispatch(); + const dispatch = useAppDispatch(); const status = useAppSelector( (store) => store.indexing.indexing.statuses[docConfig.startUrl], @@ -53,6 +54,26 @@ function DocsIndexingStatus({ docConfig }: IndexingStatusViewerProps) { } }; + const [hasDeleted, setHasDeleted] = useState(false); // simple alternative to optimistic redux update + const onDelete = () => { + // optimistic update + dispatch( + setDialogMessage( + { + ideMessenger.post("context/removeDocs", { + startUrl: docConfig.startUrl, + }); + setHasDeleted(true); + }} + />, + ), + ); + dispatch(setShowDialog(true)); + }; + const progressPercentage = useMemo(() => { if (!status) { return 0; @@ -62,6 +83,8 @@ function DocsIndexingStatus({ docConfig }: IndexingStatusViewerProps) { const Icon = STATUS_TO_ICON[status?.status]; + if (hasDeleted) return null; + return (
{/* {`${status.type} - ${status.id} - ${status.status} - ${status.progress} - ${status.description} - ${status.icon}`} */} @@ -100,6 +123,12 @@ function DocsIndexingStatus({ docConfig }: IndexingStatusViewerProps) { }`} > ) : null} + {status?.status !== "indexing" ? ( + + ) : null}
)}
@@ -125,7 +154,6 @@ function DocsIndexingStatus({ docConfig }: IndexingStatusViewerProps) { failed: reIndex, aborted: reIndex, paused: () => {}, - deleted: () => {}, pending: () => {}, }[status?.status] } @@ -137,7 +165,6 @@ function DocsIndexingStatus({ docConfig }: IndexingStatusViewerProps) { failed: "Click to retry", aborted: "Click to index", paused: "", - deleted: "", pending: "", }[status?.status] } diff --git a/gui/src/components/indexing/DocsIndexingStatuses.tsx b/gui/src/components/indexing/DocsIndexingStatuses.tsx index a54ffd2a5..76feb21e0 100644 --- a/gui/src/components/indexing/DocsIndexingStatuses.tsx +++ b/gui/src/components/indexing/DocsIndexingStatuses.tsx @@ -10,16 +10,6 @@ function DocsIndexingStatuses() { const config = useAppSelector((store) => store.config.config); const configDocs = config.docs ?? []; - // const indexingStatuses = useSelector( - // (store: RootState) => store.indexing.indexing.statuses, - // ); - // const docsStatuses = useMemo(() => { - // const docs = Object.values(indexingStatuses).filter( - // (status) => status.type === "docs" && status.status !== "deleted", - // ); - // return docs; - // }, [indexingStatuses]); - return (
@@ -38,9 +28,23 @@ function DocsIndexingStatuses() { ) : null}
- Manage your documentation sources + {configDocs.length + ? "Manage your documentation sources" + : "No docs yet"}
+
+ {configDocs.length === 0 && ( + { + dispatch(setShowDialog(true)); + dispatch(setDialogMessage()); + }} + > + Add Docs + + )} +
{configDocs.map((doc) => { return ; })} diff --git a/gui/src/components/indexing/utils.ts b/gui/src/components/indexing/utils.ts deleted file mode 100644 index 768384a52..000000000 --- a/gui/src/components/indexing/utils.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { - ArrowPathIcon, - CheckCircleIcon, - PauseCircleIcon, -} from "@heroicons/react/24/outline"; -import { IndexingStatus } from "core"; - -export const STATUS_TO_ICON: Record = { - indexing: ArrowPathIcon, - paused: PauseCircleIcon, - complete: CheckCircleIcon, - aborted: null, - deleted: null, - pending: null, - failed: null, // XMarkIcon, // Since we show an error message below -};