fix: persist request execution context between tabs (#4284)
This commit is contained in:
@@ -70,9 +70,11 @@
|
|||||||
:title="`${t(
|
:title="`${t(
|
||||||
'action.send'
|
'action.send'
|
||||||
)} <kbd>${getSpecialKey()}</kbd><kbd>↩</kbd>`"
|
)} <kbd>${getSpecialKey()}</kbd><kbd>↩</kbd>`"
|
||||||
:label="`${!loading ? t('action.send') : t('action.cancel')}`"
|
:label="`${
|
||||||
|
!isTabResponseLoading ? t('action.send') : t('action.cancel')
|
||||||
|
}`"
|
||||||
class="min-w-[5rem] flex-1 rounded-r-none"
|
class="min-w-[5rem] flex-1 rounded-r-none"
|
||||||
@click="!loading ? newSendRequest() : cancelRequest()"
|
@click="!isTabResponseLoading ? newSendRequest() : cancelRequest()"
|
||||||
/>
|
/>
|
||||||
<span class="flex">
|
<span class="flex">
|
||||||
<tippy
|
<tippy
|
||||||
@@ -238,7 +240,7 @@ import { useReadonlyStream, useStreamSubscriber } from "@composables/stream"
|
|||||||
import { useToast } from "@composables/toast"
|
import { useToast } from "@composables/toast"
|
||||||
import { useVModel } from "@vueuse/core"
|
import { useVModel } from "@vueuse/core"
|
||||||
import * as E from "fp-ts/Either"
|
import * as E from "fp-ts/Either"
|
||||||
import { Ref, computed, ref, onUnmounted } from "vue"
|
import { computed, ref, onUnmounted } from "vue"
|
||||||
import { defineActionHandler, invokeAction } from "~/helpers/actions"
|
import { defineActionHandler, invokeAction } from "~/helpers/actions"
|
||||||
import { runMutation } from "~/helpers/backend/GQLClient"
|
import { runMutation } from "~/helpers/backend/GQLClient"
|
||||||
import { UpdateRequestDocument } from "~/helpers/backend/graphql"
|
import { UpdateRequestDocument } from "~/helpers/backend/graphql"
|
||||||
@@ -302,6 +304,10 @@ const curlText = ref("")
|
|||||||
|
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
|
|
||||||
|
const isTabResponseLoading = computed(
|
||||||
|
() => tab.value.document.response?.type === "loading"
|
||||||
|
)
|
||||||
|
|
||||||
const showCurlImportModal = ref(false)
|
const showCurlImportModal = ref(false)
|
||||||
const showCodegenModal = ref(false)
|
const showCodegenModal = ref(false)
|
||||||
const showSaveRequestModal = ref(false)
|
const showSaveRequestModal = ref(false)
|
||||||
@@ -318,8 +324,6 @@ const saveRequestAction = ref<any | null>(null)
|
|||||||
|
|
||||||
const history = useReadonlyStream<RESTHistoryEntry[]>(restHistory$, [])
|
const history = useReadonlyStream<RESTHistoryEntry[]>(restHistory$, [])
|
||||||
|
|
||||||
const requestCancelFunc: Ref<(() => void) | null> = ref(null)
|
|
||||||
|
|
||||||
const userHistories = computed(() => {
|
const userHistories = computed(() => {
|
||||||
return history.value.map((history) => history.request.endpoint).slice(0, 10)
|
return history.value.map((history) => history.request.endpoint).slice(0, 10)
|
||||||
})
|
})
|
||||||
@@ -351,7 +355,8 @@ const newSendRequest = async () => {
|
|||||||
const [cancel, streamPromise] = runRESTRequest$(tab)
|
const [cancel, streamPromise] = runRESTRequest$(tab)
|
||||||
const streamResult = await streamPromise
|
const streamResult = await streamPromise
|
||||||
|
|
||||||
requestCancelFunc.value = cancel
|
tab.value.document.cancelFunction = cancel
|
||||||
|
|
||||||
if (E.isRight(streamResult)) {
|
if (E.isRight(streamResult)) {
|
||||||
subscribeToStream(
|
subscribeToStream(
|
||||||
streamResult.right,
|
streamResult.right,
|
||||||
@@ -441,7 +446,7 @@ onUnmounted(() => {
|
|||||||
|
|
||||||
const cancelRequest = () => {
|
const cancelRequest = () => {
|
||||||
loading.value = false
|
loading.value = false
|
||||||
requestCancelFunc.value?.()
|
tab.value.document.cancelFunction?.()
|
||||||
|
|
||||||
updateRESTResponse(null)
|
updateRESTResponse(null)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -87,4 +87,9 @@ export type HoppRESTDocument = {
|
|||||||
* (if any)
|
* (if any)
|
||||||
*/
|
*/
|
||||||
inheritedProperties?: HoppInheritedProperty
|
inheritedProperties?: HoppInheritedProperty
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The function responsible for cancelling the tab request call
|
||||||
|
*/
|
||||||
|
cancelFunction?: () => void
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -539,6 +539,7 @@ export const REST_TAB_STATE_SCHEMA = z
|
|||||||
responseTabPreference: z.optional(z.string()),
|
responseTabPreference: z.optional(z.string()),
|
||||||
optionTabPreference: z.optional(z.enum(validRestOperations)),
|
optionTabPreference: z.optional(z.enum(validRestOperations)),
|
||||||
inheritedProperties: z.optional(HoppInheritedPropertySchema),
|
inheritedProperties: z.optional(HoppInheritedPropertySchema),
|
||||||
|
cancelFunction: z.optional(z.function()),
|
||||||
})
|
})
|
||||||
.strict(),
|
.strict(),
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user