refactor: optional variables to createEnvironment and fixing the order of initializing GqlClient (#2944)

This commit is contained in:
Akash K
2023-03-07 16:12:11 +05:30
committed by GitHub
parent 3fa4052538
commit ae9b7183b5
4 changed files with 11 additions and 11 deletions

View File

@@ -304,8 +304,7 @@ const saveEnvironment = () => {
if (props.action === "new") { if (props.action === "new") {
// Creating a new environment // Creating a new environment
createEnvironment(name.value) createEnvironment(name.value, environmentUpdated.variables)
updateEnvironment(envList.value.length - 1, environmentUpdated)
setSelectedEnvironmentIndex({ setSelectedEnvironmentIndex({
type: "MY_ENV", type: "MY_ENV",
index: envList.value.length - 1, index: envList.value.length - 1,

View File

@@ -115,9 +115,7 @@ import {
deleteEnvironment, deleteEnvironment,
duplicateEnvironment, duplicateEnvironment,
createEnvironment, createEnvironment,
setEnvironmentVariables,
getGlobalVariables, getGlobalVariables,
environmentsStore,
} from "~/newstore/environments" } from "~/newstore/environments"
import { useI18n } from "@composables/i18n" import { useI18n } from "@composables/i18n"
import { useToast } from "@composables/toast" import { useToast } from "@composables/toast"
@@ -154,9 +152,8 @@ const removeEnvironment = () => {
const duplicateEnvironments = () => { const duplicateEnvironments = () => {
if (props.environmentIndex === null) return if (props.environmentIndex === null) return
if (props.environmentIndex === "Global") { if (props.environmentIndex === "Global") {
createEnvironment(`Global - ${t("action.duplicate")}`) createEnvironment(
setEnvironmentVariables( `Global - ${t("action.duplicate")}`,
environmentsStore.value.environments.length - 1,
cloneDeep(getGlobalVariables()) cloneDeep(getGlobalVariables())
) )
} else duplicateEnvironment(props.environmentIndex) } else duplicateEnvironment(props.environmentIndex)

View File

@@ -19,8 +19,8 @@ export function createHoppApp(el: string | Element, platformDef: PlatformDef) {
const app = createApp(App) const app = createApp(App)
// Some basic work that needs to be done before module inits even // Some basic work that needs to be done before module inits even
initializeFirebase()
initBackendGQLClient() initBackendGQLClient()
initializeFirebase()
setupLocalPersistence() setupLocalPersistence()
performMigrations() performMigrations()

View File

@@ -62,14 +62,14 @@ const dispatchers = defineDispatchers({
}, },
createEnvironment( createEnvironment(
{ environments }: EnvironmentStore, { environments }: EnvironmentStore,
{ name }: { name: string } { name, variables }: { name: string; variables: Environment["variables"] }
) { ) {
return { return {
environments: [ environments: [
...environments, ...environments,
{ {
name, name,
variables: [], variables: variables,
}, },
], ],
} }
@@ -469,11 +469,15 @@ export function appendEnvironments(envs: Environment[]) {
}) })
} }
export function createEnvironment(envName: string) { export function createEnvironment(
envName: string,
variables?: Environment["variables"]
) {
environmentsStore.dispatch({ environmentsStore.dispatch({
dispatcher: "createEnvironment", dispatcher: "createEnvironment",
payload: { payload: {
name: envName, name: envName,
variables: variables ?? [],
}, },
}) })
} }