{
)}
{
dropdownTippyRef.current.hide();
+ setRenameItemModalOpen(true);
}}>
Rename
diff --git a/renderer/providers/ReduxStore/slices/collections.js b/renderer/providers/ReduxStore/slices/collections.js
index 444db95b..f0159116 100644
--- a/renderer/providers/ReduxStore/slices/collections.js
+++ b/renderer/providers/ReduxStore/slices/collections.js
@@ -58,7 +58,6 @@ export const collectionsSlice = createSlice({
const item = findItemInCollection(collection, action.payload.itemUid);
if(item && item.draft) {
- item.name = item.draft.name;
item.request = item.draft.request;
item.draft = null;
}
@@ -92,6 +91,17 @@ export const collectionsSlice = createSlice({
deleteItemInCollection(action.payload.itemUid, collection);
}
},
+ _renameItem: (state, action) => {
+ const collection = findCollectionByUid(state.collections, action.payload.collectionUid);
+
+ if(collection) {
+ const item = findItemInCollection(collection, action.payload.itemUid);
+
+ if(item) {
+ item.name = action.payload.newName;
+ }
+ }
+ },
collectionClicked: (state, action) => {
const collection = findCollectionByUid(state.collections, action.payload);
@@ -125,6 +135,7 @@ export const {
_newFolder,
_newRequest,
_deleteItem,
+ _renameItem,
collectionClicked,
requestUrlChanged,
} = collectionsSlice.actions;
@@ -268,4 +279,30 @@ export const deleteItem = (itemUid, collectionUid) => (dispatch, getState) => {
}
};
+export const renameItem = (newName, itemUid, collectionUid) => (dispatch, getState) => {
+ const state = getState();
+ const collection = findCollectionByUid(state.collections.collections, collectionUid);
+
+ if(collection) {
+ const collectionCopy = cloneDeep(collection);
+ const item = findItemInCollection(collectionCopy, itemUid);
+ if(item) {
+ item.name = newName;
+ }
+ const collectionToSave = transformCollectionToSaveToIdb(collectionCopy, {
+ ignoreDraft: true
+ });
+
+ saveCollectionToIdb(window.__idb, collectionToSave)
+ .then(() => {
+ dispatch(_renameItem({
+ newName: newName,
+ itemUid: itemUid,
+ collectionUid: collectionUid
+ }));
+ })
+ .catch((err) => console.log(err));
+ }
+};
+
export default collectionsSlice.reducer;
diff --git a/renderer/utils/collections/index.js b/renderer/utils/collections/index.js
index 5cd24a1c..0278ca5b 100644
--- a/renderer/utils/collections/index.js
+++ b/renderer/utils/collections/index.js
@@ -53,7 +53,7 @@ export const cloneItem = (item) => {
return cloneDeep(item);
};
-export const transformCollectionToSaveToIdb = (collection) => {
+export const transformCollectionToSaveToIdb = (collection, options = {}) => {
const copyItems = (sourceItems, destItems) => {
each(sourceItems, (si) => {
const di = {
@@ -61,10 +61,10 @@ export const transformCollectionToSaveToIdb = (collection) => {
type: si.type
};
- // if items is draft, then take data from draft to save
- if(si.draft) {
- di.name = si.draft.name;
+ di.name = si.name;
+ // if items is draft, then take data from draft to save
+ if(!options.ignoreDraft && si.draft) {
if(si.draft.request) {
di.request = {
url: si.draft.request.url,
@@ -74,8 +74,6 @@ export const transformCollectionToSaveToIdb = (collection) => {
};
}
} else {
- di.name = si.name;
-
if(si.request) {
di.request = {
url: si.request.url,