From ede27e06003f58a3cf74904181ef81d328a32b9f Mon Sep 17 00:00:00 2001 From: Andrew Bastin Date: Thu, 14 Apr 2022 20:23:29 +0530 Subject: [PATCH] refactor: implement updated equality heuristics for hopprestrequest struct --- .../components/collections/my/Request.vue | 6 +- .../components/collections/teams/Request.vue | 9 +- .../components/history/index.vue | 20 +- packages/hoppscotch-app/package.json | 2 +- packages/hoppscotch-app/pages/index.vue | 5 +- packages/hoppscotch-cli/package.json | 2 +- packages/hoppscotch-data/package.json | 2 +- packages/hoppscotch-data/src/rest/index.ts | 25 ++ packages/hoppscotch-data/src/utils/eq.ts | 50 +++ packages/hoppscotch-js-sandbox/package.json | 2 +- pnpm-lock.yaml | 305 ++---------------- 11 files changed, 132 insertions(+), 296 deletions(-) create mode 100644 packages/hoppscotch-data/src/utils/eq.ts diff --git a/packages/hoppscotch-app/components/collections/my/Request.vue b/packages/hoppscotch-app/components/collections/my/Request.vue index abeb983e3..0da5f2b07 100644 --- a/packages/hoppscotch-app/components/collections/my/Request.vue +++ b/packages/hoppscotch-app/components/collections/my/Request.vue @@ -162,8 +162,8 @@ import { HoppRESTRequest, safelyExtractRESTRequest, translateToNewRequest, + isEqualHoppRESTRequest, } from "@hoppscotch/data" -import isEqual from "lodash/isEqual" import * as E from "fp-ts/Either" import { useI18n, @@ -349,9 +349,9 @@ const selectRequest = () => { const currentFullReq = getRESTRequest() // Check if whether user clicked the same request or not - if (!isActive.value) { + if (!isActive.value && currentReqWithNoChange !== undefined) { // Check if there is any changes done on the current request - if (isEqual(currentReqWithNoChange, currentFullReq)) { + if (isEqualHoppRESTRequest(currentReqWithNoChange, currentFullReq)) { setRestReq(props.request) if (props.saveRequest) emit("select", { diff --git a/packages/hoppscotch-app/components/collections/teams/Request.vue b/packages/hoppscotch-app/components/collections/teams/Request.vue index 477e61e23..ad33ee0e6 100644 --- a/packages/hoppscotch-app/components/collections/teams/Request.vue +++ b/packages/hoppscotch-app/components/collections/teams/Request.vue @@ -157,11 +157,11 @@ import { ref, computed } from "@nuxtjs/composition-api" import { HoppRESTRequest, + isEqualHoppRESTRequest, safelyExtractRESTRequest, translateToNewRequest, } from "@hoppscotch/data" import * as E from "fp-ts/Either" -import isEqual from "lodash/isEqual" import { useI18n, useToast, @@ -277,8 +277,7 @@ const isActive = computed( () => active.value && active.value.originLocation === "team-collection" && - active.value.requestID === props.requestIndex && - isEqual(active.value.req, props.request) + active.value.requestID === props.requestIndex ) const dragStart = ({ dataTransfer }: DragEvent) => { @@ -333,9 +332,9 @@ const selectRequest = () => { const currentFullReq = getRESTRequest() // Check if whether user clicked the same request or not - if (!isActive.value) { + if (!isActive.value && currentReqWithNoChange) { // Check if there is any changes done on the current request - if (isEqual(currentReqWithNoChange, currentFullReq)) { + if (isEqualHoppRESTRequest(currentReqWithNoChange, currentFullReq)) { setRestReq(props.request) if (props.saveRequest) emit("select", { diff --git a/packages/hoppscotch-app/components/history/index.vue b/packages/hoppscotch-app/components/history/index.vue index f757d4c79..2d8b653be 100644 --- a/packages/hoppscotch-app/components/history/index.vue +++ b/packages/hoppscotch-app/components/history/index.vue @@ -113,13 +113,16 @@