From 97899ec023b16087bcb29ab723010ea4fe68c7ea Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Mon, 12 Feb 2024 10:35:54 +0530 Subject: [PATCH] chore: cleanup --- .../components/collections/SaveRequest.vue | 6 --- .../src/components/http/Request.vue | 13 ----- .../components/new-collections/rest/index.vue | 5 -- .../providers/personal.workspace.ts | 52 ++++++++----------- 4 files changed, 21 insertions(+), 55 deletions(-) diff --git a/packages/hoppscotch-common/src/components/collections/SaveRequest.vue b/packages/hoppscotch-common/src/components/collections/SaveRequest.vue index ca91a5a78..89e9be3cd 100644 --- a/packages/hoppscotch-common/src/components/collections/SaveRequest.vue +++ b/packages/hoppscotch-common/src/components/collections/SaveRequest.vue @@ -302,12 +302,6 @@ const saveRequestAs = async () => { return } - if (updateRequestResult.right.type === "invalid") { - // REQUEST_INVALIDATED | REQUEST_PATH_NOT_FOUND - - return - } - // These remain here in the component RESTTabs.currentActiveTab.value.document = { request: updatedRequest, diff --git a/packages/hoppscotch-common/src/components/http/Request.vue b/packages/hoppscotch-common/src/components/http/Request.vue index 433257f2e..bc7650738 100644 --- a/packages/hoppscotch-common/src/components/http/Request.vue +++ b/packages/hoppscotch-common/src/components/http/Request.vue @@ -547,19 +547,6 @@ const saveRequest = async () => { return } - const resultHandle = updateRequestResult.right - - if (resultHandle.type === "invalid") { - // REQUEST_INVALIDATED | REQUEST_PATH_NOT_FOUND - - if (resultHandle.reason === "REQUEST_PATH_NOT_FOUND") { - // REQUEST_PATH_NOT_FOUND - tab.value.document.saveContext = undefined - await saveRequest() - } - return - } - tab.value.document.isDirty = false tab.value.document.saveContext = { 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 7d10176b1..9178768c3 100644 --- a/packages/hoppscotch-common/src/components/new-collections/rest/index.vue +++ b/packages/hoppscotch-common/src/components/new-collections/rest/index.vue @@ -779,11 +779,6 @@ const onEditRequest = async (newRequestName: string) => { return } - if (result.right.type === "invalid") { - // REQUEST_INVALIDATED - return - } - displayModalEditRequest(false) toast.success(t("request.renamed")) } 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 1b0c7cad3..0ccae4096 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 @@ -30,8 +30,8 @@ import { platform } from "~/platform" import { HandleRef } from "~/services/new-workspace/handle" import { WorkspaceProvider } from "~/services/new-workspace/provider" import { - RESTCollectionLevelAuthHeadersView, RESTCollectionChildrenView, + RESTCollectionLevelAuthHeadersView, RESTCollectionViewItem, RootRESTCollectionView, } from "~/services/new-workspace/view" @@ -42,18 +42,13 @@ import { WorkspaceRequest, } from "~/services/new-workspace/workspace" -import IconUser from "~icons/lucide/user" -import { NewWorkspaceService } from ".." import { HoppRESTRequest } from "@hoppscotch/data" +import { merge } from "lodash-es" import path from "path" -import { - resolveSaveContextOnCollectionReorder, - getFoldersByPath, -} from "~/helpers/collection/collection" import { HoppGQLHeader } from "~/helpers/graphql" import { HoppInheritedProperty } from "~/helpers/types/HoppInheritedProperties" -import { computedAsync } from "@vueuse/core" -import { merge } from "lodash-es" +import IconUser from "~icons/lucide/user" +import { NewWorkspaceService } from ".." export class PersonalWorkspaceProviderService extends Service @@ -272,13 +267,6 @@ export class PersonalWorkspaceProviderService collectionIndex, collectionToRemove ? collectionToRemove.id : undefined ) - - resolveSaveContextOnCollectionReorder({ - lastIndex: collectionIndex, - newIndex: -1, - folderPath: "", // root collection - length: this.restCollectionState.value.state.length, - }) } else { const folderToRemove = path ? navigateToFolderWithIndexPath( @@ -291,17 +279,6 @@ export class PersonalWorkspaceProviderService collectionID, folderToRemove ? folderToRemove.id : undefined ) - - const parentFolder = collectionID.split("/").slice(0, -1).join("/") // Remove last folder to get parent folder - resolveSaveContextOnCollectionReorder({ - lastIndex: this.pathToLastIndex(collectionID), - newIndex: -1, - folderPath: parentFolder, - length: getFoldersByPath( - this.restCollectionState.value.state, - parentFolder - ).length, - }) } return Promise.resolve(E.right(undefined)) @@ -453,9 +430,22 @@ export class PersonalWorkspaceProviderService ) if (!collection) { - return { - type: "invalid" as const, - reason: "COLLECTION_PATH_NOT_FOUND" as const, + const parentCollectionIndexPath = collectionID + .split("/") + .slice(0, -1) + .join("/") + const requestIndex = this.pathToLastIndex(collectionID) + + const parentCollection = navigateToFolderWithIndexPath( + this.restCollectionState.value.state, + parentCollectionIndexPath.split("/").map((x) => parseInt(x)) + ) + + if (!parentCollection || !parentCollection.requests[requestIndex]) { + return { + type: "invalid" as const, + reason: "INVALID_PATH" as const, + } } } @@ -467,7 +457,7 @@ export class PersonalWorkspaceProviderService providerID, workspaceID, collectionID, - name: collection?.name, + name: collection?.name as string, }, } })