refactor: remove redundancy from provider API method signatures
This commit is contained in:
@@ -1452,18 +1452,10 @@ const exportCollection = async (collectionIndexPath: string) => {
|
||||
return
|
||||
}
|
||||
|
||||
const collection = navigateToFolderWithIndexPath(
|
||||
restCollectionState.value,
|
||||
collectionIndexPath.split("/").map((id) => parseInt(id))
|
||||
) as HoppCollection
|
||||
|
||||
const result = await workspaceService.exportRESTCollection(
|
||||
collectionHandle,
|
||||
collection
|
||||
)
|
||||
const result = await workspaceService.exportRESTCollection(collectionHandle)
|
||||
|
||||
if (E.isLeft(result)) {
|
||||
// INVALID_COLLECTION_HANDLE
|
||||
// INVALID_COLLECTION_HANDLE | COLLECTION_NOT_FOUND
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -1912,7 +1904,6 @@ const updateRequestOrder = async (
|
||||
|
||||
const result = await workspaceService.reorderRESTRequest(
|
||||
requestHandle,
|
||||
destinationCollectionIndex,
|
||||
destinationRequestIndex
|
||||
)
|
||||
|
||||
|
||||
@@ -467,8 +467,7 @@ export class NewWorkspaceService extends Service {
|
||||
}
|
||||
|
||||
public async exportRESTCollection(
|
||||
collectionHandle: Handle<WorkspaceCollection>,
|
||||
collection: HoppCollection
|
||||
collectionHandle: Handle<WorkspaceCollection>
|
||||
): Promise<
|
||||
E.Either<WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">, void>
|
||||
> {
|
||||
@@ -486,10 +485,7 @@ export class NewWorkspaceService extends Service {
|
||||
return E.left({ type: "SERVICE_ERROR", error: "INVALID_PROVIDER" })
|
||||
}
|
||||
|
||||
const result = await provider.exportRESTCollection(
|
||||
collectionHandle,
|
||||
collection
|
||||
)
|
||||
const result = await provider.exportRESTCollection(collectionHandle)
|
||||
|
||||
if (E.isLeft(result)) {
|
||||
return E.left({ type: "PROVIDER_ERROR", error: result.left })
|
||||
@@ -564,7 +560,6 @@ export class NewWorkspaceService extends Service {
|
||||
|
||||
public async reorderRESTRequest(
|
||||
requestHandle: Handle<WorkspaceRequest>,
|
||||
destinationCollectionID: string,
|
||||
destinationRequestID: string | null
|
||||
): Promise<
|
||||
E.Either<WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">, void>
|
||||
@@ -585,7 +580,6 @@ export class NewWorkspaceService extends Service {
|
||||
|
||||
const result = await provider.reorderRESTRequest(
|
||||
requestHandle,
|
||||
destinationCollectionID,
|
||||
destinationRequestID
|
||||
)
|
||||
|
||||
|
||||
@@ -86,8 +86,7 @@ export interface WorkspaceProvider {
|
||||
workspaceHandle: Handle<Workspace>
|
||||
): Promise<E.Either<unknown, void>>
|
||||
exportRESTCollection(
|
||||
collectionHandle: Handle<WorkspaceCollection>,
|
||||
collection: HoppCollection
|
||||
collectionHandle: Handle<WorkspaceCollection>
|
||||
): Promise<E.Either<unknown, void>>
|
||||
|
||||
reorderRESTCollection(
|
||||
@@ -100,7 +99,6 @@ export interface WorkspaceProvider {
|
||||
): Promise<E.Either<unknown, void>>
|
||||
reorderRESTRequest(
|
||||
requestHandle: Handle<WorkspaceRequest>,
|
||||
destinationCollectionID: string,
|
||||
destinationRequestID: string | null
|
||||
): Promise<E.Either<unknown, void>>
|
||||
moveRESTRequest(
|
||||
|
||||
@@ -225,13 +225,11 @@ describe("PersonalWorkspaceProviderService", () => {
|
||||
}),
|
||||
}
|
||||
|
||||
const destinationCollectionID = "1"
|
||||
const destinationRequestID = "1/1"
|
||||
|
||||
const moveRequestResult =
|
||||
await personalWorkspaceProviderService.reorderRESTRequest(
|
||||
requestHandle,
|
||||
destinationCollectionID,
|
||||
destinationRequestID
|
||||
)
|
||||
|
||||
@@ -262,7 +260,7 @@ describe("PersonalWorkspaceProviderService", () => {
|
||||
|
||||
// Request (req-0/0/0/7) dragged from `0/0/0/7` to `0/0/0/2`
|
||||
const draggedRequestID = "0/0/0/7"
|
||||
const destinationCollectionID = "0/0/0"
|
||||
|
||||
const destinationRequestID = "0/0/0/2"
|
||||
|
||||
const draggedRequestHandle =
|
||||
@@ -277,7 +275,6 @@ describe("PersonalWorkspaceProviderService", () => {
|
||||
|
||||
await personalWorkspaceProviderService.reorderRESTRequest(
|
||||
draggedRequestHandle.right,
|
||||
destinationCollectionID,
|
||||
destinationRequestID
|
||||
)
|
||||
|
||||
@@ -328,7 +325,7 @@ describe("PersonalWorkspaceProviderService", () => {
|
||||
|
||||
// Request (req-0/0/0/5) dragged from `0/0/0/5` to `0/0/0/0`
|
||||
const draggedRequestID = "0/0/0/5"
|
||||
const destinationCollectionID = "0/0/0"
|
||||
|
||||
const destinationRequestID = "0/0/0/0"
|
||||
|
||||
const draggedRequestHandle =
|
||||
@@ -343,7 +340,6 @@ describe("PersonalWorkspaceProviderService", () => {
|
||||
|
||||
await personalWorkspaceProviderService.reorderRESTRequest(
|
||||
draggedRequestHandle.right,
|
||||
destinationCollectionID,
|
||||
destinationRequestID
|
||||
)
|
||||
|
||||
@@ -411,7 +407,7 @@ describe("PersonalWorkspaceProviderService", () => {
|
||||
|
||||
// Request (req-0/0/0/3) dragged from `0/0/0/3` to `0/0/0/8`
|
||||
const draggedRequestID = "0/0/0/3"
|
||||
const destinationCollectionID = "0/0/0"
|
||||
|
||||
const destinationRequestID = "0/0/0/8"
|
||||
|
||||
const draggedRequestHandle =
|
||||
@@ -426,7 +422,6 @@ describe("PersonalWorkspaceProviderService", () => {
|
||||
|
||||
await personalWorkspaceProviderService.reorderRESTRequest(
|
||||
draggedRequestHandle.right,
|
||||
destinationCollectionID,
|
||||
destinationRequestID
|
||||
)
|
||||
|
||||
@@ -478,7 +473,7 @@ describe("PersonalWorkspaceProviderService", () => {
|
||||
|
||||
// Request (req-0/0/0/5) dragged from `0/0/0/5` to `0/0/0/9`
|
||||
const draggedRequestID = "0/0/0/5"
|
||||
const destinationCollectionID = "0/0/0"
|
||||
|
||||
// Indicates move to the last position `0/0/0/9`
|
||||
const destinationRequestID = null
|
||||
|
||||
@@ -494,7 +489,6 @@ describe("PersonalWorkspaceProviderService", () => {
|
||||
|
||||
await personalWorkspaceProviderService.reorderRESTRequest(
|
||||
draggedRequestHandle.right,
|
||||
destinationCollectionID,
|
||||
destinationRequestID
|
||||
)
|
||||
|
||||
|
||||
@@ -738,8 +738,7 @@ export class PersonalWorkspaceProviderService
|
||||
}
|
||||
|
||||
public exportRESTCollection(
|
||||
collectionHandle: Handle<WorkspaceCollection>,
|
||||
collection: HoppCollection
|
||||
collectionHandle: Handle<WorkspaceCollection>
|
||||
): Promise<E.Either<unknown, void>> {
|
||||
const collectionHandleRef = collectionHandle.get()
|
||||
|
||||
@@ -749,6 +748,17 @@ export class PersonalWorkspaceProviderService
|
||||
return Promise.resolve(E.left("INVALID_COLLECTION_HANDLE" as const))
|
||||
}
|
||||
|
||||
const collection = navigateToFolderWithIndexPath(
|
||||
this.restCollectionState.value.state,
|
||||
collectionHandleRef.value.data.collectionID
|
||||
.split("/")
|
||||
.map((id) => parseInt(id))
|
||||
)
|
||||
|
||||
if (!collection) {
|
||||
return Promise.resolve(E.left("COLLECTION_NOT_FOUND" as const))
|
||||
}
|
||||
|
||||
initializeDownloadFile(JSON.stringify(collection, null, 2), collection.name)
|
||||
|
||||
return Promise.resolve(E.right(undefined))
|
||||
@@ -1098,7 +1108,6 @@ export class PersonalWorkspaceProviderService
|
||||
|
||||
public reorderRESTRequest(
|
||||
requestHandle: Handle<WorkspaceRequest>,
|
||||
destinationCollectionID: string,
|
||||
destinationRequestID: string | null
|
||||
): Promise<E.Either<unknown, void>> {
|
||||
const requestHandleRef = requestHandle.get()
|
||||
@@ -1131,7 +1140,7 @@ export class PersonalWorkspaceProviderService
|
||||
|
||||
const resolvedDestinationRequestID =
|
||||
destinationRequestIndexPos > draggedRequestIndexPos
|
||||
? `${destinationCollectionID}/${resolvedDestinationRequestIDPostfix}`
|
||||
? `${collectionID}/${resolvedDestinationRequestIDPostfix}`
|
||||
: destinationRequestID
|
||||
|
||||
const resolvedDestinationRequestIndexPos =
|
||||
@@ -1175,7 +1184,7 @@ export class PersonalWorkspaceProviderService
|
||||
updateRESTRequestOrder(
|
||||
this.pathToLastIndex(draggedRequestID),
|
||||
destinationRequestID ? destinationRequestIndexPos : null,
|
||||
destinationCollectionID
|
||||
collectionID
|
||||
)
|
||||
|
||||
affectedRequestHandleUpdateInfo.forEach(
|
||||
|
||||
Reference in New Issue
Block a user