From 569c170fec8f520ba9bd202191f1bd2e7a326e10 Mon Sep 17 00:00:00 2001 From: nivedin Date: Mon, 4 Dec 2023 17:52:49 +0530 Subject: [PATCH] refactor: update inheritence when moving request --- .../collections/graphql/Collection.vue | 20 ++++++--- .../components/collections/graphql/Folder.vue | 10 ++++- .../components/collections/graphql/index.vue | 44 +++++++++++++++++++ .../src/helpers/collection/request.ts | 10 +++-- 4 files changed, 74 insertions(+), 10 deletions(-) diff --git a/packages/hoppscotch-common/src/components/collections/graphql/Collection.vue b/packages/hoppscotch-common/src/components/collections/graphql/Collection.vue index 4e2dac72b..262d6f70c 100644 --- a/packages/hoppscotch-common/src/components/collections/graphql/Collection.vue +++ b/packages/hoppscotch-common/src/components/collections/graphql/Collection.vue @@ -178,6 +178,7 @@ " @select="$emit('select', $event)" @select-request="$emit('select-request', $event)" + @drop-request="$emit('drop-request', $event)" /> () // Template refs @@ -357,6 +363,10 @@ const dropEvent = ({ dataTransfer }: any) => { dragging.value = !dragging.value const folderPath = dataTransfer.getData("folderPath") const requestIndex = dataTransfer.getData("requestIndex") - moveGraphqlRequest(folderPath, requestIndex, `${props.collectionIndex}`) + emit("drop-request", { + folderPath, + requestIndex, + collectionIndex: props.collectionIndex, + }) } diff --git a/packages/hoppscotch-common/src/components/collections/graphql/Folder.vue b/packages/hoppscotch-common/src/components/collections/graphql/Folder.vue index 28c7a9dcc..39772258c 100644 --- a/packages/hoppscotch-common/src/components/collections/graphql/Folder.vue +++ b/packages/hoppscotch-common/src/components/collections/graphql/Folder.vue @@ -225,7 +225,7 @@ import IconSettings2 from "~icons/lucide/settings-2" import { useToast } from "@composables/toast" import { useI18n } from "@composables/i18n" import { useColorMode } from "@composables/theming" -import { removeGraphqlFolder, moveGraphqlRequest } from "~/newstore/collections" +import { removeGraphqlFolder } from "~/newstore/collections" import { computed, ref } from "vue" import { useService } from "dioc/vue" import { GQLTabService } from "~/services/tab/graphql" @@ -258,6 +258,7 @@ const emit = defineEmits([ "duplicate-request", "edit-properties", "select-request", + "drop-request", ]) // Template refs @@ -332,6 +333,11 @@ const dropEvent = ({ dataTransfer }: any) => { dragging.value = !dragging.value const folderPath = dataTransfer.getData("folderPath") const requestIndex = dataTransfer.getData("requestIndex") - moveGraphqlRequest(folderPath, requestIndex, props.folderPath) + + emit("drop-request", { + folderPath, + requestIndex, + collectionIndex: props.folderPath, + }) } diff --git a/packages/hoppscotch-common/src/components/collections/graphql/index.vue b/packages/hoppscotch-common/src/components/collections/graphql/index.vue index 114ff9054..b145824e8 100644 --- a/packages/hoppscotch-common/src/components/collections/graphql/index.vue +++ b/packages/hoppscotch-common/src/components/collections/graphql/index.vue @@ -60,6 +60,7 @@ @edit-properties="editProperties($event)" @select="$emit('select', $event)" @select-request="selectRequest($event)" + @drop-request="dropRequest($event)" /> { + const { auth, headers } = cascaseParentCollectionForHeaderAuth( + `${collectionIndex}`, + "graphql" + ) + + const possibleTab = tabs.getTabRefWithSaveContext({ + originLocation: "user-collection", + folderPath, + requestIndex: Number(requestIndex), + }) + + if (possibleTab) { + possibleTab.value.document.saveContext = { + originLocation: "user-collection", + folderPath: `${collectionIndex}`, + requestIndex: getRequestsByPath(collections.value, `${collectionIndex}`) + .length, + } + + possibleTab.value.document.inheritedProperties = { + auth, + headers, + } + } + + moveGraphqlRequest(folderPath, requestIndex, `${collectionIndex}`) + + toast.success(`${t("request.moved")}`) +} + /** * Checks if the collection is already in the root * @param id - path of the collection diff --git a/packages/hoppscotch-common/src/helpers/collection/request.ts b/packages/hoppscotch-common/src/helpers/collection/request.ts index 8bd4237a9..7198ecd2f 100644 --- a/packages/hoppscotch-common/src/helpers/collection/request.ts +++ b/packages/hoppscotch-common/src/helpers/collection/request.ts @@ -1,4 +1,8 @@ -import { HoppCollection, HoppRESTRequest } from "@hoppscotch/data" +import { + HoppCollection, + HoppGQLRequest, + HoppRESTRequest, +} from "@hoppscotch/data" import { getAffectedIndexes } from "./affectedIndex" import { RESTTabService } from "~/services/tab/rest" import { getService } from "~/modules/dioc" @@ -53,9 +57,9 @@ export function resolveSaveContextOnRequestReorder(payload: { } export function getRequestsByPath( - collections: HoppCollection[], + collections: HoppCollection[], path: string -): HoppRESTRequest[] { +): HoppRESTRequest[] | HoppGQLRequest[] { // path will be like this "0/0/1" these are the indexes of the folders const pathArray = path.split("/").map((index) => parseInt(index))