fix: update id while syncing and gist import bug (#5100)
Co-authored-by: jamesgeorge007 <25279263+jamesgeorge007@users.noreply.github.com>
This commit is contained in:
parent
a80573603b
commit
0212eba895
5 changed files with 44 additions and 12 deletions
|
|
@ -22,12 +22,23 @@ export const hoppEnvImporter = (contents: string[]) => {
|
|||
return unwrappedContent.map((contentEntry) => {
|
||||
return {
|
||||
...contentEntry,
|
||||
variables: contentEntry.variables?.map((valueEntry) => ({
|
||||
...valueEntry,
|
||||
...("initialValue" in valueEntry
|
||||
? { value: String(valueEntry.initialValue) }
|
||||
: {}),
|
||||
})),
|
||||
variables: contentEntry.variables?.map((valueEntry) => {
|
||||
if ("value" in valueEntry) {
|
||||
return {
|
||||
...valueEntry,
|
||||
value: String(valueEntry.value),
|
||||
}
|
||||
}
|
||||
|
||||
if ("initialValue" in valueEntry) {
|
||||
return {
|
||||
...valueEntry,
|
||||
initialValue: String(valueEntry.initialValue),
|
||||
}
|
||||
}
|
||||
|
||||
return valueEntry
|
||||
}),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { boolean, z } from "zod"
|
||||
import { z } from "zod"
|
||||
import { defineVersion } from "verzod"
|
||||
import { V1_SCHEMA } from "./1"
|
||||
|
||||
|
|
@ -23,14 +23,16 @@ export default defineVersion({
|
|||
...old,
|
||||
v: 2,
|
||||
variables: old.variables.map((variable) => {
|
||||
const { key, secret } = variable
|
||||
|
||||
// if the variable is secret, set initialValue and currentValue to empty string
|
||||
// else set initialValue and currentValue to value
|
||||
// and delete value
|
||||
return {
|
||||
...variable,
|
||||
initialValue: variable.secret ? "" : variable.value,
|
||||
currentValue: variable.secret ? "" : variable.value,
|
||||
value: undefined,
|
||||
key,
|
||||
secret,
|
||||
initialValue: secret ? "" : variable.value,
|
||||
currentValue: secret ? "" : variable.value,
|
||||
}
|
||||
}),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -97,7 +97,12 @@ export const storeSyncDefinition: StoreSyncDefinitionOf<
|
|||
setGlobalVariables({ entries }) {
|
||||
const backendId = getGlobalVariableID()
|
||||
if (backendId) {
|
||||
updateUserEnvironment(backendId, { name: "", variables: entries })()
|
||||
updateUserEnvironment(backendId, {
|
||||
name: "",
|
||||
variables: entries,
|
||||
id: "",
|
||||
v: 2,
|
||||
})()
|
||||
}
|
||||
},
|
||||
clearGlobalVariables() {
|
||||
|
|
|
|||
|
|
@ -22,11 +22,13 @@ import {
|
|||
} from "./api"
|
||||
import { SecretEnvironmentService } from "@hoppscotch/common/services/secret-environment.service"
|
||||
import { getService } from "@hoppscotch/common/modules/dioc"
|
||||
import { CurrentValueService } from "@hoppscotch/common/services/current-environment-value.service"
|
||||
|
||||
export const environmentsMapper = createMapper<number, string>()
|
||||
export const globalEnvironmentMapper = createMapper<number, string>()
|
||||
|
||||
const secretEnvironmentService = getService(SecretEnvironmentService)
|
||||
const currentEnvironmentValueService = getService(CurrentValueService)
|
||||
|
||||
export const storeSyncDefinition: StoreSyncDefinitionOf<
|
||||
typeof environmentsStore
|
||||
|
|
@ -44,6 +46,11 @@ export const storeSyncDefinition: StoreSyncDefinitionOf<
|
|||
id
|
||||
)
|
||||
|
||||
currentEnvironmentValueService.updateEnvironmentID(
|
||||
environmentsStore.value.environments[lastCreatedEnvIndex].id,
|
||||
id
|
||||
)
|
||||
|
||||
environmentsStore.value.environments[lastCreatedEnvIndex].id = id
|
||||
removeDuplicateEntry(id)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,11 +22,13 @@ import {
|
|||
} from "./api"
|
||||
import { SecretEnvironmentService } from "@hoppscotch/common/services/secret-environment.service"
|
||||
import { getService } from "@hoppscotch/common/modules/dioc"
|
||||
import { CurrentValueService } from "@hoppscotch/common/services/current-environment-value.service"
|
||||
|
||||
export const environmentsMapper = createMapper<number, string>()
|
||||
export const globalEnvironmentMapper = createMapper<number, string>()
|
||||
|
||||
const secretEnvironmentService = getService(SecretEnvironmentService)
|
||||
const currentEnvironmentValueService = getService(CurrentValueService)
|
||||
|
||||
export const storeSyncDefinition: StoreSyncDefinitionOf<
|
||||
typeof environmentsStore
|
||||
|
|
@ -44,6 +46,11 @@ export const storeSyncDefinition: StoreSyncDefinitionOf<
|
|||
id
|
||||
)
|
||||
|
||||
currentEnvironmentValueService.updateEnvironmentID(
|
||||
environmentsStore.value.environments[lastCreatedEnvIndex].id,
|
||||
id
|
||||
)
|
||||
|
||||
environmentsStore.value.environments[lastCreatedEnvIndex].id = id
|
||||
removeDuplicateEntry(id)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue