From b5e757702408b9259bff72004efb7f22d890a687 Mon Sep 17 00:00:00 2001 From: nivedin Date: Sat, 23 Dec 2023 16:12:55 +0530 Subject: [PATCH] fix: saving teamRequest not inheriting properties --- .../components/collections/SaveRequest.vue | 43 ++++++++++++++++++- .../src/components/collections/index.vue | 2 + .../gql/mutations/UpdateRequest.graphql | 1 + 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/packages/hoppscotch-common/src/components/collections/SaveRequest.vue b/packages/hoppscotch-common/src/components/collections/SaveRequest.vue index 0f440da48..4e7e39073 100644 --- a/packages/hoppscotch-common/src/components/collections/SaveRequest.vue +++ b/packages/hoppscotch-common/src/components/collections/SaveRequest.vue @@ -33,6 +33,7 @@ @select="onSelect" @update-team="updateTeam" @update-collection-type="updateCollectionType" + @set-team-collection-adapter="teamCollectionAdapter = $event" /> @@ -86,6 +87,7 @@ import { platform } from "~/platform" import { useService } from "dioc/vue" import { RESTTabService } from "~/services/tab/rest" import { GQLTabService } from "~/services/tab/graphql" +import TeamCollectionAdapter from "~/helpers/teams/TeamCollectionAdapter" const t = useI18n() const toast = useToast() @@ -93,6 +95,8 @@ const toast = useToast() const RESTTabs = useService(RESTTabService) const GQLTabs = useService(GQLTabService) +const teamCollectionAdapter = ref() + type SelectedTeam = GetMyTeamsQuery["myTeams"][number] | undefined type CollectionType = @@ -380,7 +384,6 @@ const saveRequestAs = async () => { platform: "rest", workspaceType: "team", }) - pipe( updateTeamRequest(picked.value.requestID, data), TE.match( @@ -388,7 +391,31 @@ const saveRequestAs = async () => { toast.error(`${getErrorMessage(err)}`) modalLoadingState.value = false }, - () => { + (result) => { + const { updateRequest } = result + + RESTTabs.currentActiveTab.value.document = { + request: requestUpdated, + isDirty: false, + saveContext: { + originLocation: "team-collection", + requestID: updateRequest.id, + collectionID: updateRequest.collectionID, + }, + } + + if (teamCollectionAdapter.value) { + const { auth, headers } = + teamCollectionAdapter.value.cascadeParentCollectionForHeaderAuth( + updateRequest.collectionID + ) + + RESTTabs.currentActiveTab.value.document.inheritedProperties = { + auth, + headers, + } + } + modalLoadingState.value = false requestSaved() } @@ -516,6 +543,18 @@ const updateTeamCollectionOrFolder = ( }, } + if (teamCollectionAdapter.value) { + const { auth, headers } = + teamCollectionAdapter.value.cascadeParentCollectionForHeaderAuth( + createRequestInCollection.collection.id + ) + + RESTTabs.currentActiveTab.value.document.inheritedProperties = { + auth, + headers, + } + } + modalLoadingState.value = false requestSaved() } diff --git a/packages/hoppscotch-common/src/components/collections/index.vue b/packages/hoppscotch-common/src/components/collections/index.vue index 235864360..11ce9add8 100644 --- a/packages/hoppscotch-common/src/components/collections/index.vue +++ b/packages/hoppscotch-common/src/components/collections/index.vue @@ -262,6 +262,7 @@ const emit = defineEmits<{ (event: "select", payload: Picked | null): void (event: "update-team", team: SelectedTeam): void (event: "update-collection-type", type: CollectionType["type"]): void + (event: "set-team-collection-adapter", adapter: TeamCollectionAdapter): void }>() type SelectedTeam = GetMyTeamsQuery["myTeams"][number] | undefined @@ -354,6 +355,7 @@ watch( (newTeam) => { if (newTeam) { teamCollectionAdapter.changeTeamID(newTeam.id) + emit("set-team-collection-adapter", teamCollectionAdapter) } } ) diff --git a/packages/hoppscotch-common/src/helpers/backend/gql/mutations/UpdateRequest.graphql b/packages/hoppscotch-common/src/helpers/backend/gql/mutations/UpdateRequest.graphql index d556ac8ad..ff9b2f944 100644 --- a/packages/hoppscotch-common/src/helpers/backend/gql/mutations/UpdateRequest.graphql +++ b/packages/hoppscotch-common/src/helpers/backend/gql/mutations/UpdateRequest.graphql @@ -2,5 +2,6 @@ mutation UpdateRequest($data: UpdateTeamRequestInput!, $requestID: ID!) { updateRequest(data: $data, requestID: $requestID) { id title + collectionID } }