localy stored variable data
This commit is contained in:
@@ -9,6 +9,7 @@ import {
|
||||
RESTReqSchemaVersion,
|
||||
HoppRESTAuth,
|
||||
ValidContentTypes,
|
||||
HoppRESTVar,
|
||||
} from "@hoppscotch/data"
|
||||
import DispatchingStore, { defineDispatchers } from "./DispatchingStore"
|
||||
import { HoppRESTResponse } from "~/helpers/types/HoppRESTResponse"
|
||||
@@ -29,6 +30,7 @@ export const getDefaultRESTRequest = (): HoppRESTRequest => ({
|
||||
endpoint: "https://echo.hoppscotch.io",
|
||||
name: "Untitled request",
|
||||
params: [],
|
||||
vars: [],
|
||||
headers: [],
|
||||
method: "GET",
|
||||
auth: {
|
||||
@@ -80,6 +82,14 @@ const dispatchers = defineDispatchers({
|
||||
},
|
||||
}
|
||||
},
|
||||
setVars(curr: RESTSession, { entries }: { entries: HoppRESTVar[] }) {
|
||||
return {
|
||||
request: {
|
||||
...curr.request,
|
||||
vars: entries,
|
||||
},
|
||||
}
|
||||
},
|
||||
addParam(curr: RESTSession, { newParam }: { newParam: HoppRESTParam }) {
|
||||
return {
|
||||
request: {
|
||||
@@ -88,6 +98,14 @@ const dispatchers = defineDispatchers({
|
||||
},
|
||||
}
|
||||
},
|
||||
addVar(curr: RESTSession, { newVar }: { newVar: HoppRESTVar }) {
|
||||
return {
|
||||
request: {
|
||||
...curr.request,
|
||||
vars: [...curr.request.vars, newVar],
|
||||
},
|
||||
}
|
||||
},
|
||||
updateParam(
|
||||
curr: RESTSession,
|
||||
{ index, updatedParam }: { index: number; updatedParam: HoppRESTParam }
|
||||
@@ -104,6 +122,22 @@ const dispatchers = defineDispatchers({
|
||||
},
|
||||
}
|
||||
},
|
||||
updateVar(
|
||||
curr: RESTSession,
|
||||
{ index, updatedVar }: { index: number; updatedVar: HoppRESTVar }
|
||||
) {
|
||||
const newVars = curr.request.vars.map((vari, i) => {
|
||||
if (i === index) return updatedVar
|
||||
else return vari
|
||||
})
|
||||
|
||||
return {
|
||||
request: {
|
||||
...curr.request,
|
||||
vars: newVars,
|
||||
},
|
||||
}
|
||||
},
|
||||
deleteParam(curr: RESTSession, { index }: { index: number }) {
|
||||
const newParams = curr.request.params.filter((_x, i) => i !== index)
|
||||
|
||||
@@ -373,6 +407,14 @@ export function setRESTParams(entries: HoppRESTParam[]) {
|
||||
},
|
||||
})
|
||||
}
|
||||
export function setRESTVars(entries: HoppRESTVar[]) {
|
||||
restSessionStore.dispatch({
|
||||
dispatcher: "setVars",
|
||||
payload: {
|
||||
entries,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export function addRESTParam(newParam: HoppRESTParam) {
|
||||
restSessionStore.dispatch({
|
||||
@@ -382,6 +424,14 @@ export function addRESTParam(newParam: HoppRESTParam) {
|
||||
},
|
||||
})
|
||||
}
|
||||
export function addRESTVar(newVar: HoppRESTVar) {
|
||||
restSessionStore.dispatch({
|
||||
dispatcher: "addVar",
|
||||
payload: {
|
||||
newVar,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export function updateRESTParam(index: number, updatedParam: HoppRESTParam) {
|
||||
restSessionStore.dispatch({
|
||||
@@ -392,6 +442,15 @@ export function updateRESTParam(index: number, updatedParam: HoppRESTParam) {
|
||||
},
|
||||
})
|
||||
}
|
||||
export function updateRESTVar(index: number, updatedVar: HoppRESTVar) {
|
||||
restSessionStore.dispatch({
|
||||
dispatcher: "updateVar",
|
||||
payload: {
|
||||
updatedVar,
|
||||
index,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export function deleteRESTParam(index: number) {
|
||||
restSessionStore.dispatch({
|
||||
@@ -592,12 +651,20 @@ export const restParams$ = restSessionStore.subject$.pipe(
|
||||
distinctUntilChanged()
|
||||
)
|
||||
|
||||
export const restVars$ = restSessionStore.subject$.pipe(
|
||||
pluck("request", "vars"),
|
||||
distinctUntilChanged()
|
||||
)
|
||||
|
||||
export const restActiveParamsCount$ = restParams$.pipe(
|
||||
map(
|
||||
(params) =>
|
||||
params.filter((x) => x.active && (x.key !== "" || x.value !== "")).length
|
||||
)
|
||||
)
|
||||
export const restActiveVarsCount$ = restVars$.pipe(
|
||||
map((vars) => vars.filter((x) => x.key !== "" || x.value !== "").length)
|
||||
)
|
||||
|
||||
export const restMethod$ = restSessionStore.subject$.pipe(
|
||||
pluck("request", "method"),
|
||||
|
||||
Reference in New Issue
Block a user