chore: merge hoppscotch/staging into self-hosted/main
This commit is contained in:
@@ -147,6 +147,7 @@ import { useI18n } from "@composables/i18n"
|
|||||||
import { useToast } from "@composables/toast"
|
import { useToast } from "@composables/toast"
|
||||||
import { useReadonlyStream } from "@composables/stream"
|
import { useReadonlyStream } from "@composables/stream"
|
||||||
import { useColorMode } from "@composables/theming"
|
import { useColorMode } from "@composables/theming"
|
||||||
|
import { environmentsStore } from "~/newstore/environments"
|
||||||
|
|
||||||
type EnvironmentVariable = {
|
type EnvironmentVariable = {
|
||||||
id: number
|
id: number
|
||||||
@@ -315,8 +316,21 @@ const saveEnvironment = () => {
|
|||||||
setGlobalEnvVariables(environmentUpdated.variables)
|
setGlobalEnvVariables(environmentUpdated.variables)
|
||||||
toast.success(`${t("environment.updated")}`)
|
toast.success(`${t("environment.updated")}`)
|
||||||
} else if (props.editingEnvironmentIndex !== null) {
|
} else if (props.editingEnvironmentIndex !== null) {
|
||||||
|
const envID =
|
||||||
|
environmentsStore.value.environments[props.editingEnvironmentIndex].id
|
||||||
|
|
||||||
// Editing an environment
|
// Editing an environment
|
||||||
updateEnvironment(props.editingEnvironmentIndex, environmentUpdated)
|
updateEnvironment(
|
||||||
|
props.editingEnvironmentIndex,
|
||||||
|
envID
|
||||||
|
? {
|
||||||
|
...environmentUpdated,
|
||||||
|
id: envID,
|
||||||
|
}
|
||||||
|
: {
|
||||||
|
...environmentUpdated,
|
||||||
|
}
|
||||||
|
)
|
||||||
toast.success(`${t("environment.updated")}`)
|
toast.success(`${t("environment.updated")}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -144,8 +144,9 @@ const deleteAction = ref<typeof HoppSmartItem>()
|
|||||||
|
|
||||||
const removeEnvironment = () => {
|
const removeEnvironment = () => {
|
||||||
if (props.environmentIndex === null) return
|
if (props.environmentIndex === null) return
|
||||||
if (props.environmentIndex !== "Global")
|
if (props.environmentIndex !== "Global") {
|
||||||
deleteEnvironment(props.environmentIndex)
|
deleteEnvironment(props.environmentIndex, props.environment.id)
|
||||||
|
}
|
||||||
toast.success(`${t("state.deleted")}`)
|
toast.success(`${t("state.deleted")}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ export const runRESTRequest$ = (
|
|||||||
updateEnvironment(
|
updateEnvironment(
|
||||||
environmentsStore.value.selectedEnvironmentIndex.index,
|
environmentsStore.value.selectedEnvironmentIndex.index,
|
||||||
{
|
{
|
||||||
name: env.name,
|
...env,
|
||||||
variables: runResult.right.envs.selected,
|
variables: runResult.right.envs.selected,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ const defaultEnvironmentsState = {
|
|||||||
},
|
},
|
||||||
] as Environment[],
|
] as Environment[],
|
||||||
|
|
||||||
|
// as a temp fix for identifying global env when syncing
|
||||||
|
globalEnvID: undefined as string | undefined,
|
||||||
globals: [] as Environment["variables"],
|
globals: [] as Environment["variables"],
|
||||||
|
|
||||||
selectedEnvironmentIndex: {
|
selectedEnvironmentIndex: {
|
||||||
@@ -62,15 +64,25 @@ const dispatchers = defineDispatchers({
|
|||||||
},
|
},
|
||||||
createEnvironment(
|
createEnvironment(
|
||||||
{ environments }: EnvironmentStore,
|
{ environments }: EnvironmentStore,
|
||||||
{ name, variables }: { name: string; variables: Environment["variables"] }
|
{
|
||||||
|
name,
|
||||||
|
variables,
|
||||||
|
envID,
|
||||||
|
}: { name: string; variables: Environment["variables"]; envID?: string }
|
||||||
) {
|
) {
|
||||||
return {
|
return {
|
||||||
environments: [
|
environments: [
|
||||||
...environments,
|
...environments,
|
||||||
{
|
envID
|
||||||
name,
|
? {
|
||||||
variables: variables,
|
id: envID,
|
||||||
},
|
name,
|
||||||
|
variables,
|
||||||
|
}
|
||||||
|
: {
|
||||||
|
name,
|
||||||
|
variables,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -84,6 +96,10 @@ const dispatchers = defineDispatchers({
|
|||||||
environments,
|
environments,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// remove the id, because this is a new environment & it will get its own id when syncing
|
||||||
|
delete newEnvironment["id"]
|
||||||
|
|
||||||
return {
|
return {
|
||||||
environments: [
|
environments: [
|
||||||
...environments,
|
...environments,
|
||||||
@@ -100,7 +116,9 @@ const dispatchers = defineDispatchers({
|
|||||||
// currentEnvironmentIndex,
|
// currentEnvironmentIndex,
|
||||||
selectedEnvironmentIndex,
|
selectedEnvironmentIndex,
|
||||||
}: EnvironmentStore,
|
}: EnvironmentStore,
|
||||||
{ envIndex }: { envIndex: number }
|
// the envID is used in the syncing code, so disabling the lint rule
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
{ envIndex, envID }: { envIndex: number; envID?: string }
|
||||||
) {
|
) {
|
||||||
let newCurrEnvIndex = selectedEnvironmentIndex
|
let newCurrEnvIndex = selectedEnvironmentIndex
|
||||||
|
|
||||||
@@ -266,6 +284,25 @@ const dispatchers = defineDispatchers({
|
|||||||
globals: globals.map((x, i) => (i !== envIndex ? x : updatedEntry)),
|
globals: globals.map((x, i) => (i !== envIndex ? x : updatedEntry)),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
setGlobalEnvID(_, { id }: { id: string }) {
|
||||||
|
return {
|
||||||
|
globalEnvID: id,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// only used for environments.sync.ts to prevent double insertion of environments from storeSync and Subscriptions
|
||||||
|
removeDuplicateEntry({ environments }, { id }: { id: string }) {
|
||||||
|
const entries = environments.filter((e) => e.id === id)
|
||||||
|
|
||||||
|
const newEnvironments = [...environments]
|
||||||
|
|
||||||
|
if (entries.length == 2) {
|
||||||
|
const indexToRemove = environments.findIndex((e) => e.id === id)
|
||||||
|
newEnvironments.splice(indexToRemove, 1)
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
environments: newEnvironments,
|
||||||
|
}
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
export const environmentsStore = new DispatchingStore(
|
export const environmentsStore = new DispatchingStore(
|
||||||
@@ -404,6 +441,18 @@ export function getGlobalVariables(): Environment["variables"] {
|
|||||||
return environmentsStore.value.globals
|
return environmentsStore.value.globals
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getGlobalVariableID() {
|
||||||
|
return environmentsStore.value.globalEnvID
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getLocalIndexByEnvironmentID(id: string) {
|
||||||
|
const envIndex = environmentsStore.value.environments.findIndex(
|
||||||
|
(env) => env.id === id
|
||||||
|
)
|
||||||
|
|
||||||
|
return envIndex != -1 ? envIndex : null
|
||||||
|
}
|
||||||
|
|
||||||
export function addGlobalEnvVariable(entry: Environment["variables"][number]) {
|
export function addGlobalEnvVariable(entry: Environment["variables"][number]) {
|
||||||
environmentsStore.dispatch({
|
environmentsStore.dispatch({
|
||||||
dispatcher: "addGlobalVariable",
|
dispatcher: "addGlobalVariable",
|
||||||
@@ -471,13 +520,15 @@ export function appendEnvironments(envs: Environment[]) {
|
|||||||
|
|
||||||
export function createEnvironment(
|
export function createEnvironment(
|
||||||
envName: string,
|
envName: string,
|
||||||
variables?: Environment["variables"]
|
variables?: Environment["variables"],
|
||||||
|
envID?: string
|
||||||
) {
|
) {
|
||||||
environmentsStore.dispatch({
|
environmentsStore.dispatch({
|
||||||
dispatcher: "createEnvironment",
|
dispatcher: "createEnvironment",
|
||||||
payload: {
|
payload: {
|
||||||
name: envName,
|
name: envName,
|
||||||
variables: variables ?? [],
|
variables: variables ?? [],
|
||||||
|
envID,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -491,11 +542,12 @@ export function duplicateEnvironment(envIndex: number) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export function deleteEnvironment(envIndex: number) {
|
export function deleteEnvironment(envIndex: number, envID?: string) {
|
||||||
environmentsStore.dispatch({
|
environmentsStore.dispatch({
|
||||||
dispatcher: "deleteEnvironment",
|
dispatcher: "deleteEnvironment",
|
||||||
payload: {
|
payload: {
|
||||||
envIndex,
|
envIndex,
|
||||||
|
envID,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -576,6 +628,24 @@ export function updateEnvironmentVariable(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function setGlobalEnvID(id: string) {
|
||||||
|
environmentsStore.dispatch({
|
||||||
|
dispatcher: "setGlobalEnvID",
|
||||||
|
payload: {
|
||||||
|
id,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function removeDuplicateEntry(id: string) {
|
||||||
|
environmentsStore.dispatch({
|
||||||
|
dispatcher: "removeDuplicateEntry",
|
||||||
|
payload: {
|
||||||
|
id,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
type SelectedEnv =
|
type SelectedEnv =
|
||||||
| { type: "NO_ENV_SELECTED" }
|
| { type: "NO_ENV_SELECTED" }
|
||||||
| { type: "MY_ENV"; index: number }
|
| { type: "MY_ENV"; index: number }
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { pipe } from "fp-ts/function"
|
|||||||
import * as E from "fp-ts/Either"
|
import * as E from "fp-ts/Either"
|
||||||
|
|
||||||
export type Environment = {
|
export type Environment = {
|
||||||
|
id?: string
|
||||||
name: string
|
name: string
|
||||||
variables: {
|
variables: {
|
||||||
key: string
|
key: string
|
||||||
|
|||||||
Reference in New Issue
Block a user