From 99817fd8bdd53b40c811c58cb93b996ae90cc407 Mon Sep 17 00:00:00 2001 From: Nivedin <53208152+nivedin@users.noreply.github.com> Date: Thu, 11 May 2023 02:03:35 +0530 Subject: [PATCH] fix: reset envs when user switches workspaces (#3039) Co-authored-by: Liyas Thomas --- .../hoppscotch-common/src/components.d.ts | 1 + .../src/components/environments/Selector.vue | 174 +++++++++++++++ .../src/components/environments/index.vue | 198 ++---------------- 3 files changed, 192 insertions(+), 181 deletions(-) create mode 100644 packages/hoppscotch-common/src/components/environments/Selector.vue diff --git a/packages/hoppscotch-common/src/components.d.ts b/packages/hoppscotch-common/src/components.d.ts index 063d9fd7f8..3fd4938e94 100644 --- a/packages/hoppscotch-common/src/components.d.ts +++ b/packages/hoppscotch-common/src/components.d.ts @@ -57,6 +57,7 @@ declare module '@vue/runtime-core' { EnvironmentsMy: typeof import('./components/environments/my/index.vue')['default'] EnvironmentsMyDetails: typeof import('./components/environments/my/Details.vue')['default'] EnvironmentsMyEnvironment: typeof import('./components/environments/my/Environment.vue')['default'] + EnvironmentsSelector: typeof import('./components/environments/Selector.vue')['default'] EnvironmentsTeams: typeof import('./components/environments/teams/index.vue')['default'] EnvironmentsTeamsDetails: typeof import('./components/environments/teams/Details.vue')['default'] EnvironmentsTeamsEnvironment: typeof import('./components/environments/teams/Environment.vue')['default'] diff --git a/packages/hoppscotch-common/src/components/environments/Selector.vue b/packages/hoppscotch-common/src/components/environments/Selector.vue new file mode 100644 index 0000000000..b62f4c207c --- /dev/null +++ b/packages/hoppscotch-common/src/components/environments/Selector.vue @@ -0,0 +1,174 @@ + + + diff --git a/packages/hoppscotch-common/src/components/environments/index.vue b/packages/hoppscotch-common/src/components/environments/index.vue index 02af537fa5..bdd8cce963 100644 --- a/packages/hoppscotch-common/src/components/environments/index.vue +++ b/packages/hoppscotch-common/src/components/environments/index.vue @@ -4,153 +4,15 @@ class="sticky top-0 z-10 flex flex-col flex-shrink-0 overflow-x-auto bg-primary" > - - - - - - - - - - - - - - + workspace.value.teamID, + () => workspace.value.type === "team" && workspace.value.teamID, (teamID) => { if (!teamID) { switchToMyEnvironments() - } else if (teamID) { + setSelectedEnvironmentIndex({ + type: "NO_ENV_SELECTED", + }) + } else { const team = myTeams.value?.find((t) => t.id === teamID) if (team) { updateSelectedTeam(team) + setSelectedEnvironmentIndex({ + type: "NO_ENV_SELECTED", + }) } } } @@ -388,33 +254,6 @@ watch( { deep: true } ) -const selectedEnv = computed(() => { - if (selectedEnvironmentIndex.value.type === "MY_ENV") { - return { - type: "MY_ENV", - index: selectedEnvironmentIndex.value.index, - } - } else if (selectedEnvironmentIndex.value.type === "TEAM_ENV") { - const teamEnv = teamEnvironmentList.value.find( - (env) => - env.id === - (selectedEnvironmentIndex.value.type === "TEAM_ENV" && - selectedEnvironmentIndex.value.teamEnvID) - ) - if (teamEnv) { - return { - type: "TEAM_ENV", - name: teamEnv.environment.name, - teamEnvID: selectedEnvironmentIndex.value.teamEnvID, - } - } else { - return { type: "NO_ENV_SELECTED" } - } - } else { - return { type: "NO_ENV_SELECTED" } - } -}) - const getErrorMessage = (err: GQLError) => { if (err.type === "network_error") { return t("error.network_error") @@ -427,7 +266,4 @@ const getErrorMessage = (err: GQLError) => { } } } - -// Template refs -const tippyActions = ref(null)