From b08b63dc73e933a4b748259ff33f1b56a992b427 Mon Sep 17 00:00:00 2001 From: Andrew Bastin Date: Thu, 24 Aug 2023 19:07:17 +0530 Subject: [PATCH] feat: cleaner save context handling for graphql (#3282) Co-authored-by: Liyas Thomas --- .../hoppscotch-common/src/components.d.ts | 4 +- .../collections/graphql/Collection.vue | 18 +++ .../components/collections/graphql/Folder.vue | 30 ++++- .../collections/graphql/Request.vue | 73 +++++++++-- .../components/collections/graphql/index.vue | 7 +- .../src/components/graphql/Authorization.vue | 2 +- .../src/components/graphql/Headers.vue | 2 +- .../src/components/graphql/Query.vue | 2 +- .../src/components/graphql/RequestOptions.vue | 22 +++- .../src/components/graphql/TabHead.vue | 118 ++++++++++++++++++ .../src/components/graphql/Variable.vue | 2 +- .../src/components/http/TabHead.vue | 2 +- .../hoppscotch-common/src/helpers/actions.ts | 2 + .../src/helpers/graphql/tab.ts | 27 ++++ .../hoppscotch-common/src/pages/graphql.vue | 82 ++++++++++-- .../searchers/collections.searcher.ts | 14 ++- 16 files changed, 365 insertions(+), 42 deletions(-) create mode 100644 packages/hoppscotch-common/src/components/graphql/TabHead.vue diff --git a/packages/hoppscotch-common/src/components.d.ts b/packages/hoppscotch-common/src/components.d.ts index 84f34ccc4..484614b1f 100644 --- a/packages/hoppscotch-common/src/components.d.ts +++ b/packages/hoppscotch-common/src/components.d.ts @@ -80,6 +80,7 @@ declare module 'vue' { GraphqlResponse: typeof import('./components/graphql/Response.vue')['default'] GraphqlSidebar: typeof import('./components/graphql/Sidebar.vue')['default'] GraphqlSubscriptionLog: typeof import('./components/graphql/SubscriptionLog.vue')['default'] + GraphqlTabHead: typeof import('./components/graphql/TabHead.vue')['default'] GraphqlType: typeof import('./components/graphql/Type.vue')['default'] GraphqlTypeLink: typeof import('./components/graphql/TypeLink.vue')['default'] GraphqlVariable: typeof import('./components/graphql/Variable.vue')['default'] @@ -89,7 +90,7 @@ declare module 'vue' { HoppButtonPrimary: typeof import('@hoppscotch/ui')['HoppButtonPrimary'] HoppButtonSecondary: typeof import('@hoppscotch/ui')['HoppButtonSecondary'] HoppSmartAnchor: typeof import('@hoppscotch/ui')['HoppSmartAnchor'] - HoppSmartAutoComplete: typeof import("@hoppscotch/ui")["HoppSmartAutoComplete"] + HoppSmartAutoComplete: typeof import('@hoppscotch/ui')['HoppSmartAutoComplete'] HoppSmartCheckbox: typeof import('@hoppscotch/ui')['HoppSmartCheckbox'] HoppSmartConfirmModal: typeof import('@hoppscotch/ui')['HoppSmartConfirmModal'] HoppSmartExpand: typeof import('@hoppscotch/ui')['HoppSmartExpand'] @@ -151,6 +152,7 @@ declare module 'vue' { IconLucideLayers: typeof import('~icons/lucide/layers')['default'] IconLucideListEnd: typeof import('~icons/lucide/list-end')['default'] IconLucideMinus: typeof import('~icons/lucide/minus')['default'] + IconLucideRss: typeof import('~icons/lucide/rss')['default'] IconLucideSearch: typeof import('~icons/lucide/search')['default'] IconLucideUsers: typeof import('~icons/lucide/users')['default'] IconLucideVerified: typeof import('~icons/lucide/verified')['default'] diff --git a/packages/hoppscotch-common/src/components/collections/graphql/Collection.vue b/packages/hoppscotch-common/src/components/collections/graphql/Collection.vue index 89ceb3e1a..a103d9bc5 100644 --- a/packages/hoppscotch-common/src/components/collections/graphql/Collection.vue +++ b/packages/hoppscotch-common/src/components/collections/graphql/Collection.vue @@ -37,6 +37,7 @@ @click=" emit('add-request', { path: `${collectionIndex}`, + index: collection.requests.length, }) " /> @@ -219,6 +220,7 @@ import { moveGraphqlRequest, } from "~/newstore/collections" import { Picked } from "~/helpers/types/HoppPicked" +import { getTabsRefTo } from "~/helpers/graphql/tab" const props = defineProps({ picked: { type: Object, default: null }, @@ -293,6 +295,22 @@ const removeCollection = () => { emit("select", null) } + const possibleTabs = getTabsRefTo((tab) => { + const ctx = tab.document.saveContext + + if (!ctx) return false + + return ( + ctx.originLocation === "user-collection" && + ctx.folderPath.startsWith(props.collectionIndex.toString()) + ) + }) + + for (const tab of possibleTabs) { + tab.value.document.saveContext = undefined + tab.value.document.isDirty = true + } + removeGraphqlCollection(props.collectionIndex, props.collection.id) toast.success(`${t("state.deleted")}`) } diff --git a/packages/hoppscotch-common/src/components/collections/graphql/Folder.vue b/packages/hoppscotch-common/src/components/collections/graphql/Folder.vue index 6ef9795ee..e3901063a 100644 --- a/packages/hoppscotch-common/src/components/collections/graphql/Folder.vue +++ b/packages/hoppscotch-common/src/components/collections/graphql/Folder.vue @@ -34,7 +34,12 @@ :icon="IconFilePlus" :title="t('request.new')" class="hidden group-hover:inline-flex" - @click="emit('add-request', { path: folderPath })" + @click=" + emit('add-request', { + path: folderPath, + index: folder.requests.length, + }) + " /> { const pick = () => { emit("select", { - picked: { - pickedType: "gql-my-folder", - folderPath: props.folderPath, - }, + pickedType: "gql-my-folder", + folderPath: props.folderPath, }) } @@ -273,6 +277,22 @@ const removeFolder = () => { emit("select", { picked: null }) } + const possibleTabs = getTabsRefTo((tab) => { + const ctx = tab.document.saveContext + + if (!ctx) return false + + return ( + ctx.originLocation === "user-collection" && + ctx.folderPath.startsWith(props.folderPath) + ) + }) + + for (const tab of possibleTabs) { + tab.value.document.saveContext = undefined + tab.value.document.isDirty = true + } + removeGraphqlFolder(props.folderPath, props.folder.id) toast.success(t("state.deleted")) } diff --git a/packages/hoppscotch-common/src/components/collections/graphql/Request.vue b/packages/hoppscotch-common/src/components/collections/graphql/Request.vue index c4adff852..9d8dacbb6 100644 --- a/packages/hoppscotch-common/src/components/collections/graphql/Request.vue +++ b/packages/hoppscotch-common/src/components/collections/graphql/Request.vue @@ -20,22 +20,28 @@ /> {{ request.name }} + + + + +
-