refactor: update components for embeds flow

This commit is contained in:
nivedin
2024-02-19 23:34:23 +05:30
committed by Andrew Bastin
parent fb615d2d2b
commit 175641246e
16 changed files with 114 additions and 19 deletions

View File

@@ -32,9 +32,13 @@
{{ tab.document.request.method }} {{ tab.document.request.method }}
</span> </span>
<div <div
class="flex items-center flex-1 flex-shrink-0 min-w-0 px-4 py-2 truncate rounded-r" class="flex items-center flex-1 flex-shrink-0 min-w-0 truncate rounded-r"
> >
{{ tab.document.request.endpoint }} <SmartEnvInput
v-model="tab.document.request.endpoint"
:readonly="true"
:envs="tabRequestVariables"
/>
</div> </div>
</div> </div>
<div class="flex mt-2 space-x-2 sm:mt-0"> <div class="flex mt-2 space-x-2 sm:mt-0">
@@ -69,6 +73,7 @@
v-model="tab.document.request" v-model="tab.document.request"
v-model:option-tab="selectedOptionTab" v-model:option-tab="selectedOptionTab"
:properties="properties" :properties="properties"
:envs="tabRequestVariables"
/> />
<HttpResponse <HttpResponse
v-if="tab.document.response" v-if="tab.document.response"
@@ -117,6 +122,15 @@ const sharedRequestURL = computed(() => {
return `${shortcodeBaseURL}/r/${props.sharedRequestID}` return `${shortcodeBaseURL}/r/${props.sharedRequestID}`
}) })
const tabRequestVariables = computed(() => {
return tab.value.document.request.requestVariables.map((v) => ({
key: v.key,
value: v.value,
secret: false,
sourceEnv: "RequestVariable",
}))
})
const { subscribeToStream } = useStreamSubscriber() const { subscribeToStream } = useStreamSubscriber()
const newSendRequest = async () => { const newSendRequest = async () => {

View File

@@ -150,7 +150,7 @@
<div v-else class="flex flex-1 border-b border-dividerLight"> <div v-else class="flex flex-1 border-b border-dividerLight">
<div class="w-2/3 border-r border-dividerLight"> <div class="w-2/3 border-r border-dividerLight">
<div v-if="auth.authType === 'basic'"> <div v-if="auth.authType === 'basic'">
<HttpAuthorizationBasic v-model="auth" /> <HttpAuthorizationBasic v-model="auth" :envs="envs" />
</div> </div>
<div v-if="auth.authType === 'inherit'" class="p-4"> <div v-if="auth.authType === 'inherit'" class="p-4">
<span v-if="inheritedProperties?.auth"> <span v-if="inheritedProperties?.auth">
@@ -173,17 +173,22 @@
v-model="auth.token" v-model="auth.token"
placeholder="Token" placeholder="Token"
:auto-complete-env="true" :auto-complete-env="true"
:envs="envs"
/> />
</div> </div>
</div> </div>
<div v-if="auth.authType === 'oauth-2'"> <div v-if="auth.authType === 'oauth-2'">
<div class="flex flex-1 border-b border-dividerLight"> <div class="flex flex-1 border-b border-dividerLight">
<SmartEnvInput v-model="auth.token" placeholder="Token" /> <SmartEnvInput
v-model="auth.token"
placeholder="Token"
:envs="envs"
/>
</div> </div>
<HttpOAuth2Authorization v-model="auth" /> <HttpOAuth2Authorization v-model="auth" :envs="envs" />
</div> </div>
<div v-if="auth.authType === 'api-key'"> <div v-if="auth.authType === 'api-key'">
<HttpAuthorizationApiKey v-model="auth" /> <HttpAuthorizationApiKey v-model="auth" :envs="envs" />
</div> </div>
</div> </div>
<div <div
@@ -219,6 +224,7 @@ import { useColorMode } from "@composables/theming"
import { useVModel } from "@vueuse/core" import { useVModel } from "@vueuse/core"
import { onMounted } from "vue" import { onMounted } from "vue"
import { HoppInheritedProperty } from "~/helpers/types/HoppInheritedProperties" import { HoppInheritedProperty } from "~/helpers/types/HoppInheritedProperties"
import { AggregateEnvironment } from "~/newstore/environments"
const t = useI18n() const t = useI18n()
@@ -229,6 +235,7 @@ const props = defineProps<{
isCollectionProperty?: boolean isCollectionProperty?: boolean
isRootCollection?: boolean isRootCollection?: boolean
inheritedProperties?: HoppInheritedProperty inheritedProperties?: HoppInheritedProperty
envs?: AggregateEnvironment[]
}>() }>()
const emit = defineEmits<{ const emit = defineEmits<{

View File

@@ -100,10 +100,12 @@
<HttpBodyParameters <HttpBodyParameters
v-if="body.contentType === 'multipart/form-data'" v-if="body.contentType === 'multipart/form-data'"
v-model="body" v-model="body"
:envs="envs"
/> />
<HttpURLEncodedParams <HttpURLEncodedParams
v-else-if="body.contentType === 'application/x-www-form-urlencoded'" v-else-if="body.contentType === 'application/x-www-form-urlencoded'"
v-model="body" v-model="body"
:envs="envs"
/> />
<HttpRawBody v-else-if="body.contentType !== null" v-model="body" /> <HttpRawBody v-else-if="body.contentType !== null" v-model="body" />
<HoppSmartPlaceholder <HoppSmartPlaceholder
@@ -141,6 +143,7 @@ import IconExternalLink from "~icons/lucide/external-link"
import IconInfo from "~icons/lucide/info" import IconInfo from "~icons/lucide/info"
import IconRefreshCW from "~icons/lucide/refresh-cw" import IconRefreshCW from "~icons/lucide/refresh-cw"
import { RESTOptionTabs } from "./RequestOptions.vue" import { RESTOptionTabs } from "./RequestOptions.vue"
import { AggregateEnvironment } from "~/newstore/environments"
const colorMode = useColorMode() const colorMode = useColorMode()
const t = useI18n() const t = useI18n()
@@ -148,6 +151,7 @@ const t = useI18n()
const props = defineProps<{ const props = defineProps<{
body: HoppRESTReqBody body: HoppRESTReqBody
headers: HoppRESTHeader[] headers: HoppRESTHeader[]
envs?: AggregateEnvironment[]
}>() }>()
const emit = defineEmits<{ const emit = defineEmits<{

View File

@@ -73,6 +73,8 @@
isFile: entry.isFile, isFile: entry.isFile,
}) })
" "
:auto-complete-env="true"
:envs="envs"
/> />
<div v-if="entry.isFile" class="file-chips-container"> <div v-if="entry.isFile" class="file-chips-container">
<div class="file-chips-wrapper space-x-1"> <div class="file-chips-wrapper space-x-1">
@@ -95,6 +97,8 @@
isFile: entry.isFile, isFile: entry.isFile,
}) })
" "
:auto-complete-env="true"
:envs="envs"
/> />
</span> </span>
<span> <span>
@@ -190,11 +194,13 @@ import { useI18n } from "@composables/i18n"
import { useToast } from "@composables/toast" import { useToast } from "@composables/toast"
import { useColorMode } from "@composables/theming" import { useColorMode } from "@composables/theming"
import { useVModel } from "@vueuse/core" import { useVModel } from "@vueuse/core"
import { AggregateEnvironment } from "~/newstore/environments"
type Body = HoppRESTReqBody & { contentType: "multipart/form-data" } type Body = HoppRESTReqBody & { contentType: "multipart/form-data" }
const props = defineProps<{ const props = defineProps<{
modelValue: Body modelValue: Body
envs: AggregateEnvironment[]
}>() }>()
const emit = defineEmits<{ const emit = defineEmits<{

View File

@@ -93,6 +93,7 @@
:env-index="index" :env-index="index"
:inspection-results="getInspectorResult(headerKeyResults, index)" :inspection-results="getInspectorResult(headerKeyResults, index)"
:auto-complete-env="true" :auto-complete-env="true"
:envs="envs"
@change=" @change="
updateHeader(index, { updateHeader(index, {
id: header.id, id: header.id,
@@ -110,6 +111,7 @@
" "
:env-index="index" :env-index="index"
:auto-complete-env="true" :auto-complete-env="true"
:envs="envs"
@change=" @change="
updateHeader(index, { updateHeader(index, {
id: header.id, id: header.id,
@@ -331,7 +333,11 @@ import {
getComputedHeaders, getComputedHeaders,
getComputedAuthHeaders, getComputedAuthHeaders,
} from "~/helpers/utils/EffectiveURL" } from "~/helpers/utils/EffectiveURL"
import { aggregateEnvs$, getAggregateEnvs } from "~/newstore/environments" import {
AggregateEnvironment,
aggregateEnvs$,
getAggregateEnvs,
} from "~/newstore/environments"
import { useVModel } from "@vueuse/core" import { useVModel } from "@vueuse/core"
import { useService } from "dioc/vue" import { useService } from "dioc/vue"
import { InspectionService, InspectorResult } from "~/services/inspection" import { InspectionService, InspectorResult } from "~/services/inspection"
@@ -361,6 +367,7 @@ const props = defineProps<{
modelValue: HoppRESTRequest modelValue: HoppRESTRequest
isCollectionProperty?: boolean isCollectionProperty?: boolean
inheritedProperties?: HoppInheritedProperty inheritedProperties?: HoppInheritedProperty
envs?: AggregateEnvironment[]
}>() }>()
const emit = defineEmits<{ const emit = defineEmits<{

View File

@@ -8,6 +8,7 @@
" "
:auto-complete-env="true" :auto-complete-env="true"
placeholder="OpenID Connect Discovery URL" placeholder="OpenID Connect Discovery URL"
:envs="envs"
/> />
</div> </div>
<div class="flex flex-1 border-b border-dividerLight"> <div class="flex flex-1 border-b border-dividerLight">
@@ -16,6 +17,7 @@
placeholder="Authorization URL" placeholder="Authorization URL"
:auto-complete-env="true" :auto-complete-env="true"
:styles="hasOIDCURL ? 'pointer-events-none opacity-70' : ''" :styles="hasOIDCURL ? 'pointer-events-none opacity-70' : ''"
:envs="envs"
></SmartEnvInput> ></SmartEnvInput>
</div> </div>
<div class="flex flex-1 border-b border-dividerLight"> <div class="flex flex-1 border-b border-dividerLight">
@@ -24,6 +26,7 @@
placeholder="Access Token URL" placeholder="Access Token URL"
:auto-complete-env="true" :auto-complete-env="true"
:styles="hasOIDCURL ? 'pointer-events-none opacity-70' : ''" :styles="hasOIDCURL ? 'pointer-events-none opacity-70' : ''"
:envs="envs"
/> />
</div> </div>
<div class="flex flex-1 border-b border-dividerLight"> <div class="flex flex-1 border-b border-dividerLight">
@@ -31,6 +34,7 @@
v-model="clientID" v-model="clientID"
:auto-complete-env="true" :auto-complete-env="true"
placeholder="Client ID" placeholder="Client ID"
:envs="envs"
/> />
</div> </div>
<div class="flex flex-1 border-b border-dividerLight"> <div class="flex flex-1 border-b border-dividerLight">
@@ -38,6 +42,7 @@
v-model="clientSecret" v-model="clientSecret"
:auto-complete-env="true" :auto-complete-env="true"
placeholder="Client Secret" placeholder="Client Secret"
:envs="envs"
/> />
</div> </div>
<div class="flex flex-1 border-b border-dividerLight"> <div class="flex flex-1 border-b border-dividerLight">
@@ -45,6 +50,7 @@
v-model="scope" v-model="scope"
:auto-complete-env="true" :auto-complete-env="true"
placeholder="Scope" placeholder="Scope"
:envs="envs"
/> />
</div> </div>
<div class="p-2"> <div class="p-2">
@@ -77,6 +83,7 @@ const toast = useToast()
const props = defineProps<{ const props = defineProps<{
modelValue: HoppRESTAuthOAuth2 | HoppGQLAuthOAuth2 modelValue: HoppRESTAuthOAuth2 | HoppGQLAuthOAuth2
envs?: AggregateEnvironment[]
}>() }>()
const emit = defineEmits<{ const emit = defineEmits<{

View File

@@ -88,6 +88,7 @@
getInspectorResult(parameterKeyResults, index) getInspectorResult(parameterKeyResults, index)
" "
:auto-complete-env="true" :auto-complete-env="true"
:envs="envs"
@change=" @change="
updateParam(index, { updateParam(index, {
id: param.id, id: param.id,
@@ -104,6 +105,7 @@
getInspectorResult(parameterValueResults, index) getInspectorResult(parameterValueResults, index)
" "
:auto-complete-env="true" :auto-complete-env="true"
:envs="envs"
@change=" @change="
updateParam(index, { updateParam(index, {
id: param.id, id: param.id,
@@ -211,6 +213,7 @@ import { InspectionService, InspectorResult } from "~/services/inspection"
import { RESTTabService } from "~/services/tab/rest" import { RESTTabService } from "~/services/tab/rest"
import { useNestedSetting } from "~/composables/settings" import { useNestedSetting } from "~/composables/settings"
import { toggleNestedSetting } from "~/newstore/settings" import { toggleNestedSetting } from "~/newstore/settings"
import { AggregateEnvironment } from "~/newstore/environments"
const colorMode = useColorMode() const colorMode = useColorMode()
@@ -244,6 +247,7 @@ useCodemirror(
const props = defineProps<{ const props = defineProps<{
modelValue: HoppRESTParam[] modelValue: HoppRESTParam[]
envs?: AggregateEnvironment[]
}>() }>()
const emit = defineEmits<{ const emit = defineEmits<{

View File

@@ -10,7 +10,7 @@
:label="`${t('tab.parameters')}`" :label="`${t('tab.parameters')}`"
:info="`${newActiveParamsCount$}`" :info="`${newActiveParamsCount$}`"
> >
<HttpParameters v-model="request.params" /> <HttpParameters v-model="request.params" :envs="envs" />
</HoppSmartTab> </HoppSmartTab>
<HoppSmartTab <HoppSmartTab
v-if="properties ? properties.includes('bodyParams') : true" v-if="properties ? properties.includes('bodyParams') : true"
@@ -20,6 +20,7 @@
<HttpBody <HttpBody
v-model:headers="request.headers" v-model:headers="request.headers"
v-model:body="request.body" v-model:body="request.body"
:envs="envs"
@change-tab="changeOptionTab" @change-tab="changeOptionTab"
/> />
</HoppSmartTab> </HoppSmartTab>
@@ -32,6 +33,7 @@
<HttpHeaders <HttpHeaders
v-model="request" v-model="request"
:inherited-properties="inheritedProperties" :inherited-properties="inheritedProperties"
:envs="envs"
@change-tab="changeOptionTab" @change-tab="changeOptionTab"
/> />
</HoppSmartTab> </HoppSmartTab>
@@ -43,6 +45,7 @@
<HttpAuthorization <HttpAuthorization
v-model="request.auth" v-model="request.auth"
:inherited-properties="inheritedProperties" :inherited-properties="inheritedProperties"
:envs="envs"
/> />
</HoppSmartTab> </HoppSmartTab>
<HoppSmartTab <HoppSmartTab
@@ -85,6 +88,7 @@ import { useVModel } from "@vueuse/core"
import { computed } from "vue" import { computed } from "vue"
import { defineActionHandler } from "~/helpers/actions" import { defineActionHandler } from "~/helpers/actions"
import { HoppInheritedProperty } from "~/helpers/types/HoppInheritedProperties" import { HoppInheritedProperty } from "~/helpers/types/HoppInheritedProperties"
import { AggregateEnvironment } from "~/newstore/environments"
const VALID_OPTION_TABS = [ const VALID_OPTION_TABS = [
"params", "params",
@@ -107,6 +111,7 @@ const props = withDefaults(
optionTab: RESTOptionTabs optionTab: RESTOptionTabs
properties?: string[] properties?: string[]
inheritedProperties?: HoppInheritedProperty inheritedProperties?: HoppInheritedProperty
envs?: AggregateEnvironment[]
}>(), }>(),
{ {
optionTab: "params", optionTab: "params",

View File

@@ -92,6 +92,8 @@
active: param.active, active: param.active,
}) })
" "
:auto-complete-env="true"
:envs="envs"
/> />
<SmartEnvInput <SmartEnvInput
v-model="param.value" v-model="param.value"
@@ -104,6 +106,8 @@
active: param.active, active: param.active,
}) })
" "
:auto-complete-env="true"
:envs="envs"
/> />
<span> <span>
<HoppButtonSecondary <HoppButtonSecondary
@@ -200,6 +204,7 @@ import { throwError } from "~/helpers/functional/error"
import { useVModel } from "@vueuse/core" import { useVModel } from "@vueuse/core"
import { useNestedSetting } from "~/composables/settings" import { useNestedSetting } from "~/composables/settings"
import { toggleNestedSetting } from "~/newstore/settings" import { toggleNestedSetting } from "~/newstore/settings"
import { AggregateEnvironment } from "~/newstore/environments"
type Body = HoppRESTReqBody & { type Body = HoppRESTReqBody & {
contentType: "application/x-www-form-urlencoded" contentType: "application/x-www-form-urlencoded"
@@ -207,6 +212,7 @@ type Body = HoppRESTReqBody & {
const props = defineProps<{ const props = defineProps<{
modelValue: Body modelValue: Body
envs: AggregateEnvironment[]
}>() }>()
const emit = defineEmits<{ const emit = defineEmits<{

View File

@@ -4,6 +4,7 @@
v-model="auth.key" v-model="auth.key"
:auto-complete-env="true" :auto-complete-env="true"
placeholder="Key" placeholder="Key"
:envs="envs"
/> />
</div> </div>
<div class="flex flex-1 border-b border-dividerLight"> <div class="flex flex-1 border-b border-dividerLight">
@@ -11,6 +12,7 @@
v-model="auth.value" v-model="auth.value"
:auto-complete-env="true" :auto-complete-env="true"
placeholder="Value" placeholder="Value"
:envs="envs"
/> />
</div> </div>
<div class="flex items-center border-b border-dividerLight"> <div class="flex items-center border-b border-dividerLight">
@@ -73,11 +75,13 @@ import { useI18n } from "@composables/i18n"
import { HoppRESTAuthAPIKey } from "@hoppscotch/data" import { HoppRESTAuthAPIKey } from "@hoppscotch/data"
import { useVModel } from "@vueuse/core" import { useVModel } from "@vueuse/core"
import { ref } from "vue" import { ref } from "vue"
import { AggregateEnvironment } from "~/newstore/environments"
const t = useI18n() const t = useI18n()
const props = defineProps<{ const props = defineProps<{
modelValue: HoppRESTAuthAPIKey modelValue: HoppRESTAuthAPIKey
envs?: AggregateEnvironment[]
}>() }>()
const emit = defineEmits<{ const emit = defineEmits<{

View File

@@ -4,6 +4,7 @@
v-model="auth.username" v-model="auth.username"
:placeholder="t('authorization.username')" :placeholder="t('authorization.username')"
:auto-complete-env="true" :auto-complete-env="true"
:envs="envs"
/> />
</div> </div>
<div class="flex flex-1 border-b border-dividerLight"> <div class="flex flex-1 border-b border-dividerLight">
@@ -11,6 +12,7 @@
v-model="auth.password" v-model="auth.password"
:placeholder="t('authorization.password')" :placeholder="t('authorization.password')"
:auto-complete-env="true" :auto-complete-env="true"
:envs="envs"
/> />
</div> </div>
</template> </template>
@@ -19,11 +21,13 @@
import { useI18n } from "@composables/i18n" import { useI18n } from "@composables/i18n"
import { HoppRESTAuthBasic } from "@hoppscotch/data" import { HoppRESTAuthBasic } from "@hoppscotch/data"
import { useVModel } from "@vueuse/core" import { useVModel } from "@vueuse/core"
import { AggregateEnvironment } from "~/newstore/environments"
const t = useI18n() const t = useI18n()
const props = defineProps<{ const props = defineProps<{
modelValue: HoppRESTAuthBasic modelValue: HoppRESTAuthBasic
envs?: AggregateEnvironment[]
}>() }>()
const emit = defineEmits<{ const emit = defineEmits<{

View File

@@ -290,7 +290,12 @@ const widgets: Widget[] = [
}, },
] ]
type EmbedTabs = "params" | "bodyParams" | "headers" | "authorization" type EmbedTabs =
| "params"
| "bodyParams"
| "headers"
| "authorization"
| "requestVariables"
type EmbedOption = { type EmbedOption = {
selectedTab: EmbedTabs selectedTab: EmbedTabs

View File

@@ -56,7 +56,12 @@ import { useI18n } from "~/composables/i18n"
const t = useI18n() const t = useI18n()
type EmbedTabs = "params" | "bodyParams" | "headers" | "authorization" type EmbedTabs =
| "params"
| "bodyParams"
| "headers"
| "authorization"
| "requestVariables"
type EmbedOption = { type EmbedOption = {
selectedTab: EmbedTabs selectedTab: EmbedTabs

View File

@@ -173,6 +173,11 @@ const embedOptions = ref<EmbedOption>({
label: t("tab.authorization"), label: t("tab.authorization"),
enabled: false, enabled: false,
}, },
{
value: "requestVariables",
label: t("tab.variables"),
enabled: false,
},
], ],
theme: "system", theme: "system",
}) })
@@ -223,7 +228,12 @@ const currentUser = useReadonlyStream(
const step = ref(1) const step = ref(1)
type EmbedTabs = "params" | "bodyParams" | "headers" | "authorization" type EmbedTabs =
| "params"
| "bodyParams"
| "headers"
| "authorization"
| "requestVariables"
type EmbedOption = { type EmbedOption = {
selectedTab: EmbedTabs selectedTab: EmbedTabs
@@ -369,6 +379,11 @@ const displayCustomizeRequestModal = (
label: t("tab.authorization"), label: t("tab.authorization"),
enabled: false, enabled: false,
}, },
{
value: "requestVariables",
label: t("tab.variables"),
enabled: false,
},
], ],
theme: "system", theme: "system",
} }

View File

@@ -28,7 +28,7 @@
</button> </button>
</div> </div>
<div <div
class="flex" class="flex overflow-x-scroll"
:class="[{ 'border-b pt-2 ': !noActiveTab }, embedColours]" :class="[{ 'border-b pt-2 ': !noActiveTab }, embedColours]"
> >
<span <span
@@ -57,7 +57,12 @@ import { computed } from "vue"
import { useI18n } from "~/composables/i18n" import { useI18n } from "~/composables/i18n"
type Tabs = "params" | "bodyParams" | "headers" | "authorization" type Tabs =
| "params"
| "bodyParams"
| "headers"
| "authorization"
| "requestVariables"
type EmbedOption = { type EmbedOption = {
selectedTab: Tabs selectedTab: Tabs

View File

@@ -87,7 +87,6 @@ import { platform } from "~/platform"
import { onClickOutside, useDebounceFn } from "@vueuse/core" import { onClickOutside, useDebounceFn } from "@vueuse/core"
import { InspectorResult } from "~/services/inspection" import { InspectorResult } from "~/services/inspection"
import { invokeAction } from "~/helpers/actions" import { invokeAction } from "~/helpers/actions"
import { Environment } from "@hoppscotch/data"
import { useI18n } from "~/composables/i18n" import { useI18n } from "~/composables/i18n"
import IconEye from "~icons/lucide/eye" import IconEye from "~icons/lucide/eye"
import IconEyeoff from "~icons/lucide/eye-off" import IconEyeoff from "~icons/lucide/eye-off"
@@ -98,14 +97,12 @@ import { RESTTabService } from "~/services/tab/rest"
const t = useI18n() const t = useI18n()
type Env = Environment["variables"][number] & { source: string }
const props = withDefaults( const props = withDefaults(
defineProps<{ defineProps<{
modelValue?: string modelValue?: string
placeholder?: string placeholder?: string
styles?: string styles?: string
envs?: Env[] | null envs?: AggregateEnvironment[] | null
focus?: boolean focus?: boolean
selectTextOnMount?: boolean selectTextOnMount?: boolean
environmentHighlights?: boolean environmentHighlights?: boolean
@@ -371,7 +368,7 @@ const envVars = computed(() => {
if (x.secret) { if (x.secret) {
return { return {
key: x.key, key: x.key,
sourceEnv: "source" in x ? x.source : null, sourceEnv: "sourceEnv" in x ? x.sourceEnv : null,
value: "********", value: "********",
secret: true, secret: true,
} }
@@ -379,7 +376,7 @@ const envVars = computed(() => {
return { return {
key: x.key, key: x.key,
value: x.value, value: x.value,
sourceEnv: "source" in x ? x.source : null, sourceEnv: "sourceEnv" in x ? x.sourceEnv : null,
secret: false, secret: false,
} }
}) })