Skip to content

Commit 0212eba

Browse files
fix: update id while syncing and gist import bug (hoppscotch#5100)
Co-authored-by: jamesgeorge007 <[email protected]>
1 parent a805736 commit 0212eba

File tree

5 files changed

+44
-12
lines changed
  • packages
    • hoppscotch-common/src/helpers/import-export/import
    • hoppscotch-data/src/environment/v
    • hoppscotch-selfhost-desktop/src/platform/environments
    • hoppscotch-selfhost-web/src/platform/environments

5 files changed

+44
-12
lines changed

packages/hoppscotch-common/src/helpers/import-export/import/hoppEnv.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,23 @@ export const hoppEnvImporter = (contents: string[]) => {
2222
return unwrappedContent.map((contentEntry) => {
2323
return {
2424
...contentEntry,
25-
variables: contentEntry.variables?.map((valueEntry) => ({
26-
...valueEntry,
27-
...("initialValue" in valueEntry
28-
? { value: String(valueEntry.initialValue) }
29-
: {}),
30-
})),
25+
variables: contentEntry.variables?.map((valueEntry) => {
26+
if ("value" in valueEntry) {
27+
return {
28+
...valueEntry,
29+
value: String(valueEntry.value),
30+
}
31+
}
32+
33+
if ("initialValue" in valueEntry) {
34+
return {
35+
...valueEntry,
36+
initialValue: String(valueEntry.initialValue),
37+
}
38+
}
39+
40+
return valueEntry
41+
}),
3142
}
3243
})
3344
}

packages/hoppscotch-data/src/environment/v/2.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { boolean, z } from "zod"
1+
import { z } from "zod"
22
import { defineVersion } from "verzod"
33
import { V1_SCHEMA } from "./1"
44

@@ -23,14 +23,16 @@ export default defineVersion({
2323
...old,
2424
v: 2,
2525
variables: old.variables.map((variable) => {
26+
const { key, secret } = variable
27+
2628
// if the variable is secret, set initialValue and currentValue to empty string
2729
// else set initialValue and currentValue to value
2830
// and delete value
2931
return {
30-
...variable,
31-
initialValue: variable.secret ? "" : variable.value,
32-
currentValue: variable.secret ? "" : variable.value,
33-
value: undefined,
32+
key,
33+
secret,
34+
initialValue: secret ? "" : variable.value,
35+
currentValue: secret ? "" : variable.value,
3436
}
3537
}),
3638
}

packages/hoppscotch-selfhost-desktop/src/platform/environments/environments.sync.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,12 @@ export const storeSyncDefinition: StoreSyncDefinitionOf<
9797
setGlobalVariables({ entries }) {
9898
const backendId = getGlobalVariableID()
9999
if (backendId) {
100-
updateUserEnvironment(backendId, { name: "", variables: entries })()
100+
updateUserEnvironment(backendId, {
101+
name: "",
102+
variables: entries,
103+
id: "",
104+
v: 2,
105+
})()
101106
}
102107
},
103108
clearGlobalVariables() {

packages/hoppscotch-selfhost-web/src/platform/environments/desktop/sync.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ import {
2222
} from "./api"
2323
import { SecretEnvironmentService } from "@hoppscotch/common/services/secret-environment.service"
2424
import { getService } from "@hoppscotch/common/modules/dioc"
25+
import { CurrentValueService } from "@hoppscotch/common/services/current-environment-value.service"
2526

2627
export const environmentsMapper = createMapper<number, string>()
2728
export const globalEnvironmentMapper = createMapper<number, string>()
2829

2930
const secretEnvironmentService = getService(SecretEnvironmentService)
31+
const currentEnvironmentValueService = getService(CurrentValueService)
3032

3133
export const storeSyncDefinition: StoreSyncDefinitionOf<
3234
typeof environmentsStore
@@ -44,6 +46,11 @@ export const storeSyncDefinition: StoreSyncDefinitionOf<
4446
id
4547
)
4648

49+
currentEnvironmentValueService.updateEnvironmentID(
50+
environmentsStore.value.environments[lastCreatedEnvIndex].id,
51+
id
52+
)
53+
4754
environmentsStore.value.environments[lastCreatedEnvIndex].id = id
4855
removeDuplicateEntry(id)
4956
}

packages/hoppscotch-selfhost-web/src/platform/environments/web/sync.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ import {
2222
} from "./api"
2323
import { SecretEnvironmentService } from "@hoppscotch/common/services/secret-environment.service"
2424
import { getService } from "@hoppscotch/common/modules/dioc"
25+
import { CurrentValueService } from "@hoppscotch/common/services/current-environment-value.service"
2526

2627
export const environmentsMapper = createMapper<number, string>()
2728
export const globalEnvironmentMapper = createMapper<number, string>()
2829

2930
const secretEnvironmentService = getService(SecretEnvironmentService)
31+
const currentEnvironmentValueService = getService(CurrentValueService)
3032

3133
export const storeSyncDefinition: StoreSyncDefinitionOf<
3234
typeof environmentsStore
@@ -44,6 +46,11 @@ export const storeSyncDefinition: StoreSyncDefinitionOf<
4446
id
4547
)
4648

49+
currentEnvironmentValueService.updateEnvironmentID(
50+
environmentsStore.value.environments[lastCreatedEnvIndex].id,
51+
id
52+
)
53+
4754
environmentsStore.value.environments[lastCreatedEnvIndex].id = id
4855
removeDuplicateEntry(id)
4956
}

0 commit comments

Comments
 (0)