From 141a4688083f0de9618bd31f1bf24ce88e433d0d Mon Sep 17 00:00:00 2001
From: Nivedin <53208152+nivedin@users.noreply.github.com>
Date: Wed, 5 Apr 2023 15:30:47 +0530
Subject: [PATCH 1/2] chore: update header UI (#2965)
---
.../src/components/app/Header.vue | 36 ++++++++-----------
.../src/components/app/Navigation.vue | 33 -----------------
2 files changed, 15 insertions(+), 54 deletions(-)
delete mode 100644 packages/hoppscotch-common/src/components/app/Navigation.vue
diff --git a/packages/hoppscotch-common/src/components/app/Header.vue b/packages/hoppscotch-common/src/components/app/Header.vue
index 53ab0a975..3df45f7aa 100644
--- a/packages/hoppscotch-common/src/components/app/Header.vue
+++ b/packages/hoppscotch-common/src/components/app/Header.vue
@@ -17,27 +17,13 @@
/>
-
-
-
-
-
- {{ t("app.search") }}
-
- /
-
+
-
-
+
-
-
-
-
-
-
-
From 1d397af6743a9d03f1c010dda6a50a8cccbb5193 Mon Sep 17 00:00:00 2001
From: Nivedin <53208152+nivedin@users.noreply.github.com>
Date: Wed, 5 Apr 2023 15:38:57 +0530
Subject: [PATCH 2/2] fix: move collection and request to bottom of list
(#2964)
---
.../src/components/collections/Collection.vue | 58 +++++++-
.../components/collections/MyCollections.vue | 65 +++++++--
.../src/components/collections/Request.vue | 70 +++++++++-
.../collections/TeamCollections.vue | 59 ++++++--
.../src/components/collections/index.vue | 112 ++++++++++-----
.../mutations/UpdateCollectionOrder.graphql | 2 +-
.../backend/mutations/TeamCollection.ts | 2 +-
.../helpers/backend/mutations/TeamRequest.ts | 2 +-
.../helpers/teams/TeamCollectionAdapter.ts | 132 ++++++++++++------
.../src/newstore/collections.ts | 66 ++++++++-
10 files changed, 455 insertions(+), 113 deletions(-)
diff --git a/packages/hoppscotch-common/src/components/collections/Collection.vue b/packages/hoppscotch-common/src/components/collections/Collection.vue
index 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 @@
+
@@ -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(null)
@@ -274,6 +294,7 @@ const options = ref(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 section
const handleDragOver = (e: DragEvent) => {
dragging.value = true
- if (e.offsetY < 10 && notSameDestination.value) {
+ if (
+ e.offsetY < 10 &&
+ notSameDestination.value &&
+ !isRequestDragging.value &&
+ isSameParent.value
+ ) {
ordering.value = true
dragging.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 = false
ordering.value = false
+ orderingLastItem.value = false
}
diff --git a/packages/hoppscotch-common/src/components/collections/MyCollections.vue b/packages/hoppscotch-common/src/components/collections/MyCollections.vue
index 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,
+ })
+ "
/>
@@ -305,6 +336,7 @@ import { currentActiveTab } from "~/helpers/rest/tab"
export type Collection = {
type: "collections"
+ isLastItem: boolean
data: {
parentIndex: null
data: HoppCollection
@@ -313,6 +345,7 @@ export type Collection = {
type Folder = {
type: "folders"
+ isLastItem: boolean
data: {
parentIndex: string
data: HoppCollection
@@ -321,6 +354,7 @@ type Folder = {
type Requests = {
type: "requests"
+ isLastItem: boolean
data: {
parentIndex: string
data: HoppRESTRequest
@@ -450,7 +484,7 @@ const emit = defineEmits<{
event: "update-request-order",
payload: {
dragedRequestIndex: string
- destinationRequestIndex: string
+ destinationRequestIndex: string | null
destinationCollectionIndex: 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) return
const 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 {
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 {
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.vue
index 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 @@
+
@@ -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(null)
@@ -233,6 +252,7 @@ const duplicate = ref(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 = true
dragging.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 dropEvent = (e: DragEvent) => {
+const handelDrop = (e: DragEvent) => {
+ if (ordering.value) {
+ updateRequestOrder(e)
+ } else if (orderingLastItem.value) {
+ updateLastItemOrder(e)
+ } else {
+ updateRequestOrder(e)
+ }
+}
+
+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 = false
ordering.value = false
+ orderingLastItem.value = false
}
diff --git a/packages/hoppscotch-common/src/components/collections/TeamCollections.vue b/packages/hoppscotch-common/src/components/collections/TeamCollections.vue
index 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,
+ })
+ "
/>
@@ -461,7 +488,7 @@ const emit = defineEmits<{
event: "update-request-order",
payload: {
dragedRequestIndex: string
- destinationRequestIndex: string
+ destinationRequestIndex: string | null
destinationCollectionIndex: 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) return
const 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: boolean
type: "collections"
data: {
parentIndex: null
@@ -632,6 +666,7 @@ type TeamCollections = {
}
type TeamFolder = {
+ isLastItem: boolean
type: "folders"
data: {
parentIndex: string
@@ -640,6 +675,7 @@ type TeamFolder = {
}
type TeamRequests = {
+ isLastItem: boolean
type: "requests"
data: {
parentIndex: string
@@ -679,9 +715,10 @@ class TeamCollectionsAdapter implements SmartTreeAdapter {
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 {
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 {
}))
: []),
...(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.vue
index 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 @@
@@ -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)
+const isSameSameParent = (
+ draggedItemPath: string,
+ destinationItemPath: string | null,
+ destinationCollectionIndex: string | null
+) => {
+ const draggedItemIndex = pathToIndex(draggedItemPath)
- // 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) {
+ // 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 | null
destinationCollectionIndex: string
}) => {
const {
@@ -1565,29 +1597,28 @@ const updateRequestOrder = (payload: {
destinationCollectionIndex,
} = payload
- if (
- !dragedRequestIndex ||
- !destinationRequestIndex ||
- !destinationCollectionIndex
- )
- return
+ if (!dragedRequestIndex || !destinationCollectionIndex) return
if (dragedRequestIndex === destinationRequestIndex) return
if (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) return
if (dragedCollectionIndex === destinationCollectionIndex) return
if (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.graphql
index 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.ts
index 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.ts
index 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.ts
index 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
- if (requestIndex === -1) return
+ const requestIndex = collection.requests.findIndex(
+ (req) => req.id === dragedRequestID
+ )
- this.reorderItems(collection.requests, requestIndex, destinationIndex)
+ // 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
+
+ // Collection is not expanded
+ if (!collection.requests) return
+
+ 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 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
+ )
- // 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
- )
+ // 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
+ )
- const destinationIndex = coll.children.findIndex(
- (coll) => coll.id === destinationCollectionID
- )
+ // 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 } = requestOrderUpdated
const { 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 } = collectionOrderUpdated
const { 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.ts
index 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 = state
const 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 | null
destinationCollectionPath: 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",