|
@@ -17,10 +17,11 @@
|
|
|
<script setup lang="ts">
|
|
|
import { watch } from "vue"
|
|
|
import { useVModel } from "@vueuse/core"
|
|
|
-import { cloneDeep } from "lodash-es"
|
|
|
-import { isEqualHoppRESTRequest } from "@hoppscotch/data"
|
|
|
+import { cloneDeep, isEqual } from "lodash-es"
|
|
|
import { HoppTab } from "~/services/tab"
|
|
|
import { HoppRESTDocument } from "~/helpers/rest/document"
|
|
|
+import { WorkspaceRequest } from "~/services/new-workspace/workspace"
|
|
|
+import { HandleRef } from "~/services/new-workspace/handle"
|
|
|
|
|
|
// TODO: Move Response and Request execution code to over here
|
|
|
|
|
@@ -32,15 +33,43 @@ const emit = defineEmits<{
|
|
|
|
|
|
const tab = useVModel(props, "modelValue", emit)
|
|
|
|
|
|
-// TODO: Come up with a better dirty check
|
|
|
let oldRequest = cloneDeep(tab.value.document.request)
|
|
|
+
|
|
|
watch(
|
|
|
() => tab.value.document.request,
|
|
|
(updatedValue) => {
|
|
|
+ // Request from the collection tree
|
|
|
if (
|
|
|
- !tab.value.document.isDirty &&
|
|
|
- !isEqualHoppRESTRequest(oldRequest, updatedValue)
|
|
|
+ tab.value.document.saveContext?.originLocation ===
|
|
|
+ "workspace-user-collection"
|
|
|
) {
|
|
|
+ const requestHandle = tab.value.document.saveContext.requestHandle as
|
|
|
+ | HandleRef<WorkspaceRequest>["value"]
|
|
|
+ | undefined
|
|
|
+
|
|
|
+ if (!requestHandle || requestHandle.type === "invalid") {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if (
|
|
|
+ !tab.value.document.isDirty &&
|
|
|
+ !isEqual(oldRequest, requestHandle?.data.request)
|
|
|
+ ) {
|
|
|
+ tab.value.document.isDirty = true
|
|
|
+ }
|
|
|
+
|
|
|
+ if (
|
|
|
+ tab.value.document.isDirty &&
|
|
|
+ isEqual(oldRequest, requestHandle?.data.request)
|
|
|
+ ) {
|
|
|
+ tab.value.document.isDirty = false
|
|
|
+ }
|
|
|
+
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // Unsaved request
|
|
|
+ if (!tab.value.document.isDirty && !isEqual(oldRequest, updatedValue)) {
|
|
|
tab.value.document.isDirty = true
|
|
|
}
|
|
|
|