diff --git a/packages/hoppscotch-app/components/environments/Environment.vue b/packages/hoppscotch-app/components/environments/Environment.vue index ab9c81dd1..ecdda9cd6 100644 --- a/packages/hoppscotch-app/components/environments/Environment.vue +++ b/packages/hoppscotch-app/components/environments/Environment.vue @@ -41,6 +41,17 @@ } " /> + import { defineComponent, PropType } from "@nuxtjs/composition-api" -import { deleteEnvironment } from "~/newstore/environments" +import { + deleteEnvironment, + duplicateEnvironment, +} from "~/newstore/environments" export default defineComponent({ props: { @@ -89,6 +103,10 @@ export default defineComponent({ icon: "delete", }) }, + duplicateEnvironment() { + if (this.environmentIndex !== "Global") + duplicateEnvironment(this.environmentIndex) + }, }, }) diff --git a/packages/hoppscotch-app/locales/en.json b/packages/hoppscotch-app/locales/en.json index 7f5340071..251ae321f 100644 --- a/packages/hoppscotch-app/locales/en.json +++ b/packages/hoppscotch-app/locales/en.json @@ -10,6 +10,7 @@ "disconnect": "Disconnect", "dismiss": "Dismiss", "download_file": "Download file", + "duplicate": "Duplicate", "edit": "Edit", "go_back": "Go back", "label": "Label", diff --git a/packages/hoppscotch-app/newstore/environments.ts b/packages/hoppscotch-app/newstore/environments.ts index c3555d911..8017a7225 100644 --- a/packages/hoppscotch-app/newstore/environments.ts +++ b/packages/hoppscotch-app/newstore/environments.ts @@ -1,3 +1,4 @@ +import { cloneDeep } from "lodash" import isEqual from "lodash/isEqual" import { combineLatest } from "rxjs" import { distinctUntilChanged, map, pluck } from "rxjs/operators" @@ -76,6 +77,26 @@ const dispatchers = defineDispatchers({ ], } }, + duplicateEnvironment( + { environments }: EnvironmentStore, + { envIndex }: { envIndex: number } + ) { + const newEnvironment = environments.find((_, index) => index === envIndex) + if (!newEnvironment) { + return { + environments, + } + } + return { + environments: [ + ...environments, + { + ...cloneDeep(newEnvironment), + name: `Duplicate of ${newEnvironment.name}`, + }, + ], + } + }, deleteEnvironment( { environments, currentEnvironmentIndex }: EnvironmentStore, { envIndex }: { envIndex: number } @@ -398,6 +419,15 @@ export function createEnvironment(envName: string) { }) } +export function duplicateEnvironment(envIndex: number) { + environmentsStore.dispatch({ + dispatcher: "duplicateEnvironment", + payload: { + envIndex, + }, + }) +} + export function deleteEnvironment(envIndex: number) { environmentsStore.dispatch({ dispatcher: "deleteEnvironment",