diff --git a/packages/bruno-app/src/components/Sidebar/Collections/Collection/StyledWrapper.js b/packages/bruno-app/src/components/Sidebar/Collections/Collection/StyledWrapper.js index 7b7438c5..b8e0d21f 100644 --- a/packages/bruno-app/src/components/Sidebar/Collections/Collection/StyledWrapper.js +++ b/packages/bruno-app/src/components/Sidebar/Collections/Collection/StyledWrapper.js @@ -52,6 +52,12 @@ const Wrapper = styled.div` } } } + + #sidebar-collection-name { + white-space: nowrap; + text-overflow: ellipsis; + overflow: hidden; + } `; export default Wrapper; 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 0e274895..7c6b8c08 100644 --- a/packages/bruno-app/src/components/Sidebar/Collections/Collection/index.js +++ b/packages/bruno-app/src/components/Sidebar/Collections/Collection/index.js @@ -98,7 +98,7 @@ const Collection = ({ collection, searchText }) => { {showRenameCollectionModal && setShowRenameCollectionModal(false)} />} {showRemoveCollectionModal && setShowRemoveCollectionModal(false)} />}
-
+
@@ -122,8 +122,7 @@ const Collection = ({ collection, searchText }) => { > New Folder
- {/* Todo: implement rename collection */} - {/*
{ menuDropdownTippyRef.current.hide(); @@ -131,7 +130,7 @@ const Collection = ({ collection, searchText }) => { }} > Rename -
*/} +
{ diff --git a/packages/bruno-app/src/providers/App/useCollectionTreeSync.js b/packages/bruno-app/src/providers/App/useCollectionTreeSync.js index 55dbd1d6..352c0c4f 100644 --- a/packages/bruno-app/src/providers/App/useCollectionTreeSync.js +++ b/packages/bruno-app/src/providers/App/useCollectionTreeSync.js @@ -10,7 +10,8 @@ import { requestSentEvent, requestQueuedEvent, testResultsEvent, - scriptEnvironmentUpdateEvent + scriptEnvironmentUpdateEvent, + collectionRenamedEvent } from 'providers/ReduxStore/slices/collections'; import toast from 'react-hot-toast'; import { openCollectionEvent, collectionAddEnvFileEvent } from 'providers/ReduxStore/slices/collections/actions'; @@ -100,6 +101,10 @@ const useCollectionTreeSync = () => { dispatch(testResultsEvent(val)); }; + const _collectionRenamed = (val) => { + dispatch(collectionRenamedEvent(val)); + }; + ipcRenderer.invoke('renderer:ready'); const removeListener1 = ipcRenderer.on('main:collection-opened', _openCollection); @@ -110,6 +115,7 @@ const useCollectionTreeSync = () => { const removeListener6 = ipcRenderer.on('main:script-environment-update', _scriptEnvironmentUpdate); const removeListener7 = ipcRenderer.on('main:http-request-queued', _httpRequestQueued); const removeListener8 = ipcRenderer.on('main:test-results', _testResults); + const removeListener9 = ipcRenderer.on('main:collection-renamed', _collectionRenamed); return () => { removeListener1(); @@ -120,6 +126,7 @@ const useCollectionTreeSync = () => { removeListener6(); removeListener7(); removeListener8(); + removeListener9(); }; }, [isElectron]); }; 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 f460c845..d51fc30d 100644 --- a/packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js +++ b/packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js @@ -11,7 +11,6 @@ import { moveCollectionItemToRootOfCollection, findCollectionByUid, recursivelyGetAllItemUids, - transformCollectionToSaveToIdb, transformRequestToSaveToFilesystem, findParentItemInCollection, findEnvironmentInCollection, @@ -48,26 +47,16 @@ export const renameCollection = (newName, collectionUid) => (dispatch, getState) const state = getState(); const collection = findCollectionByUid(state.collections.collections, collectionUid); - if (collection) { - const collectionCopy = cloneDeep(collection); - collectionCopy.name = newName; - const collectionToSave = transformCollectionToSaveToIdb(collectionCopy, { - ignoreDraft: true - }); + return new Promise((resolve, reject) => { + if (!collection) { + return reject(new Error('Collection not found')); + } - collectionSchema - .validate(collectionToSave) - .then(() => saveCollectionToIdb(window.__idb, collectionToSave)) - .then(() => { - dispatch( - _renameCollection({ - newName: newName, - collectionUid: collectionUid - }) - ); - }) - .catch((err) => console.log(err)); - } + ipcRenderer + .invoke('renderer:rename-collection', newName, collection.pathname) + .then(resolve) + .catch(reject); + }); }; export const saveRequest = (itemUid, collectionUid) => (dispatch, getState) => { diff --git a/packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js b/packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js index 31f421f4..a2020bc3 100644 --- a/packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js +++ b/packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js @@ -11,6 +11,7 @@ import { createSlice } from '@reduxjs/toolkit'; import splitOnFirst from 'split-on-first'; import { findCollectionByUid, + findCollectionByPathname, findItemInCollection, findEnvironmentInCollection, findItemInCollectionByPathname, @@ -840,6 +841,14 @@ export const collectionsSlice = createSlice({ item.testResults = results; } } + }, + collectionRenamedEvent: (state, action) => { + const { collectionPathname, newName } = action.payload; + const collection = findCollectionByPathname(state.collections, collectionPathname); + + if (collection) { + collection.name = newName; + } } } }); @@ -891,7 +900,8 @@ export const { collectionUnlinkFileEvent, collectionUnlinkDirectoryEvent, collectionAddEnvFileEvent, - testResultsEvent + testResultsEvent, + collectionRenamedEvent } = collectionsSlice.actions; export default collectionsSlice.reducer; diff --git a/packages/bruno-electron/src/ipc/collection.js b/packages/bruno-electron/src/ipc/collection.js index 4758db7c..30706a7e 100644 --- a/packages/bruno-electron/src/ipc/collection.js +++ b/packages/bruno-electron/src/ipc/collection.js @@ -64,6 +64,31 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection } }); + // rename collection + ipcMain.handle('renderer:rename-collection', async (event, newName, collectionPathname) => { + try { + const brunoJsonFilePath = path.join(collectionPathname, 'bruno.json'); + const content = fs.readFileSync(brunoJsonFilePath, 'utf8'); + const json = JSON.parse(content); + + json.name = newName; + + const newContent = await stringifyJson(json); + await writeFile(brunoJsonFilePath, newContent); + + // todo: listen for bruno.json changes and handle it in watcher + // the app will change the name of the collection after parsing the bruno.json file contents + mainWindow.webContents.send('main:collection-renamed', { + collectionPathname, + newName + }); + + return; + } catch (error) { + return Promise.reject(error); + } + }); + // new request ipcMain.handle('renderer:new-request', async (event, pathname, request) => { try {