From fff3e6d88ac4f2734a71b0007fce83207904c388 Mon Sep 17 00:00:00 2001 From: Akshat Khosya Date: Mon, 11 Dec 2023 15:57:28 +0530 Subject: [PATCH 1/5] clone functionality in collection --- package-lock.json | 84 ++++------ .../Collection/CloneCollection/index.js | 155 ++++++++++++++++++ .../Sidebar/Collections/Collection/index.js | 14 ++ .../ReduxStore/slices/collections/actions.js | 9 + packages/bruno-electron/src/ipc/collection.js | 36 ++++ 5 files changed, 244 insertions(+), 54 deletions(-) create mode 100644 packages/bruno-app/src/components/Sidebar/Collections/Collection/CloneCollection/index.js diff --git a/package-lock.json b/package-lock.json index 1c248735..c3d268c1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14297,6 +14297,7 @@ }, "node_modules/react-is": { "version": "18.2.0", + "dev": true, "license": "MIT" }, "node_modules/react-pdf": { @@ -17670,7 +17671,7 @@ }, "packages/bruno-electron": { "name": "bruno", - "version": "v1.3.0", + "version": "v1.4.0", "dependencies": { "@aws-sdk/credential-providers": "^3.425.0", "@usebruno/js": "0.9.3", @@ -21404,8 +21405,7 @@ } }, "@tabler/icons": { - "version": "1.119.0", - "requires": {} + "version": "1.119.0" }, "@tippyjs/react": { "version": "4.2.6", @@ -21957,8 +21957,7 @@ } }, "@usebruno/schema": { - "version": "file:packages/bruno-schema", - "requires": {} + "version": "file:packages/bruno-schema" }, "@usebruno/testbench": { "version": "file:packages/bruno-testbench", @@ -22102,8 +22101,7 @@ }, "@webpack-cli/configtest": { "version": "1.2.0", - "dev": true, - "requires": {} + "dev": true }, "@webpack-cli/info": { "version": "1.5.0", @@ -22114,8 +22112,7 @@ }, "@webpack-cli/serve": { "version": "1.7.0", - "dev": true, - "requires": {} + "dev": true }, "@xtuc/ieee754": { "version": "1.2.0", @@ -22197,8 +22194,7 @@ }, "ajv-keywords": { "version": "3.5.2", - "dev": true, - "requires": {} + "dev": true }, "amdefine": { "version": "0.0.8" @@ -23147,8 +23143,7 @@ "chai-string": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/chai-string/-/chai-string-1.5.0.tgz", - "integrity": "sha512-sydDC3S3pNAQMYwJrs6dQX0oBQ6KfIPuOZ78n7rocW0eJJlsHPh2t3kwW7xfwYA/1Bf6/arGtSUo16rxR2JFlw==", - "requires": {} + "integrity": "sha512-sydDC3S3pNAQMYwJrs6dQX0oBQ6KfIPuOZ78n7rocW0eJJlsHPh2t3kwW7xfwYA/1Bf6/arGtSUo16rxR2JFlw==" }, "chalk": { "version": "4.1.2", @@ -23583,8 +23578,7 @@ }, "css-declaration-sorter": { "version": "6.3.1", - "dev": true, - "requires": {} + "dev": true }, "css-loader": { "version": "6.7.3", @@ -23703,8 +23697,7 @@ }, "cssnano-utils": { "version": "3.1.0", - "dev": true, - "requires": {} + "dev": true }, "csso": { "version": "4.2.0", @@ -24931,8 +24924,7 @@ } }, "goober": { - "version": "2.1.11", - "requires": {} + "version": "2.1.11" }, "gopd": { "version": "1.0.1", @@ -25326,8 +25318,7 @@ }, "icss-utils": { "version": "5.1.0", - "dev": true, - "requires": {} + "dev": true }, "idb": { "version": "7.1.1" @@ -25927,8 +25918,7 @@ }, "jest-pnp-resolver": { "version": "1.2.3", - "dev": true, - "requires": {} + "dev": true }, "jest-regex-util": { "version": "29.2.0", @@ -26647,8 +26637,7 @@ "merge-refs": { "version": "1.2.2", "resolved": "https://registry.npmjs.org/merge-refs/-/merge-refs-1.2.2.tgz", - "integrity": "sha512-RwcT7GsQR3KbuLw1rRuodq4Nt547BKEBkliZ0qqsrpyNne9bGTFtsFIsIpx82huWhcl3kOlOlH4H0xkPk/DqVw==", - "requires": {} + "integrity": "sha512-RwcT7GsQR3KbuLw1rRuodq4Nt547BKEBkliZ0qqsrpyNne9bGTFtsFIsIpx82huWhcl3kOlOlH4H0xkPk/DqVw==" }, "merge-stream": { "version": "2.0.0", @@ -26658,8 +26647,7 @@ "version": "1.4.1" }, "meros": { - "version": "1.2.1", - "requires": {} + "version": "1.2.1" }, "methods": { "version": "1.1.2" @@ -27536,23 +27524,19 @@ }, "postcss-discard-comments": { "version": "5.1.2", - "dev": true, - "requires": {} + "dev": true }, "postcss-discard-duplicates": { "version": "5.1.0", - "dev": true, - "requires": {} + "dev": true }, "postcss-discard-empty": { "version": "5.1.1", - "dev": true, - "requires": {} + "dev": true }, "postcss-discard-overridden": { "version": "5.1.0", - "dev": true, - "requires": {} + "dev": true }, "postcss-js": { "version": "3.0.3", @@ -27634,8 +27618,7 @@ }, "postcss-modules-extract-imports": { "version": "3.0.0", - "dev": true, - "requires": {} + "dev": true }, "postcss-modules-local-by-default": { "version": "4.0.0", @@ -27668,8 +27651,7 @@ }, "postcss-normalize-charset": { "version": "5.1.0", - "dev": true, - "requires": {} + "dev": true }, "postcss-normalize-display-values": { "version": "5.1.0", @@ -28145,11 +28127,11 @@ } }, "react-inspector": { - "version": "6.0.2", - "requires": {} + "version": "6.0.2" }, "react-is": { - "version": "18.2.0" + "version": "18.2.0", + "dev": true }, "react-pdf": { "version": "7.5.1", @@ -28311,8 +28293,7 @@ } }, "redux-thunk": { - "version": "2.4.2", - "requires": {} + "version": "2.4.2" }, "regenerate": { "version": "1.4.2", @@ -28549,8 +28530,7 @@ }, "rollup-plugin-peer-deps-external": { "version": "2.2.4", - "dev": true, - "requires": {} + "dev": true }, "rollup-plugin-postcss": { "version": "4.0.2", @@ -29108,8 +29088,7 @@ }, "style-loader": { "version": "3.3.1", - "dev": true, - "requires": {} + "dev": true }, "styled-components": { "version": "5.3.6", @@ -29138,8 +29117,7 @@ } }, "styled-jsx": { - "version": "5.0.7", - "requires": {} + "version": "5.0.7" }, "stylehacks": { "version": "5.1.1", @@ -29812,8 +29790,7 @@ } }, "use-sync-external-store": { - "version": "1.2.0", - "requires": {} + "version": "1.2.0" }, "utf8-byte-length": { "version": "1.0.4", @@ -29974,8 +29951,7 @@ }, "acorn-import-assertions": { "version": "1.8.0", - "dev": true, - "requires": {} + "dev": true }, "schema-utils": { "version": "3.1.1", diff --git a/packages/bruno-app/src/components/Sidebar/Collections/Collection/CloneCollection/index.js b/packages/bruno-app/src/components/Sidebar/Collections/Collection/CloneCollection/index.js new file mode 100644 index 00000000..cd9857a1 --- /dev/null +++ b/packages/bruno-app/src/components/Sidebar/Collections/Collection/CloneCollection/index.js @@ -0,0 +1,155 @@ +import React, { useRef, useEffect } from 'react'; +import { useDispatch } from 'react-redux'; +import { useFormik } from 'formik'; +import * as Yup from 'yup'; +import { browseDirectory } from 'providers/ReduxStore/slices/collections/actions'; +import { cloneCollection } from 'providers/ReduxStore/slices/collections/actions'; +import toast from 'react-hot-toast'; +import Tooltip from 'components/Tooltip'; +import Modal from 'components/Modal'; + +const CloneCollection = ({ onClose, collection }) => { + const inputRef = useRef(); + const dispatch = useDispatch(); + + const formik = useFormik({ + enableReinitialize: true, + initialValues: { + collectionName: '', + collectionFolderName: '', + collectionLocation: '' + }, + validationSchema: Yup.object({ + collectionName: Yup.string() + .min(1, 'must be at least 1 character') + .max(50, 'must be 50 characters or less') + .required('collection name is required'), + collectionFolderName: Yup.string() + .min(1, 'must be at least 1 character') + .max(50, 'must be 50 characters or less') + .matches(/^[\w\-. ]+$/, 'Folder name contains invalid characters') + .required('folder name is required'), + collectionLocation: Yup.string().min(1, 'location is required').required('location is required') + }), + onSubmit: (values) => { + dispatch( + cloneCollection( + values.collectionName, + values.collectionFolderName, + values.collectionLocation, + collection.pathname + ) + ) + .then(() => { + toast.success('Collection created'); + onClose(); + }) + .catch(() => toast.error('An error occurred while creating the collection')); + } + }); + + const browse = () => { + dispatch(browseDirectory()) + .then((dirPath) => { + // When the user closes the diolog without selecting anything dirPath will be false + if (typeof dirPath === 'string') { + formik.setFieldValue('collectionLocation', dirPath); + } + }) + .catch((error) => { + formik.setFieldValue('collectionLocation', ''); + console.error(error); + }); + }; + + useEffect(() => { + if (inputRef && inputRef.current) { + inputRef.current.focus(); + } + }, [inputRef]); + + const onSubmit = () => formik.handleSubmit(); + + return ( + +
+
+ + { + formik.handleChange(e); + if (formik.values.collectionName === formik.values.collectionFolderName) { + formik.setFieldValue('collectionFolderName', e.target.value); + } + }} + autoComplete="off" + autoCorrect="off" + autoCapitalize="off" + spellCheck="false" + value={formik.values.collectionName || ''} + /> + {formik.touched.collectionName && formik.errors.collectionName ? ( +
{formik.errors.collectionName}
+ ) : null} + + + + {formik.touched.collectionLocation && formik.errors.collectionLocation ? ( +
{formik.errors.collectionLocation}
+ ) : null} +
+ + Browse + +
+ + + + {formik.touched.collectionFolderName && formik.errors.collectionFolderName ? ( +
{formik.errors.collectionFolderName}
+ ) : null} +
+
+
+ ); +}; + +export default CloneCollection; diff --git a/packages/bruno-app/src/components/Sidebar/Collections/Collection/index.js b/packages/bruno-app/src/components/Sidebar/Collections/Collection/index.js index dade095e..81502831 100644 --- a/packages/bruno-app/src/components/Sidebar/Collections/Collection/index.js +++ b/packages/bruno-app/src/components/Sidebar/Collections/Collection/index.js @@ -20,11 +20,13 @@ import exportCollection from 'utils/collections/export'; import RenameCollection from './RenameCollection'; import StyledWrapper from './StyledWrapper'; +import CloneCollection from './CloneCollection/index'; const Collection = ({ collection, searchText }) => { const [showNewFolderModal, setShowNewFolderModal] = useState(false); const [showNewRequestModal, setShowNewRequestModal] = useState(false); const [showRenameCollectionModal, setShowRenameCollectionModal] = useState(false); + const [showCloneCollectionModalOpen, setShowCloneCollectionModalOpen] = useState(false); const [showExportCollectionModal, setShowExportCollectionModal] = useState(false); const [showRemoveCollectionModal, setShowRemoveCollectionModal] = useState(false); const [collectionIsCollapsed, setCollectionIsCollapsed] = useState(collection.collapsed); @@ -133,6 +135,9 @@ const Collection = ({ collection, searchText }) => { {showExportCollectionModal && ( setShowExportCollectionModal(false)} /> )} + {showCloneCollectionModalOpen && ( + setShowCloneCollectionModalOpen(false)} /> + )}
{ > New Folder
+
{ + menuDropdownTippyRef.current.hide(); + setShowCloneCollectionModalOpen(true); + }} + > + Clone +
{ 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 c7bb9837..4e236b47 100644 --- a/packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js +++ b/packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js @@ -939,7 +939,16 @@ export const createCollection = (collectionName, collectionFolderName, collectio .catch(reject); }); }; +export const cloneCollection = (collectionName, collectionFolderName, collectionLocation, perviousPath) => () => { + const { ipcRenderer } = window; + return new Promise((resolve, reject) => { + ipcRenderer + .invoke('renderer:clone-collection', collectionName, collectionFolderName, collectionLocation, perviousPath) + .then(resolve) + .catch(reject); + }); +}; export const openCollection = () => () => { return new Promise((resolve, reject) => { const { ipcRenderer } = window; diff --git a/packages/bruno-electron/src/ipc/collection.js b/packages/bruno-electron/src/ipc/collection.js index ba19cfaf..38d24827 100644 --- a/packages/bruno-electron/src/ipc/collection.js +++ b/packages/bruno-electron/src/ipc/collection.js @@ -70,7 +70,43 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection } } ); + // clone collection + ipcMain.handle( + 'renderer:clone-collection', + async (event, collectionName, collectionFolderName, collectionLocation, perviousPath) => { + try { + const dirPath = path.join(collectionLocation, collectionFolderName); + if (fs.existsSync(dirPath)) { + throw new Error(`collection: ${dirPath} already exists`); + } + if (!isValidPathname(dirPath)) { + throw new Error(`collection: invalid pathname - ${dir}`); + } + + await createDirectory(dirPath); + const uid = generateUidBasedOnHash(dirPath); + const brunoJsonFilePath = path.join(perviousPath, 'bruno.json'); + const content = fs.readFileSync(brunoJsonFilePath, 'utf8'); + let json = JSON.parse(content); + json.name = collectionName; + const cont = await stringifyJson(json); + await writeFile(path.join(dirPath, 'bruno.json'), cont); + const files = searchForBruFiles(perviousPath); + console.log(files); + for (const sourceFilePath of files) { + const fileName = path.basename(sourceFilePath); + const destinationFilePath = path.join(dirPath, fileName); + console.log(destinationFilePath); + fs.copyFileSync(sourceFilePath, destinationFilePath); + } + mainWindow.webContents.send('main:collection-opened', dirPath, uid, json); + ipcMain.emit('main:collection-opened', mainWindow, dirPath, uid); + } catch (error) { + return Promise.reject(error); + } + } + ); // rename collection ipcMain.handle('renderer:rename-collection', async (event, newName, collectionPathname) => { try { From 93661bd0d25aec131ddca2a111ca47090e9f7848 Mon Sep 17 00:00:00 2001 From: Akshat Khosya Date: Sat, 16 Dec 2023 13:07:51 +0530 Subject: [PATCH 2/5] handle dir of files, comments in code --- .../ReduxStore/slices/collections/actions.js | 11 ++- packages/bruno-electron/src/ipc/collection.js | 75 +++++++++++-------- 2 files changed, 49 insertions(+), 37 deletions(-) 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 4e236b47..1a38b77c 100644 --- a/packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js +++ b/packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js @@ -943,10 +943,13 @@ export const cloneCollection = (collectionName, collectionFolderName, collection const { ipcRenderer } = window; return new Promise((resolve, reject) => { - ipcRenderer - .invoke('renderer:clone-collection', collectionName, collectionFolderName, collectionLocation, perviousPath) - .then(resolve) - .catch(reject); + ipcRenderer.invoke( + 'renderer:clone-collection', + collectionName, + collectionFolderName, + collectionLocation, + perviousPath + ); }); }; export const openCollection = () => () => { diff --git a/packages/bruno-electron/src/ipc/collection.js b/packages/bruno-electron/src/ipc/collection.js index 38d24827..f21c56ab 100644 --- a/packages/bruno-electron/src/ipc/collection.js +++ b/packages/bruno-electron/src/ipc/collection.js @@ -42,38 +42,34 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection ipcMain.handle( 'renderer:create-collection', async (event, collectionName, collectionFolderName, collectionLocation) => { - try { - const dirPath = path.join(collectionLocation, collectionFolderName); - if (fs.existsSync(dirPath)) { - throw new Error(`collection: ${dirPath} already exists`); - } - - if (!isValidPathname(dirPath)) { - throw new Error(`collection: invalid pathname - ${dir}`); - } - - await createDirectory(dirPath); - - const uid = generateUidBasedOnHash(dirPath); - const brunoConfig = { - version: '1', - name: collectionName, - type: 'collection' - }; - const content = await stringifyJson(brunoConfig); - await writeFile(path.join(dirPath, 'bruno.json'), content); - - mainWindow.webContents.send('main:collection-opened', dirPath, uid, brunoConfig); - ipcMain.emit('main:collection-opened', mainWindow, dirPath, uid); - } catch (error) { - return Promise.reject(error); + const dirPath = path.join(collectionLocation, collectionFolderName); + if (fs.existsSync(dirPath)) { + throw new Error(`collection: ${dirPath} already exists`); } + + if (!isValidPathname(dirPath)) { + throw new Error(`collection: invalid pathname - ${dir}`); + } + + await createDirectory(dirPath); + + const uid = generateUidBasedOnHash(dirPath); + const brunoConfig = { + version: '1', + name: collectionName, + type: 'collection' + }; + const content = await stringifyJson(brunoConfig); + await writeFile(path.join(dirPath, 'bruno.json'), content); + + mainWindow.webContents.send('main:collection-opened', dirPath, uid, brunoConfig); + ipcMain.emit('main:collection-opened', mainWindow, dirPath, uid); } ); // clone collection ipcMain.handle( 'renderer:clone-collection', - async (event, collectionName, collectionFolderName, collectionLocation, perviousPath) => { + async (event, collectionName, collectionFolderName, collectionLocation, previousPath) => { try { const dirPath = path.join(collectionLocation, collectionFolderName); if (fs.existsSync(dirPath)) { @@ -84,22 +80,35 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection throw new Error(`collection: invalid pathname - ${dir}`); } + // create dir await createDirectory(dirPath); const uid = generateUidBasedOnHash(dirPath); - const brunoJsonFilePath = path.join(perviousPath, 'bruno.json'); + + // open the bruno.json of previousPath + const brunoJsonFilePath = path.join(previousPath, 'bruno.json'); const content = fs.readFileSync(brunoJsonFilePath, 'utf8'); + + //Chnage new name of collection let json = JSON.parse(content); json.name = collectionName; const cont = await stringifyJson(json); + + // write the bruno.json to new dir await writeFile(path.join(dirPath, 'bruno.json'), cont); - const files = searchForBruFiles(perviousPath); - console.log(files); + + // Now copy all the files with extension name .bru along with there dir + const files = searchForBruFiles(previousPath); + for (const sourceFilePath of files) { - const fileName = path.basename(sourceFilePath); - const destinationFilePath = path.join(dirPath, fileName); - console.log(destinationFilePath); - fs.copyFileSync(sourceFilePath, destinationFilePath); + const relativePath = path.relative(previousPath, sourceFilePath); + const newFilePath = path.join(dirPath, relativePath); + + // handle dir of files + fs.mkdirSync(path.dirname(newFilePath), { recursive: true }); + // copy each files + fs.copyFileSync(sourceFilePath, newFilePath); } + mainWindow.webContents.send('main:collection-opened', dirPath, uid, json); ipcMain.emit('main:collection-opened', mainWindow, dirPath, uid); } catch (error) { From cada4f201ae8c4b344c50eb48fc8e178d33363c2 Mon Sep 17 00:00:00 2001 From: Akshat Khosya Date: Sat, 16 Dec 2023 13:16:03 +0530 Subject: [PATCH 3/5] removed try catch from clone collection --- packages/bruno-electron/src/ipc/collection.js | 110 +++++++++--------- 1 file changed, 55 insertions(+), 55 deletions(-) diff --git a/packages/bruno-electron/src/ipc/collection.js b/packages/bruno-electron/src/ipc/collection.js index f21c56ab..534ea78c 100644 --- a/packages/bruno-electron/src/ipc/collection.js +++ b/packages/bruno-electron/src/ipc/collection.js @@ -42,34 +42,6 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection ipcMain.handle( 'renderer:create-collection', async (event, collectionName, collectionFolderName, collectionLocation) => { - const dirPath = path.join(collectionLocation, collectionFolderName); - if (fs.existsSync(dirPath)) { - throw new Error(`collection: ${dirPath} already exists`); - } - - if (!isValidPathname(dirPath)) { - throw new Error(`collection: invalid pathname - ${dir}`); - } - - await createDirectory(dirPath); - - const uid = generateUidBasedOnHash(dirPath); - const brunoConfig = { - version: '1', - name: collectionName, - type: 'collection' - }; - const content = await stringifyJson(brunoConfig); - await writeFile(path.join(dirPath, 'bruno.json'), content); - - mainWindow.webContents.send('main:collection-opened', dirPath, uid, brunoConfig); - ipcMain.emit('main:collection-opened', mainWindow, dirPath, uid); - } - ); - // clone collection - ipcMain.handle( - 'renderer:clone-collection', - async (event, collectionName, collectionFolderName, collectionLocation, previousPath) => { try { const dirPath = path.join(collectionLocation, collectionFolderName); if (fs.existsSync(dirPath)) { @@ -80,42 +52,70 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection throw new Error(`collection: invalid pathname - ${dir}`); } - // create dir await createDirectory(dirPath); + const uid = generateUidBasedOnHash(dirPath); + const brunoConfig = { + version: '1', + name: collectionName, + type: 'collection' + }; + const content = await stringifyJson(brunoConfig); + await writeFile(path.join(dirPath, 'bruno.json'), content); - // open the bruno.json of previousPath - const brunoJsonFilePath = path.join(previousPath, 'bruno.json'); - const content = fs.readFileSync(brunoJsonFilePath, 'utf8'); - - //Chnage new name of collection - let json = JSON.parse(content); - json.name = collectionName; - const cont = await stringifyJson(json); - - // write the bruno.json to new dir - await writeFile(path.join(dirPath, 'bruno.json'), cont); - - // Now copy all the files with extension name .bru along with there dir - const files = searchForBruFiles(previousPath); - - for (const sourceFilePath of files) { - const relativePath = path.relative(previousPath, sourceFilePath); - const newFilePath = path.join(dirPath, relativePath); - - // handle dir of files - fs.mkdirSync(path.dirname(newFilePath), { recursive: true }); - // copy each files - fs.copyFileSync(sourceFilePath, newFilePath); - } - - mainWindow.webContents.send('main:collection-opened', dirPath, uid, json); + mainWindow.webContents.send('main:collection-opened', dirPath, uid, brunoConfig); ipcMain.emit('main:collection-opened', mainWindow, dirPath, uid); } catch (error) { return Promise.reject(error); } } ); + // clone collection + ipcMain.handle( + 'renderer:clone-collection', + async (event, collectionName, collectionFolderName, collectionLocation, previousPath) => { + const dirPath = path.join(collectionLocation, collectionFolderName); + if (fs.existsSync(dirPath)) { + throw new Error(`collection: ${dirPath} already exists`); + } + + if (!isValidPathname(dirPath)) { + throw new Error(`collection: invalid pathname - ${dir}`); + } + + // create dir + await createDirectory(dirPath); + const uid = generateUidBasedOnHash(dirPath); + + // open the bruno.json of previousPath + const brunoJsonFilePath = path.join(previousPath, 'bruno.json'); + const content = fs.readFileSync(brunoJsonFilePath, 'utf8'); + + //Chnage new name of collection + let json = JSON.parse(content); + json.name = collectionName; + const cont = await stringifyJson(json); + + // write the bruno.json to new dir + await writeFile(path.join(dirPath, 'bruno.json'), cont); + + // Now copy all the files with extension name .bru along with there dir + const files = searchForBruFiles(previousPath); + + for (const sourceFilePath of files) { + const relativePath = path.relative(previousPath, sourceFilePath); + const newFilePath = path.join(dirPath, relativePath); + + // handle dir of files + fs.mkdirSync(path.dirname(newFilePath), { recursive: true }); + // copy each files + fs.copyFileSync(sourceFilePath, newFilePath); + } + + mainWindow.webContents.send('main:collection-opened', dirPath, uid, json); + ipcMain.emit('main:collection-opened', mainWindow, dirPath, uid); + } + ); // rename collection ipcMain.handle('renderer:rename-collection', async (event, newName, collectionPathname) => { try { From a15a4e4a2d1b83468c25e89e580032d2d43a06bd Mon Sep 17 00:00:00 2001 From: Akshat Khosya Date: Sat, 16 Dec 2023 13:18:52 +0530 Subject: [PATCH 4/5] corrected typo error in comments --- packages/bruno-electron/src/ipc/collection.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/bruno-electron/src/ipc/collection.js b/packages/bruno-electron/src/ipc/collection.js index 534ea78c..76bb661d 100644 --- a/packages/bruno-electron/src/ipc/collection.js +++ b/packages/bruno-electron/src/ipc/collection.js @@ -91,7 +91,7 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection const brunoJsonFilePath = path.join(previousPath, 'bruno.json'); const content = fs.readFileSync(brunoJsonFilePath, 'utf8'); - //Chnage new name of collection + //Change new name of collection let json = JSON.parse(content); json.name = collectionName; const cont = await stringifyJson(json); From b8451d01ca179d299709fe24cc6771b9497048ea Mon Sep 17 00:00:00 2001 From: Akshat Khosya Date: Sat, 16 Dec 2023 23:19:17 +0530 Subject: [PATCH 5/5] removed promise from clone collection action --- .../ReduxStore/slices/collections/actions.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) 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 1a38b77c..9c799c23 100644 --- a/packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js +++ b/packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js @@ -942,15 +942,13 @@ export const createCollection = (collectionName, collectionFolderName, collectio export const cloneCollection = (collectionName, collectionFolderName, collectionLocation, perviousPath) => () => { const { ipcRenderer } = window; - return new Promise((resolve, reject) => { - ipcRenderer.invoke( - 'renderer:clone-collection', - collectionName, - collectionFolderName, - collectionLocation, - perviousPath - ); - }); + return ipcRenderer.invoke( + 'renderer:clone-collection', + collectionName, + collectionFolderName, + collectionLocation, + perviousPath + ); }; export const openCollection = () => () => { return new Promise((resolve, reject) => {