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:
Nivedin 2025-05-27 16:12:55 +05:30 committed by GitHub
parent a80573603b
commit 0212eba895
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 44 additions and 12 deletions

View file

@ -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
}),
}
})
}

View file

@ -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,
}
}),
}

View file

@ -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() {

View file

@ -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)
}

View file

@ -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)
}