|
@@ -11,7 +11,13 @@
|
|
|
@edit-environment="editEnvironment('Global')"
|
|
|
/>
|
|
|
</div>
|
|
|
- <EnvironmentsMy v-show="environmentType.type === 'my-environments'" />
|
|
|
+ <EnvironmentsMy
|
|
|
+ v-show="environmentType.type === 'my-environments'"
|
|
|
+ @create-environment="createEnvironment"
|
|
|
+ @duplicate-environment="duplicateEnvironment"
|
|
|
+ @update-environment="updateEnvironment"
|
|
|
+ @delete-environment="removeEnvironment"
|
|
|
+ />
|
|
|
<EnvironmentsTeams
|
|
|
v-show="environmentType.type === 'team-environments'"
|
|
|
:team="environmentType.selectedTeam"
|
|
@@ -41,7 +47,7 @@
|
|
|
:show="showConfirmRemoveEnvModal"
|
|
|
:title="`${t('confirm.remove_environment')}`"
|
|
|
@hide-modal="showConfirmRemoveEnvModal = false"
|
|
|
- @resolve="removeSelectedEnvironment()"
|
|
|
+ @resolve="removeSelectedEnvironment"
|
|
|
/>
|
|
|
</template>
|
|
|
|
|
@@ -49,10 +55,12 @@
|
|
|
import { useReadonlyStream, useStream } from "@composables/stream"
|
|
|
import { Environment } from "@hoppscotch/data"
|
|
|
import { useService } from "dioc/vue"
|
|
|
+import * as E from "fp-ts/Either"
|
|
|
import * as TE from "fp-ts/TaskEither"
|
|
|
import { pipe } from "fp-ts/function"
|
|
|
import { isEqual } from "lodash-es"
|
|
|
import { computed, ref, watch } from "vue"
|
|
|
+
|
|
|
import { useI18n } from "~/composables/i18n"
|
|
|
import { useToast } from "~/composables/toast"
|
|
|
import { defineActionHandler } from "~/helpers/actions"
|
|
@@ -61,6 +69,7 @@ import { deleteTeamEnvironment } from "~/helpers/backend/mutations/TeamEnvironme
|
|
|
import TeamEnvironmentAdapter from "~/helpers/teams/TeamEnvironmentAdapter"
|
|
|
import {
|
|
|
deleteEnvironment,
|
|
|
+ environments$,
|
|
|
getSelectedEnvironmentIndex,
|
|
|
globalEnv$,
|
|
|
selectedEnvironmentIndex$,
|
|
@@ -68,6 +77,7 @@ import {
|
|
|
} from "~/newstore/environments"
|
|
|
import { useLocalState } from "~/newstore/localstate"
|
|
|
import { platform } from "~/platform"
|
|
|
+import { NewWorkspaceService } from "~/services/new-workspace"
|
|
|
import { TeamWorkspace, WorkspaceService } from "~/services/workspace.service"
|
|
|
|
|
|
const t = useI18n()
|
|
@@ -86,6 +96,7 @@ const environmentType = ref<EnvironmentsChooseType>({
|
|
|
})
|
|
|
|
|
|
const globalEnv = useReadonlyStream(globalEnv$, [])
|
|
|
+const environments = useReadonlyStream(environments$, [])
|
|
|
|
|
|
const globalEnvironment = computed(() => ({
|
|
|
v: 1 as const,
|
|
@@ -100,6 +111,7 @@ const currentUser = useReadonlyStream(
|
|
|
)
|
|
|
|
|
|
const workspaceService = useService(WorkspaceService)
|
|
|
+const newWorkspaceService = useService(NewWorkspaceService)
|
|
|
const REMEMBERED_TEAM_ID = useLocalState("REMEMBERED_TEAM_ID")
|
|
|
|
|
|
const adapter = new TeamEnvironmentAdapter(undefined)
|
|
@@ -107,6 +119,8 @@ const adapterLoading = useReadonlyStream(adapter.loading$, false)
|
|
|
const adapterError = useReadonlyStream(adapter.error$, null)
|
|
|
const teamEnvironmentList = useReadonlyStream(adapter.teamEnvironmentList$, [])
|
|
|
|
|
|
+const activeWorkspaceHandle = newWorkspaceService.activeWorkspaceHandle
|
|
|
+
|
|
|
const loading = computed(
|
|
|
() => adapterLoading.value && teamEnvironmentList.value.length === 0
|
|
|
)
|
|
@@ -131,6 +145,7 @@ const updateEnvironmentType = (newEnvironmentType: EnvironmentType) => {
|
|
|
|
|
|
const workspace = workspaceService.currentWorkspace
|
|
|
|
|
|
+// TODO: Replace with `newWorkspaceService`
|
|
|
// 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) => {
|
|
@@ -184,15 +199,23 @@ const editEnvironment = (environmentIndex: "Global") => {
|
|
|
displayModalEdit(true)
|
|
|
}
|
|
|
|
|
|
-const removeSelectedEnvironment = () => {
|
|
|
+const removeSelectedEnvironment = async () => {
|
|
|
const selectedEnvIndex = getSelectedEnvironmentIndex()
|
|
|
- if (selectedEnvIndex?.type === "NO_ENV_SELECTED") return
|
|
|
|
|
|
+ if (
|
|
|
+ selectedEnvIndex?.type === "NO_ENV_SELECTED" ||
|
|
|
+ !activeWorkspaceHandle.value
|
|
|
+ ) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // TODO: Remove the check once the team workspace implementation is in place
|
|
|
if (selectedEnvIndex?.type === "MY_ENV") {
|
|
|
- deleteEnvironment(selectedEnvIndex.index)
|
|
|
- toast.success(`${t("state.deleted")}`)
|
|
|
+ await removeEnvironment(selectedEnvIndex.index)
|
|
|
+ return
|
|
|
}
|
|
|
|
|
|
+ // TODO: Remove once the team workspace implementation is in place
|
|
|
if (selectedEnvIndex?.type === "TEAM_ENV") {
|
|
|
pipe(
|
|
|
deleteTeamEnvironment(selectedEnvIndex.teamEnvID),
|
|
@@ -208,6 +231,138 @@ const removeSelectedEnvironment = () => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+const createEnvironment = async (newEnvironment: Environment) => {
|
|
|
+ if (!activeWorkspaceHandle.value) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ const environmentHandleResult =
|
|
|
+ await newWorkspaceService.createRESTEnvironment(
|
|
|
+ activeWorkspaceHandle.value,
|
|
|
+ newEnvironment
|
|
|
+ )
|
|
|
+
|
|
|
+ if (E.isLeft(environmentHandleResult)) {
|
|
|
+ // INVALID_WORKSPACE_HANDLE
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // Workspace invalidated
|
|
|
+ if (environmentHandleResult.right.get().value.type === "invalid") {
|
|
|
+ // INVALID_WORKSPACE_HANDLE | ENVIRONMENT_DOES_NOT_EXIST
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ setSelectedEnvironmentIndex({
|
|
|
+ type: "MY_ENV",
|
|
|
+ index: environments.value.length - 1,
|
|
|
+ })
|
|
|
+
|
|
|
+ toast.success(t("environment.created"))
|
|
|
+}
|
|
|
+
|
|
|
+const duplicateEnvironment = async (environmentID: number) => {
|
|
|
+ if (!activeWorkspaceHandle.value) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ const environmentHandleResult =
|
|
|
+ await newWorkspaceService.getRESTEnvironmentHandle(
|
|
|
+ activeWorkspaceHandle.value,
|
|
|
+ environmentID
|
|
|
+ )
|
|
|
+
|
|
|
+ if (E.isLeft(environmentHandleResult)) {
|
|
|
+ // INVALID_WORKSPACE_HANDLE
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ const environmentHandle = environmentHandleResult.right
|
|
|
+
|
|
|
+ const duplicatedEnvironmentHandleResult =
|
|
|
+ await newWorkspaceService.duplicateRESTEnvironment(environmentHandle)
|
|
|
+
|
|
|
+ if (E.isLeft(duplicatedEnvironmentHandleResult)) {
|
|
|
+ // INVALID_WORKSPACE_HANDLE
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ const duplicatedEnvironmentHandleRef =
|
|
|
+ duplicatedEnvironmentHandleResult.right.get()
|
|
|
+
|
|
|
+ // Workspace invalidated
|
|
|
+ if (duplicatedEnvironmentHandleRef.value.type === "invalid") {
|
|
|
+ // INVALID_WORKSPACE_HANDLE | ENVIRONMENT_DOES_NOT_EXIST
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ toast.success(t("environment.duplicated"))
|
|
|
+}
|
|
|
+
|
|
|
+const updateEnvironment = async (
|
|
|
+ environmentID: number,
|
|
|
+ updatedEnvironment: Partial<Environment>
|
|
|
+) => {
|
|
|
+ if (!activeWorkspaceHandle.value) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ const environmentHandleResult =
|
|
|
+ await newWorkspaceService.getRESTEnvironmentHandle(
|
|
|
+ activeWorkspaceHandle.value,
|
|
|
+ environmentID
|
|
|
+ )
|
|
|
+
|
|
|
+ if (E.isLeft(environmentHandleResult)) {
|
|
|
+ // INVALID_WORKSPACE_HANDLE
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ const environmentHandle = environmentHandleResult.right
|
|
|
+
|
|
|
+ const updatedEnvironmentHandleResult =
|
|
|
+ await newWorkspaceService.updateRESTEnvironment(
|
|
|
+ environmentHandle,
|
|
|
+ updatedEnvironment
|
|
|
+ )
|
|
|
+
|
|
|
+ if (E.isLeft(updatedEnvironmentHandleResult)) {
|
|
|
+ // INVALID_WORKSPACE_HANDLE
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ toast.success(t("environment.updated"))
|
|
|
+}
|
|
|
+
|
|
|
+const removeEnvironment = async (environmentID: number) => {
|
|
|
+ if (!activeWorkspaceHandle.value) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ const environmentHandleResult =
|
|
|
+ await newWorkspaceService.getRESTEnvironmentHandle(
|
|
|
+ activeWorkspaceHandle.value,
|
|
|
+ environmentID
|
|
|
+ )
|
|
|
+
|
|
|
+ if (E.isLeft(environmentHandleResult)) {
|
|
|
+ // INVALID_WORKSPACE_HANDLE
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ const environmentHandle = environmentHandleResult.right
|
|
|
+
|
|
|
+ const updatedEnvironmentHandleResult =
|
|
|
+ await newWorkspaceService.removeRESTEnvironment(environmentHandle)
|
|
|
+
|
|
|
+ if (E.isLeft(updatedEnvironmentHandleResult)) {
|
|
|
+ // INVALID_WORKSPACE_HANDLE
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ toast.success(t("environment.deleted"))
|
|
|
+}
|
|
|
+
|
|
|
const resetSelectedData = () => {
|
|
|
editingEnvironmentIndex.value = null
|
|
|
editingVariableName.value = ""
|