From a325f2945d41faf6924ee2d9eb402c42b6468a02 Mon Sep 17 00:00:00 2001 From: Nivedin <53208152+nivedin@users.noreply.github.com> Date: Thu, 29 May 2025 18:36:58 +0530 Subject: [PATCH] fix: fill current value to existing value (#5109) --- packages/hoppscotch-cli/src/utils/request.ts | 2 +- .../components/environments/my/Details.vue | 2 +- .../components/environments/teams/Details.vue | 2 +- .../editor/extensions/HoppEnvironment.ts | 2 +- .../import-export/export/environment.ts | 2 +- .../import-export/import/insomniaEnv.ts | 2 +- .../import-export/import/postmanEnv.ts | 2 +- .../src/helpers/utils/environments.ts | 16 ++++++++-- .../src/newstore/environments.ts | 29 +++++++------------ .../inspectors/environment.inspector.ts | 13 +++++---- .../hoppscotch-data/src/environment/index.ts | 2 +- .../hoppscotch-data/src/environment/v/2.ts | 2 +- 12 files changed, 41 insertions(+), 35 deletions(-) diff --git a/packages/hoppscotch-cli/src/utils/request.ts b/packages/hoppscotch-cli/src/utils/request.ts index 0b78f77c..d0104383 100644 --- a/packages/hoppscotch-cli/src/utils/request.ts +++ b/packages/hoppscotch-cli/src/utils/request.ts @@ -45,7 +45,7 @@ const processVariables = (variable: Environment["variables"][number]) => { currentValue: "currentValue" in variable && variable.currentValue !== "" ? variable.currentValue - : process.env[variable.key] || "", + : process.env[variable.key] || variable.initialValue, }; } return variable; diff --git a/packages/hoppscotch-common/src/components/environments/my/Details.vue b/packages/hoppscotch-common/src/components/environments/my/Details.vue index b3e50bd9..92f4970a 100644 --- a/packages/hoppscotch-common/src/components/environments/my/Details.vue +++ b/packages/hoppscotch-common/src/components/environments/my/Details.vue @@ -380,7 +380,7 @@ watch( ? "Global" : workingEnvID.value, index - ) ?? "", + ) ?? e.currentValue, initialValue: e.initialValue, secret: e.secret, }, diff --git a/packages/hoppscotch-common/src/components/environments/teams/Details.vue b/packages/hoppscotch-common/src/components/environments/teams/Details.vue index c118d38f..2c15c979 100644 --- a/packages/hoppscotch-common/src/components/environments/teams/Details.vue +++ b/packages/hoppscotch-common/src/components/environments/teams/Details.vue @@ -347,7 +347,7 @@ watch( props.editingEnvironment?.id ?? "", index, e.secret - ) ?? "", + ) ?? e.currentValue, initialValue: e.initialValue, secret: e.secret, }, diff --git a/packages/hoppscotch-common/src/helpers/editor/extensions/HoppEnvironment.ts b/packages/hoppscotch-common/src/helpers/editor/extensions/HoppEnvironment.ts index d6c7c46f..1c817f62 100644 --- a/packages/hoppscotch-common/src/helpers/editor/extensions/HoppEnvironment.ts +++ b/packages/hoppscotch-common/src/helpers/editor/extensions/HoppEnvironment.ts @@ -125,7 +125,7 @@ const cursorTooltipField = (aggregateEnvs: AggregateEnvironment[]) => ? currentSelectedEnvironment.id : "Global", tooltipEnv?.key ?? "" - )?.currentValue ?? "") + )?.currentValue ?? tooltipEnv?.currentValue) : tooltipEnv?.currentValue const hasSecretEnv = secretEnvironmentService.hasSecretValue( diff --git a/packages/hoppscotch-common/src/helpers/import-export/export/environment.ts b/packages/hoppscotch-common/src/helpers/import-export/export/environment.ts index 2ea673d8..ffbcd05b 100644 --- a/packages/hoppscotch-common/src/helpers/import-export/export/environment.ts +++ b/packages/hoppscotch-common/src/helpers/import-export/export/environment.ts @@ -47,7 +47,7 @@ export const transformEnvironmentVariables = ({ key, secret, initialValue, - currentValue: "", + currentValue: variable.secret ? "" : (variable.currentValue ?? ""), } }), } diff --git a/packages/hoppscotch-common/src/helpers/import-export/import/insomniaEnv.ts b/packages/hoppscotch-common/src/helpers/import-export/import/insomniaEnv.ts index b9781ea7..2912f07e 100644 --- a/packages/hoppscotch-common/src/helpers/import-export/import/insomniaEnv.ts +++ b/packages/hoppscotch-common/src/helpers/import-export/import/insomniaEnv.ts @@ -76,7 +76,7 @@ export const insomniaEnvImporter = (contents: string[]) => { ([key, value]) => ({ key, initialValue: value, - currentValue: "", + currentValue: value, secret: false, }) ), diff --git a/packages/hoppscotch-common/src/helpers/import-export/import/postmanEnv.ts b/packages/hoppscotch-common/src/helpers/import-export/import/postmanEnv.ts index 5f920395..fa8fca07 100644 --- a/packages/hoppscotch-common/src/helpers/import-export/import/postmanEnv.ts +++ b/packages/hoppscotch-common/src/helpers/import-export/import/postmanEnv.ts @@ -57,7 +57,7 @@ export const postmanEnvImporter = (contents: string[]) => { variables: values.map(({ key, value, type }) => ({ key, initialValue: value, - currentValue: "", + currentValue: value, secret: type === "secret", })), }) diff --git a/packages/hoppscotch-common/src/helpers/utils/environments.ts b/packages/hoppscotch-common/src/helpers/utils/environments.ts index 7f78f64b..2d952fc0 100644 --- a/packages/hoppscotch-common/src/helpers/utils/environments.ts +++ b/packages/hoppscotch-common/src/helpers/utils/environments.ts @@ -38,7 +38,13 @@ const unWrapEnvironments = ( currentValue: secretVar.value, } } - return { ...globalVar, currentValue: currentVar?.currentValue ?? "" } + return { + ...globalVar, + currentValue: + currentVar?.currentValue ?? + globalVar.currentValue ?? + globalVar.initialValue, + } }) const resolvedSelectedWithSecrets = selected.variables.map( @@ -57,7 +63,13 @@ const unWrapEnvironments = ( currentValue: secretVar.value, } } - return { ...selectedVar, currentValue: currentVar?.currentValue ?? "" } + return { + ...selectedVar, + currentValue: + currentVar?.currentValue ?? + selectedVar.currentValue ?? + selectedVar.initialValue, + } } ) diff --git a/packages/hoppscotch-common/src/newstore/environments.ts b/packages/hoppscotch-common/src/newstore/environments.ts index d662443c..80f7d1d6 100644 --- a/packages/hoppscotch-common/src/newstore/environments.ts +++ b/packages/hoppscotch-common/src/newstore/environments.ts @@ -523,17 +523,16 @@ export function getAggregateEnvs() { export function getAggregateEnvsWithSecrets() { const currentEnv = getCurrentEnvironment() + return [ ...currentEnv.variables.map((x, index) => { - let currentValue + let currentValue = x.currentValue if (x.secret) { currentValue = secretEnvironmentService.getSecretEnvironmentVariableValue( currentEnv.id, index - ) - } else { - currentValue = x.currentValue + ) ?? "" } return { @@ -545,15 +544,13 @@ export function getAggregateEnvsWithSecrets() { } }), ...getGlobalVariables().map((x, index) => { - let currentValue + let currentValue = x.currentValue if (x.secret) { currentValue = secretEnvironmentService.getSecretEnvironmentVariableValue( "Global", index - ) - } else { - currentValue = x.currentValue + ) ?? "" } return { key: x.key, @@ -571,19 +568,17 @@ export const aggregateEnvsWithSecrets$: Observable = map(([selectedEnv, globalEnv]) => { const results: AggregateEnvironment[] = [] selectedEnv?.variables.map((x, index) => { - let currentValue + let currentValue = x.currentValue if (x.secret) { currentValue = secretEnvironmentService.getSecretEnvironmentVariableValue( selectedEnv.id, index - ) - } else { - currentValue = x.currentValue + ) ?? "" } results.push({ key: x.key, - currentValue: currentValue ?? "", + currentValue: currentValue, initialValue: x.initialValue, secret: x.secret, sourceEnv: selectedEnv.name, @@ -591,19 +586,17 @@ export const aggregateEnvsWithSecrets$: Observable = }) globalEnv.variables.map((x, index) => { - let currentValue + let currentValue = x.currentValue if (x.secret) { currentValue = secretEnvironmentService.getSecretEnvironmentVariableValue( "Global", index - ) - } else { - currentValue = x.currentValue + ) ?? "" } results.push({ key: x.key, - currentValue: currentValue ?? "", + currentValue: currentValue, initialValue: x.initialValue, secret: x.secret, sourceEnv: "Global", diff --git a/packages/hoppscotch-common/src/services/inspection/inspectors/environment.inspector.ts b/packages/hoppscotch-common/src/services/inspection/inspectors/environment.inspector.ts index a7fbead2..3865104e 100644 --- a/packages/hoppscotch-common/src/services/inspection/inspectors/environment.inspector.ts +++ b/packages/hoppscotch-common/src/services/inspection/inspectors/environment.inspector.ts @@ -221,12 +221,13 @@ export class EnvironmentInspectorService extends Service implements Inspector { env.key ) - const hasCurrentValue = this.currentEnvs.hasValue( - env.sourceEnv !== "Global" - ? currentSelectedEnvironment.id - : "Global", - env.key - ) + const hasCurrentValue = + this.currentEnvs.hasValue( + env.sourceEnv !== "Global" + ? currentSelectedEnvironment.id + : "Global", + env.key + ) || env.currentValue !== "" if (env.key === formattedExEnv) { if (env.secret ? !hasSecretEnv : !hasCurrentValue) { diff --git a/packages/hoppscotch-data/src/environment/index.ts b/packages/hoppscotch-data/src/environment/index.ts index 02feb02b..e2438a29 100644 --- a/packages/hoppscotch-data/src/environment/index.ts +++ b/packages/hoppscotch-data/src/environment/index.ts @@ -204,7 +204,7 @@ export const translateToNewEnvironmentVariables = ( return { key: x.key, initialValue: x.initialValue ?? x.value ?? "", - currentValue: "", + currentValue: x.currentValue ?? x.value ?? "", secret: false, } } diff --git a/packages/hoppscotch-data/src/environment/v/2.ts b/packages/hoppscotch-data/src/environment/v/2.ts index 17ab3aef..7033dc9f 100644 --- a/packages/hoppscotch-data/src/environment/v/2.ts +++ b/packages/hoppscotch-data/src/environment/v/2.ts @@ -32,7 +32,7 @@ export default defineVersion({ key, secret, initialValue: secret ? "" : variable.value, - currentValue: "", + currentValue: secret ? "" : variable.value, } }), }