feat: bind key-value pairs and bulk editor

This commit is contained in:
liyasthomas
2021-11-04 13:36:51 +05:30
parent 235968073a
commit ad76d100ee
3 changed files with 74 additions and 42 deletions

View File

@@ -129,8 +129,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="Boolean(bulkMode)" @click.native="bulkMode ? clearBulkEditor() : clearContent()"
@click.native="headers = []"
/> />
<ButtonSecondary <ButtonSecondary
v-tippy="{ theme: 'tooltip' }" v-tippy="{ theme: 'tooltip' }"
@@ -143,7 +142,7 @@
v-tippy="{ theme: 'tooltip' }" v-tippy="{ theme: 'tooltip' }"
:title="$t('add.new')" :title="$t('add.new')"
svg="plus" svg="plus"
:disabled="Boolean(bulkMode)" :disabled="bulkMode"
@click.native="addRequestHeader" @click.native="addRequestHeader"
/> />
</div> </div>
@@ -172,10 +171,10 @@
py-1 py-1
px-4 px-4
truncate truncate
focus:outline-none
" "
class="!flex flex-1"
@input=" @input="
updateGQLHeader(index, { updateRequestHeader(index, {
key: $event, key: $event,
value: header.value, value: header.value,
active: header.active, active: header.active,
@@ -189,7 +188,7 @@
:value="header.value" :value="header.value"
autofocus autofocus
@change=" @change="
updateGQLHeader(index, { updateRequestHeader(index, {
key: header.key, key: header.key,
value: $event.target.value, value: $event.target.value,
active: header.active, active: header.active,
@@ -215,7 +214,7 @@
" "
color="green" color="green"
@click.native=" @click.native="
updateGQLHeader(index, { updateRequestHeader(index, {
key: header.key, key: header.key,
value: header.value, value: header.value,
active: !header.active, active: !header.active,
@@ -272,7 +271,7 @@
<CollectionsSaveRequest <CollectionsSaveRequest
mode="graphql" mode="graphql"
:show="Boolean(showSaveRequestModal)" :show="showSaveRequestModal"
@hide-modal="hideRequestModal" @hide-modal="hideRequestModal"
/> />
</div> </div>
@@ -390,18 +389,28 @@ const copyVariablesIcon = ref("copy")
const showSaveRequestModal = ref(false) const showSaveRequestModal = ref(false)
watch( const editBulkHeadersLine = (
headers, index: number,
() => { item?: {
if ( key: string
(headers.value[headers.value.length - 1]?.key !== "" || value: string
headers.value[headers.value.length - 1]?.value !== "") && active: boolean
headers.value.length }
) ) => {
addRequestHeader() const headers = bulkHeaders.value.split("\n")
}, if (item !== null)
{ deep: true } headers.splice(
index,
1,
`${item.active ? "" : "//"}${item.key}: ${item.value}`
) )
else headers.splice(index, 1)
bulkHeaders.value = headers.join("\n")
}
const clearBulkEditor = () => {
bulkHeaders.value = ""
}
onMounted(() => { onMounted(() => {
if (!headers.value?.length) { if (!headers.value?.length) {
@@ -504,14 +513,28 @@ const copyVariables = () => {
} }
const addRequestHeader = () => { const addRequestHeader = () => {
addGQLHeader({ const empty = { key: "", value: "", active: true }
key: "", const index = headers.value.length
value: "",
active: true, addGQLHeader(empty)
}) editBulkHeadersLine(index, empty)
}
const updateRequestHeader = (
index: number,
item: { key: string; value: string; active: boolean }
) => {
updateGQLHeader(index, item)
editBulkHeadersLine(index, item)
} }
const removeRequestHeader = (index: number) => { const removeRequestHeader = (index: number) => {
removeGQLHeader(index) removeGQLHeader(index)
editBulkHeadersLine(index, null)
}
const clearContent = () => {
headers.value = []
clearBulkEditor()
} }
</script> </script>

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' }"
@@ -222,32 +221,42 @@ watch(bulkHeaders, () => {
const headers$ = useReadonlyStream(restHeaders$, []) const headers$ = useReadonlyStream(restHeaders$, [])
watch( const editBulkHeadersLine = (index: number, item?: HoppRESTHeader) => {
headers$, const headers = bulkHeaders.value.split("\n")
(newValue) => { if (item !== null)
if ( headers.splice(
(newValue[newValue.length - 1]?.key !== "" || index,
newValue[newValue.length - 1]?.value !== "") && 1,
newValue.length `${item.active ? "" : "//"}${item.key}: ${item.value}`
)
addHeader()
},
{ deep: true }
) )
else headers.splice(index, 1)
bulkHeaders.value = headers.join("\n")
}
const clearBulkEditor = () => {
bulkHeaders.value = ""
}
const addHeader = () => { const addHeader = () => {
addRESTHeader({ key: "", value: "", active: true }) const empty = { key: "", value: "", active: true }
const index = headers$.value.length
addRESTHeader(empty)
editBulkHeadersLine(index, empty)
} }
const updateHeader = (index: number, item: HoppRESTHeader) => { const updateHeader = (index: number, item: HoppRESTHeader) => {
updateRESTHeader(index, item) updateRESTHeader(index, item)
editBulkHeadersLine(index, item)
} }
const deleteHeader = (index: number) => { const deleteHeader = (index: number) => {
deleteRESTHeader(index) deleteRESTHeader(index)
editBulkHeadersLine(index, null)
} }
const clearContent = () => { const clearContent = () => {
deleteAllRESTHeaders() deleteAllRESTHeaders()
clearBulkEditor()
} }
</script> </script>

View File

@@ -215,7 +215,7 @@ useCodemirror(bulkEditor, bulkParams, {
const params$ = useReadonlyStream(restParams$, []) const params$ = useReadonlyStream(restParams$, [])
const editBulkParamLine = (index: number, item?: HoppRESTParam) => { const editBulkParamsLine = (index: number, item?: HoppRESTParam) => {
const params = bulkParams.value.split("\n") const params = bulkParams.value.split("\n")
if (item !== null) if (item !== null)
@@ -238,17 +238,17 @@ const addParam = () => {
const index = params$.value.length const index = params$.value.length
addRESTParam(empty) addRESTParam(empty)
editBulkParamLine(index, empty) editBulkParamsLine(index, empty)
} }
const updateParam = (index: number, item: HoppRESTParam) => { const updateParam = (index: number, item: HoppRESTParam) => {
updateRESTParam(index, item) updateRESTParam(index, item)
editBulkParamLine(index, item) editBulkParamsLine(index, item)
} }
const deleteParam = (index: number) => { const deleteParam = (index: number) => {
deleteRESTParam(index) deleteRESTParam(index)
editBulkParamLine(index, null) editBulkParamsLine(index, null)
} }
const clearContent = () => { const clearContent = () => {