fix: fixed bugs related to sequencing

This commit is contained in:
Anoop M D 2023-02-01 08:37:48 +05:30
parent d9ef1692fe
commit 7dd0d10a5d
2 changed files with 30 additions and 15 deletions

View File

@ -1,6 +1,7 @@
import path from 'path'; import path from 'path';
import toast from 'react-hot-toast'; import toast from 'react-hot-toast';
import trim from 'lodash/trim'; import trim from 'lodash/trim';
import filter from 'lodash/filter';
import { uuid } from 'utils/common'; import { uuid } from 'utils/common';
import cloneDeep from 'lodash/cloneDeep'; import cloneDeep from 'lodash/cloneDeep';
import { import {
@ -252,6 +253,8 @@ export const cloneItem = (newName, itemUid, collectionUid) => (dispatch, getStat
if (!reqWithSameNameExists) { if (!reqWithSameNameExists) {
const fullName = `${collection.pathname}${PATH_SEPARATOR}${filename}`; const fullName = `${collection.pathname}${PATH_SEPARATOR}${filename}`;
const { ipcRenderer } = window; const { ipcRenderer } = window;
const requestItems = filter(collection.items, (i) => i.type !== 'folder');
itemToSave.seq = requestItems ? (requestItems.length + 1) : 1;
itemSchema itemSchema
.validate(itemToSave) .validate(itemToSave)
@ -267,6 +270,8 @@ export const cloneItem = (newName, itemUid, collectionUid) => (dispatch, getStat
const dirname = path.dirname(item.pathname); const dirname = path.dirname(item.pathname);
const fullName = `${dirname}${PATH_SEPARATOR}${filename}`; const fullName = `${dirname}${PATH_SEPARATOR}${filename}`;
const { ipcRenderer } = window; const { ipcRenderer } = window;
const requestItems = filter(parentItem.items, (i) => i.type !== 'folder');
itemToSave.seq = requestItems ? (requestItems.length + 1) : 1;
itemSchema itemSchema
.validate(itemToSave) .validate(itemToSave)
@ -360,8 +365,6 @@ export const moveItem = (collectionUid, draggedItemUid, targetItemUid) => (dispa
moveCollectionItem(collectionCopy, draggedItem, targetItem); moveCollectionItem(collectionCopy, draggedItem, targetItem);
const itemsToResequence = getItemsToResequence(draggedItemParent, collectionCopy); const itemsToResequence = getItemsToResequence(draggedItemParent, collectionCopy);
const itemsToResequence2 = getItemsToResequence(targetItemParent, collectionCopy); const itemsToResequence2 = getItemsToResequence(targetItemParent, collectionCopy);
console.log('itemsToResequence', itemsToResequence);
console.log('itemsToResequence2', itemsToResequence2);
return ipcRenderer return ipcRenderer
.invoke('renderer:move-file-item', draggedItemPathname, targetItemParent.pathname) .invoke('renderer:move-file-item', draggedItemPathname, targetItemParent.pathname)
@ -455,15 +458,23 @@ export const moveItemToRootOfCollection = (collectionUid, draggedItemUid) => (di
const draggedItemPathname = draggedItem.pathname; const draggedItemPathname = draggedItem.pathname;
moveCollectionItemToRootOfCollection(collectionCopy, draggedItem); moveCollectionItemToRootOfCollection(collectionCopy, draggedItem);
const itemsToResequence = getItemsToResequence(draggedItemParent, collectionCopy);
const itemsToResequence2 = getItemsToResequence(collectionCopy, collectionCopy);
return ipcRenderer if(isItemAFolder(draggedItem)) {
.invoke('renderer:move-file-item', draggedItemPathname, collectionCopy.pathname) return ipcRenderer
.then(() => ipcRenderer.invoke('renderer:resequence-items', itemsToResequence)) .invoke('renderer:move-folder-item', draggedItemPathname, collectionCopy.pathname)
.then(() => ipcRenderer.invoke('renderer:resequence-items', itemsToResequence2)) .then(resolve)
.then(resolve) .catch((error) => reject(error));
.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); const filename = resolveRequestFilename(requestName);
if (!itemUid) { if (!itemUid) {
const reqWithSameNameExists = find(collection.items, (i) => i.type !== 'folder' && trim(i.filename) === trim(filename)); const reqWithSameNameExists = find(collection.items, (i) => i.type !== 'folder' && trim(i.filename) === trim(filename));
item.seq = collectionCopy.items ? collectionCopy.items.length : 1; const requestItems = filter(collection.items, (i) => i.type !== 'folder');
item.seq = item.seq + 1; item.seq = requestItems.length + 1;
if (!reqWithSameNameExists) { if (!reqWithSameNameExists) {
const fullName = `${collection.pathname}${PATH_SEPARATOR}${filename}`; const fullName = `${collection.pathname}${PATH_SEPARATOR}${filename}`;
@ -516,8 +527,8 @@ export const newHttpRequest = (params) => (dispatch, getState) => {
const currentItem = findItemInCollection(collection, itemUid); const currentItem = findItemInCollection(collection, itemUid);
if (currentItem) { if (currentItem) {
const reqWithSameNameExists = find(currentItem.items, (i) => i.type !== 'folder' && trim(i.filename) === trim(filename)); const reqWithSameNameExists = find(currentItem.items, (i) => i.type !== 'folder' && trim(i.filename) === trim(filename));
item.seq = currentItem.items ? currentItem.items.length : 1; const requestItems = filter(currentItem.items, (i) => i.type !== 'folder');
item.seq = item.seq + 1; item.seq = requestItems.length + 1;
if (!reqWithSameNameExists) { if (!reqWithSameNameExists) {
const fullName = `${currentItem.pathname}${PATH_SEPARATOR}${filename}`; const fullName = `${currentItem.pathname}${PATH_SEPARATOR}${filename}`;
const { ipcRenderer } = window; const { ipcRenderer } = window;

View File

@ -164,7 +164,11 @@ export const moveCollectionItemToRootOfCollection = (collection, draggedItem) =>
draggedItemParent.items = filter(draggedItemParent.items, (i) => i.uid !== draggedItem.uid); draggedItemParent.items = filter(draggedItemParent.items, (i) => i.uid !== draggedItem.uid);
collection.items.push(draggedItem); 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) => { export const getItemsToResequence = (parent, collection) => {