From 3d3e6b7306e151b60976121797b8da9c052cf029 Mon Sep 17 00:00:00 2001 From: Antoine Dewez <44063631+Zewed@users.noreply.github.com> Date: Sun, 9 Jun 2024 18:43:18 +0200 Subject: [PATCH] feat(frontend): sharepoint and gdrive integration (#2643) # 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): --- .../sync/controller/azure_sync_routes.py | 7 +- .../sync/controller/google_sync_routes.py | 7 +- .../sync/controller/successfull_connection.py | 53 ++++ frontend/.eslintrc.js | 2 +- frontend/app/App.tsx | 14 +- .../KnowledgeToFeed.module.scss | 41 +-- .../KnowledgeToFeed/KnowledgeToFeed.tsx | 115 ++++---- .../FileLine/FileLine.module.scss | 0 .../FromConnections/FileLine/FileLine.tsx | 22 ++ .../FolderLine/FolderLine.module.scss | 0 .../FromConnections/FolderLine/FolderLine.tsx | 22 ++ .../FromConnections.module.scss | 36 +++ .../FromConnections/FromConnections.tsx | 118 ++++++++ .../FromConnection-provider.tsx | 57 ++++ .../hooks/useFromConnectionContext.tsx | 17 ++ .../SyncElementLine.module.scss | 28 ++ .../SyncElementLine/SyncElementLine.tsx | 100 +++++++ .../FromDocuments/FromDocuments.module.scss | 32 ++- .../FromDocuments/FromDocuments.tsx | 14 +- .../hooks/useFeedBrainInChat.ts | 4 +- frontend/app/globals.css | 4 +- .../Connections/Connections.module.scss} | 13 +- .../components/Connections/Connections.tsx | 12 + .../components/Settings/Settings.module.scss | 6 + .../app/user/components/Settings/Settings.tsx | 3 + frontend/app/user/page.module.scss | 15 +- frontend/app/user/page.tsx | 24 +- .../lib/api/auth/__tests__/useAuthApi.test.ts | 31 --- .../chat/__tests__/useChatApi.http.test.ts | 28 -- .../lib/api/chat/__tests__/useChatApi.test.ts | 154 ----------- .../__tests__/useNotificationApi.test.ts | 28 -- frontend/lib/api/sync/sync.ts | 110 ++++++++ frontend/lib/api/sync/types.ts | 53 ++++ frontend/lib/api/sync/useSync.ts | 54 ++++ .../AddBrainModal/AddBrainModal.module.scss | 7 +- .../AddBrainModal/AddBrainModal.tsx | 18 +- .../BrainMainInfosStep.module.scss | 15 +- .../BrainMainInfosStep/BrainMainInfosStep.tsx | 17 +- .../BrainRecapCard/BrainRecapCard.module.scss | 24 ++ .../BrainRecapCard/BrainRecapCard.tsx | 21 ++ .../BrainRecapStep/BrainRecapStep.module.scss | 76 ++++++ .../BrainRecapStep/BrainRecapStep.tsx | 135 ++++++++++ .../BrainCatalogue/BrainCatalogue.tsx | 61 ----- .../BrainTypeSelectionStep.module.scss | 42 --- .../BrainTypeSelectionStep.tsx | 43 --- .../CreateBrainStep/CreateBrainStep.tsx | 170 ------------ .../FeedBrainStep.module.scss} | 13 +- .../FeedBrainStep/FeedBrainStep.tsx | 113 ++++++++ .../hooks/useBrainCreationApi.ts | 10 + .../components/Stepper/Stepper.module.scss | 8 +- .../ConnectionCards.module.scss | 13 + .../ConnectionCards/ConnectionCards.tsx | 35 +++ .../ConnectionButton.module.scss | 26 ++ .../ConnectionButton/ConnectionButton.tsx | 36 +++ .../ConnectionLine/ConnectionLine.module.scss | 25 ++ .../ConnectionLine/ConnectionLine.tsx | 42 +++ .../ConnectionSection.module.scss | 84 ++++++ .../ConnectionSection/ConnectionSection.tsx | 255 ++++++++++++++++++ .../lib/components/PageHeader/PageHeader.tsx | 9 +- .../UploadDocumentModal.module.scss | 8 +- .../UploadDocumentModal.tsx | 89 +++++- .../UploadDocumentModal/hooks/useFeedBrain.ts | 7 +- .../hooks/useFeedBrainHandler.ts | 29 ++ .../ui/Checkbox/Checkbox.module.scss | 13 + .../lib/components/ui/Checkbox/Checkbox.tsx | 36 ++- .../ConnectionIcon/ConnectionIcon.module.scss | 18 ++ .../ui/ConnectionIcon/ConnectionIcon.tsx | 22 ++ .../lib/components/ui/Icon/Icon.module.scss | 7 + .../lib/components/ui/Modal/Modal.module.scss | 5 +- .../ui/QuivrButton/QuivrButton.module.scss | 7 + .../components/ui/QuivrButton/QuivrButton.tsx | 43 +-- .../ui/SwitchButton/SwitchButton.module.scss | 38 +++ .../ui/SwitchButton/SwitchButton.tsx | 31 +++ .../lib/components/ui/Tabs/Tabs.module.scss | 19 ++ frontend/lib/components/ui/Tabs/Tabs.tsx | 7 +- .../ui/TextAreaInput/TextAreaInput.tsx | 2 +- .../ui/TextButton/TextButton.module.scss | 6 + .../components/ui/TextButton/TextButton.tsx | 17 +- .../hooks/useKnowledgeToFeedContext.tsx | 11 +- .../lib/helpers/handleConnectionButtons.ts | 182 +++++++++++++ frontend/lib/helpers/iconList.ts | 16 +- frontend/lib/types/Icons.ts | 2 +- frontend/lib/types/QuivrButton.ts | 1 + frontend/lib/types/Tab.ts | 1 + frontend/styles/_IconSizes.module.scss | 1 + frontend/styles/_Typography.module.scss | 4 +- 86 files changed, 2369 insertions(+), 775 deletions(-) create mode 100644 backend/modules/sync/controller/successfull_connection.py create mode 100644 frontend/app/chat/[chatId]/components/ActionsBar/components/KnowledgeToFeed/components/FromConnections/FileLine/FileLine.module.scss create mode 100644 frontend/app/chat/[chatId]/components/ActionsBar/components/KnowledgeToFeed/components/FromConnections/FileLine/FileLine.tsx create mode 100644 frontend/app/chat/[chatId]/components/ActionsBar/components/KnowledgeToFeed/components/FromConnections/FolderLine/FolderLine.module.scss create mode 100644 frontend/app/chat/[chatId]/components/ActionsBar/components/KnowledgeToFeed/components/FromConnections/FolderLine/FolderLine.tsx create mode 100644 frontend/app/chat/[chatId]/components/ActionsBar/components/KnowledgeToFeed/components/FromConnections/FromConnections.module.scss create mode 100644 frontend/app/chat/[chatId]/components/ActionsBar/components/KnowledgeToFeed/components/FromConnections/FromConnections.tsx create mode 100644 frontend/app/chat/[chatId]/components/ActionsBar/components/KnowledgeToFeed/components/FromConnections/FromConnectionsProvider/FromConnection-provider.tsx create mode 100644 frontend/app/chat/[chatId]/components/ActionsBar/components/KnowledgeToFeed/components/FromConnections/FromConnectionsProvider/hooks/useFromConnectionContext.tsx create mode 100644 frontend/app/chat/[chatId]/components/ActionsBar/components/KnowledgeToFeed/components/FromConnections/SyncElementLine/SyncElementLine.module.scss create mode 100644 frontend/app/chat/[chatId]/components/ActionsBar/components/KnowledgeToFeed/components/FromConnections/SyncElementLine/SyncElementLine.tsx rename frontend/{lib/components/AddBrainModal/components/BrainTypeSelectionStep/BrainCatalogue/BrainCatalogue.module.scss => app/user/components/Connections/Connections.module.scss} (62%) create mode 100644 frontend/app/user/components/Connections/Connections.tsx delete mode 100644 frontend/lib/api/auth/__tests__/useAuthApi.test.ts delete mode 100644 frontend/lib/api/chat/__tests__/useChatApi.http.test.ts delete mode 100644 frontend/lib/api/chat/__tests__/useChatApi.test.ts delete mode 100644 frontend/lib/api/notification/__tests__/useNotificationApi.test.ts create mode 100644 frontend/lib/api/sync/sync.ts create mode 100644 frontend/lib/api/sync/types.ts create mode 100644 frontend/lib/api/sync/useSync.ts create mode 100644 frontend/lib/components/AddBrainModal/components/BrainRecapStep/BrainRecapCard/BrainRecapCard.module.scss create mode 100644 frontend/lib/components/AddBrainModal/components/BrainRecapStep/BrainRecapCard/BrainRecapCard.tsx create mode 100644 frontend/lib/components/AddBrainModal/components/BrainRecapStep/BrainRecapStep.module.scss create mode 100644 frontend/lib/components/AddBrainModal/components/BrainRecapStep/BrainRecapStep.tsx delete mode 100644 frontend/lib/components/AddBrainModal/components/BrainTypeSelectionStep/BrainCatalogue/BrainCatalogue.tsx delete mode 100644 frontend/lib/components/AddBrainModal/components/BrainTypeSelectionStep/BrainTypeSelectionStep.module.scss delete mode 100644 frontend/lib/components/AddBrainModal/components/BrainTypeSelectionStep/BrainTypeSelectionStep.tsx delete mode 100644 frontend/lib/components/AddBrainModal/components/CreateBrainStep/CreateBrainStep.tsx rename frontend/lib/components/AddBrainModal/components/{CreateBrainStep/CreateBrainStep.module.scss => FeedBrainStep/FeedBrainStep.module.scss} (85%) create mode 100644 frontend/lib/components/AddBrainModal/components/FeedBrainStep/FeedBrainStep.tsx rename frontend/lib/components/AddBrainModal/components/{CreateBrainStep => FeedBrainStep}/hooks/useBrainCreationApi.ts (88%) create mode 100644 frontend/lib/components/ConnectionCards/ConnectionCards.module.scss create mode 100644 frontend/lib/components/ConnectionCards/ConnectionCards.tsx create mode 100644 frontend/lib/components/ConnectionCards/ConnectionSection/ConnectionButton/ConnectionButton.module.scss create mode 100644 frontend/lib/components/ConnectionCards/ConnectionSection/ConnectionButton/ConnectionButton.tsx create mode 100644 frontend/lib/components/ConnectionCards/ConnectionSection/ConnectionLine/ConnectionLine.module.scss create mode 100644 frontend/lib/components/ConnectionCards/ConnectionSection/ConnectionLine/ConnectionLine.tsx create mode 100644 frontend/lib/components/ConnectionCards/ConnectionSection/ConnectionSection.module.scss create mode 100644 frontend/lib/components/ConnectionCards/ConnectionSection/ConnectionSection.tsx create mode 100644 frontend/lib/components/ui/ConnectionIcon/ConnectionIcon.module.scss create mode 100644 frontend/lib/components/ui/ConnectionIcon/ConnectionIcon.tsx create mode 100644 frontend/lib/components/ui/SwitchButton/SwitchButton.module.scss create mode 100644 frontend/lib/components/ui/SwitchButton/SwitchButton.tsx create mode 100644 frontend/lib/helpers/handleConnectionButtons.ts diff --git a/backend/modules/sync/controller/azure_sync_routes.py b/backend/modules/sync/controller/azure_sync_routes.py index e53205e44..83bdd3ad6 100644 --- a/backend/modules/sync/controller/azure_sync_routes.py +++ b/backend/modules/sync/controller/azure_sync_routes.py @@ -8,6 +8,9 @@ from modules.sync.dto.inputs import SyncsUserInput, SyncUserUpdateInput from modules.sync.service.sync_service import SyncService, SyncUserService from modules.user.entity.user_identity import UserIdentity from msal import PublicClientApplication +from .successfull_connection import successfullConnectionPage +from fastapi.responses import HTMLResponse + # Initialize logger logger = get_logger(__name__) @@ -31,7 +34,7 @@ SCOPE = [ ] -@azure_sync_router.get( +@azure_sync_router.post( "/sync/azure/authorize", dependencies=[Depends(AuthBearer())], tags=["Sync"], @@ -125,4 +128,4 @@ def oauth2callback_azure(request: Request): sync_user_service.update_sync_user(current_user, state_dict, sync_user_input) logger.info(f"Azure sync created successfully for user: {current_user}") - return {"message": "Azure sync created successfully"} + return HTMLResponse(successfullConnectionPage) diff --git a/backend/modules/sync/controller/google_sync_routes.py b/backend/modules/sync/controller/google_sync_routes.py index 86631b7c4..c20b29548 100644 --- a/backend/modules/sync/controller/google_sync_routes.py +++ b/backend/modules/sync/controller/google_sync_routes.py @@ -9,6 +9,9 @@ from middlewares.auth import AuthBearer, get_current_user from modules.sync.dto.inputs import SyncsUserInput, SyncUserUpdateInput from modules.sync.service.sync_service import SyncService, SyncUserService from modules.user.entity.user_identity import UserIdentity +from .successfull_connection import successfullConnectionPage +from fastapi.responses import HTMLResponse + # Set environment variable for OAuthlib os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1" @@ -47,7 +50,7 @@ CLIENT_SECRETS_FILE_CONTENT = { } -@google_sync_router.get( +@google_sync_router.post( "/sync/google/authorize", dependencies=[Depends(AuthBearer())], tags=["Sync"], @@ -138,4 +141,4 @@ def oauth2callback_google(request: Request): ) sync_user_service.update_sync_user(current_user, state_dict, sync_user_input) logger.info(f"Google Drive sync created successfully for user: {current_user}") - return {"message": "Google Drive sync created successfully"} + return HTMLResponse(successfullConnectionPage) diff --git a/backend/modules/sync/controller/successfull_connection.py b/backend/modules/sync/controller/successfull_connection.py new file mode 100644 index 000000000..ffdb877e8 --- /dev/null +++ b/backend/modules/sync/controller/successfull_connection.py @@ -0,0 +1,53 @@ +successfullConnectionPage = """ + + +
+ + + + +