FE to allow full re-indexing

This commit is contained in:
Weves 2024-02-07 00:06:18 -08:00 committed by Chris Weaver
parent 2362c2bdcc
commit 4d6b3c8f08
2 changed files with 104 additions and 18 deletions

View File

@ -1,11 +1,94 @@
"use client";
import { usePopup } from "@/components/admin/connectors/Popup";
import { PopupSpec, usePopup } from "@/components/admin/connectors/Popup";
import { runConnector } from "@/lib/connector";
import { Button } from "@tremor/react";
import { Button, Divider, Text } from "@tremor/react";
import { useRouter } from "next/navigation";
import { mutate } from "swr";
import { buildCCPairInfoUrl } from "./lib";
import { useState } from "react";
import { Modal } from "@/components/Modal";
function ReIndexPopup({
connectorId,
credentialId,
ccPairId,
setPopup,
hide,
}: {
connectorId: number;
credentialId: number;
ccPairId: number;
setPopup: (popupSpec: PopupSpec | null) => void;
hide: () => void;
}) {
async function triggerIndexing(fromBeginning: boolean) {
const errorMsg = await runConnector(
connectorId,
[credentialId],
fromBeginning
);
if (errorMsg) {
setPopup({
message: errorMsg,
type: "error",
});
} else {
setPopup({
message: "Triggered connector run",
type: "success",
});
}
mutate(buildCCPairInfoUrl(ccPairId));
}
return (
<Modal title="Run Indexing" onOutsideClick={hide}>
<div>
<Button
className="ml-auto"
color="green"
size="xs"
onClick={() => {
triggerIndexing(false);
hide();
}}
>
Run Update
</Button>
<Text className="mt-2">
This will pull in and index all documents that have changed and/or
have been added since the last successful indexing run.
</Text>
<Divider />
<Button
className="ml-auto"
color="green"
size="xs"
onClick={() => {
triggerIndexing(true);
hide();
}}
>
Run Complete Re-Indexing
</Button>
<Text className="mt-2">
This will cause a complete re-indexing of all documents from the
source.
</Text>
<Text className="mt-2">
<b>NOTE:</b> depending on the number of documents stored in the
source, this may take a long time.
</Text>
</div>
</Modal>
);
}
export function ReIndexButton({
ccPairId,
@ -19,28 +102,26 @@ export function ReIndexButton({
isDisabled: boolean;
}) {
const { popup, setPopup } = usePopup();
const [reIndexPopupVisible, setReIndexPopupVisible] = useState(false);
return (
<>
{reIndexPopupVisible && (
<ReIndexPopup
connectorId={connectorId}
credentialId={credentialId}
ccPairId={ccPairId}
setPopup={setPopup}
hide={() => setReIndexPopupVisible(false)}
/>
)}
{popup}
<Button
className="ml-auto"
color="green"
size="xs"
onClick={async () => {
const errorMsg = await runConnector(connectorId, [credentialId]);
if (errorMsg) {
setPopup({
message: errorMsg,
type: "error",
});
} else {
setPopup({
message: "Triggered connector run",
type: "success",
});
}
mutate(buildCCPairInfoUrl(ccPairId));
onClick={() => {
setReIndexPopupVisible(true);
}}
disabled={isDisabled}
tooltip={

View File

@ -74,12 +74,17 @@ export async function deleteConnector(
export async function runConnector(
connectorId: number,
credentialIds: number[] | null = null
credentialIds: number[],
fromBeginning: boolean = false
): Promise<string | null> {
const response = await fetch("/api/manage/admin/connector/run-once", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ connector_id: connectorId, credentialIds }),
body: JSON.stringify({
connector_id: connectorId,
credentialIds,
from_beginning: fromBeginning,
}),
});
if (!response.ok) {
return (await response.json()).detail;