From 7dd0d10a5d296d81608346e264d94bb19f8c0bd1 Mon Sep 17 00:00:00 2001 From: Anoop M D Date: Wed, 1 Feb 2023 08:37:48 +0530 Subject: [PATCH] fix: fixed bugs related to sequencing --- .../ReduxStore/slices/collections/actions.js | 39 ++++++++++++------- .../bruno-app/src/utils/collections/index.js | 6 ++- 2 files changed, 30 insertions(+), 15 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 e92e1ccd7..f460c8457 100644 --- a/packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js +++ b/packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js @@ -1,6 +1,7 @@ import path from 'path'; import toast from 'react-hot-toast'; import trim from 'lodash/trim'; +import filter from 'lodash/filter'; import { uuid } from 'utils/common'; import cloneDeep from 'lodash/cloneDeep'; import { @@ -252,6 +253,8 @@ export const cloneItem = (newName, itemUid, collectionUid) => (dispatch, getStat if (!reqWithSameNameExists) { const fullName = `${collection.pathname}${PATH_SEPARATOR}${filename}`; const { ipcRenderer } = window; + const requestItems = filter(collection.items, (i) => i.type !== 'folder'); + itemToSave.seq = requestItems ? (requestItems.length + 1) : 1; itemSchema .validate(itemToSave) @@ -267,6 +270,8 @@ export const cloneItem = (newName, itemUid, collectionUid) => (dispatch, getStat const dirname = path.dirname(item.pathname); const fullName = `${dirname}${PATH_SEPARATOR}${filename}`; const { ipcRenderer } = window; + const requestItems = filter(parentItem.items, (i) => i.type !== 'folder'); + itemToSave.seq = requestItems ? (requestItems.length + 1) : 1; itemSchema .validate(itemToSave) @@ -360,8 +365,6 @@ export const moveItem = (collectionUid, draggedItemUid, targetItemUid) => (dispa moveCollectionItem(collectionCopy, draggedItem, targetItem); const itemsToResequence = getItemsToResequence(draggedItemParent, collectionCopy); const itemsToResequence2 = getItemsToResequence(targetItemParent, collectionCopy); - console.log('itemsToResequence', itemsToResequence); - console.log('itemsToResequence2', itemsToResequence2); return ipcRenderer .invoke('renderer:move-file-item', draggedItemPathname, targetItemParent.pathname) @@ -455,15 +458,23 @@ export const moveItemToRootOfCollection = (collectionUid, draggedItemUid) => (di const draggedItemPathname = draggedItem.pathname; moveCollectionItemToRootOfCollection(collectionCopy, draggedItem); - const itemsToResequence = getItemsToResequence(draggedItemParent, collectionCopy); - const itemsToResequence2 = getItemsToResequence(collectionCopy, collectionCopy); - return ipcRenderer - .invoke('renderer:move-file-item', draggedItemPathname, collectionCopy.pathname) - .then(() => ipcRenderer.invoke('renderer:resequence-items', itemsToResequence)) - .then(() => ipcRenderer.invoke('renderer:resequence-items', itemsToResequence2)) - .then(resolve) - .catch((error) => reject(error)); + if(isItemAFolder(draggedItem)) { + return ipcRenderer + .invoke('renderer:move-folder-item', draggedItemPathname, collectionCopy.pathname) + .then(resolve) + .catch((error) => reject(error)); + } else { + const itemsToResequence = getItemsToResequence(draggedItemParent, collectionCopy); + const itemsToResequence2 = getItemsToResequence(collectionCopy, collectionCopy); + + return ipcRenderer + .invoke('renderer:move-file-item', draggedItemPathname, collectionCopy.pathname) + .then(() => ipcRenderer.invoke('renderer:resequence-items', itemsToResequence)) + .then(() => ipcRenderer.invoke('renderer:resequence-items', itemsToResequence2)) + .then(resolve) + .catch((error) => reject(error)); + } }); }; @@ -501,8 +512,8 @@ export const newHttpRequest = (params) => (dispatch, getState) => { const filename = resolveRequestFilename(requestName); if (!itemUid) { const reqWithSameNameExists = find(collection.items, (i) => i.type !== 'folder' && trim(i.filename) === trim(filename)); - item.seq = collectionCopy.items ? collectionCopy.items.length : 1; - item.seq = item.seq + 1; + const requestItems = filter(collection.items, (i) => i.type !== 'folder'); + item.seq = requestItems.length + 1; if (!reqWithSameNameExists) { const fullName = `${collection.pathname}${PATH_SEPARATOR}${filename}`; @@ -516,8 +527,8 @@ export const newHttpRequest = (params) => (dispatch, getState) => { const currentItem = findItemInCollection(collection, itemUid); if (currentItem) { const reqWithSameNameExists = find(currentItem.items, (i) => i.type !== 'folder' && trim(i.filename) === trim(filename)); - item.seq = currentItem.items ? currentItem.items.length : 1; - item.seq = item.seq + 1; + const requestItems = filter(currentItem.items, (i) => i.type !== 'folder'); + item.seq = requestItems.length + 1; if (!reqWithSameNameExists) { const fullName = `${currentItem.pathname}${PATH_SEPARATOR}${filename}`; const { ipcRenderer } = window; diff --git a/packages/bruno-app/src/utils/collections/index.js b/packages/bruno-app/src/utils/collections/index.js index 8628da56c..3b42dd59a 100644 --- a/packages/bruno-app/src/utils/collections/index.js +++ b/packages/bruno-app/src/utils/collections/index.js @@ -164,7 +164,11 @@ export const moveCollectionItemToRootOfCollection = (collection, draggedItem) => draggedItemParent.items = filter(draggedItemParent.items, (i) => i.uid !== draggedItem.uid); collection.items.push(draggedItem); - draggedItem.pathname = path.join(collection.pathname, draggedItem.filename); + if(draggedItem.type == 'folder') { + draggedItem.pathname = path.join(collection.pathname, draggedItem.name); + } else { + draggedItem.pathname = path.join(collection.pathname, draggedItem.filename); + } }; export const getItemsToResequence = (parent, collection) => {