From c95bc8fdf9a1e7c88cf64c06d61bad2c4aef1819 Mon Sep 17 00:00:00 2001 From: Anoop M D Date: Sat, 15 Oct 2022 21:22:25 +0530 Subject: [PATCH] feat: remove local collection from workspace (resolves #22) --- .../RemoveCollectionFromWorkspace/index.js | 4 +++- .../Sidebar/Collections/Collection/index.js | 18 +++++++++++------- .../ReduxStore/slices/collections/actions.js | 15 +++++++++++++++ .../bruno-app/src/utils/collections/index.js | 4 ++++ .../bruno-electron/src/ipc/local-collection.js | 1 + 5 files changed, 34 insertions(+), 8 deletions(-) diff --git a/packages/bruno-app/src/components/Sidebar/Collections/Collection/RemoveCollectionFromWorkspace/index.js b/packages/bruno-app/src/components/Sidebar/Collections/Collection/RemoveCollectionFromWorkspace/index.js index 94064dfa..a5dbbf71 100644 --- a/packages/bruno-app/src/components/Sidebar/Collections/Collection/RemoveCollectionFromWorkspace/index.js +++ b/packages/bruno-app/src/components/Sidebar/Collections/Collection/RemoveCollectionFromWorkspace/index.js @@ -4,6 +4,7 @@ import Modal from 'components/Modal'; import { useSelector, useDispatch } from 'react-redux'; import { recursivelyGetAllItemUids } from 'utils/collections'; import { removeCollectionFromWorkspace } from 'providers/ReduxStore/slices/workspaces/actions'; +import { removeLocalCollection } from 'providers/ReduxStore/slices/collections/actions'; import { closeTabs } from 'providers/ReduxStore/slices/tabs'; const RemoveCollectionFromWorkspace = ({onClose, collection}) => { @@ -16,8 +17,9 @@ const RemoveCollectionFromWorkspace = ({onClose, collection}) => { dispatch(closeTabs({ tabUids: recursivelyGetAllItemUids(collection.items) })); - toast.success("Collection removed from workspace"); }) + .then(() => dispatch(removeLocalCollection(collection.uid))) + .then(() => toast.success("Collection removed from workspace")) .catch((err) => console.log(err) && toast.error("An error occured while removing the collection")); }; 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 c8e59944..3510dbc1 100644 --- a/packages/bruno-app/src/components/Sidebar/Collections/Collection/index.js +++ b/packages/bruno-app/src/components/Sidebar/Collections/Collection/index.js @@ -11,7 +11,7 @@ import NewFolder from 'components/Sidebar/NewFolder'; import CollectionItem from './CollectionItem'; import RemoveCollectionFromWorkspace from './RemoveCollectionFromWorkspace'; import { doesCollectionHaveItemsMatchingSearchText } from 'utils/collections/search'; -import { isItemAFolder, isItemARequest, transformCollectionToSaveToIdb } from 'utils/collections'; +import { isItemAFolder, isItemARequest, transformCollectionToSaveToIdb, isLocalCollection } from 'utils/collections'; import exportCollection from 'utils/collections/export'; import RenameCollection from './RenameCollection'; @@ -67,6 +67,8 @@ const Collection = ({collection, searchText}) => { exportCollection(transformCollectionToSaveToIdb(collectionCopy)); }; + const isLocal = isLocalCollection(collection); + return ( {showNewRequestModal && setShowNewRequestModal(false)}/>} @@ -115,12 +117,14 @@ const Collection = ({collection, searchText}) => { }}> Remove from Workspace -
{ - menuDropdownTippyRef.current.hide(); - setShowDeleteCollectionModal(true); - }}> - Delete -
+ {!isLocal ? ( +
{ + menuDropdownTippyRef.current.hide(); + setShowDeleteCollectionModal(true); + }}> + Delete +
+ ) : 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 ca12a75b..4ce67b05 100644 --- a/packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js +++ b/packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js @@ -612,4 +612,19 @@ export const newHttpRequest = (params) => (dispatch, getState) => { .then(() => resolve()) .catch(reject); }); +}; + +export const removeLocalCollection = (collectionUid) => (dispatch, getState) => { + return new Promise((resolve, reject) => { + const state = getState(); + const collection = findCollectionByUid(state.collections.collections, collectionUid); + if(!collection) { + return reject(new Error('Collection not found')); + } + const { ipcRenderer } = window; + ipcRenderer + .invoke('renderer:remove-collection', collection.pathname) + .then(resolve) + .catch(reject); + }); }; \ No newline at end of file diff --git a/packages/bruno-app/src/utils/collections/index.js b/packages/bruno-app/src/utils/collections/index.js index 95724696..249ba72b 100644 --- a/packages/bruno-app/src/utils/collections/index.js +++ b/packages/bruno-app/src/utils/collections/index.js @@ -338,3 +338,7 @@ export const refreshUidsInItem = (item) => { return item; } + +export const isLocalCollection = (collection) => { + return collection.pathname ? true : false; +}; diff --git a/packages/bruno-electron/src/ipc/local-collection.js b/packages/bruno-electron/src/ipc/local-collection.js index 702c3794..5a5acdda 100644 --- a/packages/bruno-electron/src/ipc/local-collection.js +++ b/packages/bruno-electron/src/ipc/local-collection.js @@ -153,6 +153,7 @@ const registerRendererEventHandlers = (mainWindow, watcher) => { ipcMain.handle('renderer:remove-collection', async (event, collectionPath) => { if(watcher && mainWindow) { + console.log(`watcher stopWatching: ${collectionPath}`); watcher.removeWatcher(collectionPath, mainWindow); } });