feat: environment aware smart input in parameters and headers

This commit is contained in:
liyasthomas
2021-08-01 13:07:07 +05:30
parent fcb194d08a
commit 1e4bb65db2
6 changed files with 133 additions and 43 deletions

View File

@@ -43,6 +43,15 @@
:spellcheck="false" :spellcheck="false"
:value="header.key" :value="header.key"
autofocus autofocus
styles="
bg-primaryLight
flex
font-semibold font-mono
flex-1
py-1
px-4
focus:outline-none
"
@input=" @input="
updateHeader(index, { updateHeader(index, {
key: $event, key: $event,
@@ -51,7 +60,29 @@
}) })
" "
/> />
<SmartEnvInput
v-if="EXPERIMENTAL_URL_BAR_ENABLED"
v-model="header.value"
:placeholder="$t('value_count', { count: index + 1 })"
styles="
bg-primaryLight
flex
font-semibold font-mono
flex-1
py-1
px-4
focus:outline-none
"
@change="
updateHeader(index, {
key: header.key,
value: $event.target.value,
active: header.active,
})
"
/>
<input <input
v-else
class=" class="
bg-primaryLight bg-primaryLight
flex flex
@@ -131,6 +162,7 @@ import {
} from "~/newstore/RESTSession" } from "~/newstore/RESTSession"
import { commonHeaders } from "~/helpers/headers" import { commonHeaders } from "~/helpers/headers"
import { getSettingSubject } from "~/newstore/settings"
export default { export default {
data() { data() {
@@ -141,6 +173,9 @@ export default {
subscriptions() { subscriptions() {
return { return {
headers$: restHeaders$, headers$: restHeaders$,
EXPERIMENTAL_URL_BAR_ENABLED: getSettingSubject(
"EXPERIMENTAL_URL_BAR_ENABLED"
),
} }
}, },
// watch: { // watch: {

View File

@@ -37,7 +37,29 @@
class="divide-x divide-dividerLight border-b border-dividerLight flex" class="divide-x divide-dividerLight border-b border-dividerLight flex"
:class="{ 'border-t': index == 0 }" :class="{ 'border-t': index == 0 }"
> >
<SmartEnvInput
v-if="EXPERIMENTAL_URL_BAR_ENABLED"
v-model="param.key"
:placeholder="$t('parameter_count', { count: index + 1 })"
styles="
bg-primaryLight
flex
font-semibold font-mono
flex-1
py-1
px-4
focus:outline-none
"
@change="
updateParam(index, {
key: $event.target.value,
value: param.value,
active: param.active,
})
"
/>
<input <input
v-else
class=" class="
bg-primaryLight bg-primaryLight
flex flex
@@ -59,7 +81,29 @@
}) })
" "
/> />
<SmartEnvInput
v-if="EXPERIMENTAL_URL_BAR_ENABLED"
v-model="param.value"
:placeholder="$t('value_count', { count: index + 1 })"
styles="
bg-primaryLight
flex
font-semibold font-mono
flex-1
py-1
px-4
focus:outline-none
"
@change="
updateParam(index, {
key: param.key,
value: $event.target.value,
active: param.active,
})
"
/>
<input <input
v-else
class=" class="
bg-primaryLight bg-primaryLight
flex flex
@@ -137,6 +181,7 @@ import {
deleteRESTParam, deleteRESTParam,
deleteAllRESTParams, deleteAllRESTParams,
} from "~/newstore/RESTSession" } from "~/newstore/RESTSession"
import { getSettingSubject } from "~/newstore/settings"
export default { export default {
data() { data() {
@@ -147,6 +192,9 @@ export default {
subscriptions() { subscriptions() {
return { return {
params$: restParams$, params$: restParams$,
EXPERIMENTAL_URL_BAR_ENABLED: getSettingSubject(
"EXPERIMENTAL_URL_BAR_ENABLED"
),
} }
}, },
// watch: { // watch: {

View File

@@ -3,7 +3,7 @@
<div class="relative inline-flex"> <div class="relative inline-flex">
<span class="select-wrapper"> <span class="select-wrapper">
<tippy <tippy
ref="options" ref="methodOptions"
interactive interactive
tabindex="-1" tabindex="-1"
trigger="click" trigger="click"
@@ -44,9 +44,23 @@
</span> </span>
</div> </div>
<div class="flex-1 inline-flex"> <div class="flex-1 inline-flex">
<SmartUrlField <SmartEnvInput
v-if="EXPERIMENTAL_URL_BAR_ENABLED" v-if="EXPERIMENTAL_URL_BAR_ENABLED"
v-model="newEndpoint" v-model="newEndpoint"
:placeholder="$t('url')"
styles="
bg-primaryLight
border border-divider
flex
font-semibold font-mono
flex-1
text-secondaryDark
py-1
px-4
transition
truncate
focus:outline-none focus:border-accent
"
@enter="newSendRequest()" @enter="newSendRequest()"
/> />
<input <input
@@ -242,8 +256,9 @@ export default defineComponent({
// Template refs // Template refs
// //
const options = ref<any | null>(null) const methodOptions = ref<any | null>(null)
const saveOptions = ref<any | null>(null) const saveOptions = ref<any | null>(null)
const sendOptions = ref<any | null>(null)
const newSendRequest = () => { const newSendRequest = () => {
loading.value = true loading.value = true
@@ -279,7 +294,7 @@ export default defineComponent({
const onSelectMethod = (method: string) => { const onSelectMethod = (method: string) => {
updateMethod(method) updateMethod(method)
// Vue-tippy has no typescript support yet // Vue-tippy has no typescript support yet
options.value.tippy().hide() methodOptions.value.tippy().hide()
} }
const clearContent = () => { const clearContent = () => {
@@ -369,7 +384,8 @@ export default defineComponent({
EXPERIMENTAL_URL_BAR_ENABLED: useSetting("EXPERIMENTAL_URL_BAR_ENABLED"), EXPERIMENTAL_URL_BAR_ENABLED: useSetting("EXPERIMENTAL_URL_BAR_ENABLED"),
// Template refs // Template refs
options, methodOptions,
sendOptions,
saveOptions, saveOptions,
} }
}, },

View File

@@ -3,15 +3,6 @@
<input <input
ref="acInput" ref="acInput"
v-model="text" v-model="text"
class="
bg-primaryLight
flex
font-semibold font-mono
flex-1
py-2
px-4
focus:outline-none
"
type="text" type="text"
:placeholder="placeholder" :placeholder="placeholder"
:spellcheck="spellcheck" :spellcheck="spellcheck"
@@ -196,7 +187,8 @@ export default {
<style scoped lang="scss"> <style scoped lang="scss">
.autocomplete-wrapper { .autocomplete-wrapper {
@apply relative; @apply relative;
@apply flex flex-1; @apply flex;
@apply w-full;
input:focus + ul.suggestions, input:focus + ul.suggestions,
ul.suggestions:hover { ul.suggestions:hover {

View File

@@ -7,10 +7,15 @@
<div class="url-field-container"> <div class="url-field-container">
<div <div
ref="editor" ref="editor"
:placeholder="$t('url')" :placeholder="placeholder"
class="url-field" class="url-field"
:class="styles"
contenteditable="true" contenteditable="true"
@keyup.enter="$emit('enter')" @keyup.enter="$emit('enter', $event)"
@change="$emit('change', $event)"
@keyup="$emit('keyup', $event)"
@click="$emit('click', $event)"
@keydown="$emit('keydown', $event)"
></div> ></div>
</div> </div>
</template> </template>
@@ -32,6 +37,14 @@ export default {
type: String, type: String,
default: "", default: "",
}, },
placeholder: {
type: String,
default: "",
},
styles: {
type: String,
default: "",
},
}, },
data() { data() {
return { return {
@@ -41,7 +54,7 @@ export default {
highlight: [ highlight: [
{ {
text: /(<<\w+>>)/g, text: /(<<\w+>>)/g,
style: "text-white bg-accentDark rounded px-1.5 py-0.5 mx-0.5", style: "text-white bg-accentDark rounded px-1 mx-0.5",
}, },
], ],
highlightEnabled: true, highlightEnabled: true,
@@ -396,18 +409,17 @@ export default {
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
[contenteditable="true"]:empty { [contenteditable="true"] {
@apply h-8; &:empty {
line-height: 1.9;
line-height: 1.9; &::before {
@apply text-secondary;
@apply opacity-75;
@apply pointer-events-none;
&::before { content: attr(placeholder);
@apply text-secondary; }
@apply opacity-75;
@apply pointer-events-none;
@apply block;
content: attr(placeholder);
} }
} }
@@ -420,22 +432,9 @@ export default {
@apply flex; @apply flex;
@apply items-center; @apply items-center;
@apply justify-items-start; @apply justify-items-start;
@apply bg-primaryLight;
@apply border;
@apply border-divider;
@apply font-semibold;
@apply font-mono;
@apply flex-1;
@apply text-secondaryDark;
@apply py-1;
@apply px-4;
@apply transition;
@apply truncate;
@apply focus:outline-none;
@apply focus:border-accent;
@apply truncate;
@apply whitespace-nowrap; @apply whitespace-nowrap;
@apply overflow-x-auto; @apply overflow-x-auto;
@apply overflow-y-hidden;
@apply resize-none; @apply resize-none;
} }

View File

@@ -1,7 +1,7 @@
<template> <template>
<div class="page page-error"> <div class="page page-error">
<h1 class="font-mono mb-4 text-4xl heading">{{ statusCode }}</h1> <h1 class="font-mono mb-4 text-4xl heading">{{ statusCode }}</h1>
<h3 class="font-mono font-semibold text-xs">{{ message }}</h3> <h3 class="font-mono font-semibold text-xs select-text">{{ message }}</h3>
<p class="mt-4"> <p class="mt-4">
<ButtonSecondary to="/" icon="home" :label="$t('go_home')" /> <ButtonSecondary to="/" icon="home" :label="$t('go_home')" />
<ButtonSecondary <ButtonSecondary