feat: add ability to copy environments (#1848)

Co-authored-by: StephaneBischoffSSENSE <stephane.bischoff@ssense.com>
This commit is contained in:
Stephane
2021-10-03 09:08:36 -04:00
committed by GitHub
parent 5dcfa66c5d
commit 2844710ea8
3 changed files with 50 additions and 1 deletions

View File

@@ -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",