feat: bulk edit for graphql headers

This commit is contained in:
liyasthomas
2021-08-30 18:49:35 +05:30
parent b9fa254ab5
commit ada568cb75

View File

@@ -27,6 +27,13 @@
class="rounded-none !text-accent" class="rounded-none !text-accent"
@click.native="runQuery()" @click.native="runQuery()"
/> />
<ButtonSecondary
v-tippy="{ theme: 'tooltip' }"
to="https://docs.hoppscotch.io"
blank
:title="$t('app.wiki')"
svg="help-circle"
/>
<ButtonSecondary <ButtonSecondary
v-tippy="{ theme: 'tooltip' }" v-tippy="{ theme: 'tooltip' }"
:title="$t('action.copy')" :title="$t('action.copy')"
@@ -86,6 +93,13 @@
{{ $t("request.variables") }} {{ $t("request.variables") }}
</label> </label>
<div class="flex"> <div class="flex">
<ButtonSecondary
v-tippy="{ theme: 'tooltip' }"
to="https://docs.hoppscotch.io"
blank
:title="$t('app.wiki')"
svg="help-circle"
/>
<ButtonSecondary <ButtonSecondary
v-tippy="{ theme: 'tooltip' }" v-tippy="{ theme: 'tooltip' }"
:title="$t('action.copy')" :title="$t('action.copy')"
@@ -129,20 +143,56 @@
{{ $t("tab.headers") }} {{ $t("tab.headers") }}
</label> </label>
<div class="flex"> <div class="flex">
<ButtonSecondary
v-tippy="{ theme: 'tooltip' }"
to="https://docs.hoppscotch.io"
blank
:title="$t('app.wiki')"
svg="help-circle"
/>
<ButtonSecondary <ButtonSecondary
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="headers = []" @click.native="headers = []"
/> />
<ButtonSecondary
v-tippy="{ theme: 'tooltip' }"
:title="$t('state.bulk_mode')"
svg="edit"
:class="{ '!text-accent': bulkMode }"
@click.native="bulkMode = !bulkMode"
/>
<ButtonSecondary <ButtonSecondary
v-tippy="{ theme: 'tooltip' }" v-tippy="{ theme: 'tooltip' }"
:title="$t('add.new')" :title="$t('add.new')"
svg="plus" svg="plus"
:disabled="bulkMode"
@click.native="addRequestHeader" @click.native="addRequestHeader"
/> />
</div> </div>
</div> </div>
<div v-if="bulkMode" class="flex">
<textarea
v-model="bulkHeaders"
v-focus
name="bulk-parameters"
class="
bg-transparent
border-b border-dividerLight
flex flex-1
py-2
px-4
whitespace-pre
resize-y
overflow-auto
"
rows="10"
:placeholder="$t('state.bulk_mode_placeholder')"
></textarea>
</div>
<div v-else>
<div <div
v-for="(header, index) in headers" v-for="(header, index) in headers"
:key="`header-${index}`" :key="`header-${index}`"
@@ -246,6 +296,7 @@
@click.native="addRequestHeader" @click.native="addRequestHeader"
/> />
</div> </div>
</div>
</AppSection> </AppSection>
</SmartTab> </SmartTab>
</SmartTabs> </SmartTabs>
@@ -311,6 +362,25 @@ export default defineComponent({
const t = i18n.t.bind(i18n) const t = i18n.t.bind(i18n)
const nuxt = useNuxt() const nuxt = useNuxt()
const bulkMode = ref(false)
const bulkHeaders = ref("")
watch(bulkHeaders, () => {
try {
const transformation = bulkHeaders.value.split("\n").map((item) => ({
key: item.substr(0, item.indexOf(":")).trim(),
value: item.substr(item.indexOf(":") + 1).trim(),
active: !item.trim().startsWith("//"),
}))
setGQLHeaders(transformation)
} catch (e) {
$toast.error(t("error.something_went_wrong").toString(), {
icon: "error_outline",
})
console.error(e)
}
})
const url = useReadonlyStream(gqlURL$, "") const url = useReadonlyStream(gqlURL$, "")
const gqlQueryString = useStream(gqlQuery$, "", setGQLQuery) const gqlQueryString = useStream(gqlQuery$, "", setGQLQuery)
const variableString = useStream(gqlVariables$, "", setGQLVariables) const variableString = useStream(gqlVariables$, "", setGQLVariables)
@@ -475,6 +545,8 @@ export default defineComponent({
commonHeaders, commonHeaders,
updateGQLHeader, updateGQLHeader,
bulkMode,
bulkHeaders,
} }
}, },
}) })