Skip to content

Commit a325f29

Browse files
authored
fix: fill current value to existing value (hoppscotch#5109)
1 parent caeddac commit a325f29

File tree

12 files changed

+41
-35
lines changed

12 files changed

+41
-35
lines changed

packages/hoppscotch-cli/src/utils/request.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const processVariables = (variable: Environment["variables"][number]) => {
4545
currentValue:
4646
"currentValue" in variable && variable.currentValue !== ""
4747
? variable.currentValue
48-
: process.env[variable.key] || "",
48+
: process.env[variable.key] || variable.initialValue,
4949
};
5050
}
5151
return variable;

packages/hoppscotch-common/src/components/environments/my/Details.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ watch(
380380
? "Global"
381381
: workingEnvID.value,
382382
index
383-
) ?? "",
383+
) ?? e.currentValue,
384384
initialValue: e.initialValue,
385385
secret: e.secret,
386386
},

packages/hoppscotch-common/src/components/environments/teams/Details.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ watch(
347347
props.editingEnvironment?.id ?? "",
348348
index,
349349
e.secret
350-
) ?? "",
350+
) ?? e.currentValue,
351351
initialValue: e.initialValue,
352352
secret: e.secret,
353353
},

packages/hoppscotch-common/src/helpers/editor/extensions/HoppEnvironment.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ const cursorTooltipField = (aggregateEnvs: AggregateEnvironment[]) =>
125125
? currentSelectedEnvironment.id
126126
: "Global",
127127
tooltipEnv?.key ?? ""
128-
)?.currentValue ?? "")
128+
)?.currentValue ?? tooltipEnv?.currentValue)
129129
: tooltipEnv?.currentValue
130130

131131
const hasSecretEnv = secretEnvironmentService.hasSecretValue(

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export const transformEnvironmentVariables = ({
4747
key,
4848
secret,
4949
initialValue,
50-
currentValue: "",
50+
currentValue: variable.secret ? "" : (variable.currentValue ?? ""),
5151
}
5252
}),
5353
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export const insomniaEnvImporter = (contents: string[]) => {
7676
([key, value]) => ({
7777
key,
7878
initialValue: value,
79-
currentValue: "",
79+
currentValue: value,
8080
secret: false,
8181
})
8282
),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export const postmanEnvImporter = (contents: string[]) => {
5757
variables: values.map(({ key, value, type }) => ({
5858
key,
5959
initialValue: value,
60-
currentValue: "",
60+
currentValue: value,
6161
secret: type === "secret",
6262
})),
6363
})

packages/hoppscotch-common/src/helpers/utils/environments.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,13 @@ const unWrapEnvironments = (
3838
currentValue: secretVar.value,
3939
}
4040
}
41-
return { ...globalVar, currentValue: currentVar?.currentValue ?? "" }
41+
return {
42+
...globalVar,
43+
currentValue:
44+
currentVar?.currentValue ??
45+
globalVar.currentValue ??
46+
globalVar.initialValue,
47+
}
4248
})
4349

4450
const resolvedSelectedWithSecrets = selected.variables.map(
@@ -57,7 +63,13 @@ const unWrapEnvironments = (
5763
currentValue: secretVar.value,
5864
}
5965
}
60-
return { ...selectedVar, currentValue: currentVar?.currentValue ?? "" }
66+
return {
67+
...selectedVar,
68+
currentValue:
69+
currentVar?.currentValue ??
70+
selectedVar.currentValue ??
71+
selectedVar.initialValue,
72+
}
6173
}
6274
)
6375

packages/hoppscotch-common/src/newstore/environments.ts

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -523,17 +523,16 @@ export function getAggregateEnvs() {
523523

524524
export function getAggregateEnvsWithSecrets() {
525525
const currentEnv = getCurrentEnvironment()
526+
526527
return [
527528
...currentEnv.variables.map((x, index) => {
528-
let currentValue
529+
let currentValue = x.currentValue
529530
if (x.secret) {
530531
currentValue =
531532
secretEnvironmentService.getSecretEnvironmentVariableValue(
532533
currentEnv.id,
533534
index
534-
)
535-
} else {
536-
currentValue = x.currentValue
535+
) ?? ""
537536
}
538537

539538
return <AggregateEnvironment>{
@@ -545,15 +544,13 @@ export function getAggregateEnvsWithSecrets() {
545544
}
546545
}),
547546
...getGlobalVariables().map((x, index) => {
548-
let currentValue
547+
let currentValue = x.currentValue
549548
if (x.secret) {
550549
currentValue =
551550
secretEnvironmentService.getSecretEnvironmentVariableValue(
552551
"Global",
553552
index
554-
)
555-
} else {
556-
currentValue = x.currentValue
553+
) ?? ""
557554
}
558555
return <AggregateEnvironment>{
559556
key: x.key,
@@ -571,39 +568,35 @@ export const aggregateEnvsWithSecrets$: Observable<AggregateEnvironment[]> =
571568
map(([selectedEnv, globalEnv]) => {
572569
const results: AggregateEnvironment[] = []
573570
selectedEnv?.variables.map((x, index) => {
574-
let currentValue
571+
let currentValue = x.currentValue
575572
if (x.secret) {
576573
currentValue =
577574
secretEnvironmentService.getSecretEnvironmentVariableValue(
578575
selectedEnv.id,
579576
index
580-
)
581-
} else {
582-
currentValue = x.currentValue
577+
) ?? ""
583578
}
584579
results.push({
585580
key: x.key,
586-
currentValue: currentValue ?? "",
581+
currentValue: currentValue,
587582
initialValue: x.initialValue,
588583
secret: x.secret,
589584
sourceEnv: selectedEnv.name,
590585
})
591586
})
592587

593588
globalEnv.variables.map((x, index) => {
594-
let currentValue
589+
let currentValue = x.currentValue
595590
if (x.secret) {
596591
currentValue =
597592
secretEnvironmentService.getSecretEnvironmentVariableValue(
598593
"Global",
599594
index
600-
)
601-
} else {
602-
currentValue = x.currentValue
595+
) ?? ""
603596
}
604597
results.push({
605598
key: x.key,
606-
currentValue: currentValue ?? "",
599+
currentValue: currentValue,
607600
initialValue: x.initialValue,
608601
secret: x.secret,
609602
sourceEnv: "Global",

packages/hoppscotch-common/src/services/inspection/inspectors/environment.inspector.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -221,12 +221,13 @@ export class EnvironmentInspectorService extends Service implements Inspector {
221221
env.key
222222
)
223223

224-
const hasCurrentValue = this.currentEnvs.hasValue(
225-
env.sourceEnv !== "Global"
226-
? currentSelectedEnvironment.id
227-
: "Global",
228-
env.key
229-
)
224+
const hasCurrentValue =
225+
this.currentEnvs.hasValue(
226+
env.sourceEnv !== "Global"
227+
? currentSelectedEnvironment.id
228+
: "Global",
229+
env.key
230+
) || env.currentValue !== ""
230231

231232
if (env.key === formattedExEnv) {
232233
if (env.secret ? !hasSecretEnv : !hasCurrentValue) {

0 commit comments

Comments
 (0)