diff --git a/packages/hoppscotch-common/src/components/new-collections/rest/Collection.vue b/packages/hoppscotch-common/src/components/new-collections/rest/Collection.vue
index e22d572e6..f28567745 100644
--- a/packages/hoppscotch-common/src/components/new-collections/rest/Collection.vue
+++ b/packages/hoppscotch-common/src/components/new-collections/rest/Collection.vue
@@ -23,7 +23,7 @@
{
}
}
-const handelDrop = (e: DragEvent) => {
+const handleDrop = (e: DragEvent) => {
if (ordering.value) {
orderUpdateCollectionEvent(e)
} else if (orderingLastItem.value) {
diff --git a/packages/hoppscotch-common/src/components/new-collections/rest/index.vue b/packages/hoppscotch-common/src/components/new-collections/rest/index.vue
index 786a4a323..832f0ed7b 100644
--- a/packages/hoppscotch-common/src/components/new-collections/rest/index.vue
+++ b/packages/hoppscotch-common/src/components/new-collections/rest/index.vue
@@ -1255,7 +1255,10 @@ const dragRequest = (
requestIndex,
}: { parentCollectionIndexPath: string | null; requestIndex: string }
) => {
- if (!parentCollectionIndexPath) return
+ if (!parentCollectionIndexPath) {
+ return
+ }
+
dataTransfer.setData("parentCollectionIndexPath", parentCollectionIndexPath)
dataTransfer.setData("requestIndex", requestIndex)
}
diff --git a/packages/hoppscotch-common/src/services/new-workspace/index.ts b/packages/hoppscotch-common/src/services/new-workspace/index.ts
index 497f8bea1..9413207e1 100644
--- a/packages/hoppscotch-common/src/services/new-workspace/index.ts
+++ b/packages/hoppscotch-common/src/services/new-workspace/index.ts
@@ -476,6 +476,128 @@ export class NewWorkspaceService extends Service {
return E.right(result.right)
}
+ public async reorderRESTCollection(
+ collectionHandle: HandleRef,
+ destinationCollectionIndex: string
+ ): Promise<
+ E.Either, void>
+ > {
+ if (collectionHandle.value.type === "invalid") {
+ return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
+ }
+
+ const provider = this.registeredProviders.get(
+ collectionHandle.value.data.providerID
+ )
+
+ if (!provider) {
+ return E.left({ type: "SERVICE_ERROR", error: "INVALID_PROVIDER" })
+ }
+
+ const result = await provider.reorderRESTCollection(
+ collectionHandle,
+ destinationCollectionIndex
+ )
+
+ if (E.isLeft(result)) {
+ return E.left({ type: "PROVIDER_ERROR", error: result.left })
+ }
+
+ return E.right(result.right)
+ }
+
+ public async moveRESTCollection(
+ collectionHandle: HandleRef,
+ destinationCollectionIndex: string
+ ): Promise<
+ E.Either, void>
+ > {
+ if (collectionHandle.value.type === "invalid") {
+ return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
+ }
+
+ const provider = this.registeredProviders.get(
+ collectionHandle.value.data.providerID
+ )
+
+ if (!provider) {
+ return E.left({ type: "SERVICE_ERROR", error: "INVALID_PROVIDER" })
+ }
+
+ const result = await provider.moveRESTCollection(
+ collectionHandle,
+ destinationCollectionIndex
+ )
+
+ if (E.isLeft(result)) {
+ return E.left({ type: "PROVIDER_ERROR", error: result.left })
+ }
+
+ return E.right(result.right)
+ }
+
+ public async reorderRESTRequest(
+ requestHandle: HandleRef,
+ destinationRequestIndex: string,
+ destinationCollectionIndex: string
+ ): Promise<
+ E.Either, void>
+ > {
+ if (requestHandle.value.type === "invalid") {
+ return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
+ }
+
+ const provider = this.registeredProviders.get(
+ requestHandle.value.data.providerID
+ )
+
+ if (!provider) {
+ return E.left({ type: "SERVICE_ERROR", error: "INVALID_PROVIDER" })
+ }
+
+ const result = await provider.reorderRESTRequest(
+ requestHandle,
+ destinationRequestIndex,
+ destinationCollectionIndex
+ )
+
+ if (E.isLeft(result)) {
+ return E.left({ type: "PROVIDER_ERROR", error: result.left })
+ }
+
+ return E.right(result.right)
+ }
+
+ public async moveRESTRequest(
+ requestHandle: HandleRef,
+ destinationCollectionIndex: string
+ ): Promise<
+ E.Either, void>
+ > {
+ if (requestHandle.value.type === "invalid") {
+ return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
+ }
+
+ const provider = this.registeredProviders.get(
+ requestHandle.value.data.providerID
+ )
+
+ if (!provider) {
+ return E.left({ type: "SERVICE_ERROR", error: "INVALID_PROVIDER" })
+ }
+
+ const result = await provider.moveRESTRequest(
+ requestHandle,
+ destinationCollectionIndex
+ )
+
+ if (E.isLeft(result)) {
+ return E.left({ type: "PROVIDER_ERROR", error: result.left })
+ }
+
+ return E.right(result.right)
+ }
+
public async getRESTCollectionChildrenView(
collectionHandle: HandleRef
): Promise<
diff --git a/packages/hoppscotch-common/src/services/new-workspace/provider.ts b/packages/hoppscotch-common/src/services/new-workspace/provider.ts
index 5886d7422..99a5a43a2 100644
--- a/packages/hoppscotch-common/src/services/new-workspace/provider.ts
+++ b/packages/hoppscotch-common/src/services/new-workspace/provider.ts
@@ -80,4 +80,22 @@ export interface WorkspaceProvider {
collectionHandle: HandleRef,
collection: HoppCollection
): Promise>
+
+ reorderRESTCollection(
+ collectionHandle: HandleRef,
+ destinationCollectionIndex: string
+ ): Promise>
+ moveRESTCollection(
+ collectionHandle: HandleRef,
+ destinationCollectionIndex: string | null
+ ): Promise>
+ reorderRESTRequest(
+ requestHandle: HandleRef,
+ destinationRequestIndex: string,
+ destinationCollectionIndex: string
+ ): Promise>
+ moveRESTRequest(
+ requestHandle: HandleRef,
+ destinationCollectionIndex: string
+ ): Promise>
}
diff --git a/packages/hoppscotch-common/src/services/new-workspace/providers/personal.workspace.ts b/packages/hoppscotch-common/src/services/new-workspace/providers/personal.workspace.ts
index 4b53d0a67..ed1004462 100644
--- a/packages/hoppscotch-common/src/services/new-workspace/providers/personal.workspace.ts
+++ b/packages/hoppscotch-common/src/services/new-workspace/providers/personal.workspace.ts
@@ -16,15 +16,20 @@ import {
addRESTCollection,
addRESTFolder,
appendRESTCollections,
+ cascadeParentCollectionForHeaderAuth,
editRESTCollection,
editRESTFolder,
editRESTRequest,
+ moveRESTFolder,
+ moveRESTRequest,
navigateToFolderWithIndexPath,
removeRESTCollection,
removeRESTFolder,
removeRESTRequest,
restCollectionStore,
saveRESTRequestAs,
+ updateRESTCollectionOrder,
+ updateRESTRequestOrder,
} from "~/newstore/collections"
import { platform } from "~/platform"
@@ -51,6 +56,16 @@ import { HoppInheritedProperty } from "~/helpers/types/HoppInheritedProperties"
import IconUser from "~icons/lucide/user"
import { NewWorkspaceService } from ".."
import { initializeDownloadFile } from "~/helpers/import-export/export"
+import {
+ getFoldersByPath,
+ resolveSaveContextOnCollectionReorder,
+ updateInheritedPropertiesForAffectedRequests,
+ updateSaveContextForAffectedRequests,
+} from "~/helpers/collection/collection"
+import {
+ getRequestsByPath,
+ resolveSaveContextOnRequestReorder,
+} from "~/helpers/collection/request"
export class PersonalWorkspaceProviderService
extends Service
@@ -475,6 +490,189 @@ export class PersonalWorkspaceProviderService
return Promise.resolve(E.right(undefined))
}
+ public reorderRESTCollection(
+ collectionHandle: HandleRef,
+ destinationCollectionIndex: string
+ ): Promise> {
+ if (
+ collectionHandle.value.type !== "ok" ||
+ collectionHandle.value.data.providerID !== this.providerID ||
+ collectionHandle.value.data.workspaceID !== "personal"
+ ) {
+ return Promise.resolve(E.left("INVALID_COLLECTION_HANDLE" as const))
+ }
+
+ const draggedCollectionIndex = collectionHandle.value.data.collectionID
+
+ updateRESTCollectionOrder(
+ draggedCollectionIndex,
+ destinationCollectionIndex
+ )
+ // resolveSaveContextOnCollectionReorder({
+ // lastIndex: pathToLastIndex(draggedCollectionIndex),
+ // newIndex: pathToLastIndex(
+ // destinationCollectionIndex ? destinationCollectionIndex : ""
+ // ),
+ // folderPath: draggedCollectionIndex.split("/").slice(0, -1).join("/"),
+ // })
+
+ return Promise.resolve(E.right(undefined))
+ }
+
+ public moveRESTCollection(
+ collectionHandle: HandleRef,
+ destinationCollectionIndex: string | null
+ ): Promise> {
+ if (
+ collectionHandle.value.type !== "ok" ||
+ collectionHandle.value.data.providerID !== this.providerID ||
+ collectionHandle.value.data.workspaceID !== "personal"
+ ) {
+ return Promise.resolve(E.left("INVALID_COLLECTION_HANDLE" as const))
+ }
+
+ const draggedCollectionIndex = collectionHandle.value.data.collectionID
+
+ // const parentFolder = draggedCollectionIndex
+ // .split("/")
+ // .slice(0, -1)
+ // .join("/") // remove last folder to get parent folder
+
+ // const totalFoldersOfDestinationCollection =
+ // getFoldersByPath(
+ // restCollectionStore.value.state,
+ // destinationCollectionIndex
+ // ).length - (parentFolder === destinationCollectionIndex ? 1 : 0)
+
+ moveRESTFolder(draggedCollectionIndex, destinationCollectionIndex)
+
+ // resolveSaveContextOnCollectionReorder(
+ // {
+ // lastIndex: pathToLastIndex(draggedCollectionIndex),
+ // newIndex: -1,
+ // folderPath: parentFolder,
+ // length: getFoldersByPath(restCollectionStore.value.state, parentFolder)
+ // .length,
+ // },
+ // "drop"
+ // )
+
+ // updateSaveContextForAffectedRequests(
+ // draggedCollectionIndex,
+ // `${destinationCollectionIndex}/${totalFoldersOfDestinationCollection}`
+ // )
+
+ // const { auth, headers } = cascadeParentCollectionForHeaderAuth(
+ // `${destinationCollectionIndex}/${totalFoldersOfDestinationCollection}`,
+ // "rest"
+ // )
+
+ // const inheritedProperty = {
+ // auth,
+ // headers,
+ // }
+
+ // updateInheritedPropertiesForAffectedRequests(
+ // `${destinationCollectionIndex}/${totalFoldersOfDestinationCollection}`,
+ // inheritedProperty,
+ // "rest"
+ // )
+
+ return Promise.resolve(E.right(undefined))
+ }
+
+ public reorderRESTRequest(
+ requestHandle: HandleRef,
+ destinationCollectionIndex: string,
+ destinationRequestIndex: string
+ ): Promise> {
+ if (
+ requestHandle.value.type !== "ok" ||
+ requestHandle.value.data.providerID !== this.providerID ||
+ requestHandle.value.data.workspaceID !== "personal"
+ ) {
+ return Promise.resolve(E.left("INVALID_REQUEST_HANDLE" as const))
+ }
+
+ const draggedRequestIndex = requestHandle.value.data.requestID
+
+ updateRESTRequestOrder(
+ this.pathToLastIndex(draggedRequestIndex),
+ destinationRequestIndex
+ ? this.pathToLastIndex(destinationRequestIndex)
+ : null,
+ destinationCollectionIndex
+ )
+
+ return Promise.resolve(E.right(undefined))
+ }
+
+ public moveRESTRequest(
+ requestHandle: HandleRef,
+ destinationCollectionIndex: string
+ ): Promise> {
+ if (
+ requestHandle.value.type !== "ok" ||
+ requestHandle.value.data.providerID !== this.providerID ||
+ requestHandle.value.data.workspaceID !== "personal"
+ ) {
+ return Promise.resolve(E.left("INVALID_REQUEST_HANDLE" as const))
+ }
+
+ const requestIndex = requestHandle.value.data.requestID
+ const parentCollectionIndexPath = requestIndex
+ .split("/")
+ .slice(0, -1)
+ .join("/")
+
+ // const { auth, headers } = cascadeParentCollectionForHeaderAuth(
+ // destinationCollectionIndex,
+ // "rest"
+ // )
+
+ // const possibleTab = tabs.getTabRefWithSaveContext({
+ // originLocation: "user-collection",
+ // folderPath: parentCollectionIndexPath,
+ // requestIndex: this.pathToLastIndex(requestIndex),
+ // })
+
+ // // If there is a tab attached to this request, change save its save context
+ // if (possibleTab) {
+ // possibleTab.value.document.saveContext = {
+ // originLocation: "user-collection",
+ // folderPath: destinationCollectionIndex,
+ // requestIndex: getRequestsByPath(
+ // restCollectionStore.value.state,
+ // destinationCollectionIndex
+ // ).length,
+ // }
+
+ // possibleTab.value.document.inheritedProperties = {
+ // auth,
+ // headers,
+ // }
+ // }
+
+ // // When it's drop it's basically getting deleted from last folder. reordering last folder accordingly
+ // resolveSaveContextOnRequestReorder({
+ // lastIndex: this.pathToLastIndex(requestIndex),
+ // newIndex: -1, // being deleted from last folder
+ // folderPath: parentCollectionIndexPath,
+ // length: getRequestsByPath(
+ // restCollectionStore.value.state,
+ // parentCollectionIndexPath
+ // ).length,
+ // })
+
+ moveRESTRequest(
+ parentCollectionIndexPath,
+ this.pathToLastIndex(requestIndex),
+ destinationCollectionIndex
+ )
+
+ return Promise.resolve(E.right(undefined))
+ }
+
public getCollectionHandle(
workspaceHandle: HandleRef,
collectionID: string