-
-
+
+ {!!currentSyncId && (
+ {
+ setCurrentSyncId(undefined);
+ }}
+ />
+ )}
+ {currentSyncId ? (
+
+ ) : (
+ {
+ setOpenedConnections([]);
+ void handleFeedBrain();
+ }}
+ disabled={disabled}
+ isLoading={feeding}
+ important={true}
+ />
+ )}
diff --git a/frontend/lib/components/UploadDocumentModal/hooks/useFeedBrain.ts b/frontend/lib/components/UploadDocumentModal/hooks/useFeedBrain.ts
index 9fa1e00dc..d3d442eb2 100644
--- a/frontend/lib/components/UploadDocumentModal/hooks/useFeedBrain.ts
+++ b/frontend/lib/components/UploadDocumentModal/hooks/useFeedBrain.ts
@@ -1,6 +1,7 @@
import { useState } from "react";
import { useTranslation } from "react-i18next";
+import { useFromConnectionsContext } from "@/app/chat/[chatId]/components/ActionsBar/components/KnowledgeToFeed/components/FromConnections/FromConnectionsProvider/hooks/useFromConnectionContext";
import { useChatApi } from "@/lib/api/chat/useChatApi";
import { useBrainContext } from "@/lib/context/BrainProvider/hooks/useBrainContext";
import { useKnowledgeToFeedContext } from "@/lib/context/KnowledgeToFeedProvider/hooks/useKnowledgeToFeedContext";
@@ -25,6 +26,7 @@ export const useFeedBrain = ({
useKnowledgeToFeedContext();
const [hasPendingRequests, setHasPendingRequests] = useState(false);
const { handleFeedBrain } = useFeedBrainHandler();
+ const { openedConnections } = useFromConnectionsContext();
const { createChat, deleteChat } = useChatApi();
@@ -39,7 +41,7 @@ export const useFeedBrain = ({
return;
}
- if (knowledgeToFeed.length === 0) {
+ if (knowledgeToFeed.length === 0 && !openedConnections.length) {
publish({
variant: "danger",
text: t("addFiles"),
@@ -55,12 +57,11 @@ export const useFeedBrain = ({
dispatchHasPendingRequests?.();
closeFeedInput?.();
setHasPendingRequests(true);
- setShouldDisplayFeedCard(false);
await handleFeedBrain({
brainId,
chatId: currentChatId,
});
-
+ setShouldDisplayFeedCard(false);
setKnowledgeToFeed([]);
} catch (e) {
publish({
diff --git a/frontend/lib/components/UploadDocumentModal/hooks/useFeedBrainHandler.ts b/frontend/lib/components/UploadDocumentModal/hooks/useFeedBrainHandler.ts
index b88a8ab0d..5b4232c9c 100644
--- a/frontend/lib/components/UploadDocumentModal/hooks/useFeedBrainHandler.ts
+++ b/frontend/lib/components/UploadDocumentModal/hooks/useFeedBrainHandler.ts
@@ -1,5 +1,7 @@
import { UUID } from "crypto";
+import { useFromConnectionsContext } from "@/app/chat/[chatId]/components/ActionsBar/components/KnowledgeToFeed/components/FromConnections/FromConnectionsProvider/hooks/useFromConnectionContext";
+import { useSync } from "@/lib/api/sync/useSync";
import { useKnowledgeToFeedInput } from "@/lib/components/KnowledgeToFeedInput/hooks/useKnowledgeToFeedInput.ts";
import { useKnowledgeToFeedFilesAndUrls } from "@/lib/hooks/useKnowledgeToFeed";
import { useOnboarding } from "@/lib/hooks/useOnboarding";
@@ -13,6 +15,13 @@ export const useFeedBrainHandler = () => {
const { files, urls } = useKnowledgeToFeedFilesAndUrls();
const { crawlWebsiteHandler, uploadFileHandler } = useKnowledgeToFeedInput();
const { updateOnboarding, onboarding } = useOnboarding();
+ const {
+ syncFiles,
+ getActiveSyncsForBrain,
+ deleteActiveSync,
+ updateActiveSync,
+ } = useSync();
+ const { openedConnections } = useFromConnectionsContext();
const updateOnboardingA = async () => {
if (onboarding.onboarding_a) {
@@ -33,6 +42,26 @@ export const useFeedBrainHandler = () => {
crawlWebsiteHandler(url, brainId, chatId)
);
+ const existingConnections = await getActiveSyncsForBrain(brainId);
+
+ await Promise.all(
+ openedConnections.map(async (openedConnection) => {
+ const existingConnectionIds = existingConnections.map(
+ (connection) => connection.id
+ );
+ if (
+ !openedConnection.id ||
+ !existingConnectionIds.includes(openedConnection.id)
+ ) {
+ await syncFiles(openedConnection, brainId);
+ } else if (!openedConnection.selectedFiles.files.length) {
+ await deleteActiveSync(openedConnection.id);
+ } else {
+ await updateActiveSync(openedConnection);
+ }
+ })
+ );
+
await Promise.all([
...uploadPromises,
...crawlPromises,
diff --git a/frontend/lib/components/ui/Checkbox/Checkbox.module.scss b/frontend/lib/components/ui/Checkbox/Checkbox.module.scss
index c35d68715..608701f68 100644
--- a/frontend/lib/components/ui/Checkbox/Checkbox.module.scss
+++ b/frontend/lib/components/ui/Checkbox/Checkbox.module.scss
@@ -12,9 +12,22 @@
height: 16px;
border: 1px solid var(--border-2);
border-radius: Radius.$small;
+ display: flex;
+ justify-content: center;
+ align-items: center;
&.filled {
background-color: var(--primary-0);
}
}
+
+ &.disabled {
+ background-color: var(--background-3);
+ opacity: 0.4;
+ cursor: default;
+ }
+
+ &:hover {
+ background-color: var(--background-3);
+ }
}
diff --git a/frontend/lib/components/ui/Checkbox/Checkbox.tsx b/frontend/lib/components/ui/Checkbox/Checkbox.tsx
index 46e351cd1..ee71cd604 100644
--- a/frontend/lib/components/ui/Checkbox/Checkbox.tsx
+++ b/frontend/lib/components/ui/Checkbox/Checkbox.tsx
@@ -2,16 +2,23 @@ import { useEffect, useState } from "react";
import styles from "./Checkbox.module.scss";
+import { Icon } from "../Icon/Icon";
+import Tooltip from "../Tooltip/Tooltip";
+
interface CheckboxProps {
- label: string;
+ label?: string;
checked: boolean;
setChecked: (value: boolean) => void;
+ disabled?: boolean;
+ tooltip?: string;
}
export const Checkbox = ({
label,
checked,
setChecked,
+ disabled,
+ tooltip,
}: CheckboxProps): JSX.Element => {
const [currentChecked, setCurrentChecked] = useState
(checked);
@@ -19,18 +26,31 @@ export const Checkbox = ({
setCurrentChecked(checked);
}, [checked]);
- return (
+ const checkboxElement = (
{
- setChecked(!currentChecked);
- setCurrentChecked(!currentChecked);
+ className={`${styles.checkbox_wrapper} ${
+ disabled ? styles.disabled : ""
+ }`}
+ onClick={(event) => {
+ event.stopPropagation();
+ if (!disabled) {
+ setChecked(!currentChecked);
+ setCurrentChecked(!currentChecked);
+ }
}}
>
-
{label}
+ >
+ {currentChecked &&
}
+
+ {label && {label}}
);
+
+ return tooltip ? (
+