File tree Expand file tree Collapse file tree 5 files changed +44
-12
lines changed
hoppscotch-common/src/helpers/import-export/import
hoppscotch-data/src/environment/v
hoppscotch-selfhost-desktop/src/platform/environments
hoppscotch-selfhost-web/src/platform/environments Expand file tree Collapse file tree 5 files changed +44
-12
lines changed Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff line change 1- import { boolean , z } from "zod"
1+ import { z } from "zod"
22import { defineVersion } from "verzod"
33import { 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 }
Original file line number Diff line number Diff 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 ( ) {
Original file line number Diff line number Diff line change @@ -22,11 +22,13 @@ import {
2222} from "./api"
2323import { SecretEnvironmentService } from "@hoppscotch/common/services/secret-environment.service"
2424import { getService } from "@hoppscotch/common/modules/dioc"
25+ import { CurrentValueService } from "@hoppscotch/common/services/current-environment-value.service"
2526
2627export const environmentsMapper = createMapper < number , string > ( )
2728export const globalEnvironmentMapper = createMapper < number , string > ( )
2829
2930const secretEnvironmentService = getService ( SecretEnvironmentService )
31+ const currentEnvironmentValueService = getService ( CurrentValueService )
3032
3133export 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 }
Original file line number Diff line number Diff line change @@ -22,11 +22,13 @@ import {
2222} from "./api"
2323import { SecretEnvironmentService } from "@hoppscotch/common/services/secret-environment.service"
2424import { getService } from "@hoppscotch/common/modules/dioc"
25+ import { CurrentValueService } from "@hoppscotch/common/services/current-environment-value.service"
2526
2627export const environmentsMapper = createMapper < number , string > ( )
2728export const globalEnvironmentMapper = createMapper < number , string > ( )
2829
2930const secretEnvironmentService = getService ( SecretEnvironmentService )
31+ const currentEnvironmentValueService = getService ( CurrentValueService )
3032
3133export 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 }
You can’t perform that action at this time.
0 commit comments