sync request params with bulk editor. (#1930)

This commit is contained in:
0xc0Der
2021-11-04 09:31:56 +02:00
committed by GitHub
parent ad7b8da37e
commit 235968073a

View File

@@ -28,8 +28,7 @@
v-tippy="{ theme: 'tooltip' }" v-tippy="{ theme: 'tooltip' }"
:title="$t('action.clear_all')" :title="$t('action.clear_all')"
svg="trash-2" svg="trash-2"
:disabled="bulkMode" @click.native="bulkMode ? clearBulkEditor() : clearContent()"
@click.native="clearContent"
/> />
<ButtonSecondary <ButtonSecondary
v-tippy="{ theme: 'tooltip' }" v-tippy="{ theme: 'tooltip' }"
@@ -216,32 +215,44 @@ useCodemirror(bulkEditor, bulkParams, {
const params$ = useReadonlyStream(restParams$, []) const params$ = useReadonlyStream(restParams$, [])
watch( const editBulkParamLine = (index: number, item?: HoppRESTParam) => {
params$, const params = bulkParams.value.split("\n")
(newValue) => {
if ( if (item !== null)
(newValue[newValue.length - 1]?.key !== "" || params.splice(
newValue[newValue.length - 1]?.value !== "") && index,
newValue.length 1,
`${item.active ? "" : "//"}${item.key}: ${item.value}`
) )
addParam() else params.splice(index, 1)
},
{ deep: true } bulkParams.value = params.join("\n")
) }
const clearBulkEditor = () => {
bulkParams.value = ""
}
const addParam = () => { const addParam = () => {
addRESTParam({ key: "", value: "", active: true }) const empty = { key: "", value: "", active: true }
const index = params$.value.length
addRESTParam(empty)
editBulkParamLine(index, empty)
} }
const updateParam = (index: number, item: HoppRESTParam) => { const updateParam = (index: number, item: HoppRESTParam) => {
updateRESTParam(index, item) updateRESTParam(index, item)
editBulkParamLine(index, item)
} }
const deleteParam = (index: number) => { const deleteParam = (index: number) => {
deleteRESTParam(index) deleteRESTParam(index)
editBulkParamLine(index, null)
} }
const clearContent = () => { const clearContent = () => {
deleteAllRESTParams() deleteAllRESTParams()
clearBulkEditor()
} }
</script> </script>