mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-07-04 22:02:16 +02:00
refactor(web): consume runtime config in connectors and document uploads
This commit is contained in:
parent
c5dd55e964
commit
bc31b10ca6
5 changed files with 22 additions and 12 deletions
|
|
@ -43,11 +43,6 @@ export const CirclebackConfig: FC<CirclebackConfigProps> = ({ connector, onNameC
|
||||||
if (!connector.search_space_id) return;
|
if (!connector.search_space_id) return;
|
||||||
|
|
||||||
const baseUrl = BACKEND_URL;
|
const baseUrl = BACKEND_URL;
|
||||||
if (!baseUrl) {
|
|
||||||
console.error("NEXT_PUBLIC_FASTAPI_BACKEND_URL is not configured");
|
|
||||||
setIsLoading(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import type { FC } from "react";
|
||||||
import { EnumConnectorName } from "@/contracts/enums/connector";
|
import { EnumConnectorName } from "@/contracts/enums/connector";
|
||||||
import type { SearchSourceConnector } from "@/contracts/types/connector.types";
|
import type { SearchSourceConnector } from "@/contracts/types/connector.types";
|
||||||
import { usePlatform } from "@/hooks/use-platform";
|
import { usePlatform } from "@/hooks/use-platform";
|
||||||
import { isSelfHosted } from "@/lib/env-config";
|
import { useIsSelfHosted } from "@/components/providers/runtime-config";
|
||||||
import { ConnectorCard } from "../components/connector-card";
|
import { ConnectorCard } from "../components/connector-card";
|
||||||
import {
|
import {
|
||||||
COMPOSIO_CONNECTORS,
|
COMPOSIO_CONNECTORS,
|
||||||
|
|
@ -22,6 +22,11 @@ type OAuthConnector = (typeof OAUTH_CONNECTORS)[number];
|
||||||
type ComposioConnector = (typeof COMPOSIO_CONNECTORS)[number];
|
type ComposioConnector = (typeof COMPOSIO_CONNECTORS)[number];
|
||||||
type OtherConnector = (typeof OTHER_CONNECTORS)[number];
|
type OtherConnector = (typeof OTHER_CONNECTORS)[number];
|
||||||
type CrawlerConnector = (typeof CRAWLERS)[number];
|
type CrawlerConnector = (typeof CRAWLERS)[number];
|
||||||
|
type DeploymentFilterableConnector = {
|
||||||
|
readonly id: string;
|
||||||
|
readonly selfHostedOnly?: boolean;
|
||||||
|
readonly desktopOnly?: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extract the display name from a full connector name.
|
* Extract the display name from a full connector name.
|
||||||
|
|
@ -66,14 +71,14 @@ export const AllConnectorsTab: FC<AllConnectorsTabProps> = ({
|
||||||
onManage,
|
onManage,
|
||||||
onViewAccountsList,
|
onViewAccountsList,
|
||||||
}) => {
|
}) => {
|
||||||
const selfHosted = isSelfHosted();
|
const selfHosted = useIsSelfHosted();
|
||||||
const { isDesktop } = usePlatform();
|
const { isDesktop } = usePlatform();
|
||||||
|
|
||||||
const matchesSearch = (title: string, description: string) =>
|
const matchesSearch = (title: string, description: string) =>
|
||||||
title.toLowerCase().includes(searchQuery.toLowerCase()) ||
|
title.toLowerCase().includes(searchQuery.toLowerCase()) ||
|
||||||
description.toLowerCase().includes(searchQuery.toLowerCase());
|
description.toLowerCase().includes(searchQuery.toLowerCase());
|
||||||
|
|
||||||
const passesDeploymentFilter = (c: { selfHostedOnly?: boolean; desktopOnly?: boolean }) =>
|
const passesDeploymentFilter = (c: DeploymentFilterableConnector) =>
|
||||||
(!c.selfHostedOnly || selfHosted) && (!c.desktopOnly || isDesktop);
|
(!c.selfHostedOnly || selfHosted) && (!c.desktopOnly || isDesktop);
|
||||||
|
|
||||||
// Filter connectors based on search and deployment mode
|
// Filter connectors based on search and deployment mode
|
||||||
|
|
|
||||||
|
|
@ -72,6 +72,7 @@ import type { DocumentTypeEnum } from "@/contracts/types/document.types";
|
||||||
import { useDebouncedValue } from "@/hooks/use-debounced-value";
|
import { useDebouncedValue } from "@/hooks/use-debounced-value";
|
||||||
import { useMediaQuery } from "@/hooks/use-media-query";
|
import { useMediaQuery } from "@/hooks/use-media-query";
|
||||||
import { useElectronAPI, usePlatform } from "@/hooks/use-platform";
|
import { useElectronAPI, usePlatform } from "@/hooks/use-platform";
|
||||||
|
import { useRuntimeConfig } from "@/components/providers/runtime-config";
|
||||||
import { anonymousChatApiService } from "@/lib/apis/anonymous-chat-api.service";
|
import { anonymousChatApiService } from "@/lib/apis/anonymous-chat-api.service";
|
||||||
import { documentsApiService } from "@/lib/apis/documents-api.service";
|
import { documentsApiService } from "@/lib/apis/documents-api.service";
|
||||||
import { foldersApiService } from "@/lib/apis/folders-api.service";
|
import { foldersApiService } from "@/lib/apis/folders-api.service";
|
||||||
|
|
@ -226,6 +227,7 @@ function AuthenticatedDocumentsSidebarBase({
|
||||||
const isMobile = !useMediaQuery("(min-width: 640px)");
|
const isMobile = !useMediaQuery("(min-width: 640px)");
|
||||||
const platformElectronAPI = useElectronAPI();
|
const platformElectronAPI = useElectronAPI();
|
||||||
const electronAPI = desktopFeaturesEnabled ? platformElectronAPI : null;
|
const electronAPI = desktopFeaturesEnabled ? platformElectronAPI : null;
|
||||||
|
const { etlService } = useRuntimeConfig();
|
||||||
const searchSpaceId = Number(params.search_space_id);
|
const searchSpaceId = Number(params.search_space_id);
|
||||||
const setConnectorDialogOpen = useSetAtom(connectorDialogOpenAtom);
|
const setConnectorDialogOpen = useSetAtom(connectorDialogOpenAtom);
|
||||||
const openEditorPanel = useSetAtom(openEditorPanelAtom);
|
const openEditorPanel = useSetAtom(openEditorPanelAtom);
|
||||||
|
|
@ -618,7 +620,8 @@ function AuthenticatedDocumentsSidebarBase({
|
||||||
folderName: matched.name,
|
folderName: matched.name,
|
||||||
searchSpaceId,
|
searchSpaceId,
|
||||||
excludePatterns: matched.excludePatterns ?? DEFAULT_EXCLUDE_PATTERNS,
|
excludePatterns: matched.excludePatterns ?? DEFAULT_EXCLUDE_PATTERNS,
|
||||||
fileExtensions: matched.fileExtensions ?? Array.from(getSupportedExtensionsSet()),
|
fileExtensions:
|
||||||
|
matched.fileExtensions ?? Array.from(getSupportedExtensionsSet(undefined, etlService)),
|
||||||
rootFolderId: folder.id,
|
rootFolderId: folder.id,
|
||||||
});
|
});
|
||||||
toast.success(`Re-scan complete: ${matched.name}`);
|
toast.success(`Re-scan complete: ${matched.name}`);
|
||||||
|
|
@ -626,7 +629,7 @@ function AuthenticatedDocumentsSidebarBase({
|
||||||
toast.error((err as Error)?.message || "Failed to re-scan folder");
|
toast.error((err as Error)?.message || "Failed to re-scan folder");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[searchSpaceId, electronAPI]
|
[searchSpaceId, electronAPI, etlService]
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleStopWatching = useCallback(
|
const handleStopWatching = useCallback(
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import { type ChangeEvent, useCallback, useEffect, useMemo, useRef, useState } f
|
||||||
import { useDropzone } from "react-dropzone";
|
import { useDropzone } from "react-dropzone";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import { uploadDocumentMutationAtom } from "@/atoms/documents/document-mutation.atoms";
|
import { uploadDocumentMutationAtom } from "@/atoms/documents/document-mutation.atoms";
|
||||||
|
import { useRuntimeConfig } from "@/components/providers/runtime-config";
|
||||||
import {
|
import {
|
||||||
Accordion,
|
Accordion,
|
||||||
AccordionContent,
|
AccordionContent,
|
||||||
|
|
@ -136,6 +137,7 @@ export function DocumentUploadTab({
|
||||||
onAccordionStateChange,
|
onAccordionStateChange,
|
||||||
}: DocumentUploadTabProps) {
|
}: DocumentUploadTabProps) {
|
||||||
const t = useTranslations("upload_documents");
|
const t = useTranslations("upload_documents");
|
||||||
|
const { etlService } = useRuntimeConfig();
|
||||||
const [files, setFiles] = useState<FileWithId[]>([]);
|
const [files, setFiles] = useState<FileWithId[]>([]);
|
||||||
const [uploadProgress, setUploadProgress] = useState(0);
|
const [uploadProgress, setUploadProgress] = useState(0);
|
||||||
const [accordionValue, setAccordionValue] = useState<string>("");
|
const [accordionValue, setAccordionValue] = useState<string>("");
|
||||||
|
|
@ -160,7 +162,7 @@ export function DocumentUploadTab({
|
||||||
const electronAPI = useElectronAPI();
|
const electronAPI = useElectronAPI();
|
||||||
const isElectron = !!electronAPI?.browseFiles;
|
const isElectron = !!electronAPI?.browseFiles;
|
||||||
|
|
||||||
const acceptedFileTypes = useMemo(() => getAcceptedFileTypes(), []);
|
const acceptedFileTypes = useMemo(() => getAcceptedFileTypes(etlService), [etlService]);
|
||||||
const supportedExtensions = useMemo(
|
const supportedExtensions = useMemo(
|
||||||
() => getSupportedExtensions(acceptedFileTypes),
|
() => getSupportedExtensions(acceptedFileTypes),
|
||||||
[acceptedFileTypes]
|
[acceptedFileTypes]
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
import { X } from "lucide-react";
|
import { X } from "lucide-react";
|
||||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
|
import { useRuntimeConfig } from "@/components/providers/runtime-config";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
|
|
@ -48,6 +49,7 @@ export function FolderWatchDialog({
|
||||||
const [submitting, setSubmitting] = useState(false);
|
const [submitting, setSubmitting] = useState(false);
|
||||||
const [progress, setProgress] = useState<FolderSyncProgress | null>(null);
|
const [progress, setProgress] = useState<FolderSyncProgress | null>(null);
|
||||||
const abortRef = useRef<AbortController | null>(null);
|
const abortRef = useRef<AbortController | null>(null);
|
||||||
|
const { etlService } = useRuntimeConfig();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (open && initialFolder) {
|
if (open && initialFolder) {
|
||||||
|
|
@ -55,7 +57,10 @@ export function FolderWatchDialog({
|
||||||
}
|
}
|
||||||
}, [open, initialFolder]);
|
}, [open, initialFolder]);
|
||||||
|
|
||||||
const supportedExtensions = useMemo(() => Array.from(getSupportedExtensionsSet()), []);
|
const supportedExtensions = useMemo(
|
||||||
|
() => Array.from(getSupportedExtensionsSet(undefined, etlService)),
|
||||||
|
[etlService]
|
||||||
|
);
|
||||||
|
|
||||||
const handleSelectFolder = useCallback(async () => {
|
const handleSelectFolder = useCallback(async () => {
|
||||||
const api = window.electronAPI;
|
const api = window.electronAPI;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue