From 0ed063724e2c7d8315bc00effa2e2851ac04f9aa Mon Sep 17 00:00:00 2001 From: nivedin Date: Fri, 9 Feb 2024 16:50:05 +0530 Subject: [PATCH] feat: add request variable --- packages/hoppscotch-common/locales/en.json | 2 + .../src/components/http/RequestOptions.vue | 18 + .../src/components/http/RequestVariables.vue | 409 ++++++++++++++++++ .../src/helpers/rest/default.ts | 1 + .../persistence/validation-schemas/index.ts | 1 + .../collections/collections.platform.ts | 2 + 6 files changed, 433 insertions(+) create mode 100644 packages/hoppscotch-common/src/components/http/RequestVariables.vue diff --git a/packages/hoppscotch-common/locales/en.json b/packages/hoppscotch-common/locales/en.json index 4160bb7ce..1b07f6eb9 100644 --- a/packages/hoppscotch-common/locales/en.json +++ b/packages/hoppscotch-common/locales/en.json @@ -239,6 +239,7 @@ "pending_invites": "There are no pending invites for this team", "profile": "Login to view your profile", "protocols": "Protocols are empty", + "request_variables": "This request does not have any request variables", "schema": "Connect to a GraphQL endpoint to view schema", "secret_environments": "Secrets are not synced to Hoppscotch", "shared_requests": "Shared requests are empty", @@ -560,6 +561,7 @@ "raw_body": "Raw Request Body", "rename": "Rename Request", "renamed": "Request renamed", + "request_variables": "Request variables", "run": "Run", "save": "Save", "save_as": "Save as", diff --git a/packages/hoppscotch-common/src/components/http/RequestOptions.vue b/packages/hoppscotch-common/src/components/http/RequestOptions.vue index 06a96d52f..a2fdf1a71 100644 --- a/packages/hoppscotch-common/src/components/http/RequestOptions.vue +++ b/packages/hoppscotch-common/src/components/http/RequestOptions.vue @@ -67,6 +67,14 @@ > + + + @@ -85,6 +93,7 @@ const VALID_OPTION_TABS = [ "authorization", "preRequestScript", "tests", + "requestVariables", ] as const export type RESTOptionTabs = (typeof VALID_OPTION_TABS)[number] @@ -134,6 +143,15 @@ const newActiveHeadersCount$ = computed(() => { return `${e}` }) +const newActiveRequestVariablesCount$ = computed(() => { + const e = request.value.requestVariables.filter( + (x) => x.active && (x.key !== "" || x.value !== "") + ).length + + if (e === 0) return null + return `${e}` +}) + defineActionHandler("request.open-tab", ({ tab }) => { selectedOptionTab.value = tab as RESTOptionTabs }) diff --git a/packages/hoppscotch-common/src/components/http/RequestVariables.vue b/packages/hoppscotch-common/src/components/http/RequestVariables.vue new file mode 100644 index 000000000..a25ff4b06 --- /dev/null +++ b/packages/hoppscotch-common/src/components/http/RequestVariables.vue @@ -0,0 +1,409 @@ + + + diff --git a/packages/hoppscotch-common/src/helpers/rest/default.ts b/packages/hoppscotch-common/src/helpers/rest/default.ts index d5bd45e9f..b6304d803 100644 --- a/packages/hoppscotch-common/src/helpers/rest/default.ts +++ b/packages/hoppscotch-common/src/helpers/rest/default.ts @@ -17,4 +17,5 @@ export const getDefaultRESTRequest = (): HoppRESTRequest => ({ contentType: null, body: null, }, + requestVariables: [], }) diff --git a/packages/hoppscotch-common/src/services/persistence/validation-schemas/index.ts b/packages/hoppscotch-common/src/services/persistence/validation-schemas/index.ts index bb4c03799..5b864a437 100644 --- a/packages/hoppscotch-common/src/services/persistence/validation-schemas/index.ts +++ b/packages/hoppscotch-common/src/services/persistence/validation-schemas/index.ts @@ -514,6 +514,7 @@ const validRestOperations = [ "authorization", "preRequestScript", "tests", + "requestVariables", ] as const export const REST_TAB_STATE_SCHEMA = z diff --git a/packages/hoppscotch-selfhost-web/src/platform/collections/collections.platform.ts b/packages/hoppscotch-selfhost-web/src/platform/collections/collections.platform.ts index 234d45e57..67c6c39e7 100644 --- a/packages/hoppscotch-selfhost-web/src/platform/collections/collections.platform.ts +++ b/packages/hoppscotch-selfhost-web/src/platform/collections/collections.platform.ts @@ -133,6 +133,7 @@ function exportedCollectionToHoppCollection( params, preRequestScript, testScript, + requestVariables, }) => ({ id, v, @@ -145,6 +146,7 @@ function exportedCollectionToHoppCollection( params, preRequestScript, testScript, + requestVariables, }) ), auth: data.auth,