refactor: provider method definitions for collection reorder/move
This commit is contained in:
@@ -23,7 +23,7 @@
|
|||||||
<div
|
<div
|
||||||
class="z-[3] group pointer-events-auto relative flex cursor-pointer items-stretch"
|
class="z-[3] group pointer-events-auto relative flex cursor-pointer items-stretch"
|
||||||
@dragstart="dragStart"
|
@dragstart="dragStart"
|
||||||
@drop="handelDrop($event)"
|
@drop="handleDrop($event)"
|
||||||
@dragover="handleDragOver($event)"
|
@dragover="handleDragOver($event)"
|
||||||
@dragleave="resetDragState"
|
@dragleave="resetDragState"
|
||||||
@dragend="
|
@dragend="
|
||||||
@@ -387,7 +387,7 @@ const handleDragOver = (e: DragEvent) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const handelDrop = (e: DragEvent) => {
|
const handleDrop = (e: DragEvent) => {
|
||||||
if (ordering.value) {
|
if (ordering.value) {
|
||||||
orderUpdateCollectionEvent(e)
|
orderUpdateCollectionEvent(e)
|
||||||
} else if (orderingLastItem.value) {
|
} else if (orderingLastItem.value) {
|
||||||
|
|||||||
@@ -1255,7 +1255,10 @@ const dragRequest = (
|
|||||||
requestIndex,
|
requestIndex,
|
||||||
}: { parentCollectionIndexPath: string | null; requestIndex: string }
|
}: { parentCollectionIndexPath: string | null; requestIndex: string }
|
||||||
) => {
|
) => {
|
||||||
if (!parentCollectionIndexPath) return
|
if (!parentCollectionIndexPath) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
dataTransfer.setData("parentCollectionIndexPath", parentCollectionIndexPath)
|
dataTransfer.setData("parentCollectionIndexPath", parentCollectionIndexPath)
|
||||||
dataTransfer.setData("requestIndex", requestIndex)
|
dataTransfer.setData("requestIndex", requestIndex)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -476,6 +476,128 @@ export class NewWorkspaceService extends Service {
|
|||||||
return E.right(result.right)
|
return E.right(result.right)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async reorderRESTCollection(
|
||||||
|
collectionHandle: HandleRef<WorkspaceCollection>,
|
||||||
|
destinationCollectionIndex: string
|
||||||
|
): Promise<
|
||||||
|
E.Either<WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">, 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<WorkspaceCollection>,
|
||||||
|
destinationCollectionIndex: string
|
||||||
|
): Promise<
|
||||||
|
E.Either<WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">, 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<WorkspaceRequest>,
|
||||||
|
destinationRequestIndex: string,
|
||||||
|
destinationCollectionIndex: string
|
||||||
|
): Promise<
|
||||||
|
E.Either<WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">, 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<WorkspaceRequest>,
|
||||||
|
destinationCollectionIndex: string
|
||||||
|
): Promise<
|
||||||
|
E.Either<WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">, 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(
|
public async getRESTCollectionChildrenView(
|
||||||
collectionHandle: HandleRef<WorkspaceCollection>
|
collectionHandle: HandleRef<WorkspaceCollection>
|
||||||
): Promise<
|
): Promise<
|
||||||
|
|||||||
@@ -80,4 +80,22 @@ export interface WorkspaceProvider {
|
|||||||
collectionHandle: HandleRef<WorkspaceCollection>,
|
collectionHandle: HandleRef<WorkspaceCollection>,
|
||||||
collection: HoppCollection
|
collection: HoppCollection
|
||||||
): Promise<E.Either<unknown, void>>
|
): Promise<E.Either<unknown, void>>
|
||||||
|
|
||||||
|
reorderRESTCollection(
|
||||||
|
collectionHandle: HandleRef<WorkspaceCollection>,
|
||||||
|
destinationCollectionIndex: string
|
||||||
|
): Promise<E.Either<unknown, void>>
|
||||||
|
moveRESTCollection(
|
||||||
|
collectionHandle: HandleRef<WorkspaceCollection>,
|
||||||
|
destinationCollectionIndex: string | null
|
||||||
|
): Promise<E.Either<unknown, void>>
|
||||||
|
reorderRESTRequest(
|
||||||
|
requestHandle: HandleRef<WorkspaceRequest>,
|
||||||
|
destinationRequestIndex: string,
|
||||||
|
destinationCollectionIndex: string
|
||||||
|
): Promise<E.Either<unknown, void>>
|
||||||
|
moveRESTRequest(
|
||||||
|
requestHandle: HandleRef<WorkspaceRequest>,
|
||||||
|
destinationCollectionIndex: string
|
||||||
|
): Promise<E.Either<unknown, void>>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,15 +16,20 @@ import {
|
|||||||
addRESTCollection,
|
addRESTCollection,
|
||||||
addRESTFolder,
|
addRESTFolder,
|
||||||
appendRESTCollections,
|
appendRESTCollections,
|
||||||
|
cascadeParentCollectionForHeaderAuth,
|
||||||
editRESTCollection,
|
editRESTCollection,
|
||||||
editRESTFolder,
|
editRESTFolder,
|
||||||
editRESTRequest,
|
editRESTRequest,
|
||||||
|
moveRESTFolder,
|
||||||
|
moveRESTRequest,
|
||||||
navigateToFolderWithIndexPath,
|
navigateToFolderWithIndexPath,
|
||||||
removeRESTCollection,
|
removeRESTCollection,
|
||||||
removeRESTFolder,
|
removeRESTFolder,
|
||||||
removeRESTRequest,
|
removeRESTRequest,
|
||||||
restCollectionStore,
|
restCollectionStore,
|
||||||
saveRESTRequestAs,
|
saveRESTRequestAs,
|
||||||
|
updateRESTCollectionOrder,
|
||||||
|
updateRESTRequestOrder,
|
||||||
} from "~/newstore/collections"
|
} from "~/newstore/collections"
|
||||||
import { platform } from "~/platform"
|
import { platform } from "~/platform"
|
||||||
|
|
||||||
@@ -51,6 +56,16 @@ import { HoppInheritedProperty } from "~/helpers/types/HoppInheritedProperties"
|
|||||||
import IconUser from "~icons/lucide/user"
|
import IconUser from "~icons/lucide/user"
|
||||||
import { NewWorkspaceService } from ".."
|
import { NewWorkspaceService } from ".."
|
||||||
import { initializeDownloadFile } from "~/helpers/import-export/export"
|
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
|
export class PersonalWorkspaceProviderService
|
||||||
extends Service
|
extends Service
|
||||||
@@ -475,6 +490,189 @@ export class PersonalWorkspaceProviderService
|
|||||||
return Promise.resolve(E.right(undefined))
|
return Promise.resolve(E.right(undefined))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public reorderRESTCollection(
|
||||||
|
collectionHandle: HandleRef<WorkspaceCollection>,
|
||||||
|
destinationCollectionIndex: string
|
||||||
|
): Promise<E.Either<unknown, void>> {
|
||||||
|
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<WorkspaceCollection>,
|
||||||
|
destinationCollectionIndex: string | null
|
||||||
|
): Promise<E.Either<unknown, void>> {
|
||||||
|
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<WorkspaceRequest>,
|
||||||
|
destinationCollectionIndex: string,
|
||||||
|
destinationRequestIndex: string
|
||||||
|
): Promise<E.Either<unknown, void>> {
|
||||||
|
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<WorkspaceRequest>,
|
||||||
|
destinationCollectionIndex: string
|
||||||
|
): Promise<E.Either<unknown, void>> {
|
||||||
|
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(
|
public getCollectionHandle(
|
||||||
workspaceHandle: HandleRef<Workspace>,
|
workspaceHandle: HandleRef<Workspace>,
|
||||||
collectionID: string
|
collectionID: string
|
||||||
|
|||||||
Reference in New Issue
Block a user