From 6cc114100fd5b5bb5bf102af4d5e7d26fc5f8019 Mon Sep 17 00:00:00 2001 From: naman-bruno Date: Mon, 15 Dec 2025 18:17:11 +0530 Subject: [PATCH] fix (#6409) --- .../Sidebar/ImportCollectionLocation/index.js | 14 ++++++-- .../Sections/CollectionsSection/index.js | 13 ++----- .../components/Sidebar/SidebarHeader/index.js | 13 ++----- .../WorkspaceHome/WorkspaceOverview/index.js | 34 +++++++++++++++---- 4 files changed, 44 insertions(+), 30 deletions(-) diff --git a/packages/bruno-app/src/components/Sidebar/ImportCollectionLocation/index.js b/packages/bruno-app/src/components/Sidebar/ImportCollectionLocation/index.js index 581ff9847..3d0501aad 100644 --- a/packages/bruno-app/src/components/Sidebar/ImportCollectionLocation/index.js +++ b/packages/bruno-app/src/components/Sidebar/ImportCollectionLocation/index.js @@ -1,7 +1,8 @@ import React, { useRef, useEffect, useState, forwardRef } from 'react'; -import { useDispatch } from 'react-redux'; +import { useDispatch, useSelector } from 'react-redux'; import { useFormik } from 'formik'; import * as Yup from 'yup'; +import get from 'lodash/get'; import { IconCaretDown } from '@tabler/icons'; import { browseDirectory } from 'providers/ReduxStore/slices/collections/actions'; import { postmanToBruno } from 'utils/importers/postman-collection'; @@ -88,12 +89,21 @@ const ImportCollectionLocation = ({ onClose, handleSubmit, rawData, format }) => const dropdownTippyRef = useRef(); const isOpenApi = format === 'openapi'; + const { workspaces, activeWorkspaceUid } = useSelector((state) => state.workspaces); + const preferences = useSelector((state) => state.app.preferences); + const activeWorkspace = workspaces.find((w) => w.uid === activeWorkspaceUid); + const isDefaultWorkspace = !activeWorkspace || activeWorkspace.type === 'default'; + + const defaultLocation = isDefaultWorkspace + ? get(preferences, 'general.defaultCollectionLocation', '') + : (activeWorkspace?.pathname ? `${activeWorkspace.pathname}/collections` : ''); + const collectionName = getCollectionName(format, rawData); const formik = useFormik({ enableReinitialize: true, initialValues: { - collectionLocation: '' + collectionLocation: defaultLocation }, validationSchema: Yup.object({ collectionLocation: Yup.string() diff --git a/packages/bruno-app/src/components/Sidebar/Sections/CollectionsSection/index.js b/packages/bruno-app/src/components/Sidebar/Sections/CollectionsSection/index.js index e28414959..dd52e1662 100644 --- a/packages/bruno-app/src/components/Sidebar/Sections/CollectionsSection/index.js +++ b/packages/bruno-app/src/components/Sidebar/Sections/CollectionsSection/index.js @@ -15,7 +15,6 @@ import { import { importCollection, openCollection } from 'providers/ReduxStore/slices/collections/actions'; import { sortCollections } from 'providers/ReduxStore/slices/collections/index'; -import { importCollectionInWorkspace } from 'providers/ReduxStore/slices/workspaces/actions'; import MenuDropdown from 'ui/MenuDropdown'; import ActionIcon from 'ui/ActionIcon'; @@ -45,16 +44,8 @@ const CollectionsSection = () => { const handleImportCollection = ({ rawData, type }) => { setImportCollectionModalOpen(false); - - if (activeWorkspace && activeWorkspace.type !== 'default') { - dispatch(importCollectionInWorkspace(rawData, activeWorkspace.uid, undefined, type)) - .catch((err) => { - toast.error('An error occurred while importing the collection'); - }); - } else { - setImportData({ rawData, type }); - setImportCollectionLocationModalOpen(true); - } + setImportData({ rawData, type }); + setImportCollectionLocationModalOpen(true); }; const handleImportCollectionLocation = (convertedCollection, collectionLocation) => { diff --git a/packages/bruno-app/src/components/Sidebar/SidebarHeader/index.js b/packages/bruno-app/src/components/Sidebar/SidebarHeader/index.js index b53aff940..e0eeeb3e0 100644 --- a/packages/bruno-app/src/components/Sidebar/SidebarHeader/index.js +++ b/packages/bruno-app/src/components/Sidebar/SidebarHeader/index.js @@ -19,7 +19,6 @@ import { useDispatch, useSelector } from 'react-redux'; import { importCollection, openCollection } from 'providers/ReduxStore/slices/collections/actions'; import { sortCollections } from 'providers/ReduxStore/slices/collections/index'; -import { importCollectionInWorkspace } from 'providers/ReduxStore/slices/workspaces/actions'; import { openApiSpec } from 'providers/ReduxStore/slices/apiSpec'; import MenuDropdown from 'ui/MenuDropdown'; @@ -51,16 +50,8 @@ const SidebarHeader = ({ setShowSearch }) => { const handleImportCollection = ({ rawData, type }) => { setImportCollectionModalOpen(false); - - if (activeWorkspace && activeWorkspace.type !== 'default') { - dispatch(importCollectionInWorkspace(rawData, activeWorkspace.uid, undefined, type)) - .catch((err) => { - toast.error('An error occurred while importing the collection'); - }); - } else { - setImportData({ rawData, type }); - setImportCollectionLocationModalOpen(true); - } + setImportData({ rawData, type }); + setImportCollectionLocationModalOpen(true); }; const handleImportCollectionLocation = (convertedCollection, collectionLocation) => { diff --git a/packages/bruno-app/src/components/WorkspaceHome/WorkspaceOverview/index.js b/packages/bruno-app/src/components/WorkspaceHome/WorkspaceOverview/index.js index 4105157b4..4b1cea5cf 100644 --- a/packages/bruno-app/src/components/WorkspaceHome/WorkspaceOverview/index.js +++ b/packages/bruno-app/src/components/WorkspaceHome/WorkspaceOverview/index.js @@ -1,11 +1,11 @@ import React, { useState } from 'react'; import { useSelector, useDispatch } from 'react-redux'; import { IconPlus, IconFolder, IconFileImport } from '@tabler/icons'; -import { importCollectionInWorkspace } from 'providers/ReduxStore/slices/workspaces/actions'; -import { openCollection } from 'providers/ReduxStore/slices/collections/actions'; +import { importCollection, openCollection } from 'providers/ReduxStore/slices/collections/actions'; import toast from 'react-hot-toast'; import CreateCollection from 'components/Sidebar/CreateCollection'; import ImportCollection from 'components/Sidebar/ImportCollection'; +import ImportCollectionLocation from 'components/Sidebar/ImportCollectionLocation'; import CollectionsList from './CollectionsList'; import WorkspaceDocs from '../WorkspaceDocs'; import StyledWrapper from './StyledWrapper'; @@ -16,6 +16,8 @@ const WorkspaceOverview = ({ workspace }) => { const [createCollectionModalOpen, setCreateCollectionModalOpen] = useState(false); const [importCollectionModalOpen, setImportCollectionModalOpen] = useState(false); + const [importCollectionLocationModalOpen, setImportCollectionLocationModalOpen] = useState(false); + const [importData, setImportData] = useState(null); const workspaceCollectionsCount = workspace?.collections?.length || 0; @@ -50,10 +52,21 @@ const WorkspaceOverview = ({ workspace }) => { const handleImportCollectionSubmit = ({ rawData, type }) => { setImportCollectionModalOpen(false); - dispatch(importCollectionInWorkspace(rawData, workspace.uid, undefined, type)).catch((err) => { - console.error(err); - toast.error('An error occurred while importing the collection'); - }); + setImportData({ rawData, type }); + setImportCollectionLocationModalOpen(true); + }; + + const handleImportCollectionLocation = (convertedCollection, collectionLocation) => { + dispatch(importCollection(convertedCollection, collectionLocation)) + .then(() => { + setImportCollectionLocationModalOpen(false); + setImportData(null); + toast.success('Collection imported successfully'); + }) + .catch((err) => { + console.error(err); + toast.error(err.message); + }); }; return ( @@ -69,6 +82,15 @@ const WorkspaceOverview = ({ workspace }) => { /> )} + {importCollectionLocationModalOpen && importData && ( + setImportCollectionLocationModalOpen(false)} + handleSubmit={handleImportCollectionLocation} + /> + )} +