diff --git a/packages/bruno-app/src/components/Sidebar/ImportCollectionLocation/index.js b/packages/bruno-app/src/components/Sidebar/ImportCollectionLocation/index.js index 967c8edce..0e295e055 100644 --- a/packages/bruno-app/src/components/Sidebar/ImportCollectionLocation/index.js +++ b/packages/bruno-app/src/components/Sidebar/ImportCollectionLocation/index.js @@ -92,6 +92,7 @@ const ImportCollectionLocation = ({ onClose, handleSubmit, rawData, format }) => const inputRef = useRef(); const dispatch = useDispatch(); const [groupingType, setGroupingType] = useState('tags'); + const [collectionFormat, setCollectionFormat] = useState('bru'); const dropdownTippyRef = useRef(); const isOpenApi = format === 'openapi'; @@ -119,7 +120,7 @@ const ImportCollectionLocation = ({ onClose, handleSubmit, rawData, format }) => }), onSubmit: async (values) => { const convertedCollection = await convertCollection(format, rawData, groupingType); - handleSubmit(convertedCollection, values.collectionLocation); + handleSubmit(convertedCollection, values.collectionLocation, { format: collectionFormat }); } }); @@ -209,6 +210,31 @@ const ImportCollectionLocation = ({ onClose, handleSubmit, rawData, format }) => Browse + +
+ + +
{isOpenApi && ( 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 ce812931b..2749157aa 100644 --- a/packages/bruno-app/src/components/Sidebar/Sections/CollectionsSection/index.js +++ b/packages/bruno-app/src/components/Sidebar/Sections/CollectionsSection/index.js @@ -58,8 +58,8 @@ const CollectionsSection = () => { setImportCollectionLocationModalOpen(true); }; - const handleImportCollectionLocation = (convertedCollection, collectionLocation) => { - dispatch(importCollection(convertedCollection, collectionLocation)) + const handleImportCollectionLocation = (convertedCollection, collectionLocation, options = {}) => { + dispatch(importCollection(convertedCollection, collectionLocation, options)) .then(() => { setImportCollectionLocationModalOpen(false); setImportData(null); diff --git a/packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js b/packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js index b328009d1..050594686 100644 --- a/packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js +++ b/packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js @@ -2389,7 +2389,7 @@ export const importCollection = (collection, collectionLocation, options = {}) = const state = getState(); const activeWorkspace = state.workspaces.workspaces.find((w) => w.uid === state.workspaces.activeWorkspaceUid); - const collectionPath = await ipcRenderer.invoke('renderer:import-collection', collection, collectionLocation); + const collectionPath = await ipcRenderer.invoke('renderer:import-collection', collection, collectionLocation, options.format || 'bru'); if (activeWorkspace && activeWorkspace.pathname && activeWorkspace.type !== 'default') { const workspaceCollection = { diff --git a/packages/bruno-electron/src/ipc/collection.js b/packages/bruno-electron/src/ipc/collection.js index 768556354..e41ed3ead 100644 --- a/packages/bruno-electron/src/ipc/collection.js +++ b/packages/bruno-electron/src/ipc/collection.js @@ -851,11 +851,22 @@ const registerRendererEventHandlers = (mainWindow, watcher) => { throw new Error(`collection: ${collectionPath} already exists`); } + const getFilenameWithFormat = (item, format) => { + if (item?.filename) { + const ext = path.extname(item.filename); + if (ext === '.bru' || ext === '.yml') { + return item.filename.replace(ext, `.${format}`); + } + return item.filename; + } + return `${item.name}.${format}`; + }; + // Recursive function to parse the collection items and create files/folders const parseCollectionItems = async (items = [], currentPath) => { await Promise.all(items.map(async (item) => { if (['http-request', 'graphql-request', 'grpc-request', 'ws-request'].includes(item.type)) { - let sanitizedFilename = sanitizeName(item?.filename || `${item.name}.${format}`); + let sanitizedFilename = sanitizeName(getFilenameWithFormat(item, format)); const content = await stringifyRequestViaWorker(item, { format }); const filePath = path.join(currentPath, sanitizedFilename); safeWriteFileSync(filePath, content);