fix: invalid environment index can break the app (#3041)
This commit is contained in:
@@ -37,14 +37,23 @@ type EnvironmentStore = typeof defaultEnvironmentsState
|
|||||||
|
|
||||||
const dispatchers = defineDispatchers({
|
const dispatchers = defineDispatchers({
|
||||||
setSelectedEnvironmentIndex(
|
setSelectedEnvironmentIndex(
|
||||||
_: EnvironmentStore,
|
store: EnvironmentStore,
|
||||||
{
|
{
|
||||||
selectedEnvironmentIndex,
|
selectedEnvironmentIndex,
|
||||||
}: { selectedEnvironmentIndex: SelectedEnvironmentIndex }
|
}: { selectedEnvironmentIndex: SelectedEnvironmentIndex }
|
||||||
|
) {
|
||||||
|
if (
|
||||||
|
selectedEnvironmentIndex.type === "MY_ENV" &&
|
||||||
|
!!store.environments[selectedEnvironmentIndex.index]
|
||||||
) {
|
) {
|
||||||
return {
|
return {
|
||||||
selectedEnvironmentIndex,
|
selectedEnvironmentIndex,
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
type: "NO_ENV_SELECTED",
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
appendEnvironments(
|
appendEnvironments(
|
||||||
{ environments }: EnvironmentStore,
|
{ environments }: EnvironmentStore,
|
||||||
@@ -325,7 +334,8 @@ export const selectedEnvironmentIndex$ = environmentsStore.subject$.pipe(
|
|||||||
distinctUntilChanged()
|
distinctUntilChanged()
|
||||||
)
|
)
|
||||||
|
|
||||||
export const currentEnvironment$ = environmentsStore.subject$.pipe(
|
export const currentEnvironment$: Observable<Environment | undefined> =
|
||||||
|
environmentsStore.subject$.pipe(
|
||||||
map(({ environments, selectedEnvironmentIndex }) => {
|
map(({ environments, selectedEnvironmentIndex }) => {
|
||||||
if (selectedEnvironmentIndex.type === "NO_ENV_SELECTED") {
|
if (selectedEnvironmentIndex.type === "NO_ENV_SELECTED") {
|
||||||
const env: Environment = {
|
const env: Environment = {
|
||||||
@@ -358,7 +368,7 @@ export const aggregateEnvs$: Observable<AggregateEnvironment[]> = combineLatest(
|
|||||||
map(([selectedEnv, globalVars]) => {
|
map(([selectedEnv, globalVars]) => {
|
||||||
const results: AggregateEnvironment[] = []
|
const results: AggregateEnvironment[] = []
|
||||||
|
|
||||||
selectedEnv.variables.forEach(({ key, value }) =>
|
selectedEnv?.variables.forEach(({ key, value }) =>
|
||||||
results.push({ key, value, sourceEnv: selectedEnv.name })
|
results.push({ key, value, sourceEnv: selectedEnv.name })
|
||||||
)
|
)
|
||||||
globalVars.forEach(({ key, value }) =>
|
globalVars.forEach(({ key, value }) =>
|
||||||
|
|||||||
Reference in New Issue
Block a user