Skip to content

Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia

fix: reset currentEnv if there is a shared workspace change (#4255)

Nivedin9fdde2b78865
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.