Merge pull request #3257 from continuedev/dallin/docs-ui-improvements

Docs UI updates
This commit is contained in:
Nate Sesti 2024-12-09 08:44:28 -08:00 • committed by GitHub
commit 63f668eadd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 88 additions and 83 deletions

View file

@ -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) => {

9
core/index.d.ts vendored
View file

@ -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;

View file

@ -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);
}

View file

@ -215,13 +215,23 @@ function AddDocsDialog() {
{/* <div>
<LinkIcon className="h-2 w-2" />
</div> */}
<p className="lines lines-1 m-0 p-0">
<p
className="lines lines-1 m-0 p-0 hover:underline"
onClick={(e) => {
e.stopPropagation();
ideMessenger.post("openUrl", details.docsLink);
}}
>
{details.docsLink}
</p>
</div>
)}
</div>
<div>
<div
onClick={(e) => {
e.stopPropagation();
}}
>
<InformationCircleIcon
data-tooltip-id={id + "-info"}
className="text-vsc-foreground-muted h-3.5 w-3.5 select-none"

View file

@ -1,16 +1,18 @@
import { IndexingStatus, SiteIndexingConfig } from "core";
import { useContext, useMemo } from "react";
import { useDispatch } from "react-redux";
import { useContext, useMemo, useState } from "react";
import { IdeMessengerContext } from "../../context/IdeMessenger";
import {
ArrowPathIcon,
ArrowTopRightOnSquareIcon,
CheckCircleIcon,
PauseCircleIcon,
TrashIcon,
XMarkIcon,
} from "@heroicons/react/24/outline";
import { useAppSelector } from "../../redux/hooks";
import { useAppDispatch, useAppSelector } from "../../redux/hooks";
import { updateIndexingStatus } from "../../redux/slices/indexingSlice";
import { setDialogMessage, setShowDialog } from "../../redux/slices/uiSlice";
import ConfirmationDialog from "../dialogs/ConfirmationDialog";
interface IndexingStatusViewerProps {
docConfig: SiteIndexingConfig;
@ -21,14 +23,13 @@ const STATUS_TO_ICON: Record<IndexingStatus["status"], any> = {
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(
<ConfirmationDialog
title={`Delete ${docConfig.title}`}
text={`Are you sure you want to remove ${docConfig.title} from your configuration?`}
onConfirm={() => {
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 (
<div className="mt-2 flex w-full flex-col">
{/* {`${status.type} - ${status.id} - ${status.status} - ${status.progress} - ${status.description} - ${status.icon}`} */}
@ -100,6 +123,12 @@ function DocsIndexingStatus({ docConfig }: IndexingStatusViewerProps) {
}`}
></Icon>
) : null}
{status?.status !== "indexing" ? (
<TrashIcon
className="h-4 w-4 cursor-pointer text-stone-500"
onClick={onDelete}
/>
) : null}
</div>
)}
</div>
@ -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]
}

View file

@ -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 (
<div className="flex flex-col gap-1">
<div className="flex flex-row items-center justify-between">
@ -38,9 +28,23 @@ function DocsIndexingStatuses() {
) : null}
</div>
<span className="text-xs text-stone-500">
Manage your documentation sources
{configDocs.length
? "Manage your documentation sources"
: "No docs yet"}
</span>
<div className="flex max-h-[170px] flex-col gap-1 overflow-x-hidden overflow-y-scroll pr-2">
<div>
{configDocs.length === 0 && (
<SecondaryButton
onClick={() => {
dispatch(setShowDialog(true));
dispatch(setDialogMessage(<AddDocsDialog />));
}}
>
Add Docs
</SecondaryButton>
)}
</div>
{configDocs.map((doc) => {
return <DocsIndexingStatus key={doc.startUrl} docConfig={doc} />;
})}

View file

@ -1,16 +0,0 @@
import {
ArrowPathIcon,
CheckCircleIcon,
PauseCircleIcon,
} from "@heroicons/react/24/outline";
import { IndexingStatus } from "core";
export const STATUS_TO_ICON: Record<IndexingStatus["status"], any> = {
indexing: ArrowPathIcon,
paused: PauseCircleIcon,
complete: CheckCircleIcon,
aborted: null,
deleted: null,
pending: null,
failed: null, // XMarkIcon, // Since we show an error message below
};