mirror of
https://github.com/danswer-ai/danswer.git
synced 2025-09-28 04:49:21 +02:00
Auto-delete unlinked connectors on creation of a new connector with the same name
This commit is contained in:
@@ -8,7 +8,7 @@ import {
|
|||||||
ValidInputTypes,
|
ValidInputTypes,
|
||||||
ValidSources,
|
ValidSources,
|
||||||
} from "@/lib/types";
|
} from "@/lib/types";
|
||||||
import { deleteConnectorIfExists } from "@/lib/connector";
|
import { deleteConnectorIfExistsAndIsUnlinked } from "@/lib/connector";
|
||||||
import { FormBodyBuilder, RequireAtLeastOne } from "./types";
|
import { FormBodyBuilder, RequireAtLeastOne } from "./types";
|
||||||
import { TextFormField } from "./Field";
|
import { TextFormField } from "./Field";
|
||||||
import { linkCredential } from "@/lib/credential";
|
import { linkCredential } from "@/lib/credential";
|
||||||
@@ -113,6 +113,25 @@ export function ConnectorForm<T extends Yup.AnyObject>({
|
|||||||
const connectorConfig = Object.fromEntries(
|
const connectorConfig = Object.fromEntries(
|
||||||
Object.keys(initialValues).map((key) => [key, values[key]])
|
Object.keys(initialValues).map((key) => [key, values[key]])
|
||||||
) as T;
|
) as T;
|
||||||
|
|
||||||
|
// best effort check to see if existing connector exists
|
||||||
|
// delete it if:
|
||||||
|
// 1. it exists
|
||||||
|
// 2. AND it has no credentials linked to it
|
||||||
|
// If the ^ are true, that means things have gotten into a bad
|
||||||
|
// state, and we should delete the connector to recover
|
||||||
|
const errorMsg = await deleteConnectorIfExistsAndIsUnlinked({
|
||||||
|
source,
|
||||||
|
name: connectorName,
|
||||||
|
});
|
||||||
|
if (errorMsg) {
|
||||||
|
setPopup({
|
||||||
|
message: `Unable to delete existing connector - ${errorMsg}`,
|
||||||
|
type: "error",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const { message, isSuccess, response } = await submitConnector<T>({
|
const { message, isSuccess, response } = await submitConnector<T>({
|
||||||
name: connectorName,
|
name: connectorName,
|
||||||
source,
|
source,
|
||||||
|
@@ -66,7 +66,7 @@ export async function runConnector(
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function deleteConnectorIfExists({
|
export async function deleteConnectorIfExistsAndIsUnlinked({
|
||||||
source,
|
source,
|
||||||
name,
|
name,
|
||||||
}: {
|
}: {
|
||||||
@@ -80,7 +80,10 @@ export async function deleteConnectorIfExists({
|
|||||||
(connector) =>
|
(connector) =>
|
||||||
connector.source === source && (!name || connector.name === name)
|
connector.source === source && (!name || connector.name === name)
|
||||||
);
|
);
|
||||||
if (matchingConnectors.length > 0) {
|
if (
|
||||||
|
matchingConnectors.length > 0 &&
|
||||||
|
matchingConnectors[0].credential_ids.length === 0
|
||||||
|
) {
|
||||||
const errorMsg = await deleteConnector(matchingConnectors[0].id);
|
const errorMsg = await deleteConnector(matchingConnectors[0].id);
|
||||||
if (errorMsg) {
|
if (errorMsg) {
|
||||||
return errorMsg;
|
return errorMsg;
|
||||||
|
Reference in New Issue
Block a user