+
+
+ {{ t("state.loading") }}
+
+
()
const emit = defineEmits<{
@@ -124,15 +137,38 @@ const emit = defineEmits<{
const toast = useToast()
const t = useI18n()
-const environments = useReadonlyStream(environments$, [])
+
+const loading = ref(false)
+
+const myEnvironments = useReadonlyStream(environments$, [])
const currentUser = useReadonlyStream(currentUser$, null)
+const selectedEnvType = getSelectedEnvironmentType()
+
+const currentSelectedEnvionmentType = computed(() => {
+ if (selectedEnvType === "MY_ENV" || props.teamEnvironments === undefined) {
+ return "MY_ENV"
+ } else {
+ return "TEAM_ENV"
+ }
+})
+
// Template refs
-const tippyActions = ref(null)
+const tippyActions = ref(null)
const inputChooseFileToImportFrom = ref()
const environmentJson = computed(() => {
- return JSON.stringify(environments.value, null, 2)
+ if (
+ currentSelectedEnvionmentType.value === "TEAM_ENV" &&
+ props.teamEnvironments !== undefined
+ ) {
+ const teamEnvironments = props.teamEnvironments.map(
+ (x) => x.environment as Environment
+ )
+ return JSON.stringify(teamEnvironments, null, 2)
+ } else {
+ return JSON.stringify(myEnvironments.value, null, 2)
+ }
})
const createEnvironmentGist = async () => {
@@ -196,8 +232,13 @@ const readEnvironmentGist = async () => {
}
}
const environments = JSON.parse(Object.values(files)[0].content)
- replaceEnvironments(environments)
- fileImported()
+
+ if (currentSelectedEnvionmentType.value === "MY_ENV") {
+ replaceEnvironments(environments)
+ fileImported()
+ } else {
+ importToTeams(environments)
+ }
} catch (e) {
failedImport()
console.error(e)
@@ -213,6 +254,34 @@ const openDialogChooseFileToImportFrom = () => {
inputChooseFileToImportFrom.value.click()
}
+const importToTeams = async (content: Environment[]) => {
+ loading.value = true
+ for (const [i, env] of content.entries()) {
+ if (i === content.length - 1) {
+ loading.value = false
+ hideModal()
+ fileImported()
+ } else {
+ await pipe(
+ createTeamEnvironment(
+ JSON.stringify(env.variables),
+ props.teamId as string,
+ env.name
+ ),
+ TE.match(
+ (err: GQLError) => {
+ console.error(err)
+ toast.error(`${getErrorMessage(err)}`)
+ },
+ () => {
+ // wait for all the environments to be created then fire the toast
+ }
+ )
+ )()
+ }
+ }
+}
+
const importFromJSON = () => {
if (!inputChooseFileToImportFrom.value) return
@@ -235,6 +304,7 @@ const importFromJSON = () => {
}
const environments = JSON.parse(content)
+
if (
environments._postman_variable_scope === "environment" ||
environments._postman_variable_scope === "globals"
@@ -256,8 +326,12 @@ const importFromJSON = () => {
}
const importFromHoppscotch = (environments: Environment[]) => {
- appendEnvironments(environments)
- fileImported()
+ if (currentSelectedEnvionmentType.value === "MY_ENV") {
+ appendEnvironments(environments)
+ fileImported()
+ } else {
+ importToTeams(environments)
+ }
}
const importFromPostman = ({
@@ -290,4 +364,17 @@ const exportJSON = () => {
URL.revokeObjectURL(url)
}, 1000)
}
+
+const getErrorMessage = (err: GQLError) => {
+ if (err.type === "network_error") {
+ return t("error.network_error")
+ } else {
+ switch (err.error) {
+ case "team_environment/not_found":
+ return t("team_environment.not_found")
+ default:
+ return t("error.something_went_wrong")
+ }
+ }
+}
diff --git a/packages/hoppscotch-app/src/components/environments/index.vue b/packages/hoppscotch-app/src/components/environments/index.vue
index 76da71957..7df6b2ef3 100644
--- a/packages/hoppscotch-app/src/components/environments/index.vue
+++ b/packages/hoppscotch-app/src/components/environments/index.vue
@@ -2,19 +2,23 @@
{
- selectedEnvironmentIndex = -1
+ selectedEnvironmentIndex = { type: 'NO_ENV_SELECTED' }
hide()
}
"
/>
-
+
{
- selectedEnvironmentIndex = index
+ selectedEnvironmentIndex = { type: 'MY_ENV', index: index }
hide()
}
"
@@ -58,140 +67,258 @@
-
-
-
-
-
+
+
+
{
+ selectedEnvironmentIndex = { type: 'NO_ENV_SELECTED' }
+ hide()
+ }
+ "
+ />
+
+
+ {{ t("state.loading") }}
+
+
+
+ {
+ selectedEnvironmentIndex = {
+ type: 'TEAM_ENV',
+ teamEnvID: gen.id,
+ teamID: gen.teamID,
+ environment: gen.environment,
+ }
+ hide()
+ }
+ "
+ />
+
+
+ help_outline
+ {{ getErrorMessage(adapterError) }}
+
+
+
+
+
-
-
![]()
-
- {{ t("empty.environments") }}
-
-
-
-
-
+
diff --git a/packages/hoppscotch-app/src/components/environments/Details.vue b/packages/hoppscotch-app/src/components/environments/my/Details.vue
similarity index 91%
rename from packages/hoppscotch-app/src/components/environments/Details.vue
rename to packages/hoppscotch-app/src/components/environments/my/Details.vue
index 5cb8ff41d..92be74f7b 100644
--- a/packages/hoppscotch-app/src/components/environments/Details.vue
+++ b/packages/hoppscotch-app/src/components/environments/my/Details.vue
@@ -101,18 +101,12 @@
-
+
-
+
@@ -120,7 +114,7 @@
diff --git a/packages/hoppscotch-app/src/components/environments/teams/Details.vue b/packages/hoppscotch-app/src/components/environments/teams/Details.vue
new file mode 100644
index 000000000..e4a83943e
--- /dev/null
+++ b/packages/hoppscotch-app/src/components/environments/teams/Details.vue
@@ -0,0 +1,340 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {{ t("environment.nested_overflow") }}
+
+
+
+
+
![]()
+
+ {{ t("empty.environments") }}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/packages/hoppscotch-app/src/components/environments/teams/Environment.vue b/packages/hoppscotch-app/src/components/environments/teams/Environment.vue
new file mode 100644
index 000000000..cc4796451
--- /dev/null
+++ b/packages/hoppscotch-app/src/components/environments/teams/Environment.vue
@@ -0,0 +1,176 @@
+
+
+
+
+
+
+
+ {{ environment.environment.name }}
+
+
+
+
+
+
+
+ {
+ emit('edit-environment')
+ hide()
+ }
+ "
+ />
+ {
+ duplicateEnvironments()
+ hide()
+ }
+ "
+ />
+ {
+ confirmRemove = true
+ hide()
+ }
+ "
+ />
+
+
+
+
+
+
+
+
+
diff --git a/packages/hoppscotch-app/src/components/environments/teams/index.vue b/packages/hoppscotch-app/src/components/environments/teams/index.vue
new file mode 100644
index 000000000..f37b9a386
--- /dev/null
+++ b/packages/hoppscotch-app/src/components/environments/teams/index.vue
@@ -0,0 +1,177 @@
+
+
+
+
+
![]()
+
+ {{ t("empty.environments") }}
+
+
+
+
+
+
+
+
+
+ {{ t("state.loading") }}
+
+
+ help_outline
+ {{ getErrorMessage(adapterError) }}
+
+
+
+
+
+
+
diff --git a/packages/hoppscotch-app/src/components/http/TestResult.vue b/packages/hoppscotch-app/src/components/http/TestResult.vue
index c3d5d2317..29a459682 100644
--- a/packages/hoppscotch-app/src/components/http/TestResult.vue
+++ b/packages/hoppscotch-app/src/components/http/TestResult.vue
@@ -194,7 +194,7 @@
class="my-4"
/>
-