mirror of
https://github.com/Kong/insomnia.git
synced 2026-11-04 20:13:48 -05:00
fix:dragging a request to another collection within same project is allowed (#10612)
This commit is contained in:
1 file changed
+17
-9
+17
-9
@@ -99,9 +99,12 @@ function indentRemForLevel(level: number, depthOffset: number): number {
|
||||
|
||||
// Deeper and shallower side of a multi-depth gap, or null for a same-level
|
||||
// insert. Both raw forms of one gap map to the same pair.
|
||||
function resolveGapSides(
|
||||
{ dropPosition, targetItem, realTargetItem, nextItem }: BoundaryTargets,
|
||||
): { deep: CollectionChildFlatItem; shallow: CollectionChildFlatItem } | null {
|
||||
function resolveGapSides({
|
||||
dropPosition,
|
||||
targetItem,
|
||||
realTargetItem,
|
||||
nextItem,
|
||||
}: BoundaryTargets): { deep: CollectionChildFlatItem; shallow: CollectionChildFlatItem } | null {
|
||||
const otherItem = dropPosition === 'before' ? realTargetItem : nextItem;
|
||||
if (!isCollectionChild(targetItem) || !isCollectionChild(otherItem)) {
|
||||
return null;
|
||||
@@ -115,9 +118,7 @@ function resolveGapSides(
|
||||
if (dropPosition === 'after' && targetLevel < otherLevel) {
|
||||
return null;
|
||||
}
|
||||
return targetLevel > otherLevel
|
||||
? { deep: targetItem, shallow: otherItem }
|
||||
: { deep: otherItem, shallow: targetItem };
|
||||
return targetLevel > otherLevel ? { deep: targetItem, shallow: otherItem } : { deep: otherItem, shallow: targetItem };
|
||||
}
|
||||
|
||||
// react-stately treats `after X` and `before nextKey(X)` as one insertion point
|
||||
@@ -381,10 +382,10 @@ export function canDrop(
|
||||
return false;
|
||||
}
|
||||
|
||||
// move request and request group into collection
|
||||
// move request and request group into collection/design
|
||||
if (
|
||||
realDropItem.kind === 'workspace' &&
|
||||
models.workspace.isCollection(realDropItem.doc) &&
|
||||
(models.workspace.isCollection(realDropItem.doc) || models.workspace.isDesign(realDropItem.doc)) && // collection is same with design
|
||||
(models.requestGroup.isRequestGroup(dragItem.doc) || models.request.isRequest(dragItem.doc))
|
||||
) {
|
||||
// Repositioning inside its own collection is not a cross-collection move, so
|
||||
@@ -392,6 +393,10 @@ export function canDrop(
|
||||
if (isCollectionChild(dragItem) && dragItem.workspace._id === realDropItem.doc._id) {
|
||||
return true;
|
||||
}
|
||||
// allow if they are both part of the same project
|
||||
if (dragItem.project._id === realDropItem.project._id) {
|
||||
return true;
|
||||
}
|
||||
// Moving BETWEEN collections cannot involve cloud sync on either side.
|
||||
const dropInCloud = models.project.isRemoteProject(realDropItem.project);
|
||||
return !dragInCloud && !dropInCloud;
|
||||
@@ -806,7 +811,10 @@ export const useSidebarDragAndDrop = ({
|
||||
targetId: realTargetItem!.doc._id,
|
||||
id: draggedItem.doc._id,
|
||||
dropPosition: 'after', // collection only accepts move into, so treat all drops as "after"
|
||||
metaSortKey: firstChildOfCollection?.doc.metaSortKey != null ? firstChildOfCollection.doc.metaSortKey - 100 : -1 * Date.now(),
|
||||
metaSortKey:
|
||||
firstChildOfCollection?.doc.metaSortKey != null
|
||||
? firstChildOfCollection.doc.metaSortKey - 100
|
||||
: -1 * Date.now(),
|
||||
},
|
||||
});
|
||||
return;
|
||||
|
||||
Reference in new issue
Block a user