From 59735c15e4e2af9bef681ddcb3c461e5d9b69625 Mon Sep 17 00:00:00 2001 From: nivedin Date: Tue, 28 Nov 2023 22:39:27 +0530 Subject: [PATCH] refactor: update components to encapsulate --- .../src/components/http/Authorization.vue | 37 ++++++ .../src/components/http/Headers.vue | 121 ++++++++++++++++++ .../src/components/http/RequestOptions.vue | 13 +- .../src/components/http/RequestTab.vue | 1 + 4 files changed, 170 insertions(+), 2 deletions(-) diff --git a/packages/hoppscotch-common/src/components/http/Authorization.vue b/packages/hoppscotch-common/src/components/http/Authorization.vue index ffae0025c..808c3fca9 100644 --- a/packages/hoppscotch-common/src/components/http/Authorization.vue +++ b/packages/hoppscotch-common/src/components/http/Authorization.vue @@ -42,6 +42,18 @@ } " /> + +
+
+ Inherited + {{ getAuthName(inheritedProperties?.auth?.authType) }} from Parent + Collection {{ inheritedProperties?.parentName }} +
+
@@ -186,6 +205,8 @@ import { pluckRef } from "@composables/ref" import { useI18n } from "@composables/i18n" import { useColorMode } from "@composables/theming" import { useVModel } from "@vueuse/core" +import { onMounted } from "vue" +import { HoppInheritedProperty } from "~/helpers/types/HoppInheritedProperties" const t = useI18n() @@ -194,6 +215,8 @@ const colorMode = useColorMode() const props = defineProps<{ modelValue: HoppRESTAuth isCollectionProperty?: boolean + isRootCollection?: boolean + inheritedProperties?: HoppInheritedProperty }>() const emit = defineEmits<{ @@ -202,18 +225,32 @@ const emit = defineEmits<{ const auth = useVModel(props, "modelValue", emit) +onMounted(() => { + if (props.isRootCollection && auth.value.authType === "inherit") { + console.log("isRootCollection", auth.value.authType) + auth.value.authType = "none" + } +}) + const AUTH_KEY_NAME = { basic: "Basic Auth", bearer: "Bearer", "oauth-2": "OAuth 2.0", "api-key": "API key", none: "None", + inherit: "Inherit", } as const const authType = pluckRef(auth, "authType") const authName = computed(() => AUTH_KEY_NAME[authType.value] ? AUTH_KEY_NAME[authType.value] : "None" ) + +const getAuthName = (type: HoppRESTAuth["authType"] | undefined) => { + if (!type) return "None" + return AUTH_KEY_NAME[type] ? AUTH_KEY_NAME[type] : "None" +} + const authActive = pluckRef(auth, "authActive") const clearContent = () => { diff --git a/packages/hoppscotch-common/src/components/http/Headers.vue b/packages/hoppscotch-common/src/components/http/Headers.vue index 969f800b2..b8009cfda 100644 --- a/packages/hoppscotch-common/src/components/http/Headers.vue +++ b/packages/hoppscotch-common/src/components/http/Headers.vue @@ -208,6 +208,64 @@
+ + + + + void } | null>(null) const props = defineProps<{ modelValue: HoppRESTRequest isCollectionProperty?: boolean + inheritedProperties?: HoppInheritedProperty }>() const emit = defineEmits<{ @@ -502,6 +564,65 @@ const computedHeaders = computed(() => ) ) +const inheritedProperties = computed(() => { + if (!props.inheritedProperties?.auth || !props.inheritedProperties.headers) + return [] + + //filter out headers that are already in the request headers + + const inheritedHeaders = props.inheritedProperties.headers.filter( + (header) => + !request.value.headers.some( + (requestHeader) => requestHeader.key === header.key + ) + ) + + const headers = inheritedHeaders.map((header, index) => ({ + inheritedFrom: props.inheritedProperties?.parentName, + source: "headers", + id: `header-${index}`, + header: { + key: header.key, + value: header.value, + active: header.active, + }, + })) + + let auth = [] as { + inheritedFrom: string + source: "auth" + id: string + header: { + key: string + value: string + active: boolean + } + }[] + + const computedAuthHeader = getComputedAuthHeaders( + aggregateEnvs.value, + request.value, + props.inheritedProperties.auth + )[0] + + if ( + computedAuthHeader && + request.value.auth.authType === "inherit" && + request.value.auth.authActive + ) { + auth = [ + { + inheritedFrom: props.inheritedProperties?.parentName, + source: "auth", + id: `header-auth`, + header: computedAuthHeader, + }, + ] + } + + return [...headers, ...auth] +}) + const masking = ref(true) const toggleMask = () => { diff --git a/packages/hoppscotch-common/src/components/http/RequestOptions.vue b/packages/hoppscotch-common/src/components/http/RequestOptions.vue index 2507b9bae..f51bbc67e 100644 --- a/packages/hoppscotch-common/src/components/http/RequestOptions.vue +++ b/packages/hoppscotch-common/src/components/http/RequestOptions.vue @@ -29,14 +29,21 @@ :label="`${t('tab.headers')}`" :info="`${newActiveHeadersCount$}`" > - + - + (), { optionTab: "params", diff --git a/packages/hoppscotch-common/src/components/http/RequestTab.vue b/packages/hoppscotch-common/src/components/http/RequestTab.vue index 18518726b..4d95020ed 100644 --- a/packages/hoppscotch-common/src/components/http/RequestTab.vue +++ b/packages/hoppscotch-common/src/components/http/RequestTab.vue @@ -5,6 +5,7 @@