forked from extern/bruno
feat: remove local collection from workspace (resolves #22)
This commit is contained in:
parent
44aa019754
commit
c95bc8fdf9
@ -4,6 +4,7 @@ import Modal from 'components/Modal';
|
|||||||
import { useSelector, useDispatch } from 'react-redux';
|
import { useSelector, useDispatch } from 'react-redux';
|
||||||
import { recursivelyGetAllItemUids } from 'utils/collections';
|
import { recursivelyGetAllItemUids } from 'utils/collections';
|
||||||
import { removeCollectionFromWorkspace } from 'providers/ReduxStore/slices/workspaces/actions';
|
import { removeCollectionFromWorkspace } from 'providers/ReduxStore/slices/workspaces/actions';
|
||||||
|
import { removeLocalCollection } from 'providers/ReduxStore/slices/collections/actions';
|
||||||
import { closeTabs } from 'providers/ReduxStore/slices/tabs';
|
import { closeTabs } from 'providers/ReduxStore/slices/tabs';
|
||||||
|
|
||||||
const RemoveCollectionFromWorkspace = ({onClose, collection}) => {
|
const RemoveCollectionFromWorkspace = ({onClose, collection}) => {
|
||||||
@ -16,8 +17,9 @@ const RemoveCollectionFromWorkspace = ({onClose, collection}) => {
|
|||||||
dispatch(closeTabs({
|
dispatch(closeTabs({
|
||||||
tabUids: recursivelyGetAllItemUids(collection.items)
|
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"));
|
.catch((err) => console.log(err) && toast.error("An error occured while removing the collection"));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ import NewFolder from 'components/Sidebar/NewFolder';
|
|||||||
import CollectionItem from './CollectionItem';
|
import CollectionItem from './CollectionItem';
|
||||||
import RemoveCollectionFromWorkspace from './RemoveCollectionFromWorkspace';
|
import RemoveCollectionFromWorkspace from './RemoveCollectionFromWorkspace';
|
||||||
import { doesCollectionHaveItemsMatchingSearchText } from 'utils/collections/search';
|
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 exportCollection from 'utils/collections/export';
|
||||||
|
|
||||||
import RenameCollection from './RenameCollection';
|
import RenameCollection from './RenameCollection';
|
||||||
@ -67,6 +67,8 @@ const Collection = ({collection, searchText}) => {
|
|||||||
exportCollection(transformCollectionToSaveToIdb(collectionCopy));
|
exportCollection(transformCollectionToSaveToIdb(collectionCopy));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const isLocal = isLocalCollection(collection);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<StyledWrapper className="flex flex-col">
|
<StyledWrapper className="flex flex-col">
|
||||||
{showNewRequestModal && <NewRequest collection={collection} onClose={() => setShowNewRequestModal(false)}/>}
|
{showNewRequestModal && <NewRequest collection={collection} onClose={() => setShowNewRequestModal(false)}/>}
|
||||||
@ -115,12 +117,14 @@ const Collection = ({collection, searchText}) => {
|
|||||||
}}>
|
}}>
|
||||||
Remove from Workspace
|
Remove from Workspace
|
||||||
</div>
|
</div>
|
||||||
<div className="dropdown-item delete-collection" onClick={(e) => {
|
{!isLocal ? (
|
||||||
menuDropdownTippyRef.current.hide();
|
<div className="dropdown-item delete-collection" onClick={(e) => {
|
||||||
setShowDeleteCollectionModal(true);
|
menuDropdownTippyRef.current.hide();
|
||||||
}}>
|
setShowDeleteCollectionModal(true);
|
||||||
Delete
|
}}>
|
||||||
</div>
|
Delete
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
</Dropdown>
|
</Dropdown>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -612,4 +612,19 @@ export const newHttpRequest = (params) => (dispatch, getState) => {
|
|||||||
.then(() => resolve())
|
.then(() => resolve())
|
||||||
.catch(reject);
|
.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);
|
||||||
|
});
|
||||||
};
|
};
|
@ -338,3 +338,7 @@ export const refreshUidsInItem = (item) => {
|
|||||||
|
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const isLocalCollection = (collection) => {
|
||||||
|
return collection.pathname ? true : false;
|
||||||
|
};
|
||||||
|
@ -153,6 +153,7 @@ const registerRendererEventHandlers = (mainWindow, watcher) => {
|
|||||||
|
|
||||||
ipcMain.handle('renderer:remove-collection', async (event, collectionPath) => {
|
ipcMain.handle('renderer:remove-collection', async (event, collectionPath) => {
|
||||||
if(watcher && mainWindow) {
|
if(watcher && mainWindow) {
|
||||||
|
console.log(`watcher stopWatching: ${collectionPath}`);
|
||||||
watcher.removeWatcher(collectionPath, mainWindow);
|
watcher.removeWatcher(collectionPath, mainWindow);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user