From 7006fa57e27dcaf170466f76bb3562a5a5cbef22 Mon Sep 17 00:00:00 2001 From: Jason Casareno Date: Thu, 21 Jul 2022 20:58:53 -0700 Subject: [PATCH 1/3] Small naming changes --- .github/workflows/deploy-netlify.yml | 2 +- Dockerfile | 2 +- .../components/http/Variables.vue | 33 ++++++++++++++++--- .../hoppscotch-app/newstore/RESTSession.ts | 2 +- .../newstore/localpersistence.ts | 2 -- 5 files changed, 32 insertions(+), 9 deletions(-) diff --git a/.github/workflows/deploy-netlify.yml b/.github/workflows/deploy-netlify.yml index e141db6e0..4837d45bc 100644 --- a/.github/workflows/deploy-netlify.yml +++ b/.github/workflows/deploy-netlify.yml @@ -19,7 +19,7 @@ jobs: run_install: true - name: Setup Environment - run: mv packages/hoppscotch-app/.env.example packages/hoppscotch-app/.env + run: mv packages/hoppscotch-app/.env packages/hoppscotch-app/.env - name: Build Site run: pnpm run generate diff --git a/Dockerfile b/Dockerfile index 1572b03f3..4b3f6b654 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,7 +22,7 @@ RUN pnpm i --unsafe-perm=true ENV HOST 0.0.0.0 EXPOSE 3000 -RUN mv packages/hoppscotch-app/.env.example packages/hoppscotch-app/.env +RUN mv packages/hoppscotch-app/.env packages/hoppscotch-app/.env RUN pnpm run generate diff --git a/packages/hoppscotch-app/components/http/Variables.vue b/packages/hoppscotch-app/components/http/Variables.vue index f768f4302..e0493e064 100644 --- a/packages/hoppscotch-app/components/http/Variables.vue +++ b/packages/hoppscotch-app/components/http/Variables.vue @@ -92,7 +92,7 @@ const toast = useToast() const emptyVars: string = "Add a new variable" -const idTickerV = ref(0) +const idTicker = ref(0) const deletionToast = ref<{ goAway: (delay: number) => void } | null>(null) @@ -101,7 +101,7 @@ const vars = useStream(restVars$, [], setRESTVars) as Ref // The UI representation of the variables list (has the empty end variable) const workingVars = ref>([ { - id: idTickerV.value++, + id: idTicker.value++, key: "", value: "", }, @@ -111,13 +111,38 @@ const workingVars = ref>([ watch(workingVars, (varsList) => { if (varsList.length > 0 && varsList[varsList.length - 1].key !== "") { workingVars.value.push({ - id: idTickerV.value++, + id: idTicker.value++, key: "", value: "", }) } }) +// Sync logic between params and working/bulk params +watch( + vars, + (newParamsList) => { + // Sync should overwrite working params + const filteredWorkingVars: HoppRESTVar[] = pipe( + workingVars.value, + A.filterMap( + flow( + O.fromPredicate((e) => e.key !== ""), + O.map(objRemoveKey("id")) + ) + ) + ) + + if (!isEqual(newParamsList, filteredWorkingVars)) { + workingVars.value = pipe( + newParamsList, + A.map((x) => ({ id: idTicker.value++, ...x })) + ) + } + }, + { immediate: true } +) + watch(workingVars, (newWorkingVars) => { const fixedVars = pipe( newWorkingVars, @@ -136,7 +161,7 @@ watch(workingVars, (newWorkingVars) => { const addVar = () => { workingVars.value.push({ - id: idTickerV.value++, + id: idTicker.value++, key: "", value: "", }) diff --git a/packages/hoppscotch-app/newstore/RESTSession.ts b/packages/hoppscotch-app/newstore/RESTSession.ts index a410da2bc..eb21d0f27 100644 --- a/packages/hoppscotch-app/newstore/RESTSession.ts +++ b/packages/hoppscotch-app/newstore/RESTSession.ts @@ -4,12 +4,12 @@ import { FormDataKeyValue, HoppRESTHeader, HoppRESTParam, + HoppRESTVar, HoppRESTReqBody, HoppRESTRequest, RESTReqSchemaVersion, HoppRESTAuth, ValidContentTypes, - HoppRESTVar, } from "@hoppscotch/data" import DispatchingStore, { defineDispatchers } from "./DispatchingStore" import { HoppRESTResponse } from "~/helpers/types/HoppRESTResponse" diff --git a/packages/hoppscotch-app/newstore/localpersistence.ts b/packages/hoppscotch-app/newstore/localpersistence.ts index 83c654fb9..a6f7a033a 100644 --- a/packages/hoppscotch-app/newstore/localpersistence.ts +++ b/packages/hoppscotch-app/newstore/localpersistence.ts @@ -321,8 +321,6 @@ function setupRequestPersistence() { } window.localStorage.setItem("restRequest", JSON.stringify(reqClone)) }) - - console.log("localRequest", localRequest) } export function setupLocalPersistence() { From 5413bc584a9932e54197c9e1d9e9dd5d88ec315a Mon Sep 17 00:00:00 2001 From: Jason Casareno Date: Fri, 22 Jul 2022 12:37:47 -0700 Subject: [PATCH 2/3] Added missing dispatcher and function --- .../hoppscotch-app/newstore/RESTSession.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/packages/hoppscotch-app/newstore/RESTSession.ts b/packages/hoppscotch-app/newstore/RESTSession.ts index eb21d0f27..7a9e7cfe4 100644 --- a/packages/hoppscotch-app/newstore/RESTSession.ts +++ b/packages/hoppscotch-app/newstore/RESTSession.ts @@ -148,6 +148,16 @@ const dispatchers = defineDispatchers({ }, } }, + deleteVar(curr: RESTSession, { index }: { index: number }) { + const newVars = curr.request.vars.filter((_x, i) => i !== index) + + return { + request: { + ...curr.request, + vars: newVars, + }, + } + }, deleteAllParams(curr: RESTSession) { return { request: { @@ -461,6 +471,15 @@ export function deleteRESTParam(index: number) { }) } +export function deleteRESTVar(index: number) { + restSessionStore.dispatch({ + dispatcher: "deleteVar", + payload: { + index, + }, + }) +} + export function deleteAllRESTParams() { restSessionStore.dispatch({ dispatcher: "deleteAllParams", From 8aa066e2abd7d3135128146b03b6e07a051c27a0 Mon Sep 17 00:00:00 2001 From: Jason Casareno Date: Wed, 27 Jul 2022 17:47:37 -0700 Subject: [PATCH 3/3] Created default value for HoppRESTRequest for testing --- packages/hoppscotch-app/components/http/Variables.vue | 7 ++++--- packages/hoppscotch-app/newstore/RESTSession.ts | 7 ++++++- packages/hoppscotch-data/src/rest/index.ts | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/hoppscotch-app/components/http/Variables.vue b/packages/hoppscotch-app/components/http/Variables.vue index e0493e064..0590a6a47 100644 --- a/packages/hoppscotch-app/components/http/Variables.vue +++ b/packages/hoppscotch-app/components/http/Variables.vue @@ -96,6 +96,7 @@ const idTicker = ref(0) const deletionToast = ref<{ goAway: (delay: number) => void } | null>(null) +// The functional variables list (the variables actually applied to the session) const vars = useStream(restVars$, [], setRESTVars) as Ref // The UI representation of the variables list (has the empty end variable) @@ -121,7 +122,7 @@ watch(workingVars, (varsList) => { // Sync logic between params and working/bulk params watch( vars, - (newParamsList) => { + (newVarsList) => { // Sync should overwrite working params const filteredWorkingVars: HoppRESTVar[] = pipe( workingVars.value, @@ -133,9 +134,9 @@ watch( ) ) - if (!isEqual(newParamsList, filteredWorkingVars)) { + if (!isEqual(newVarsList, filteredWorkingVars)) { workingVars.value = pipe( - newParamsList, + newVarsList, A.map((x) => ({ id: idTicker.value++, ...x })) ) } diff --git a/packages/hoppscotch-app/newstore/RESTSession.ts b/packages/hoppscotch-app/newstore/RESTSession.ts index 7a9e7cfe4..5d00070de 100644 --- a/packages/hoppscotch-app/newstore/RESTSession.ts +++ b/packages/hoppscotch-app/newstore/RESTSession.ts @@ -30,7 +30,12 @@ export const getDefaultRESTRequest = (): HoppRESTRequest => ({ endpoint: "https://echo.hoppscotch.io", name: "Untitled request", params: [], - vars: [], + vars: [ + { + key: "amount", + value: "23", + }, + ], headers: [], method: "GET", auth: { diff --git a/packages/hoppscotch-data/src/rest/index.ts b/packages/hoppscotch-data/src/rest/index.ts index 89ce2b89d..a9fb8aa12 100644 --- a/packages/hoppscotch-data/src/rest/index.ts +++ b/packages/hoppscotch-data/src/rest/index.ts @@ -8,7 +8,7 @@ import { lodashIsEqualEq, mapThenEq, undefinedEq } from "../utils/eq" export * from "./content-types" export * from "./HoppRESTAuth" -export const RESTReqSchemaVersion = "2" +export const RESTReqSchemaVersion = "1" export type HoppRESTParam = { key: string