refactor: persist request handle under tab saveContext
Bump vue version.
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<div
|
<div
|
||||||
v-tippy="{ theme: 'tooltip', delay: [500, 20] }"
|
v-tippy="{ theme: 'tooltip', delay: [500, 20] }"
|
||||||
:title="tab.document.request.name"
|
:title="tabDocument.request.name"
|
||||||
class="flex items-center truncate px-2"
|
class="flex items-center truncate px-2"
|
||||||
@dblclick="emit('open-rename-modal')"
|
@dblclick="emit('open-rename-modal')"
|
||||||
@contextmenu.prevent="options?.tippy?.show()"
|
@contextmenu.prevent="options?.tippy?.show()"
|
||||||
@@ -9,9 +9,9 @@
|
|||||||
>
|
>
|
||||||
<span
|
<span
|
||||||
class="text-tiny font-semibold mr-2"
|
class="text-tiny font-semibold mr-2"
|
||||||
:style="{ color: getMethodLabelColorClassOf(tab.document.request) }"
|
:style="{ color: getMethodLabelColorClassOf(tabDocument.request) }"
|
||||||
>
|
>
|
||||||
{{ tab.document.request.method }}
|
{{ tabDocument.request.method }}
|
||||||
</span>
|
</span>
|
||||||
<tippy
|
<tippy
|
||||||
ref="options"
|
ref="options"
|
||||||
@@ -21,7 +21,7 @@
|
|||||||
:on-shown="() => tippyActions!.focus()"
|
:on-shown="() => tippyActions!.focus()"
|
||||||
>
|
>
|
||||||
<span class="truncate">
|
<span class="truncate">
|
||||||
{{ tab.document.request.name }}
|
{{ tabDocument.request.name }}
|
||||||
</span>
|
</span>
|
||||||
<template #content="{ hide }">
|
<template #content="{ hide }">
|
||||||
<div
|
<div
|
||||||
@@ -104,7 +104,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref } from "vue"
|
import { ComputedRef, ref, watch } from "vue"
|
||||||
import { TippyComponent } from "vue-tippy"
|
import { TippyComponent } from "vue-tippy"
|
||||||
import { getMethodLabelColorClassOf } from "~/helpers/rest/labelColoring"
|
import { getMethodLabelColorClassOf } from "~/helpers/rest/labelColoring"
|
||||||
import { useI18n } from "~/composables/i18n"
|
import { useI18n } from "~/composables/i18n"
|
||||||
@@ -115,10 +115,13 @@ import IconCopy from "~icons/lucide/copy"
|
|||||||
import IconShare2 from "~icons/lucide/share-2"
|
import IconShare2 from "~icons/lucide/share-2"
|
||||||
import { HoppTab } from "~/services/tab"
|
import { HoppTab } from "~/services/tab"
|
||||||
import { HoppRESTDocument } from "~/helpers/rest/document"
|
import { HoppRESTDocument } from "~/helpers/rest/document"
|
||||||
|
import { computed } from "vue"
|
||||||
|
import { HandleRef } from "~/services/new-workspace/handle"
|
||||||
|
import { WorkspaceRequest } from "~/services/new-workspace/workspace"
|
||||||
|
|
||||||
const t = useI18n()
|
const t = useI18n()
|
||||||
|
|
||||||
defineProps<{
|
const props = defineProps<{
|
||||||
tab: HoppTab<HoppRESTDocument>
|
tab: HoppTab<HoppRESTDocument>
|
||||||
isRemovable: boolean
|
isRemovable: boolean
|
||||||
}>()
|
}>()
|
||||||
@@ -139,4 +142,40 @@ const closeAction = ref<HTMLButtonElement | null>(null)
|
|||||||
const closeOthersAction = ref<HTMLButtonElement | null>(null)
|
const closeOthersAction = ref<HTMLButtonElement | null>(null)
|
||||||
const duplicateAction = ref<HTMLButtonElement | null>(null)
|
const duplicateAction = ref<HTMLButtonElement | null>(null)
|
||||||
const shareRequestAction = ref<HTMLButtonElement | null>(null)
|
const shareRequestAction = ref<HTMLButtonElement | null>(null)
|
||||||
|
const tabDocument = ref<HoppRESTDocument>(props.tab.document)
|
||||||
|
|
||||||
|
const requestHandleForCurrentTab = computed(() => {
|
||||||
|
return props.tab.document.saveContext?.originLocation ===
|
||||||
|
"workspace-user-collection"
|
||||||
|
? props.tab.document.saveContext.requestHandle
|
||||||
|
: undefined
|
||||||
|
}) as ComputedRef<HandleRef<WorkspaceRequest>["value"] | undefined>
|
||||||
|
|
||||||
|
watch(
|
||||||
|
requestHandleForCurrentTab,
|
||||||
|
(newRequestHandleState) => {
|
||||||
|
if (!newRequestHandleState) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newRequestHandleState.type !== "ok") {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
tabDocument.value.request.name !== newRequestHandleState.data.request.name
|
||||||
|
) {
|
||||||
|
tabDocument.value.request.name = newRequestHandleState.data.request.name
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ deep: true }
|
||||||
|
)
|
||||||
|
|
||||||
|
watch(
|
||||||
|
props.tab.document,
|
||||||
|
(newTabDocument) => {
|
||||||
|
;(tabDocument.value as HoppRESTDocument) = newTabDocument
|
||||||
|
},
|
||||||
|
{ deep: true }
|
||||||
|
)
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -616,17 +616,6 @@ const onRemoveRequest = async () => {
|
|||||||
possibleTab.value.document.isDirty = true
|
possibleTab.value.document.isDirty = true
|
||||||
}
|
}
|
||||||
|
|
||||||
const { collectionID, requestID } = requestHandle.value.data
|
|
||||||
const requestIndex = parseInt(requestID.split("/").slice(-1)[0])
|
|
||||||
|
|
||||||
// The same function is used to reorder requests since after removing, it's basically doing reorder
|
|
||||||
resolveSaveContextOnRequestReorder({
|
|
||||||
lastIndex: requestIndex,
|
|
||||||
newIndex: -1,
|
|
||||||
folderPath: collectionID,
|
|
||||||
length: getRequestsByPath(restCollectionState.value, collectionID).length,
|
|
||||||
})
|
|
||||||
|
|
||||||
toast.success(t("state.deleted"))
|
toast.success(t("state.deleted"))
|
||||||
displayConfirmModal(false)
|
displayConfirmModal(false)
|
||||||
}
|
}
|
||||||
@@ -668,8 +657,6 @@ const selectRequest = async (requestIndexPath: string) => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const request = requestHandle.value.data.request
|
|
||||||
|
|
||||||
// If there is a request with this save context, switch into it
|
// If there is a request with this save context, switch into it
|
||||||
let possibleTab = null
|
let possibleTab = null
|
||||||
|
|
||||||
@@ -701,7 +688,7 @@ const selectRequest = async (requestIndexPath: string) => {
|
|||||||
} else {
|
} else {
|
||||||
// If not, open the request in a new tab
|
// If not, open the request in a new tab
|
||||||
tabs.createNewTab({
|
tabs.createNewTab({
|
||||||
request: cloneDeep(request),
|
request: cloneDeep(requestHandle.value.data.request),
|
||||||
isDirty: false,
|
isDirty: false,
|
||||||
saveContext: {
|
saveContext: {
|
||||||
originLocation: "workspace-user-collection",
|
originLocation: "workspace-user-collection",
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ import {
|
|||||||
import { HoppGQLHeader } from "~/helpers/graphql"
|
import { HoppGQLHeader } from "~/helpers/graphql"
|
||||||
import { HoppInheritedProperty } from "~/helpers/types/HoppInheritedProperties"
|
import { HoppInheritedProperty } from "~/helpers/types/HoppInheritedProperties"
|
||||||
import { computedAsync } from "@vueuse/core"
|
import { computedAsync } from "@vueuse/core"
|
||||||
|
import { merge } from "lodash-es"
|
||||||
|
|
||||||
export class PersonalWorkspaceProviderService
|
export class PersonalWorkspaceProviderService
|
||||||
extends Service
|
extends Service
|
||||||
@@ -231,10 +232,7 @@ export class PersonalWorkspaceProviderService
|
|||||||
collectionID.split("/").map((id) => parseInt(id))
|
collectionID.split("/").map((id) => parseInt(id))
|
||||||
)
|
)
|
||||||
|
|
||||||
const newCollection = {
|
const newCollection = merge(collection, updatedCollection)
|
||||||
...collection,
|
|
||||||
...updatedCollection,
|
|
||||||
}
|
|
||||||
|
|
||||||
const isRootCollection = collectionID.split("/").length === 1
|
const isRootCollection = collectionID.split("/").length === 1
|
||||||
|
|
||||||
@@ -403,10 +401,7 @@ export class PersonalWorkspaceProviderService
|
|||||||
const { collectionID, requestID, request } = requestHandle.value.data
|
const { collectionID, requestID, request } = requestHandle.value.data
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const newRequest: HoppRESTRequest = {
|
const newRequest: HoppRESTRequest = merge(request, updatedRequest)
|
||||||
...request,
|
|
||||||
...updatedRequest,
|
|
||||||
}
|
|
||||||
const requestIndex = parseInt(requestID)
|
const requestIndex = parseInt(requestID)
|
||||||
editRESTRequest(collectionID, requestIndex, newRequest)
|
editRESTRequest(collectionID, requestIndex, newRequest)
|
||||||
|
|
||||||
|
|||||||
2
pnpm-lock.yaml
generated
2
pnpm-lock.yaml
generated
@@ -1772,12 +1772,14 @@ packages:
|
|||||||
'@babel/plugin-proposal-class-properties@7.18.6':
|
'@babel/plugin-proposal-class-properties@7.18.6':
|
||||||
resolution: {integrity: sha512-cumfXOF0+nzZrrN8Rf0t7M+tF6sZc7vhQwYQck9q1/5w2OExlD+b4v4RpMJFaV1Z7WcDRgO6FqvxqxGlwo+RHQ==}
|
resolution: {integrity: sha512-cumfXOF0+nzZrrN8Rf0t7M+tF6sZc7vhQwYQck9q1/5w2OExlD+b4v4RpMJFaV1Z7WcDRgO6FqvxqxGlwo+RHQ==}
|
||||||
engines: {node: '>=6.9.0'}
|
engines: {node: '>=6.9.0'}
|
||||||
|
deprecated: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-class-properties instead.
|
||||||
peerDependencies:
|
peerDependencies:
|
||||||
'@babel/core': ^7.0.0-0
|
'@babel/core': ^7.0.0-0
|
||||||
|
|
||||||
'@babel/plugin-proposal-object-rest-spread@7.18.6':
|
'@babel/plugin-proposal-object-rest-spread@7.18.6':
|
||||||
resolution: {integrity: sha512-9yuM6wr4rIsKa1wlUAbZEazkCrgw2sMPEXCr4Rnwetu7cEW1NydkCWytLuYletbf8vFxdJxFhwEZqMpOx2eZyw==}
|
resolution: {integrity: sha512-9yuM6wr4rIsKa1wlUAbZEazkCrgw2sMPEXCr4Rnwetu7cEW1NydkCWytLuYletbf8vFxdJxFhwEZqMpOx2eZyw==}
|
||||||
engines: {node: '>=6.9.0'}
|
engines: {node: '>=6.9.0'}
|
||||||
|
deprecated: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-object-rest-spread instead.
|
||||||
peerDependencies:
|
peerDependencies:
|
||||||
'@babel/core': ^7.0.0-0
|
'@babel/core': ^7.0.0-0
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user