feat: tab service added (#3367)

This commit is contained in:
Anwarul Islam
2023-10-11 18:51:07 +06:00
committed by GitHub
parent 51510566bc
commit ba31cdabea
60 changed files with 1112 additions and 841 deletions

View File

@@ -64,7 +64,6 @@
<script setup lang="ts">
import { platform } from "~/platform"
import { useI18n } from "@composables/i18n"
import { currentActiveTab } from "~/helpers/graphql/tab"
import { computed, ref, watch } from "vue"
import { connection } from "~/helpers/graphql/connection"
import { connect } from "~/helpers/graphql/connection"
@@ -72,8 +71,10 @@ import { disconnect } from "~/helpers/graphql/connection"
import { InterceptorService } from "~/services/interceptor.service"
import { useService } from "dioc/vue"
import { defineActionHandler } from "~/helpers/actions"
import { GQLTabService } from "~/services/tab/graphql"
const t = useI18n()
const tabs = useService(GQLTabService)
const interceptorService = useService(InterceptorService)
@@ -82,9 +83,9 @@ const connectionSwitchModal = ref(false)
const connected = computed(() => connection.state === "CONNECTED")
const url = computed({
get: () => currentActiveTab.value?.document.request.url ?? "",
get: () => tabs.currentActiveTab.value?.document.request.url ?? "",
set: (value) => {
currentActiveTab.value!.document.request.url = value
tabs.currentActiveTab.value!.document.request.url = value
},
})
@@ -97,7 +98,7 @@ const onConnectClick = () => {
}
const gqlConnect = () => {
connect(url.value, currentActiveTab.value?.document.request.headers)
connect(url.value, tabs.currentActiveTab.value?.document.request.headers)
platform.analytics?.logEvent({
type: "HOPP_REQUEST_RUN",
@@ -114,7 +115,7 @@ const switchConnection = () => {
const lastTwoUrls = ref<string[]>([])
watch(
currentActiveTab,
tabs.currentActiveTab,
(newVal) => {
if (newVal) {
lastTwoUrls.value.push(newVal.document.request.url)

View File

@@ -58,8 +58,7 @@ import { computed, ref, watch } from "vue"
import { defineActionHandler } from "~/helpers/actions"
import { HoppGQLRequest } from "@hoppscotch/data"
import { platform } from "~/platform"
import { currentActiveTab } from "~/helpers/graphql/tab"
import { computedWithControl } from "@vueuse/core"
import { computedWithControl, useVModel } from "@vueuse/core"
import {
GQLResponseEvent,
runGQLOperation,
@@ -68,26 +67,39 @@ import {
import { useService } from "dioc/vue"
import { InterceptorService } from "~/services/interceptor.service"
import { editGraphqlRequest } from "~/newstore/collections"
import { GQLTabService } from "~/services/tab/graphql"
const VALID_GQL_OPERATIONS = [
"query",
"headers",
"variables",
"authorization",
] as const
export type GQLOptionTabs = (typeof VALID_GQL_OPERATIONS)[number]
export type GQLOptionTabs = "query" | "headers" | "variables" | "authorization"
const selectedOptionTab = ref<GQLOptionTabs>("query")
const interceptorService = useService(InterceptorService)
const t = useI18n()
const toast = useToast()
const tabs = useService(GQLTabService)
// v-model integration with props and emit
const props = withDefaults(
defineProps<{
modelValue: HoppGQLRequest
response?: GQLResponseEvent[] | null
optionTab?: GQLOptionTabs
tabId: string
}>(),
{
response: null,
optionTab: "query",
}
)
const emit = defineEmits(["update:modelValue", "update:response"])
const selectedOptionTab = useVModel(props, "optionTab", emit)
const request = ref(props.modelValue)
@@ -100,8 +112,8 @@ watch(
)
const url = computedWithControl(
() => currentActiveTab.value,
() => currentActiveTab.value.document.request.url
() => tabs.currentActiveTab.value,
() => tabs.currentActiveTab.value.document.request.url
)
const activeGQLHeadersCount = computed(
@@ -185,17 +197,17 @@ const hideRequestModal = () => {
}
const saveRequest = () => {
if (
currentActiveTab.value.document.saveContext &&
currentActiveTab.value.document.saveContext.originLocation ===
tabs.currentActiveTab.value.document.saveContext &&
tabs.currentActiveTab.value.document.saveContext.originLocation ===
"user-collection"
) {
editGraphqlRequest(
currentActiveTab.value.document.saveContext.folderPath,
currentActiveTab.value.document.saveContext.requestIndex,
currentActiveTab.value.document.request
tabs.currentActiveTab.value.document.saveContext.folderPath,
tabs.currentActiveTab.value.document.saveContext.requestIndex,
tabs.currentActiveTab.value.document.request
)
currentActiveTab.value.document.isDirty = false
tabs.currentActiveTab.value.document.isDirty = false
} else {
showSaveRequestModal.value = true
}

View File

@@ -3,12 +3,13 @@
<template #primary>
<GraphqlRequestOptions
v-model="tab.document.request"
v-model:response="tab.response"
v-model:response="tab.document.response"
v-model:option-tab="tab.document.optionTabPreference"
:tab-id="tab.id"
/>
</template>
<template #secondary>
<GraphqlResponse :response="tab.response" />
<GraphqlResponse :response="tab.document.response" />
</template>
</AppPaneLayout>
</template>
@@ -18,14 +19,15 @@ import { useVModel } from "@vueuse/core"
import { cloneDeep } from "lodash-es"
import { watch } from "vue"
import { isEqualHoppGQLRequest } from "~/helpers/graphql"
import { HoppGQLTab } from "~/helpers/graphql/tab"
import { HoppGQLDocument } from "~/helpers/graphql/document"
import { HoppTab } from "~/services/tab"
// TODO: Move Response and Request execution code to over here
const props = defineProps<{ modelValue: HoppGQLTab }>()
const props = defineProps<{ modelValue: HoppTab<HoppGQLDocument> }>()
const emit = defineEmits<{
(e: "update:modelValue", val: HoppGQLTab): void
(e: "update:modelValue", val: HoppTab<HoppGQLDocument>): void
}>()
const tab = useVModel(props, "modelValue", emit)

View File

@@ -92,12 +92,13 @@ import IconXCircle from "~icons/lucide/x-circle"
import IconXSquare from "~icons/lucide/x-square"
import IconFileEdit from "~icons/lucide/file-edit"
import IconCopy from "~icons/lucide/copy"
import { HoppGQLTab } from "~/helpers/graphql/tab"
import { HoppTab } from "~/services/tab"
import { HoppGQLDocument } from "~/helpers/graphql/document"
const t = useI18n()
defineProps<{
tab: HoppGQLTab
tab: HoppTab<HoppGQLDocument>
isRemovable: boolean
}>()