Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia
TypeScript apiapi-clientapi-restapi-testingdeveloper-toolsgraphqlhttphttp-clientpwarestrest-apispatestingtesting-toolstoolsvuevuejswebsocket
fix: move collection and request to bottom of list (#2964)
Nivedin1d397af6743a
diff --git a/packages/hoppscotch-common/src/components/collections/Collection.vue b/packages/hoppscotch-common/src/components/collections/Collection.vueindex 9a8695a3e..7babb29f1 100644--- a/packages/hoppscotch-common/src/components/collections/Collection.vue+++ b/packages/hoppscotch-common/src/components/collections/Collection.vue@@ -165,6 +165,20 @@</div></div></div>+ <div+ v-if="isLastItem"+ class="w-full transition"+ :class="[+ {+ 'bg-accentDark': isLastItemReorderable,+ 'h-1 ': isLastItem,+ },+ ]"+ @drop="updateLastItemOrder"+ @dragover.prevent="orderingLastItem = true"+ @dragleave="orderingLastItem = false"+ @dragend="resetDragState"+ ></div></div></template>@@ -249,6 +263,11 @@ const props = defineProps({default: () => [],required: false,},+ isLastItem: {+ type: Boolean,+ default: false,+ required: false,+ },})const emit = defineEmits<{@@ -262,6 +281,7 @@ const emit = defineEmits<{(event: "drag-event", payload: DataTransfer): void(event: "dragging", payload: boolean): void(event: "update-collection-order", payload: DataTransfer): void+ (event: "update-last-collection-order", payload: DataTransfer): void}>()const tippyActions = ref<TippyComponent | null>(null)@@ -274,6 +294,7 @@ const options = ref<TippyComponent | null>(null)const dragging = ref(false)const ordering = ref(false)+const orderingLastItem = ref(false)const dropItemID = ref("")const currentReorderingStatus = useReadonlyStream(currentReorderingStatus$, {@@ -333,6 +354,14 @@ const isReorderable = computed(() => {isSameParent.value)})+const isLastItemReorderable = computed(() => {+ return (+ orderingLastItem.value &&+ notSameDestination.value &&+ !isRequestDragging.value &&+ isSameParent.value+ )+})const dragStart = ({ dataTransfer }: DragEvent) => {if (dataTransfer) {@@ -350,17 +379,35 @@ const dragStart = ({ dataTransfer }: DragEvent) => {// Trigger the re-ordering event when a collection is dragged over another collection's top sectionconst handleDragOver = (e: DragEvent) => {dragging.value = true- if (e.offsetY < 10 && notSameDestination.value) {+ if (+ e.offsetY < 10 &&+ notSameDestination.value &&+ !isRequestDragging.value &&+ isSameParent.value+ ) {ordering.value = truedragging.value = false+ orderingLastItem.value = false+ } else if (+ e.offsetY > 18 &&+ notSameDestination.value &&+ !isRequestDragging.value &&+ isSameParent.value+ ) {+ orderingLastItem.value = true+ dragging.value = false+ ordering.value = false} else {ordering.value = false+ orderingLastItem.value = false}}const handelDrop = (e: DragEvent) => {if (ordering.value) {orderUpdateCollectionEvent(e)+ } else if (orderingLastItem.value) {+ updateLastItemOrder(e)} else {dropEvent(e)}@@ -382,6 +429,14 @@ const orderUpdateCollectionEvent = (e: DragEvent) => {}}+const updateLastItemOrder = (e: DragEvent) => {+ if (e.dataTransfer) {+ e.stopPropagation()+ emit("update-last-collection-order", e.dataTransfer)+ resetDragState()+ }+}+const notSameDestination = computed(() => {return dropItemID.value !== props.id})@@ -397,5 +452,6 @@ const isCollLoading = computed(() => {const resetDragState = () => {dragging.value = falseordering.value = false+ orderingLastItem.value = false}</script>diff --git a/packages/hoppscotch-common/src/components/collections/MyCollections.vue b/packages/hoppscotch-common/src/components/collections/MyCollections.vueindex d09b93a45..ca13025a4 100644--- a/packages/hoppscotch-common/src/components/collections/MyCollections.vue+++ b/packages/hoppscotch-common/src/components/collections/MyCollections.vue@@ -43,6 +43,7 @@:data="node.data.data.data":collections-type="collectionsType.type":is-open="isOpen"+ :is-last-item="node.data.isLastItem":is-selected="isSelected({collectionIndex: parseInt(node.id),@@ -77,7 +78,18 @@@remove-collection="emit('remove-collection', node.id)"@drop-event="dropEvent($event, node.id)"@drag-event="dragEvent($event, node.id)"- @update-collection-order="updateCollectionOrder($event, node.id)"+ @update-collection-order="+ updateCollectionOrder($event, {+ destinationCollectionIndex: node.id,+ destinationCollectionParentIndex: node.data.data.parentIndex,+ })+ "+ @update-last-collection-order="+ updateCollectionOrder($event, {+ destinationCollectionIndex: null,+ destinationCollectionParentIndex: node.data.data.parentIndex,+ })+ "@dragging="(isDraging) => highlightChildren(isDraging ? node.id : null)"@@ -99,6 +111,7 @@:data="node.data.data.data":collections-type="collectionsType.type":is-open="isOpen"+ :is-last-item="node.data.isLastItem":is-selected="isSelected({folderPath: node.id,@@ -133,7 +146,18 @@@remove-collection="emit('remove-folder', node.id)"@drop-event="dropEvent($event, node.id)"@drag-event="dragEvent($event, node.id)"- @update-collection-order="updateCollectionOrder($event, node.id)"+ @update-collection-order="+ updateCollectionOrder($event, {+ destinationCollectionIndex: node.id,+ destinationCollectionParentIndex: node.data.data.parentIndex,+ })+ "+ @update-last-collection-order="+ updateCollectionOrder($event, {+ destinationCollectionIndex: null,+ destinationCollectionParentIndex: node.data.data.parentIndex,+ })+ "@dragging="(isDraging) => highlightChildren(isDraging ? node.id : null)"@@ -155,6 +179,7 @@:parent-i-d="node.data.data.parentIndex":collections-type="collectionsType.type":save-request="saveRequest"+ :is-last-item="node.data.isLastItem":is-active="isActiveRequest(node.data.data.parentIndex,@@ -209,6 +234,12 @@requestIndex: node.id,})"+ @update-last-request-order="+ updateRequestOrder($event, {+ folderPath: node.data.data.parentIndex,+ requestIndex: null,+ })+ "/></template><template #emptyNode="{ node }">@@ -305,6 +336,7 @@ import { currentActiveTab } from "~/helpers/rest/tab"export type Collection = {type: "collections"+ isLastItem: booleandata: {parentIndex: nulldata: HoppCollection<HoppRESTRequest>@@ -313,6 +345,7 @@ export type Collection = {type Folder = {type: "folders"+ isLastItem: booleandata: {parentIndex: stringdata: HoppCollection<HoppRESTRequest>@@ -321,6 +354,7 @@ type Folder = {type Requests = {type: "requests"+ isLastItem: booleandata: {parentIndex: stringdata: HoppRESTRequest@@ -450,7 +484,7 @@ const emit = defineEmits<{event: "update-request-order",payload: {dragedRequestIndex: string- destinationRequestIndex: string+ destinationRequestIndex: string | nulldestinationCollectionIndex: string}): void@@ -458,7 +492,10 @@ const emit = defineEmits<{event: "update-collection-order",payload: {dragedCollectionIndex: string- destinationCollectionIndex: string+ destinationCollection: {+ destinationCollectionIndex: string | null+ destinationCollectionParentIndex: string | null+ }}): void(event: "select", payload: Picked | null): void@@ -589,7 +626,7 @@ const updateRequestOrder = ({folderPath,requestIndex,- }: { folderPath: string | null; requestIndex: string }+ }: { folderPath: string | null; requestIndex: string | null }) => {if (!folderPath) returnconst dragedRequestIndex = dataTransfer.getData("requestIndex")@@ -605,13 +642,16 @@ const updateRequestOrder = (const updateCollectionOrder = (dataTransfer: DataTransfer,- destinationCollectionIndex: string+ destinationCollection: {+ destinationCollectionIndex: string | null+ destinationCollectionParentIndex: string | null+ }) => {const dragedCollectionIndex = dataTransfer.getData("collectionIndex")emit("update-collection-order", {dragedCollectionIndex,- destinationCollectionIndex,+ destinationCollection,})}@@ -641,6 +681,7 @@ class MyCollectionsAdapter implements SmartTreeAdapter<MyCollectionNode> {id: index.toString(),data: {type: "collections",+ isLastItem: index === this.data.value.length - 1,data: {parentIndex: null,data: item,@@ -662,23 +703,25 @@ class MyCollectionsAdapter implements SmartTreeAdapter<MyCollectionNode> {if (item) {const data = [- ...item.folders.map((item, index) => ({+ ...item.folders.map((folder, index) => ({id: `${id}/${index}`,data: {+ isLastItem: index === item.folders.length - 1,type: "folders",data: {parentIndex: id,- data: item,+ data: folder,},},})),- ...item.requests.map((item, index) => ({+ ...item.requests.map((requests, index) => ({id: `${id}/${index}`,data: {+ isLastItem: index === item.requests.length - 1,type: "requests",data: {parentIndex: id,- data: item,+ data: requests,},},})),diff --git a/packages/hoppscotch-common/src/components/collections/Request.vue b/packages/hoppscotch-common/src/components/collections/Request.vueindex 3aab24047..7defd39ad 100644--- a/packages/hoppscotch-common/src/components/collections/Request.vue+++ b/packages/hoppscotch-common/src/components/collections/Request.vue@@ -1,13 +1,13 @@<template><div class="flex flex-col"><div- class="h-1"+ class="h-1 w-full transition":class="[{'bg-accentDark': isReorderable,},]"- @drop="dropEvent"+ @drop="updateRequestOrder"@dragover.prevent="ordering = true"@dragleave="resetDragState"@dragend="resetDragState"@@ -15,7 +15,7 @@<divclass="flex items-stretch group":draggable="!hasNoTeamAccess"- @drop="dropEvent"+ @drop="handelDrop"@dragstart="dragStart"@dragover="handleDragOver($event)"@dragleave="resetDragState"@@ -138,6 +138,19 @@</span></div></div>+ <div+ class="w-full transition"+ :class="[+ {+ 'bg-accentDark': isLastItemReorderable,+ 'h-1 ': isLastItem,+ },+ ]"+ @drop="handelDrop"+ @dragover.prevent="orderingLastItem = true"+ @dragleave="resetDragState"+ @dragend="resetDragState"+ ></div></div></template>@@ -214,6 +227,11 @@ const props = defineProps({default: () => [],required: false,},+ isLastItem: {+ type: Boolean,+ default: false,+ required: false,+ },})const emit = defineEmits<{@@ -223,6 +241,7 @@ const emit = defineEmits<{(event: "select-request"): void(event: "drag-request", payload: DataTransfer): void(event: "update-request-order", payload: DataTransfer): void+ (event: "update-last-request-order", payload: DataTransfer): void}>()const tippyActions = ref<TippyComponent | null>(null)@@ -233,6 +252,7 @@ const duplicate = ref<HTMLButtonElement | null>(null)const dragging = ref(false)const ordering = ref(false)+const orderingLastItem = ref(false)const currentReorderingStatus = useReadonlyStream(currentReorderingStatus$, {type: "collection",@@ -269,6 +289,10 @@ const dragStart = ({ dataTransfer }: DragEvent) => {}}+const isSameRequest = computed(() => {+ return currentReorderingStatus.value.id === props.requestID+})+const isCollectionDragging = computed(() => {return currentReorderingStatus.value.type === "collection"})@@ -278,7 +302,18 @@ const isSameParent = computed(() => {})const isReorderable = computed(() => {- return ordering.value && !isCollectionDragging.value && isSameParent.value+ return (+ ordering.value &&+ !isCollectionDragging.value &&+ isSameParent.value &&+ !isSameRequest.value+ )+})++const isLastItemReorderable = computed(() => {+ return (+ orderingLastItem.value && isSameParent.value && !isCollectionDragging.value+ )})// Trigger the re-ordering event when a request is dragged over another request's top section@@ -287,12 +322,28 @@ const handleDragOver = (e: DragEvent) => {if (e.offsetY < 10) {ordering.value = truedragging.value = false+ orderingLastItem.value = false+ } else if (e.offsetY > 18) {+ orderingLastItem.value = true+ dragging.value = false+ ordering.value = false} else {ordering.value = false+ orderingLastItem.value = false+ }+}++const handelDrop = (e: DragEvent) => {+ if (ordering.value) {+ updateRequestOrder(e)+ } else if (orderingLastItem.value) {+ updateLastItemOrder(e)+ } else {+ updateRequestOrder(e)}}-const dropEvent = (e: DragEvent) => {+const updateRequestOrder = (e: DragEvent) => {if (e.dataTransfer) {e.stopPropagation()resetDragState()@@ -300,6 +351,14 @@ const dropEvent = (e: DragEvent) => {}}+const updateLastItemOrder = (e: DragEvent) => {+ if (e.dataTransfer) {+ e.stopPropagation()+ resetDragState()+ emit("update-last-request-order", e.dataTransfer)+ }+}+const isRequestLoading = computed(() => {if (props.requestMoveLoading.length > 0 && props.requestID) {return props.requestMoveLoading.includes(props.requestID)@@ -311,5 +370,6 @@ const isRequestLoading = computed(() => {const resetDragState = () => {dragging.value = falseordering.value = false+ orderingLastItem.value = false}</script>diff --git a/packages/hoppscotch-common/src/components/collections/TeamCollections.vue b/packages/hoppscotch-common/src/components/collections/TeamCollections.vueindex 3660c23b7..2c7a8c379 100644--- a/packages/hoppscotch-common/src/components/collections/TeamCollections.vue+++ b/packages/hoppscotch-common/src/components/collections/TeamCollections.vue@@ -60,6 +60,7 @@:export-loading="exportLoading":has-no-team-access="hasNoTeamAccess":collection-move-loading="collectionMoveLoading"+ :is-last-item="node.data.isLastItem":is-selected="isSelected({collectionID: node.id,@@ -95,7 +96,16 @@@drop-event="dropEvent($event, node.id)"@drag-event="dragEvent($event, node.id)"@update-collection-order="- updateCollectionOrder($event, node.data.data.data.id)+ updateCollectionOrder($event, {+ destinationCollectionIndex: node.data.data.data.id,+ destinationCollectionParentIndex: node.data.data.parentIndex,+ })+ "+ @update-last-collection-order="+ updateCollectionOrder($event, {+ destinationCollectionIndex: null,+ destinationCollectionParentIndex: node.data.data.parentIndex,+ })"@dragging="(isDraging) =>@@ -122,6 +132,7 @@:export-loading="exportLoading":has-no-team-access="hasNoTeamAccess":collection-move-loading="collectionMoveLoading"+ :is-last-item="node.data.isLastItem":is-selected="isSelected({folderID: node.data.data.data.id,@@ -159,7 +170,16 @@@drop-event="dropEvent($event, node.data.data.data.id)"@drag-event="dragEvent($event, node.data.data.data.id)"@update-collection-order="- updateCollectionOrder($event, node.data.data.data.id)+ updateCollectionOrder($event, {+ destinationCollectionIndex: node.data.data.data.id,+ destinationCollectionParentIndex: node.data.data.parentIndex,+ })+ "+ @update-last-collection-order="+ updateCollectionOrder($event, {+ destinationCollectionIndex: null,+ destinationCollectionParentIndex: node.data.data.parentIndex,+ })"@dragging="(isDraging) =>@@ -186,6 +206,7 @@:is-active="isActiveRequest(node.data.data.data.id)":has-no-team-access="hasNoTeamAccess":request-move-loading="requestMoveLoading"+ :is-last-item="node.data.isLastItem":is-selected="isSelected({requestID: node.data.data.data.id,@@ -231,6 +252,12 @@requestIndex: node.data.data.data.id,})"+ @update-last-request-order="+ updateRequestOrder($event, {+ folderPath: node.data.data.parentIndex,+ requestIndex: null,+ })+ "/></template><template #emptyNode="{ node }">@@ -461,7 +488,7 @@ const emit = defineEmits<{event: "update-request-order",payload: {dragedRequestIndex: string- destinationRequestIndex: string+ destinationRequestIndex: string | nulldestinationCollectionIndex: string}): void@@ -469,7 +496,10 @@ const emit = defineEmits<{event: "update-collection-order",payload: {dragedCollectionIndex: string- destinationCollectionIndex: string+ destinationCollection: {+ destinationCollectionIndex: string | null+ destinationCollectionParentIndex: string | null+ }}): void(event: "select", payload: Picked | null): void@@ -597,7 +627,7 @@ const updateRequestOrder = ({folderPath,requestIndex,- }: { folderPath: string | null; requestIndex: string }+ }: { folderPath: string | null; requestIndex: string | null }) => {if (!folderPath) returnconst dragedRequestIndex = dataTransfer.getData("requestIndex")@@ -613,17 +643,21 @@ const updateRequestOrder = (const updateCollectionOrder = (dataTransfer: DataTransfer,- destinationCollectionIndex: string+ destinationCollection: {+ destinationCollectionIndex: string | null+ destinationCollectionParentIndex: string | null+ }) => {const dragedCollectionIndex = dataTransfer.getData("collectionIndex")emit("update-collection-order", {dragedCollectionIndex,- destinationCollectionIndex,+ destinationCollection,})}type TeamCollections = {+ isLastItem: booleantype: "collections"data: {parentIndex: null@@ -632,6 +666,7 @@ type TeamCollections = {}type TeamFolder = {+ isLastItem: booleantype: "folders"data: {parentIndex: string@@ -640,6 +675,7 @@ type TeamFolder = {}type TeamRequests = {+ isLastItem: booleantype: "requests"data: {parentIndex: string@@ -679,9 +715,10 @@ class TeamCollectionsAdapter implements SmartTreeAdapter<TeamCollectionNode> {status: "loading",}} else {- const data = this.data.value.map((item) => ({+ const data = this.data.value.map((item, index) => ({id: item.id,data: {+ isLastItem: index === this.data.value.length - 1,type: "collections",data: {parentIndex: null,@@ -709,9 +746,10 @@ class TeamCollectionsAdapter implements SmartTreeAdapter<TeamCollectionNode> {if (items) {const data = [...(items.children- ? items.children.map((item) => ({+ ? items.children.map((item, index) => ({id: `${id}/${item.id}`,data: {+ isLastItem: index === items.children.length - 1,type: "folders",data: {parentIndex: parsedID,@@ -721,9 +759,10 @@ class TeamCollectionsAdapter implements SmartTreeAdapter<TeamCollectionNode> {})): []),...(items.requests- ? items.requests.map((item) => ({+ ? items.requests.map((item, index) => ({id: `${id}/${item.id}`,data: {+ isLastItem: index === items.requests.length - 1,type: "requests",data: {parentIndex: parsedID,diff --git a/packages/hoppscotch-common/src/components/collections/index.vue b/packages/hoppscotch-common/src/components/collections/index.vueindex 79925d556..61d53a996 100644--- a/packages/hoppscotch-common/src/components/collections/index.vue+++ b/packages/hoppscotch-common/src/components/collections/index.vue@@ -2,7 +2,8 @@<div:class="{'rounded border border-divider': saveRequest,- 'bg-primaryDark': draggingToRoot,+ 'bg-primaryDark':+ draggingToRoot && currentReorderingStatus.type !== 'request',}"class="flex-1"@drop.prevent="dropToRoot"@@ -85,7 +86,9 @@/><divclass="hidden bg-primaryDark flex-col flex-1 items-center py-15 justify-center px-4 text-secondaryLight"- :class="{ '!flex': draggingToRoot }"+ :class="{+ '!flex': draggingToRoot && currentReorderingStatus.type !== 'request',+ }"><component :is="IconListEnd" class="svg-icons !w-8 !h-8" /></div>@@ -232,6 +235,7 @@ import {resolveSaveContextOnCollectionReorder,updateSaveContextForAffectedRequests,} from "~/helpers/collection/collection"+import { currentReorderingStatus$ } from "~/newstore/reordering"const t = useI18n()const toast = useToast()@@ -396,6 +400,12 @@ watch(})+const currentReorderingStatus = useReadonlyStream(currentReorderingStatus$, {+ type: "collection",+ id: "",+ parentID: "",+})+const hasTeamWriteAccess = computed(() => {if (!collectionsType.value.selectedTeam) return false@@ -1525,27 +1535,49 @@ const dropToRoot = ({ dataTransfer }: DragEvent) => {/*** Used to check if the request/collection is being moved to the same parent since reorder is only allowed within the same parent- * @param draggedReq - path index of the dragged request- * @param destinationReq - path index of the destination request+ * @param draggedItem - path index of the dragged request+ * @param destinationItem - path index of the destination request+ * @param destinationCollectionIndex - index of the destination collection* @returns boolean - true if the request is being moved to the same parent*/-const isSameSameParent = (draggedItem: string, destinationItem: string) => {- const draggedItemIndex = pathToIndex(draggedItem)- const destinationItemIndex = pathToIndex(destinationItem)-- // length of 1 means the request is in the root- if (draggedItemIndex.length === 1 && destinationItemIndex.length === 1) {- return true- } else if (draggedItemIndex.length === destinationItemIndex.length) {+const isSameSameParent = (+ draggedItemPath: string,+ destinationItemPath: string | null,+ destinationCollectionIndex: string | null+) => {+ const draggedItemIndex = pathToIndex(draggedItemPath)++ // if the destinationItemPath and destinationCollectionIndex is null, it means the request is being moved to the root+ if (destinationItemPath === null && destinationCollectionIndex === null) {+ return draggedItemIndex.length === 1+ } else if (+ destinationItemPath === null &&+ destinationCollectionIndex !== null &&+ draggedItemIndex.length === 1+ ) {+ return draggedItemIndex[0] === destinationCollectionIndex+ } else if (destinationItemPath === null && draggedItemIndex.length !== 1) {const dragedItemParent = draggedItemIndex.slice(0, -1)- const destinationItemParent = destinationItemIndex.slice(0, -1)- if (isEqual(dragedItemParent, destinationItemParent)) {++ return dragedItemParent[0] === destinationCollectionIndex+ } else {+ if (destinationItemPath === null) return false+ const destinationItemIndex = pathToIndex(destinationItemPath)++ // length of 1 means the request is in the root+ if (draggedItemIndex.length === 1 && destinationItemIndex.length === 1) {return true+ } else if (draggedItemIndex.length === destinationItemIndex.length) {+ const dragedItemParent = draggedItemIndex.slice(0, -1)+ const destinationItemParent = destinationItemIndex.slice(0, -1)+ if (isEqual(dragedItemParent, destinationItemParent)) {+ return true+ } else {+ return false+ }} else {return false}- } else {- return false}}@@ -1556,7 +1588,7 @@ const isSameSameParent = (draggedItem: string, destinationItem: string) => {*/const updateRequestOrder = (payload: {dragedRequestIndex: string- destinationRequestIndex: string+ destinationRequestIndex: string | nulldestinationCollectionIndex: string}) => {const {@@ -1565,29 +1597,28 @@ const updateRequestOrder = (payload: {destinationCollectionIndex,} = payload- if (- !dragedRequestIndex ||- !destinationRequestIndex ||- !destinationCollectionIndex- )- return+ if (!dragedRequestIndex || !destinationCollectionIndex) returnif (dragedRequestIndex === destinationRequestIndex) returnif (collectionsType.value.type === "my-collections") {- if (!isSameSameParent(dragedRequestIndex, destinationRequestIndex)) {+ if (+ !isSameSameParent(+ dragedRequestIndex,+ destinationRequestIndex,+ destinationCollectionIndex+ )+ ) {toast.error(`${t("collection.different_parent")}`)} else {updateRESTRequestOrder(pathToLastIndex(dragedRequestIndex),- pathToLastIndex(destinationRequestIndex),+ destinationRequestIndex+ ? pathToLastIndex(destinationRequestIndex)+ : null,destinationCollectionIndex)- resolveSaveContextOnRequestReorder({- lastIndex: pathToLastIndex(dragedRequestIndex),- newIndex: pathToLastIndex(destinationRequestIndex),- folderPath: destinationCollectionIndex,- })+toast.success(`${t("request.order_changed")}`)}} else if (hasTeamWriteAccess.value) {@@ -1628,14 +1659,25 @@ const updateRequestOrder = (payload: {*/const updateCollectionOrder = (payload: {dragedCollectionIndex: string- destinationCollectionIndex: string+ destinationCollection: {+ destinationCollectionIndex: string | null+ destinationCollectionParentIndex: string | null+ }}) => {- const { dragedCollectionIndex, destinationCollectionIndex } = payload- if (!dragedCollectionIndex || !destinationCollectionIndex) return+ const { dragedCollectionIndex, destinationCollection } = payload+ const { destinationCollectionIndex, destinationCollectionParentIndex } =+ destinationCollection+ if (!dragedCollectionIndex) returnif (dragedCollectionIndex === destinationCollectionIndex) returnif (collectionsType.value.type === "my-collections") {- if (!isSameSameParent(dragedCollectionIndex, destinationCollectionIndex)) {+ if (+ !isSameSameParent(+ dragedCollectionIndex,+ destinationCollectionIndex,+ destinationCollectionParentIndex+ )+ ) {toast.error(`${t("collection.different_parent")}`)} else {updateRESTCollectionOrder(@@ -1644,7 +1686,9 @@ const updateCollectionOrder = (payload: {)resolveSaveContextOnCollectionReorder({lastIndex: pathToLastIndex(dragedCollectionIndex),- newIndex: pathToLastIndex(destinationCollectionIndex),+ newIndex: pathToLastIndex(+ destinationCollectionIndex ? destinationCollectionIndex : ""+ ),folderPath: dragedCollectionIndex.split("/").slice(0, -1).join("/"),})toast.success(`${t("collection.order_changed")}`)diff --git a/packages/hoppscotch-common/src/helpers/backend/gql/mutations/UpdateCollectionOrder.graphql b/packages/hoppscotch-common/src/helpers/backend/gql/mutations/UpdateCollectionOrder.graphqlindex fdc422fa2..cb5bff551 100644--- a/packages/hoppscotch-common/src/helpers/backend/gql/mutations/UpdateCollectionOrder.graphql+++ b/packages/hoppscotch-common/src/helpers/backend/gql/mutations/UpdateCollectionOrder.graphql@@ -1,3 +1,3 @@-mutation UpdateCollectionOrder($collectionID: ID!, $destCollID: ID!) {+mutation UpdateCollectionOrder($collectionID: ID!, $destCollID: ID) {updateCollectionOrder(collectionID: $collectionID, destCollID: $destCollID)}diff --git a/packages/hoppscotch-common/src/helpers/backend/mutations/TeamCollection.ts b/packages/hoppscotch-common/src/helpers/backend/mutations/TeamCollection.tsindex 23a450897..90ae55af6 100644--- a/packages/hoppscotch-common/src/helpers/backend/mutations/TeamCollection.ts+++ b/packages/hoppscotch-common/src/helpers/backend/mutations/TeamCollection.ts@@ -103,7 +103,7 @@ export const moveRESTTeamCollection = (export const updateOrderRESTTeamCollection = (collectionID: string,- destCollID: string+ destCollID: string | null) =>runMutation<UpdateCollectionOrderMutation,diff --git a/packages/hoppscotch-common/src/helpers/backend/mutations/TeamRequest.ts b/packages/hoppscotch-common/src/helpers/backend/mutations/TeamRequest.tsindex daff454a5..184f1910a 100644--- a/packages/hoppscotch-common/src/helpers/backend/mutations/TeamRequest.ts+++ b/packages/hoppscotch-common/src/helpers/backend/mutations/TeamRequest.ts@@ -84,7 +84,7 @@ export const moveRESTTeamRequest = (collectionID: string, requestID: string) =>export const updateOrderRESTTeamRequest = (requestID: string,- nextRequestID: string,+ nextRequestID: string | null,collectionID: string) =>runMutation<diff --git a/packages/hoppscotch-common/src/helpers/teams/TeamCollectionAdapter.ts b/packages/hoppscotch-common/src/helpers/teams/TeamCollectionAdapter.tsindex aee9af86f..681bfb174 100644--- a/packages/hoppscotch-common/src/helpers/teams/TeamCollectionAdapter.ts+++ b/packages/hoppscotch-common/src/helpers/teams/TeamCollectionAdapter.ts@@ -558,67 +558,112 @@ export default class NewTeamCollectionAdapter {public updateRequestOrder(dragedRequestID: string,- destinationRequestID: string,+ destinationRequestID: string | null,destinationCollectionID: string) {const tree = this.collections$.value- // Find collection in tree, don't attempt if no collection is found- const collection = findCollInTree(tree, destinationCollectionID)- if (!collection) return // Ignore order update+ // If the destination request is null, then it is the last request in the collection+ if (destinationRequestID === null) {+ const collection = findCollInTree(tree, destinationCollectionID)- // Collection is not expanded- if (!collection.requests) return+ if (!collection) return // Ignore order update- const requestIndex = collection.requests.findIndex(- (req) => req.id === dragedRequestID- )- const destinationIndex = collection.requests.findIndex(- (req) => req.id === destinationRequestID- )+ // Collection is not expanded+ if (!collection.requests) return++ const requestIndex = collection.requests.findIndex(+ (req) => req.id === dragedRequestID+ )++ // If the collection index is not found, don't update+ if (requestIndex === -1) return++ // Move the request to the end of the requests+ collection.requests.push(collection.requests.splice(requestIndex, 1)[0])+ } else {+ // Find collection in tree, don't attempt if no collection is found+ const collection = findCollInTree(tree, destinationCollectionID)+ if (!collection) return // Ignore order update- if (requestIndex === -1) return+ // Collection is not expanded+ if (!collection.requests) return- this.reorderItems(collection.requests, requestIndex, destinationIndex)+ const requestIndex = collection.requests.findIndex(+ (req) => req.id === dragedRequestID+ )+ const destinationIndex = collection.requests.findIndex(+ (req) => req.id === destinationRequestID+ )++ if (requestIndex === -1) return++ this.reorderItems(collection.requests, requestIndex, destinationIndex)+ }this.collections$.next(tree)}public updateCollectionOrder = (collectionID: string,- destinationCollectionID: string+ destinationCollectionID: string | null) => {const tree = this.collections$.value- // Find collection in tree- const coll = findParentOfColl(tree, destinationCollectionID)-- // If the collection has a parent collection and check if it has children- if (coll && coll.children) {- const collectionIndex = coll.children.findIndex(- (coll) => coll.id === collectionID- )+ // If the destination collection is null, then it is the last collection in the tree+ if (destinationCollectionID === null) {+ const collLast = findParentOfColl(tree, collectionID)+ if (collLast && collLast.children) {+ const collectionIndex = collLast.children.findIndex(+ (coll) => coll.id === collectionID+ )- const destinationIndex = coll.children.findIndex(- (coll) => coll.id === destinationCollectionID- )+ // reorder the collection to the end of the collections+ collLast.children.push(collLast.children.splice(collectionIndex, 1)[0])+ } else {+ const collectionIndex = tree.findIndex(+ (coll) => coll.id === collectionID+ )- // If the collection index is not found, don't update- if (collectionIndex === -1) return+ // If the collection index is not found, don't update+ if (collectionIndex === -1) return- this.reorderItems(coll.children, collectionIndex, destinationIndex)+ // reorder the collection to the end of the collections in the root+ tree.push(tree.splice(collectionIndex, 1)[0])+ }} else {- // If the collection has no parent collection, it is a root collection- const collectionIndex = tree.findIndex((coll) => coll.id === collectionID)+ // Find collection in tree+ const coll = findParentOfColl(tree, destinationCollectionID)- const destinationIndex = tree.findIndex(- (coll) => coll.id === destinationCollectionID- )+ // If the collection has a parent collection and check if it has children+ if (coll && coll.children) {+ const collectionIndex = coll.children.findIndex(+ (coll) => coll.id === collectionID+ )- // If the collection index is not found, don't update- if (collectionIndex === -1) return+ const destinationIndex = coll.children.findIndex(+ (coll) => coll.id === destinationCollectionID+ )- this.reorderItems(tree, collectionIndex, destinationIndex)+ // If the collection index is not found, don't update+ if (collectionIndex === -1) return++ this.reorderItems(coll.children, collectionIndex, destinationIndex)+ } else {+ // If the collection has no parent collection, it is a root collection+ const collectionIndex = tree.findIndex(+ (coll) => coll.id === collectionID+ )++ const destinationIndex = tree.findIndex(+ (coll) => coll.id === destinationCollectionID+ )++ // If the collection index is not found, don't update+ if (collectionIndex === -1) return++ this.reorderItems(tree, collectionIndex, destinationIndex)+ }}this.collections$.next(tree)@@ -821,12 +866,10 @@ export default class NewTeamCollectionAdapter {const { request } = requestOrderUpdatedconst { nextRequest } = requestOrderUpdated- if (!nextRequest) return-this.updateRequestOrder(request.id,- nextRequest.id,- nextRequest.collectionID+ nextRequest ? nextRequest.id : null,+ nextRequest ? nextRequest.collectionID : request.collectionID)})@@ -851,9 +894,10 @@ export default class NewTeamCollectionAdapter {const { collection } = collectionOrderUpdatedconst { nextCollection } = collectionOrderUpdated- if (!nextCollection) return-- this.updateCollectionOrder(collection.id, nextCollection.id)+ this.updateCollectionOrder(+ collection.id,+ nextCollection ? nextCollection.id : null+ )})}diff --git a/packages/hoppscotch-common/src/newstore/collections.ts b/packages/hoppscotch-common/src/newstore/collections.tsindex 63870627d..aff9bd9b9 100644--- a/packages/hoppscotch-common/src/newstore/collections.ts+++ b/packages/hoppscotch-common/src/newstore/collections.ts@@ -8,6 +8,7 @@ import {import DispatchingStore, { defineDispatchers } from "./DispatchingStore"import { cloneDeep } from "lodash-es"import { getTabRefWithSaveContext } from "~/helpers/rest/tab"+import { resolveSaveContextOnRequestReorder } from "~/helpers/collection/request"const defaultRESTCollectionState = {state: [@@ -288,18 +289,49 @@ const restCollectionDispatchers = defineDispatchers({destinationCollectionIndex,}: {collectionIndex: string- destinationCollectionIndex: string+ destinationCollectionIndex: string | null}) {const newState = stateconst indexPaths = collectionIndex.split("/").map((x) => parseInt(x))+ if (indexPaths.length === 0) {+ console.log("Given path too short. Skipping request.")+ return {}+ }++ // Reordering the collection to the last position+ if (destinationCollectionIndex === null) {+ const folderIndex = indexPaths.pop() as number++ const containingFolder = navigateToFolderWithIndexPath(+ newState,+ indexPaths+ )++ if (containingFolder === null) {+ newState.push(newState.splice(folderIndex, 1)[0])+ return {+ state: newState,+ }+ }++ // Pushing the folder to the end of the array (last position)+ containingFolder.folders.push(+ containingFolder.folders.splice(folderIndex, 1)[0]+ )++ return {+ state: newState,+ }+ }+const destinationIndexPaths = destinationCollectionIndex.split("/").map((x) => parseInt(x))- if (indexPaths.length === 0 || destinationIndexPaths.length === 0) {+ if (destinationIndexPaths.length === 0) {console.log("Given path too short. Skipping request.")return {}}@@ -487,7 +519,7 @@ const restCollectionDispatchers = defineDispatchers({destinationCollectionPath,}: {requestIndex: number- destinationRequestIndex: number+ destinationRequestIndex: number | nulldestinationCollectionPath: string}) {@@ -511,8 +543,32 @@ const restCollectionDispatchers = defineDispatchers({return {}}+ // if the destination is null, we are moving to the end of the list+ if (destinationRequestIndex === null) {+ // move to the end of the list+ targetLocation.requests.push(+ targetLocation.requests.splice(requestIndex, 1)[0]+ )++ resolveSaveContextOnRequestReorder({+ lastIndex: requestIndex,+ newIndex: targetLocation.requests.length,+ folderPath: destinationCollectionPath,+ })++ return {+ state: newState,+ }+ }+reorderItems(targetLocation.requests, requestIndex, destinationRequestIndex)+ resolveSaveContextOnRequestReorder({+ lastIndex: requestIndex,+ newIndex: destinationRequestIndex,+ folderPath: destinationCollectionPath,+ })+return {state: newState,}@@ -967,7 +1023,7 @@ export function moveRESTRequest(export function updateRESTRequestOrder(requestIndex: number,- destinationRequestIndex: number,+ destinationRequestIndex: number | null,destinationCollectionPath: string) {restCollectionStore.dispatch({@@ -982,7 +1038,7 @@ export function updateRESTRequestOrder(export function updateRESTCollectionOrder(collectionIndex: string,- destinationCollectionIndex: string+ destinationCollectionIndex: string | null) {restCollectionStore.dispatch({dispatcher: "updateCollectionOrder",