From f3f98910177c6f0e27a956567e99756d7d1cdfe7 Mon Sep 17 00:00:00 2001 From: Nivedin Date: Mon, 8 May 2023 13:00:47 +0530 Subject: [PATCH] feat: env selector change --- .../hoppscotch-common/src/components.d.ts | 1 + .../src/components/environments/Selector.vue | 409 ++++++++++++++++++ .../src/components/environments/index.vue | 203 +-------- 3 files changed, 433 insertions(+), 180 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 659b1871d..42e2d67d4 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 000000000..0913df2f0 --- /dev/null +++ b/packages/hoppscotch-common/src/components/environments/Selector.vue @@ -0,0 +1,409 @@ + + + diff --git a/packages/hoppscotch-common/src/components/environments/index.vue b/packages/hoppscotch-common/src/components/environments/index.vue index 02af537fa..b4f740f0b 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" > - - - - - - - - - - - - - - + t.id === REMEMBERED_TEAM_ID.value) - if (team) updateSelectedTeam(team) + if (team) { + updateSelectedTeam(team) + } } } } @@ -295,10 +157,21 @@ watch( (teamID) => { if (!teamID) { switchToMyEnvironments() + + // If the user selected a team environment, and then switch to personal workspace, + // we need to reset the selected environment + if (selectedEnvironmentIndex.value.type === "TEAM_ENV") { + setSelectedEnvironmentIndex({ + type: "NO_ENV_SELECTED", + }) + } } else if (teamID) { const team = myTeams.value?.find((t) => t.id === teamID) if (team) { updateSelectedTeam(team) + setSelectedEnvironmentIndex({ + type: "NO_ENV_SELECTED", + }) } } } @@ -388,33 +261,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 +273,4 @@ const getErrorMessage = (err: GQLError) => { } } } - -// Template refs -const tippyActions = ref(null)