mirror of
https://github.com/danswer-ai/danswer.git
synced 2025-10-09 20:55:06 +02:00
FE to allow full re-indexing
This commit is contained in:
@@ -1,11 +1,94 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { usePopup } from "@/components/admin/connectors/Popup";
|
import { PopupSpec, usePopup } from "@/components/admin/connectors/Popup";
|
||||||
import { runConnector } from "@/lib/connector";
|
import { runConnector } from "@/lib/connector";
|
||||||
import { Button } from "@tremor/react";
|
import { Button, Divider, Text } from "@tremor/react";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import { mutate } from "swr";
|
import { mutate } from "swr";
|
||||||
import { buildCCPairInfoUrl } from "./lib";
|
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({
|
export function ReIndexButton({
|
||||||
ccPairId,
|
ccPairId,
|
||||||
@@ -19,28 +102,26 @@ export function ReIndexButton({
|
|||||||
isDisabled: boolean;
|
isDisabled: boolean;
|
||||||
}) {
|
}) {
|
||||||
const { popup, setPopup } = usePopup();
|
const { popup, setPopup } = usePopup();
|
||||||
|
const [reIndexPopupVisible, setReIndexPopupVisible] = useState(false);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
{reIndexPopupVisible && (
|
||||||
|
<ReIndexPopup
|
||||||
|
connectorId={connectorId}
|
||||||
|
credentialId={credentialId}
|
||||||
|
ccPairId={ccPairId}
|
||||||
|
setPopup={setPopup}
|
||||||
|
hide={() => setReIndexPopupVisible(false)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
{popup}
|
{popup}
|
||||||
<Button
|
<Button
|
||||||
className="ml-auto"
|
className="ml-auto"
|
||||||
color="green"
|
color="green"
|
||||||
size="xs"
|
size="xs"
|
||||||
onClick={async () => {
|
onClick={() => {
|
||||||
const errorMsg = await runConnector(connectorId, [credentialId]);
|
setReIndexPopupVisible(true);
|
||||||
if (errorMsg) {
|
|
||||||
setPopup({
|
|
||||||
message: errorMsg,
|
|
||||||
type: "error",
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
setPopup({
|
|
||||||
message: "Triggered connector run",
|
|
||||||
type: "success",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
mutate(buildCCPairInfoUrl(ccPairId));
|
|
||||||
}}
|
}}
|
||||||
disabled={isDisabled}
|
disabled={isDisabled}
|
||||||
tooltip={
|
tooltip={
|
||||||
|
@@ -74,12 +74,17 @@ export async function deleteConnector(
|
|||||||
|
|
||||||
export async function runConnector(
|
export async function runConnector(
|
||||||
connectorId: number,
|
connectorId: number,
|
||||||
credentialIds: number[] | null = null
|
credentialIds: number[],
|
||||||
|
fromBeginning: boolean = false
|
||||||
): Promise<string | null> {
|
): Promise<string | null> {
|
||||||
const response = await fetch("/api/manage/admin/connector/run-once", {
|
const response = await fetch("/api/manage/admin/connector/run-once", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
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) {
|
if (!response.ok) {
|
||||||
return (await response.json()).detail;
|
return (await response.json()).detail;
|
||||||
|
Reference in New Issue
Block a user