fix: bind key-value with bulk editor at startup. (#1936)

This commit is contained in:
0xc0Der
2021-11-04 17:13:21 +02:00
committed by GitHub
parent 69a6207a4d
commit 136b1ff63b
3 changed files with 37 additions and 31 deletions

View File

@@ -397,15 +397,15 @@ const editBulkHeadersLine = (
active: boolean active: boolean
} }
) => { ) => {
const headers = bulkHeaders.value.split("\n") bulkHeaders.value = headers.value
if (item !== null) .reduce((all, header, pIndex) => {
headers.splice( const current =
index, index === pIndex && item !== null
1, ? `${item.active ? "" : "//"}${item.key}: ${item.value}`
`${item.active ? "" : "//"}${item.key}: ${item.value}` : `${header.active ? "" : "//"}${header.key}: ${header.value}`
) return [...all, current]
else headers.splice(index, 1) }, [])
bulkHeaders.value = headers.join("\n") .join("\n")
} }
const clearBulkEditor = () => { const clearBulkEditor = () => {

View File

@@ -170,7 +170,7 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref, useContext, watch } from "@nuxtjs/composition-api" import { ref, useContext, watch, onMounted } from "@nuxtjs/composition-api"
import { useCodemirror } from "~/helpers/editor/codemirror" import { useCodemirror } from "~/helpers/editor/codemirror"
import { import {
addRESTHeader, addRESTHeader,
@@ -221,16 +221,20 @@ watch(bulkHeaders, () => {
const headers$ = useReadonlyStream(restHeaders$, []) const headers$ = useReadonlyStream(restHeaders$, [])
const editBulkHeadersLine = (index: number, item?: HoppRESTHeader) => { onMounted(() => editBulkHeadersLine(-1, null))
const headers = bulkHeaders.value.split("\n")
if (item !== null) const editBulkHeadersLine = (index: number, item?: HoppRESTParam) => {
headers.splice( const headers = headers$.value
index,
1, bulkHeaders.value = headers
`${item.active ? "" : "//"}${item.key}: ${item.value}` .reduce((all, header, pIndex) => {
) const current =
else headers.splice(index, 1) index === pIndex && item !== null
bulkHeaders.value = headers.join("\n") ? `${item.active ? "" : "//"}${item.key}: ${item.value}`
: `${header.active ? "" : "//"}${header.key}: ${header.value}`
return [...all, current]
}, [])
.join("\n")
} }
const clearBulkEditor = () => { const clearBulkEditor = () => {

View File

@@ -163,7 +163,7 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref, useContext, watch } from "@nuxtjs/composition-api" import { ref, useContext, watch, onMounted } from "@nuxtjs/composition-api"
import { useCodemirror } from "~/helpers/editor/codemirror" import { useCodemirror } from "~/helpers/editor/codemirror"
import { HoppRESTParam } from "~/helpers/types/HoppRESTRequest" import { HoppRESTParam } from "~/helpers/types/HoppRESTRequest"
import { useReadonlyStream } from "~/helpers/utils/composables" import { useReadonlyStream } from "~/helpers/utils/composables"
@@ -215,18 +215,20 @@ useCodemirror(bulkEditor, bulkParams, {
const params$ = useReadonlyStream(restParams$, []) const params$ = useReadonlyStream(restParams$, [])
onMounted(() => editBulkParamsLine(-1, null))
const editBulkParamsLine = (index: number, item?: HoppRESTParam) => { const editBulkParamsLine = (index: number, item?: HoppRESTParam) => {
const params = bulkParams.value.split("\n") const params = params$.value
if (item !== null) bulkParams.value = params
params.splice( .reduce((all, param, pIndex) => {
index, const current =
1, index === pIndex && item !== null
`${item.active ? "" : "//"}${item.key}: ${item.value}` ? `${item.active ? "" : "//"}${item.key}: ${item.value}`
) : `${param.active ? "" : "//"}${param.key}: ${param.value}`
else params.splice(index, 1) return [...all, current]
}, [])
bulkParams.value = params.join("\n") .join("\n")
} }
const clearBulkEditor = () => { const clearBulkEditor = () => {