From 5c214a8da03830cacd9598c23fcd963e0cdb2b49 Mon Sep 17 00:00:00 2001 From: Nivedin <53208152+nivedin@users.noreply.github.com> Date: Mon, 3 Jun 2024 14:28:58 +0530 Subject: [PATCH] fix: persist interceptor state for logged out user (#4060) * fix: persist interceptor state for loged out user * refactor: update interceptor section in settings page * chore: update settings page interceptor section UI * chore: minoir ui and code refactor --- .../src/components/app/Interceptor.vue | 14 ++- .../src/components/settings/Extension.vue | 32 ------ .../src/components/settings/Proxy.vue | 33 +------ .../src/newstore/settings.ts | 97 ++++++++----------- .../hoppscotch-common/src/pages/settings.vue | 6 ++ 5 files changed, 66 insertions(+), 116 deletions(-) diff --git a/packages/hoppscotch-common/src/components/app/Interceptor.vue b/packages/hoppscotch-common/src/components/app/Interceptor.vue index 427770310..d66e14087 100644 --- a/packages/hoppscotch-common/src/components/app/Interceptor.vue +++ b/packages/hoppscotch-common/src/components/app/Interceptor.vue @@ -1,6 +1,6 @@ diff --git a/packages/hoppscotch-common/src/components/settings/Proxy.vue b/packages/hoppscotch-common/src/components/settings/Proxy.vue index e8c2ddd19..270706b06 100644 --- a/packages/hoppscotch-common/src/components/settings/Proxy.vue +++ b/packages/hoppscotch-common/src/components/settings/Proxy.vue @@ -8,16 +8,6 @@ :label="t('app.proxy_privacy_policy')" />. -
-
- - {{ t("settings.proxy_use_toggle") }} - -
-
+ interceptorService.currentInterceptorID.value === + proxyInterceptor.interceptorID +) const clearIcon = refAutoReset( IconRotateCCW, diff --git a/packages/hoppscotch-common/src/newstore/settings.ts b/packages/hoppscotch-common/src/newstore/settings.ts index 778de8d47..eb582f2f1 100644 --- a/packages/hoppscotch-common/src/newstore/settings.ts +++ b/packages/hoppscotch-common/src/newstore/settings.ts @@ -1,8 +1,6 @@ import { cloneDeep, defaultsDeep, has } from "lodash-es" import { Observable } from "rxjs" import { distinctUntilChanged, pluck } from "rxjs/operators" -import { nextTick } from "vue" -import { platform } from "~/platform" import type { KeysMatching } from "~/types/ts-utils" import DispatchingStore, { defineDispatchers } from "./DispatchingStore" @@ -70,63 +68,52 @@ export type SettingsDef = { HAS_OPENED_SPOTLIGHT: boolean } -export const getDefaultSettings = (): SettingsDef => { - const defaultSettings: SettingsDef = { - syncCollections: true, - syncHistory: true, - syncEnvironments: true, +export const getDefaultSettings = (): SettingsDef => ({ + syncCollections: true, + syncHistory: true, + syncEnvironments: true, - WRAP_LINES: { - httpRequestBody: true, - httpResponseBody: true, - httpHeaders: true, - httpParams: true, - httpUrlEncoded: true, - httpPreRequest: true, - httpTest: true, - httpRequestVariables: true, - graphqlQuery: true, - graphqlResponseBody: true, - graphqlHeaders: false, - graphqlVariables: false, - graphqlSchema: true, - importCurl: true, - codeGen: true, - cookie: true, - }, + WRAP_LINES: { + httpRequestBody: true, + httpResponseBody: true, + httpHeaders: true, + httpParams: true, + httpUrlEncoded: true, + httpPreRequest: true, + httpTest: true, + httpRequestVariables: true, + graphqlQuery: true, + graphqlResponseBody: true, + graphqlHeaders: false, + graphqlVariables: false, + graphqlSchema: true, + importCurl: true, + codeGen: true, + cookie: true, + }, - CURRENT_INTERCEPTOR_ID: "", + // Set empty because interceptor module will set the default value + CURRENT_INTERCEPTOR_ID: "", - // TODO: Interceptor related settings should move under the interceptor systems - PROXY_URL: "https://proxy.hoppscotch.io/", - URL_EXCLUDES: { - auth: true, - httpUser: true, - httpPassword: true, - bearerToken: true, - oauth2Token: true, - }, - THEME_COLOR: "indigo", - BG_COLOR: "system", - TELEMETRY_ENABLED: true, - EXPAND_NAVIGATION: false, - SIDEBAR: true, - SIDEBAR_ON_LEFT: false, - COLUMN_LAYOUT: true, + // TODO: Interceptor related settings should move under the interceptor systems + PROXY_URL: "https://proxy.hoppscotch.io/", + URL_EXCLUDES: { + auth: true, + httpUser: true, + httpPassword: true, + bearerToken: true, + oauth2Token: true, + }, + THEME_COLOR: "indigo", + BG_COLOR: "system", + TELEMETRY_ENABLED: true, + EXPAND_NAVIGATION: false, + SIDEBAR: true, + SIDEBAR_ON_LEFT: false, + COLUMN_LAYOUT: true, - HAS_OPENED_SPOTLIGHT: false, - } - - // Wait for platform to initialize before setting CURRENT_INTERCEPTOR_ID - nextTick(() => { - applySetting( - "CURRENT_INTERCEPTOR_ID", - platform?.interceptors.default || "browser" - ) - }) - - return defaultSettings -} + HAS_OPENED_SPOTLIGHT: false, +}) type ApplySettingPayload = { [K in keyof SettingsDef]: { diff --git a/packages/hoppscotch-common/src/pages/settings.vue b/packages/hoppscotch-common/src/pages/settings.vue index 2285e68f6..cab99e319 100644 --- a/packages/hoppscotch-common/src/pages/settings.vue +++ b/packages/hoppscotch-common/src/pages/settings.vue @@ -98,6 +98,12 @@

+
+

+ {{ t("settings.interceptor") }} +

+ +

{{ settings.entryTitle(t) }}