From 9fdde2b7886506783370cb54aedbbd0203fbca82 Mon Sep 17 00:00:00 2001 From: Nivedin <53208152+nivedin@users.noreply.github.com> Date: Mon, 19 Aug 2024 15:43:32 +0530 Subject: [PATCH] fix: reset currentEnv if there is a shared workspace change (#4255) * fix: reset currentEnv if there is a shared workspace change * chore: cleanup --------- Co-authored-by: jamesgeorge007 <25279263+jamesgeorge007@users.noreply.github.com> --- .../src/components/environments/index.vue | 25 +++++++++++++------ .../services/secret-environment.service.ts | 3 +-- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/packages/hoppscotch-common/src/components/environments/index.vue b/packages/hoppscotch-common/src/components/environments/index.vue index cc239d7d6..a0c9cd5c6 100644 --- a/packages/hoppscotch-common/src/components/environments/index.vue +++ b/packages/hoppscotch-common/src/components/environments/index.vue @@ -139,16 +139,27 @@ const workspace = workspaceService.currentWorkspace // Switch to my environments if workspace is personal and to team environments if workspace is team // also resets selected environment if workspace is personal and the previous selected environment was a team environment watch(workspace, (newWorkspace) => { - if (newWorkspace.type === "personal") { + const { type: newWorkspaceType } = newWorkspace + + if (newWorkspaceType === "personal") { switchToMyEnvironments() - if (selectedEnvironmentIndex.value.type !== "MY_ENV") { - setSelectedEnvironmentIndex({ - type: "NO_ENV_SELECTED", - }) - } - } else if (newWorkspace.type === "team") { + } else { updateSelectedTeam(newWorkspace) } + + const newTeamID = + newWorkspaceType === "team" ? newWorkspace.teamID : undefined + + // Set active environment to the `No environment` state + // if navigating away from a team workspace + if ( + selectedEnvironmentIndex.value.type === "TEAM_ENV" && + selectedEnvironmentIndex.value.teamID !== newTeamID + ) { + setSelectedEnvironmentIndex({ + type: "NO_ENV_SELECTED", + }) + } }) watch( diff --git a/packages/hoppscotch-common/src/services/secret-environment.service.ts b/packages/hoppscotch-common/src/services/secret-environment.service.ts index 4411df685..1f68d00c4 100644 --- a/packages/hoppscotch-common/src/services/secret-environment.service.ts +++ b/packages/hoppscotch-common/src/services/secret-environment.service.ts @@ -1,6 +1,5 @@ import { Service } from "dioc" -import { reactive } from "vue" -import { computed } from "vue" +import { reactive, computed } from "vue" /** * Defines a secret environment variable.