From 6383918f7b7088be280c0880e8ea8a9fd75c43cc Mon Sep 17 00:00:00 2001 From: Antoine Dewez <44063631+Zewed@users.noreply.github.com> Date: Wed, 14 Feb 2024 16:37:33 -0800 Subject: [PATCH] feat(frontend): new brain creation modal (#2192) # Description Please include a summary of the changes and the related issue. Please also include relevant motivation and context. ## Checklist before requesting a review Please delete options that are not relevant. - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my code - [ ] I have commented hard-to-understand areas - [ ] I have ideally added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged ## Screenshots (if appropriate): --- frontend/app/App.tsx | 2 +- .../components/MentionsList/MentionsList.tsx | 2 +- .../KnowledgeToFeed.module.scss | 3 + .../KnowledgeToFeed/KnowledgeToFeed.tsx | 32 +++--- .../FromDocuments/FromDocuments.module.scss | 5 + frontend/app/chat/[chatId]/page.tsx | 2 +- frontend/app/search/page.tsx | 2 +- frontend/app/studio/page.tsx | 2 +- .../AddBrainModal/AddBrainModal.module.scss | 21 ++++ .../AddBrainModal/AddBrainModal.tsx | 36 +++++- .../brainCreation-provider.tsx | 12 +- .../AddBrainSteps/AddBrainSteps.tsx | 44 -------- .../BrainKnowledgeStep/BrainKnowledgeStep.tsx | 80 ------------- .../components/KnowledgeToFeedInput.tsx | 26 ----- .../hooks/useBrainCreationHandler.ts | 52 --------- .../hooks/useBrainKnowledgeStep.ts | 24 ---- .../BrainParamsStep/BrainParamsStep.tsx | 96 ---------------- .../PublicAccessConfirmationModal.tsx | 42 ------- .../hooks/useBrainParamsStep.ts | 16 --- .../hooks/useBrainStatusOptions.ts | 25 ----- .../hooks/usePublicAccessConfirmationModal.ts | 43 ------- .../BrainTypeSelectionStep.tsx | 56 ---------- .../hooks/useBrainTypeSelectionStep.ts | 21 ---- .../hooks/useKnowledgeSourceLabel.ts | 35 ------ .../components/Stepper/Stepper.tsx | 31 ------ .../components/Stepper/components/Step.tsx | 39 ------- .../components/AddBrainSteps/index.ts | 1 - .../components/AddBrainSteps/types.ts | 6 - .../BrainKnowledgeStep.module.scss | 19 ++++ .../BrainKnowledgeStep/BrainKnowledgeStep.tsx | 51 +++++++++ .../ConnectableBrain/ConnectableBrain.tsx | 0 .../hooks/useConnectableBrain.ts | 2 +- .../CompositeBrainConnections.tsx | 0 .../hooks/useBrainCreationApi.ts | 22 ++-- .../BrainMainInfosStep.module.scss | 25 +++++ .../BrainMainInfosStep/BrainMainInfosStep.tsx | 76 +++++++++++++ .../BrainTypeSelection.module.scss | 47 ++++++++ .../BrainTypeSelection/BrainTypeSelection.tsx | 41 +++++++ .../BrainTypeSelectionStep.module.scss | 31 ++++++ .../BrainTypeSelectionStep.tsx | 69 ++++++++++++ .../components/Stepper/Stepper.module.scss | 105 ++++++++++++++++++ .../components/Stepper/Stepper.tsx | 58 ++++++++++ .../AddBrainModal/components/index.ts | 1 - .../hooks/useBrainCreationSteps.ts | 7 +- .../AddBrainModal/{ => types}/types.ts | 14 +++ .../hooks/useParamsDefinitionDefaultValues.ts | 2 +- .../useSecretsDefinitionDefaultValues.ts | 2 +- .../lib/components/ui/Modal/Modal.module.scss | 2 +- .../TextAreaInput/TextAreaInput.module.scss | 35 ++++++ .../ui/TextAreaInput/TextAreaInput.tsx | 32 ++++++ frontend/lib/helpers/iconList.ts | 8 ++ frontend/lib/hooks/useDropzone.ts | 2 +- frontend/styles/_Colors.module.scss | 3 + frontend/styles/_Radius.module.scss | 1 + frontend/styles/_Typography.module.scss | 1 + 55 files changed, 729 insertions(+), 683 deletions(-) create mode 100644 frontend/lib/components/AddBrainModal/AddBrainModal.module.scss rename frontend/lib/components/AddBrainModal/{components/AddBrainSteps => }/brainCreation-provider.tsx (74%) delete mode 100644 frontend/lib/components/AddBrainModal/components/AddBrainSteps/AddBrainSteps.tsx delete mode 100644 frontend/lib/components/AddBrainModal/components/AddBrainSteps/components/BrainKnowledgeStep/BrainKnowledgeStep.tsx delete mode 100644 frontend/lib/components/AddBrainModal/components/AddBrainSteps/components/BrainKnowledgeStep/components/KnowledgeToFeedInput.tsx delete mode 100644 frontend/lib/components/AddBrainModal/components/AddBrainSteps/components/BrainKnowledgeStep/hooks/useBrainCreationHandler.ts delete mode 100644 frontend/lib/components/AddBrainModal/components/AddBrainSteps/components/BrainKnowledgeStep/hooks/useBrainKnowledgeStep.ts delete mode 100644 frontend/lib/components/AddBrainModal/components/AddBrainSteps/components/BrainParamsStep/BrainParamsStep.tsx delete mode 100644 frontend/lib/components/AddBrainModal/components/AddBrainSteps/components/BrainParamsStep/components/PublicAccessConfirmationModal.tsx delete mode 100644 frontend/lib/components/AddBrainModal/components/AddBrainSteps/components/BrainParamsStep/hooks/useBrainParamsStep.ts delete mode 100644 frontend/lib/components/AddBrainModal/components/AddBrainSteps/components/BrainParamsStep/hooks/useBrainStatusOptions.ts delete mode 100644 frontend/lib/components/AddBrainModal/components/AddBrainSteps/components/BrainParamsStep/hooks/usePublicAccessConfirmationModal.ts delete mode 100644 frontend/lib/components/AddBrainModal/components/AddBrainSteps/components/BrainTypeSelectionStep/BrainTypeSelectionStep.tsx delete mode 100644 frontend/lib/components/AddBrainModal/components/AddBrainSteps/components/BrainTypeSelectionStep/hooks/useBrainTypeSelectionStep.ts delete mode 100644 frontend/lib/components/AddBrainModal/components/AddBrainSteps/components/BrainTypeSelectionStep/hooks/useKnowledgeSourceLabel.ts delete mode 100644 frontend/lib/components/AddBrainModal/components/AddBrainSteps/components/Stepper/Stepper.tsx delete mode 100644 frontend/lib/components/AddBrainModal/components/AddBrainSteps/components/Stepper/components/Step.tsx delete mode 100644 frontend/lib/components/AddBrainModal/components/AddBrainSteps/index.ts delete mode 100644 frontend/lib/components/AddBrainModal/components/AddBrainSteps/types.ts create mode 100644 frontend/lib/components/AddBrainModal/components/BrainKnowledgeStep/BrainKnowledgeStep.module.scss create mode 100644 frontend/lib/components/AddBrainModal/components/BrainKnowledgeStep/BrainKnowledgeStep.tsx rename frontend/lib/components/AddBrainModal/components/{AddBrainSteps/components => }/BrainKnowledgeStep/components/CompositeBrainConnections/Components/ConnectableBrain/ConnectableBrain.tsx (100%) rename frontend/lib/components/AddBrainModal/components/{AddBrainSteps/components => }/BrainKnowledgeStep/components/CompositeBrainConnections/Components/ConnectableBrain/hooks/useConnectableBrain.ts (98%) rename frontend/lib/components/AddBrainModal/components/{AddBrainSteps/components => }/BrainKnowledgeStep/components/CompositeBrainConnections/CompositeBrainConnections.tsx (100%) rename frontend/lib/components/AddBrainModal/components/{AddBrainSteps/components => }/BrainKnowledgeStep/hooks/useBrainCreationApi.ts (88%) create mode 100644 frontend/lib/components/AddBrainModal/components/BrainMainInfosStep/BrainMainInfosStep.module.scss create mode 100644 frontend/lib/components/AddBrainModal/components/BrainMainInfosStep/BrainMainInfosStep.tsx create mode 100644 frontend/lib/components/AddBrainModal/components/BrainTypeSelectionStep/BrainTypeSelection/BrainTypeSelection.module.scss create mode 100644 frontend/lib/components/AddBrainModal/components/BrainTypeSelectionStep/BrainTypeSelection/BrainTypeSelection.tsx create mode 100644 frontend/lib/components/AddBrainModal/components/BrainTypeSelectionStep/BrainTypeSelectionStep.module.scss create mode 100644 frontend/lib/components/AddBrainModal/components/BrainTypeSelectionStep/BrainTypeSelectionStep.tsx create mode 100644 frontend/lib/components/AddBrainModal/components/Stepper/Stepper.module.scss create mode 100644 frontend/lib/components/AddBrainModal/components/Stepper/Stepper.tsx delete mode 100644 frontend/lib/components/AddBrainModal/components/index.ts rename frontend/lib/components/AddBrainModal/{components/AddBrainSteps => }/hooks/useBrainCreationSteps.ts (92%) rename frontend/lib/components/AddBrainModal/{ => types}/types.ts (54%) create mode 100644 frontend/lib/components/ui/TextAreaInput/TextAreaInput.module.scss create mode 100644 frontend/lib/components/ui/TextAreaInput/TextAreaInput.tsx diff --git a/frontend/app/App.tsx b/frontend/app/App.tsx index bad51005b..19b929595 100644 --- a/frontend/app/App.tsx +++ b/frontend/app/App.tsx @@ -5,7 +5,7 @@ import { posthog } from "posthog-js"; import { PostHogProvider } from "posthog-js/react"; import { PropsWithChildren, useEffect } from "react"; -import { BrainCreationProvider } from "@/lib/components/AddBrainModal/components/AddBrainSteps/brainCreation-provider"; +import { BrainCreationProvider } from "@/lib/components/AddBrainModal/brainCreation-provider"; import { Menu } from "@/lib/components/Menu/Menu"; import { useOutsideClickListener } from "@/lib/components/Menu/hooks/useOutsideClickListener"; import SearchModal from "@/lib/components/SearchModal/SearchModal"; diff --git a/frontend/app/chat/[chatId]/components/ActionsBar/components/ChatInput/components/ChatEditor/components/Editor/components/MentionsList/MentionsList.tsx b/frontend/app/chat/[chatId]/components/ActionsBar/components/ChatInput/components/ChatEditor/components/Editor/components/MentionsList/MentionsList.tsx index d15394afa..db77ab007 100644 --- a/frontend/app/chat/[chatId]/components/ActionsBar/components/ChatInput/components/ChatEditor/components/Editor/components/MentionsList/MentionsList.tsx +++ b/frontend/app/chat/[chatId]/components/ActionsBar/components/ChatInput/components/ChatEditor/components/Editor/components/MentionsList/MentionsList.tsx @@ -2,7 +2,7 @@ import { SuggestionKeyDownProps } from "@tiptap/suggestion"; import { forwardRef } from "react"; import { FaAngleDoubleDown } from "react-icons/fa"; -import { useBrainCreationContext } from "@/lib/components/AddBrainModal/components/AddBrainSteps/brainCreation-provider"; +import { useBrainCreationContext } from "@/lib/components/AddBrainModal/brainCreation-provider"; import TextButton from "@/lib/components/ui/TextButton/TextButton"; import { AddNewPromptButton } from "./components/AddNewPromptButton"; diff --git a/frontend/app/chat/[chatId]/components/ActionsBar/components/KnowledgeToFeed/KnowledgeToFeed.module.scss b/frontend/app/chat/[chatId]/components/ActionsBar/components/KnowledgeToFeed/KnowledgeToFeed.module.scss index 7da93fdb2..db6d9ff01 100644 --- a/frontend/app/chat/[chatId]/components/ActionsBar/components/KnowledgeToFeed/KnowledgeToFeed.module.scss +++ b/frontend/app/chat/[chatId]/components/ActionsBar/components/KnowledgeToFeed/KnowledgeToFeed.module.scss @@ -9,6 +9,7 @@ padding-block: Spacings.$spacing05; width: 100%; gap: Spacings.$spacing05; + overflow: hidden; .single_selector_wrapper { width: 30%; @@ -37,6 +38,7 @@ overflow: scroll; flex-direction: column; gap: Spacings.$spacing02; + flex-grow: 1; overflow: scroll; .uploaded_knowledge { @@ -46,6 +48,7 @@ justify-content: space-between; width: 100%; overflow: hidden; + font-size: Typography.$small; .left { display: flex; diff --git a/frontend/app/chat/[chatId]/components/ActionsBar/components/KnowledgeToFeed/KnowledgeToFeed.tsx b/frontend/app/chat/[chatId]/components/ActionsBar/components/KnowledgeToFeed/KnowledgeToFeed.tsx index b3fc9e6db..37477dbd0 100644 --- a/frontend/app/chat/[chatId]/components/ActionsBar/components/KnowledgeToFeed/KnowledgeToFeed.tsx +++ b/frontend/app/chat/[chatId]/components/ActionsBar/components/KnowledgeToFeed/KnowledgeToFeed.tsx @@ -13,7 +13,11 @@ import { FromDocuments } from "./components/FromDocuments/FromDocuments"; import { FromWebsites } from "./components/FromWebsites/FromWebsites"; import { formatMinimalBrainsToSelectComponentInput } from "./utils/formatMinimalBrainsToSelectComponentInput"; -export const KnowledgeToFeed = (): JSX.Element => { +export const KnowledgeToFeed = ({ + hideBrainSelector, +}: { + hideBrainSelector?: boolean; +}): JSX.Element => { const { allBrains, setCurrentBrainId, currentBrain } = useBrainContext(); const [selectedTab, setSelectedTab] = useState("From documents"); const { knowledgeToFeed, removeKnowledgeToFeed } = @@ -46,18 +50,20 @@ export const KnowledgeToFeed = (): JSX.Element => { return (
-
- -
+ {!hideBrainSelector && ( +
+ +
+ )}
{selectedTab === "From documents" && } diff --git a/frontend/app/chat/[chatId]/components/ActionsBar/components/KnowledgeToFeed/components/FromDocuments/FromDocuments.module.scss b/frontend/app/chat/[chatId]/components/ActionsBar/components/KnowledgeToFeed/components/FromDocuments/FromDocuments.module.scss index 9ed85a759..edf3dcce4 100644 --- a/frontend/app/chat/[chatId]/components/ActionsBar/components/KnowledgeToFeed/components/FromDocuments/FromDocuments.module.scss +++ b/frontend/app/chat/[chatId]/components/ActionsBar/components/KnowledgeToFeed/components/FromDocuments/FromDocuments.module.scss @@ -1,5 +1,6 @@ @use "@/styles/Colors.module.scss"; @use "@/styles/Radius.module.scss"; +@use "@/styles/ScreenSizes.module.scss"; @use "@/styles/Spacings.module.scss"; .from_document_wrapper { @@ -24,6 +25,10 @@ display: flex; gap: Spacings.$spacing02; + @media (max-width: ScreenSizes.$small) { + flex-direction: column; + } + .clickable { cursor: pointer; font-weight: bold; diff --git a/frontend/app/chat/[chatId]/page.tsx b/frontend/app/chat/[chatId]/page.tsx index 12c79e4ef..3c7d1ce38 100644 --- a/frontend/app/chat/[chatId]/page.tsx +++ b/frontend/app/chat/[chatId]/page.tsx @@ -4,7 +4,7 @@ import { UUID } from "crypto"; import { useEffect } from "react"; import { AddBrainModal } from "@/lib/components/AddBrainModal"; -import { useBrainCreationContext } from "@/lib/components/AddBrainModal/components/AddBrainSteps/brainCreation-provider"; +import { useBrainCreationContext } from "@/lib/components/AddBrainModal/brainCreation-provider"; import PageHeader from "@/lib/components/PageHeader/PageHeader"; import { UploadDocumentModal } from "@/lib/components/UploadDocumentModal/UploadDocumentModal"; import { useChatContext } from "@/lib/context"; diff --git a/frontend/app/search/page.tsx b/frontend/app/search/page.tsx index c93694f9b..e3439ab70 100644 --- a/frontend/app/search/page.tsx +++ b/frontend/app/search/page.tsx @@ -4,7 +4,7 @@ import { useEffect } from "react"; import { QuivrLogo } from "@/lib/assets/QuivrLogo"; import { AddBrainModal } from "@/lib/components/AddBrainModal"; -import { useBrainCreationContext } from "@/lib/components/AddBrainModal/components/AddBrainSteps/brainCreation-provider"; +import { useBrainCreationContext } from "@/lib/components/AddBrainModal/brainCreation-provider"; import PageHeader from "@/lib/components/PageHeader/PageHeader"; import { UploadDocumentModal } from "@/lib/components/UploadDocumentModal/UploadDocumentModal"; import { SearchBar } from "@/lib/components/ui/SearchBar/SearchBar"; diff --git a/frontend/app/studio/page.tsx b/frontend/app/studio/page.tsx index 3b8b377b2..12aed219d 100644 --- a/frontend/app/studio/page.tsx +++ b/frontend/app/studio/page.tsx @@ -3,7 +3,7 @@ import { useState } from "react"; import { AddBrainModal } from "@/lib/components/AddBrainModal"; -import { useBrainCreationContext } from "@/lib/components/AddBrainModal/components/AddBrainSteps/brainCreation-provider"; +import { useBrainCreationContext } from "@/lib/components/AddBrainModal/brainCreation-provider"; import PageHeader from "@/lib/components/PageHeader/PageHeader"; import { UploadDocumentModal } from "@/lib/components/UploadDocumentModal/UploadDocumentModal"; import { Tabs } from "@/lib/components/ui/Tabs/Tabs"; diff --git a/frontend/lib/components/AddBrainModal/AddBrainModal.module.scss b/frontend/lib/components/AddBrainModal/AddBrainModal.module.scss new file mode 100644 index 000000000..4fabc95fd --- /dev/null +++ b/frontend/lib/components/AddBrainModal/AddBrainModal.module.scss @@ -0,0 +1,21 @@ +@use "@/styles/Spacings.module.scss"; + +.add_brain_modal_container { + display: flex; + padding-block: Spacings.$spacing05; + flex-direction: column; + width: 100%; + height: 100%; + overflow: hidden; + gap: Spacings.$spacing08; + + .stepper_container { + width: 100%; + padding-inline: Spacings.$spacing08; + } + + .content_wrapper { + flex-grow: 1; + overflow: scroll; + } +} diff --git a/frontend/lib/components/AddBrainModal/AddBrainModal.tsx b/frontend/lib/components/AddBrainModal/AddBrainModal.tsx index 70869b8a8..183321e83 100644 --- a/frontend/lib/components/AddBrainModal/AddBrainModal.tsx +++ b/frontend/lib/components/AddBrainModal/AddBrainModal.tsx @@ -1,11 +1,23 @@ import { FormProvider, useForm } from "react-hook-form"; +import { useTranslation } from "react-i18next"; +import { Modal } from "@/lib/components/ui/Modal/Modal"; import { addBrainDefaultValues } from "@/lib/config/defaultBrainConfig"; -import { AddBrainSteps } from "./components/AddBrainSteps/AddBrainSteps"; -import { CreateBrainProps } from "./types"; +import styles from "./AddBrainModal.module.scss"; +import { useBrainCreationContext } from "./brainCreation-provider"; +import { BrainKnowledgeStep } from "./components/BrainKnowledgeStep/BrainKnowledgeStep"; +import { BrainMainInfosStep } from "./components/BrainMainInfosStep/BrainMainInfosStep"; +import { BrainTypeSelectionStep } from "./components/BrainTypeSelectionStep/BrainTypeSelectionStep"; +import { Stepper } from "./components/Stepper/Stepper"; +import { CreateBrainProps } from "./types/types"; export const AddBrainModal = (): JSX.Element => { + const { t } = useTranslation(["translation", "brain", "config"]); + + const { isBrainCreationModalOpened, setIsBrainCreationModalOpened } = + useBrainCreationContext(); + const defaultValues: CreateBrainProps = { ...addBrainDefaultValues, setDefault: true, @@ -18,7 +30,25 @@ export const AddBrainModal = (): JSX.Element => { return ( - + } + > +
+
+ +
+
+ + + +
+
+
); }; diff --git a/frontend/lib/components/AddBrainModal/components/AddBrainSteps/brainCreation-provider.tsx b/frontend/lib/components/AddBrainModal/brainCreation-provider.tsx similarity index 74% rename from frontend/lib/components/AddBrainModal/components/AddBrainSteps/brainCreation-provider.tsx rename to frontend/lib/components/AddBrainModal/brainCreation-provider.tsx index 92e62d032..d19c2b5e5 100644 --- a/frontend/lib/components/AddBrainModal/components/AddBrainSteps/brainCreation-provider.tsx +++ b/frontend/lib/components/AddBrainModal/brainCreation-provider.tsx @@ -3,6 +3,8 @@ import { createContext, useContext, useState } from "react"; interface BrainCreationContextProps { isBrainCreationModalOpened: boolean; setIsBrainCreationModalOpened: React.Dispatch>; + creating: boolean; + setCreating: React.Dispatch>; } export const BrainCreationContext = createContext< @@ -15,11 +17,17 @@ export const BrainCreationProvider = ({ children: React.ReactNode; }): JSX.Element => { const [isBrainCreationModalOpened, setIsBrainCreationModalOpened] = - useState(false); + useState(false); + const [creating, setCreating] = useState(false); return ( {children} diff --git a/frontend/lib/components/AddBrainModal/components/AddBrainSteps/AddBrainSteps.tsx b/frontend/lib/components/AddBrainModal/components/AddBrainSteps/AddBrainSteps.tsx deleted file mode 100644 index 24ed99b4f..000000000 --- a/frontend/lib/components/AddBrainModal/components/AddBrainSteps/AddBrainSteps.tsx +++ /dev/null @@ -1,44 +0,0 @@ -import { useTranslation } from "react-i18next"; - -import { Modal } from "@/lib/components/ui/Modal/Modal"; - -import { useBrainCreationContext } from "./brainCreation-provider"; -import { BrainKnowledgeStep } from "./components/BrainKnowledgeStep/BrainKnowledgeStep"; -import { BrainParamsStep } from "./components/BrainParamsStep/BrainParamsStep"; -import { BrainTypeSelectionStep } from "./components/BrainTypeSelectionStep/BrainTypeSelectionStep"; -import { Stepper } from "./components/Stepper/Stepper"; - -export const AddBrainSteps = (): JSX.Element => { - const { t } = useTranslation(["translation", "brain", "config"]); - - const { isBrainCreationModalOpened, setIsBrainCreationModalOpened } = - useBrainCreationContext(); - - return ( - } - > -
{ - e.preventDefault(); - }} - className="my-10 flex flex-col items-center gap-2 justify-center" - > - - setIsBrainCreationModalOpened(false)} - /> - setIsBrainCreationModalOpened(false)} - /> - setIsBrainCreationModalOpened(false)} - /> - -
- ); -}; diff --git a/frontend/lib/components/AddBrainModal/components/AddBrainSteps/components/BrainKnowledgeStep/BrainKnowledgeStep.tsx b/frontend/lib/components/AddBrainModal/components/AddBrainSteps/components/BrainKnowledgeStep/BrainKnowledgeStep.tsx deleted file mode 100644 index 3ab1c161a..000000000 --- a/frontend/lib/components/AddBrainModal/components/AddBrainSteps/components/BrainKnowledgeStep/BrainKnowledgeStep.tsx +++ /dev/null @@ -1,80 +0,0 @@ -import { Fragment } from "react"; -import { useTranslation } from "react-i18next"; -import { FaArrowLeft } from "react-icons/fa"; - -import { ApiRequestDefinition } from "@/lib/components/ApiRequestDefinition"; -import Button from "@/lib/components/ui/Button"; -import { BrainType } from "@/lib/types/BrainConfig"; - -import { CompositeBrainConnections } from "./components/CompositeBrainConnections/CompositeBrainConnections"; -import { KnowledgeToFeedInput } from "./components/KnowledgeToFeedInput"; -import { useBrainCreationHandler } from "./hooks/useBrainCreationHandler"; -import { useBrainKnowledgeStep } from "./hooks/useBrainKnowledgeStep"; - -import { useBrainCreationSteps } from "../../hooks/useBrainCreationSteps"; - -type BrainKnowledgeStepProps = { - onCancelBrainCreation: () => void; -}; - -export const BrainKnowledgeStep = ({ - onCancelBrainCreation, -}: BrainKnowledgeStepProps): JSX.Element => { - const { brainType, isSubmitButtonDisabled } = useBrainKnowledgeStep(); - const { t } = useTranslation(["translation"]); - const { goToPreviousStep, currentStep } = useBrainCreationSteps(); - const { handleCreateBrain, isBrainCreationPending } = useBrainCreationHandler( - { - closeBrainCreationModal: onCancelBrainCreation, - } - ); - - const brainTypeToKnowledgeComponent: Record = { - doc: , - api: , - composite: , - }; - - if (currentStep !== "KNOWLEDGE" || brainType === undefined) { - return ; - } - - return ( - <> - {brainTypeToKnowledgeComponent[brainType]} -
- -
- - - -
-
- - ); -}; diff --git a/frontend/lib/components/AddBrainModal/components/AddBrainSteps/components/BrainKnowledgeStep/components/KnowledgeToFeedInput.tsx b/frontend/lib/components/AddBrainModal/components/AddBrainSteps/components/BrainKnowledgeStep/components/KnowledgeToFeedInput.tsx deleted file mode 100644 index 0c86360b1..000000000 --- a/frontend/lib/components/AddBrainModal/components/AddBrainSteps/components/BrainKnowledgeStep/components/KnowledgeToFeedInput.tsx +++ /dev/null @@ -1,26 +0,0 @@ -import { useTranslation } from "react-i18next"; - -import { - Crawler, - FeedItems, - FileUploader, -} from "@/lib/components/KnowledgeToFeedInput/components"; - -export const KnowledgeToFeedInput = (): JSX.Element => { - const { t } = useTranslation(["translation", "upload"]); - - return ( -
-
- - - {`${t("and", { ns: "translation" })} / ${t("or", { - ns: "translation", - })}`} - - -
- -
- ); -}; diff --git a/frontend/lib/components/AddBrainModal/components/AddBrainSteps/components/BrainKnowledgeStep/hooks/useBrainCreationHandler.ts b/frontend/lib/components/AddBrainModal/components/AddBrainSteps/components/BrainKnowledgeStep/hooks/useBrainCreationHandler.ts deleted file mode 100644 index bb75bc272..000000000 --- a/frontend/lib/components/AddBrainModal/components/AddBrainSteps/components/BrainKnowledgeStep/hooks/useBrainCreationHandler.ts +++ /dev/null @@ -1,52 +0,0 @@ -import { useFormContext } from "react-hook-form"; -import { useTranslation } from "react-i18next"; - -import { CreateBrainProps } from "@/lib/components/AddBrainModal/types"; -import { useToast } from "@/lib/hooks"; - -import { useBrainCreationApi } from "./useBrainCreationApi"; - -type UseBrainCreationHandler = { - closeBrainCreationModal: () => void; -}; - -// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types -export const useBrainCreationHandler = ({ - closeBrainCreationModal, -}: UseBrainCreationHandler) => { - const { getValues } = useFormContext(); - const { publish } = useToast(); - const { t } = useTranslation(["brain", "config"]); - - const { isBrainCreationPending, createBrain } = useBrainCreationApi({ - closeBrainCreationModal, - }); - - const handleCreateBrain = () => { - const { name, description } = getValues(); - - if (name.trim() === "" || isBrainCreationPending) { - publish({ - variant: "danger", - text: t("nameRequired", { ns: "config" }), - }); - - return; - } - - if (description.trim() === "") { - publish({ - variant: "danger", - text: t("descriptionRequired", { ns: "config" }), - }); - - return; - } - createBrain(); - }; - - return { - handleCreateBrain, - isBrainCreationPending, - }; -}; diff --git a/frontend/lib/components/AddBrainModal/components/AddBrainSteps/components/BrainKnowledgeStep/hooks/useBrainKnowledgeStep.ts b/frontend/lib/components/AddBrainModal/components/AddBrainSteps/components/BrainKnowledgeStep/hooks/useBrainKnowledgeStep.ts deleted file mode 100644 index be2418cde..000000000 --- a/frontend/lib/components/AddBrainModal/components/AddBrainSteps/components/BrainKnowledgeStep/hooks/useBrainKnowledgeStep.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { useFormContext } from "react-hook-form"; - -import { CreateBrainProps } from "@/lib/components/AddBrainModal/types"; - -// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types -export const useBrainKnowledgeStep = () => { - const { watch } = useFormContext(); - const brainType = watch("brain_type"); - const url = watch("brain_definition.url"); - const compositeBrainConnections = watch("connected_brains_ids") ?? []; - const isApiBrain = brainType === "api"; - const isCompositeBrain = brainType === "composite"; - - const isApiBrainDefinitionsFilled = url !== ""; - - const isSubmitButtonDisabled = - (isCompositeBrain && compositeBrainConnections.length === 0) || - (isApiBrain && !isApiBrainDefinitionsFilled); - - return { - brainType, - isSubmitButtonDisabled, - }; -}; diff --git a/frontend/lib/components/AddBrainModal/components/AddBrainSteps/components/BrainParamsStep/BrainParamsStep.tsx b/frontend/lib/components/AddBrainModal/components/AddBrainSteps/components/BrainParamsStep/BrainParamsStep.tsx deleted file mode 100644 index 601dd9fb9..000000000 --- a/frontend/lib/components/AddBrainModal/components/AddBrainSteps/components/BrainParamsStep/BrainParamsStep.tsx +++ /dev/null @@ -1,96 +0,0 @@ -import { Fragment } from "react"; -import { useTranslation } from "react-i18next"; -import { FaArrowLeft, FaArrowRight } from "react-icons/fa"; - -import Button from "@/lib/components/ui/Button"; -import Field from "@/lib/components/ui/Field"; -import { TextArea } from "@/lib/components/ui/TextArea"; - -import { PublicAccessConfirmationModal } from "./components/PublicAccessConfirmationModal"; -import { useBrainParamsStep } from "./hooks/useBrainParamsStep"; -import { usePublicAccessConfirmationModal } from "./hooks/usePublicAccessConfirmationModal"; - -import { useBrainCreationSteps } from "../../hooks/useBrainCreationSteps"; -import { useBrainTypeSelectionStep } from "../BrainTypeSelectionStep/hooks/useBrainTypeSelectionStep"; - -type BrainParamsStepProps = { - onCancelBrainCreation: () => void; -}; - -export const BrainParamsStep = ({ - onCancelBrainCreation, -}: BrainParamsStepProps): JSX.Element => { - const { goToNextStep, goToPreviousStep, currentStep } = - useBrainCreationSteps(); - const { register } = useBrainTypeSelectionStep(); - const { t } = useTranslation(["translation", "brain", "config"]); - const { isNextButtonDisabled } = useBrainParamsStep(); - const { - isPublicAccessConfirmationModalOpened, - onCancelPublicAccess, - onConfirmPublicAccess, - } = usePublicAccessConfirmationModal(); - - if (currentStep !== "BRAIN_PARAMS") { - return ; - } - - return ( - <> - -