diff --git a/packages/hoppscotch-common/src/components/collections/Properties.vue b/packages/hoppscotch-common/src/components/collections/Properties.vue index 0db2eb59f..76c83c694 100644 --- a/packages/hoppscotch-common/src/components/collections/Properties.vue +++ b/packages/hoppscotch-common/src/components/collections/Properties.vue @@ -75,7 +75,7 @@ import { import { useVModel } from "@vueuse/core" import { useService } from "dioc/vue" import { clone } from "lodash-es" -import { ref, watch } from "vue" +import { ref, toRefs, watch } from "vue" import { HoppInheritedProperty } from "~/helpers/types/HoppInheritedProperties" import { PersistenceService } from "~/services/persistence" @@ -100,11 +100,15 @@ const props = withDefaults( editingProperties: EditingProperties | null source: "REST" | "GraphQL" modelValue: string + // TODO: Purpose of this prop is to maintain backwards compatibility + // To be removed after porting all usages of this component + emitWithFullCollection: boolean }>(), { show: false, loadingState: false, editingProperties: null, + emitWithFullCollection: true, } ) @@ -178,15 +182,24 @@ watch( const saveEditedCollection = () => { if (!props.editingProperties) return const finalCollection = clone(editableCollection.value) + delete finalCollection.body + + const { path } = toRefs(props.editingProperties) + const collection = { - path: props.editingProperties.path, + path: path.value, collection: { ...props.editingProperties.collection, ...finalCollection, }, isRootCollection: props.editingProperties.isRootCollection, } - emit("set-collection-properties", collection as EditingProperties) + + const data = props.emitWithFullCollection + ? collection + : { ...finalCollection, collIndexPath: path.value } + emit("set-collection-properties", data as EditingProperties) + persistenceService.removeLocalConfig("unsaved_collection_properties") } diff --git a/packages/hoppscotch-common/src/components/http/Request.vue b/packages/hoppscotch-common/src/components/http/Request.vue index 1f7263ee7..dacba5b3c 100644 --- a/packages/hoppscotch-common/src/components/http/Request.vue +++ b/packages/hoppscotch-common/src/components/http/Request.vue @@ -245,7 +245,6 @@ import { UpdateRequestDocument } from "~/helpers/backend/graphql" import { getPlatformSpecialKey as getSpecialKey } from "~/helpers/platformutils" import { runRESTRequest$ } from "~/helpers/RequestRunner" import { HoppRESTResponse } from "~/helpers/types/HoppRESTResponse" -import { editRESTRequest } from "~/newstore/collections" import IconChevronDown from "~icons/lucide/chevron-down" import IconCode2 from "~icons/lucide/code-2" import IconFileCode from "~icons/lucide/file-code" @@ -265,9 +264,11 @@ import { HoppRESTDocument } from "~/helpers/rest/document" import { RESTTabService } from "~/services/tab/rest" import { getMethodLabelColorClassOf } from "~/helpers/rest/labelColoring" import { WorkspaceService } from "~/services/workspace.service" +import { NewWorkspaceService } from "~/services/new-workspace" const t = useI18n() const interceptorService = useService(InterceptorService) +const newWorkspaceService = useService(NewWorkspaceService) const methods = [ "GET", @@ -506,7 +507,7 @@ const cycleDownMethod = () => { } } -const saveRequest = () => { +const saveRequest = async () => { const saveCtx = tab.value.document.saveContext if (!saveCtx) { @@ -514,25 +515,72 @@ const saveRequest = () => { return } if (saveCtx.originLocation === "user-collection") { - const req = tab.value.document.request + const updatedRequest = tab.value.document.request - try { - editRESTRequest(saveCtx.folderPath, saveCtx.requestIndex, req) - - tab.value.document.isDirty = false - - platform.analytics?.logEvent({ - type: "HOPP_SAVE_REQUEST", - platform: "rest", - createdNow: false, - workspaceType: "personal", - }) - - toast.success(`${t("request.saved")}`) - } catch (e) { - tab.value.document.saveContext = undefined - saveRequest() + if (!newWorkspaceService.activeWorkspaceHandle.value) { + return } + + const collHandleResult = await newWorkspaceService.getCollectionHandle( + newWorkspaceService.activeWorkspaceHandle.value, + saveCtx.folderPath + ) + + if (E.isLeft(collHandleResult)) { + // INVALID_WORKSPACE_HANDLE + return + } + + const collHandle = collHandleResult.right + + if (collHandle.value.type === "invalid") { + // WORKSPACE_INVALIDATED | INVALID_COLLECTION_HANDLE + return + } + + const requestHandleResult = await newWorkspaceService.getRequestHandle( + collHandle, + `${saveCtx.folderPath}/${saveCtx.requestIndex.toString()}` + ) + + if (E.isLeft(requestHandleResult)) { + // INVALID_REQUEST_HANDLE + return + } + + const requestHandle = requestHandleResult.right + + if (requestHandle.value.type === "invalid") { + // WORKSPACE_INVALIDATED | INVALID_REQUEST_HANDLE + return + } + + const updatedRequestResult = await newWorkspaceService.saveRESTRequest( + requestHandle, + updatedRequest + ) + + if (E.isLeft(updatedRequestResult)) { + // INVALID_REQUEST_HANDLE + return + } + + const resultHandle = updatedRequestResult.right + + if (resultHandle.value.type === "invalid") { + // REQUEST_INVALIDATED | REQUEST_PATH_NOT_FOUND + + if (resultHandle.value.reason === "REQUEST_PATH_NOT_FOUND") { + // REQUEST_PATH_NOT_FOUND + tab.value.document.saveContext = undefined + await saveRequest() + } + return + } + + tab.value.document.isDirty = false + + toast.success(`${t("request.saved")}`) } else if (saveCtx.originLocation === "team-collection") { const req = tab.value.document.request 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 196a423cc..d98581db6 100644 --- a/packages/hoppscotch-common/src/components/new-collections/rest/Collection.vue +++ b/packages/hoppscotch-common/src/components/new-collections/rest/Collection.vue @@ -18,7 +18,7 @@ class="pointer-events-none flex min-w-0 flex-1 py-2 pr-2 transition group-hover:text-secondaryDark" > - {{ collection.name }} + {{ collectionView.collection.name }} @@ -28,22 +28,14 @@ :icon="IconFilePlus" :title="t('request.new')" class="hidden group-hover:inline-flex" - @click=" - emit('add-request', { - path: collection.collectionID, - }) - " + @click="addRequest" />