From e040f44245d499063b4259930669a1aa98ac04b8 Mon Sep 17 00:00:00 2001 From: James George <25279263+jamesgeorge007@users.noreply.github.com> Date: Fri, 22 Nov 2024 09:01:00 -0800 Subject: [PATCH] fix: resolve GraphQL collection tree and tab dissociation issues (#4537) --- .../components/collections/SaveRequest.vue | 49 ++++++++++++++++--- .../collections/graphql/AddRequest.vue | 6 +-- .../collections/graphql/EditRequest.vue | 20 +++++++- .../components/collections/graphql/index.vue | 14 ++---- .../src/newstore/collections.ts | 10 ++++ .../persistence/validation-schemas/index.ts | 3 +- 6 files changed, 78 insertions(+), 24 deletions(-) diff --git a/packages/hoppscotch-common/src/components/collections/SaveRequest.vue b/packages/hoppscotch-common/src/components/collections/SaveRequest.vue index a597cd956..fdb40c3c1 100644 --- a/packages/hoppscotch-common/src/components/collections/SaveRequest.vue +++ b/packages/hoppscotch-common/src/components/collections/SaveRequest.vue @@ -135,6 +135,7 @@ import { useSubmitFeedback, } from "~/composables/ai-experiments" import { GQLError } from "~/helpers/backend/GQLClient" +import { ReqType } from "~/helpers/backend/graphql" import { createRequestInCollection, updateTeamRequest, @@ -521,6 +522,16 @@ const saveRequestAs = async () => { requestUpdated as HoppGQLRequest ) + GQLTabs.currentActiveTab.value.document = { + request: requestUpdated as HoppGQLRequest, + isDirty: false, + saveContext: { + originLocation: "user-collection", + folderPath: picked.value.folderPath, + requestIndex: picked.value.requestIndex, + }, + } + platform.analytics?.logEvent({ type: "HOPP_SAVE_REQUEST", createdNow: false, @@ -538,14 +549,24 @@ const saveRequestAs = async () => { headers, } - requestSaved() + requestSaved(ReqType.Gql) } else if (picked.value.pickedType === "gql-my-folder") { // TODO: Check for GQL request ? - saveGraphqlRequestAs( + const insertionIndex = saveGraphqlRequestAs( picked.value.folderPath, requestUpdated as HoppGQLRequest ) + GQLTabs.currentActiveTab.value.document = { + request: requestUpdated as HoppGQLRequest, + isDirty: false, + saveContext: { + originLocation: "user-collection", + folderPath: picked.value.folderPath, + requestIndex: insertionIndex, + }, + } + platform.analytics?.logEvent({ type: "HOPP_SAVE_REQUEST", createdNow: true, @@ -563,14 +584,24 @@ const saveRequestAs = async () => { headers, } - requestSaved() + requestSaved(ReqType.Gql) } else if (picked.value.pickedType === "gql-my-collection") { // TODO: Check for GQL request ? - saveGraphqlRequestAs( + const insertionIndex = saveGraphqlRequestAs( `${picked.value.collectionIndex}`, requestUpdated as HoppGQLRequest ) + GQLTabs.currentActiveTab.value.document = { + request: requestUpdated as HoppGQLRequest, + isDirty: false, + saveContext: { + originLocation: "user-collection", + folderPath: `${picked.value.collectionIndex}`, + requestIndex: insertionIndex, + }, + } + platform.analytics?.logEvent({ type: "HOPP_SAVE_REQUEST", createdNow: true, @@ -588,7 +619,7 @@ const saveRequestAs = async () => { headers, } - requestSaved() + requestSaved(ReqType.Gql) } } @@ -643,10 +674,14 @@ const updateTeamCollectionOrFolder = ( )() } -const requestSaved = () => { +const requestSaved = (tab: ReqType = ReqType.Rest) => { toast.success(`${t("request.added")}`) nextTick(() => { - RESTTabs.currentActiveTab.value.document.isDirty = false + if (tab === ReqType.Rest) { + RESTTabs.currentActiveTab.value.document.isDirty = false + } else { + GQLTabs.currentActiveTab.value.document.isDirty = false + } }) hideModal() } diff --git a/packages/hoppscotch-common/src/components/collections/graphql/AddRequest.vue b/packages/hoppscotch-common/src/components/collections/graphql/AddRequest.vue index e51449cb0..f6cfda00a 100644 --- a/packages/hoppscotch-common/src/components/collections/graphql/AddRequest.vue +++ b/packages/hoppscotch-common/src/components/collections/graphql/AddRequest.vue @@ -96,7 +96,7 @@