environments.ts (hoppscotch-2.0.0) | : | environments.ts (hoppscotch-2.1.0) | ||
---|---|---|---|---|
import { cloneDeep } from "lodash" | ||||
import isEqual from "lodash/isEqual" | import isEqual from "lodash/isEqual" | |||
import { combineLatest } from "rxjs" | import { combineLatest } from "rxjs" | |||
import { distinctUntilChanged, map, pluck } from "rxjs/operators" | import { distinctUntilChanged, map, pluck } from "rxjs/operators" | |||
import DispatchingStore, { | import DispatchingStore, { | |||
defineDispatchers, | defineDispatchers, | |||
} from "~/newstore/DispatchingStore" | } from "~/newstore/DispatchingStore" | |||
export type Environment = { | export type Environment = { | |||
name: string | name: string | |||
variables: { | variables: { | |||
skipping to change at line 42 | skipping to change at line 43 | |||
const dispatchers = defineDispatchers({ | const dispatchers = defineDispatchers({ | |||
setCurrentEnviromentIndex( | setCurrentEnviromentIndex( | |||
{ environments }: EnvironmentStore, | { environments }: EnvironmentStore, | |||
{ newIndex }: { newIndex: number } | { newIndex }: { newIndex: number } | |||
) { | ) { | |||
if (newIndex >= environments.length || newIndex <= -2) { | if (newIndex >= environments.length || newIndex <= -2) { | |||
console.log( | console.log( | |||
`Ignoring possibly invalid current environment index assignment (value: ${newIndex})` | `Ignoring possibly invalid current environment index assignment (value: ${newIndex})` | |||
) | ) | |||
return {} | return {} | |||
} | } | |||
return { | return { | |||
currentEnvironmentIndex: newIndex, | currentEnvironmentIndex: newIndex, | |||
} | } | |||
}, | }, | |||
appendEnvironments( | appendEnvironments( | |||
{ environments }: EnvironmentStore, | { environments }: EnvironmentStore, | |||
{ envs }: { envs: Environment[] } | { envs }: { envs: Environment[] } | |||
skipping to change at line 80 | skipping to change at line 80 | |||
return { | return { | |||
environments: [ | environments: [ | |||
...environments, | ...environments, | |||
{ | { | |||
name, | name, | |||
variables: [], | variables: [], | |||
}, | }, | |||
], | ], | |||
} | } | |||
}, | }, | |||
duplicateEnvironment( | ||||
{ environments }: EnvironmentStore, | ||||
{ envIndex }: { envIndex: number } | ||||
) { | ||||
const newEnvironment = environments.find((_, index) => index === envIndex) | ||||
if (!newEnvironment) { | ||||
return { | ||||
environments, | ||||
} | ||||
} | ||||
const index = | ||||
environments.filter((env) => env.name === newEnvironment.name).length + 1 | ||||
return { | ||||
environments: [ | ||||
...environments, | ||||
{ | ||||
...cloneDeep(newEnvironment), | ||||
name: `${newEnvironment.name} ${index}`, | ||||
}, | ||||
], | ||||
} | ||||
}, | ||||
deleteEnvironment( | deleteEnvironment( | |||
{ environments, currentEnvironmentIndex }: EnvironmentStore, | { environments, currentEnvironmentIndex }: EnvironmentStore, | |||
{ envIndex }: { envIndex: number } | { envIndex }: { envIndex: number } | |||
) { | ) { | |||
return { | return { | |||
environments: environments.filter((_, index) => index !== envIndex), | environments: environments.filter((_, index) => index !== envIndex), | |||
currentEnvironmentIndex: | currentEnvironmentIndex: | |||
envIndex === currentEnvironmentIndex ? -1 : currentEnvironmentIndex, | envIndex === currentEnvironmentIndex ? -1 : currentEnvironmentIndex, | |||
} | } | |||
}, | }, | |||
skipping to change at line 402 | skipping to change at line 424 | |||
export function createEnvironment(envName: string) { | export function createEnvironment(envName: string) { | |||
environmentsStore.dispatch({ | environmentsStore.dispatch({ | |||
dispatcher: "createEnvironment", | dispatcher: "createEnvironment", | |||
payload: { | payload: { | |||
name: envName, | name: envName, | |||
}, | }, | |||
}) | }) | |||
} | } | |||
export function duplicateEnvironment(envIndex: number) { | ||||
environmentsStore.dispatch({ | ||||
dispatcher: "duplicateEnvironment", | ||||
payload: { | ||||
envIndex, | ||||
}, | ||||
}) | ||||
} | ||||
export function deleteEnvironment(envIndex: number) { | export function deleteEnvironment(envIndex: number) { | |||
environmentsStore.dispatch({ | environmentsStore.dispatch({ | |||
dispatcher: "deleteEnvironment", | dispatcher: "deleteEnvironment", | |||
payload: { | payload: { | |||
envIndex, | envIndex, | |||
}, | }, | |||
}) | }) | |||
} | } | |||
export function renameEnvironment(envIndex: number, newName: string) { | export function renameEnvironment(envIndex: number, newName: string) { | |||
End of changes. 4 change blocks. | ||||
1 lines changed or deleted | 32 lines changed or added |