fix: additional envs

This commit is contained in:
liyasthomas
2022-02-19 18:29:43 +05:30
parent b3f05c42e8
commit 578148f45f
4 changed files with 82 additions and 23 deletions

View File

@@ -38,11 +38,37 @@
v-for="(env, index) in testResults.envDiff.global.updations" v-for="(env, index) in testResults.envDiff.global.updations"
:key="`env-${env.key}-${index}`" :key="`env-${env.key}-${index}`"
:env="env" :env="env"
status="updations"
/>
<HttpTestResultEnv
v-for="(env, index) in testResults.envDiff.global.additions"
:key="`env-${env.key}-${index}`"
:env="env"
status="additions"
/>
<HttpTestResultEnv
v-for="(env, index) in testResults.envDiff.global.deletions"
:key="`env-${env.key}-${index}`"
:env="env"
status="deletions"
/> />
<HttpTestResultEnv <HttpTestResultEnv
v-for="(env, index) in testResults.envDiff.selected.updations" v-for="(env, index) in testResults.envDiff.selected.updations"
:key="`env-${env.key}-${index}`" :key="`env-${env.key}-${index}`"
:env="env" :env="env"
status="updations"
/>
<HttpTestResultEnv
v-for="(env, index) in testResults.envDiff.selected.additions"
:key="`env-${env.key}-${index}`"
:env="env"
status="additions"
/>
<HttpTestResultEnv
v-for="(env, index) in testResults.envDiff.selected.deletions"
:key="`env-${env.key}-${index}`"
:env="env"
status="deletions"
/> />
</div> </div>
</details> </details>
@@ -151,8 +177,12 @@ const clearContent = () => setRESTTestResults(null)
const haveEnvVariables = computed(() => { const haveEnvVariables = computed(() => {
if (!testResults.value) return false if (!testResults.value) return false
return ( return (
testResults.value.envDiff.global.additions.length ||
testResults.value.envDiff.global.updations.length || testResults.value.envDiff.global.updations.length ||
testResults.value.envDiff.selected.updations.length testResults.value.envDiff.global.deletions.length ||
testResults.value.envDiff.selected.additions.length ||
testResults.value.envDiff.selected.updations.length ||
testResults.value.envDiff.selected.deletions.length
) )
}) })
</script> </script>

View File

@@ -1,24 +1,52 @@
<template> <template>
<div class="flex items-center px-4 py-2"> <div class="flex items-center px-4 py-2">
<i class="mr-4 material-icons text-accentLight"> lock </i> <i class="mr-4 material-icons" :class="getStyle(status)">
{{ getIcon(status) }}
</i>
<span class="text-secondaryDark"> <span class="text-secondaryDark">
{{ env.key }} {{ env.key }}
</span> </span>
<span class="text-secondaryDark"> <span class="text-secondaryDark">
{{ ` \xA0 — \xA0 ${env.value}` }} {{ ` \xA0 — \xA0 ${env.value}` }}
</span> </span>
<span class="text-secondaryLight"> <span v-if="status === 'updations'" class="text-secondaryLight">
{{ ` \xA0 \xA0 ${env.previousValue}` }} {{ ` \xA0 \xA0 ${env.previousValue}` }}
</span> </span>
</div> </div>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
defineProps<{ type Status = "updations" | "additions" | "deletions"
type Props = {
env: { env: {
key: string key: string
value: string value: string
previousValue: string previousValue?: string
} }
}>() status: Status
}
defineProps<Props>()
const getIcon = (status: Status) => {
switch (status) {
case "additions":
return "add_circle_outline"
case "updations":
return "check_circle_outline"
case "deletions":
return "remove_circle_outline"
}
}
const getStyle = (status: Status) => {
switch (status) {
case "additions":
return "text-green-500"
case "updations":
return "text-yellow-500"
case "deletions":
return "text-red-500"
}
}
</script> </script>

View File

@@ -11,6 +11,7 @@ import {
TestDescriptor, TestDescriptor,
} from "@hoppscotch/js-sandbox" } from "@hoppscotch/js-sandbox"
import { isRight } from "fp-ts/Either" import { isRight } from "fp-ts/Either"
import cloneDeep from "lodash/cloneDeep"
import { import {
getCombinedEnvVariables, getCombinedEnvVariables,
getFinalEnvsFromPreRequest, getFinalEnvsFromPreRequest,
@@ -91,8 +92,6 @@ export const runRESTRequest$ = (): TaskEither<
})() })()
if (isRight(runResult)) { if (isRight(runResult)) {
debugger
setRESTTestResults(translateToSandboxTestResults(runResult.right)) setRESTTestResults(translateToSandboxTestResults(runResult.right))
setGlobalEnvVariables(runResult.right.envs.global) setGlobalEnvVariables(runResult.right.envs.global)
@@ -156,22 +155,23 @@ const getUpdatedEnvVariables = (
updated, updated,
A.filterMap( A.filterMap(
flow( flow(
O.fromPredicate( O.of,
(x) => current.findIndex((y) => x.key === y.key) === -1 O.bindTo("env"),
O.bind("index", ({ env }) =>
pipe(
current.findIndex((x) => x.key === env.key),
O.fromPredicate((x) => x !== -1)
)
), ),
O.chain( O.chain(
O.fromPredicate( O.fromPredicate(
(x) => current.findIndex((y) => x.value !== y.value) === -1 ({ env, index }) => env.value !== current[index].value
) )
), ),
O.map((x) => { O.map(({ env, index }) => ({
const match = current.find((y) => x.key === y.key)!.value ...env,
previousValue: current[index].value,
return { }))
...x,
previousValue: match,
}
})
) )
) )
) )
@@ -187,8 +187,8 @@ function translateToSandboxTestResults(
} }
} }
const globals = getGlobalVariables() const globals = cloneDeep(getGlobalVariables())
const env = getCurrentEnvironment() const env = cloneDeep(getCurrentEnvironment())
return { return {
description: "", description: "",

View File

@@ -1,13 +1,14 @@
import { runPreRequestScript } from "@hoppscotch/js-sandbox" import { runPreRequestScript } from "@hoppscotch/js-sandbox"
import { Environment } from "@hoppscotch/data" import { Environment } from "@hoppscotch/data"
import cloneDeep from "lodash/cloneDeep"
import { import {
getCurrentEnvironment, getCurrentEnvironment,
getGlobalVariables, getGlobalVariables,
} from "~/newstore/environments" } from "~/newstore/environments"
export const getCombinedEnvVariables = () => ({ export const getCombinedEnvVariables = () => ({
global: getGlobalVariables(), global: cloneDeep(getGlobalVariables()),
selected: getCurrentEnvironment().variables, selected: cloneDeep(getCurrentEnvironment().variables),
}) })
export const getFinalEnvsFromPreRequest = ( export const getFinalEnvsFromPreRequest = (