fix(common): environment variables not detected in request body editors (#5616)
Co-authored-by: nivedin <nivedinp@gmail.com>
This commit is contained in:
parent
420aa7eda0
commit
e51676eea0
3 changed files with 62 additions and 24 deletions
|
|
@ -1880,6 +1880,9 @@ const onRemoveRequest = async () => {
|
|||
|
||||
// since the request is deleted, we need to remove the saved responses as well
|
||||
possibleTab.value.document.request.responses = {}
|
||||
|
||||
// remove inherited properties
|
||||
possibleTab.value.document.inheritedProperties = undefined
|
||||
}
|
||||
|
||||
const requestToRemove = navigateToFolderWithIndexPath(
|
||||
|
|
@ -1941,6 +1944,9 @@ const onRemoveRequest = async () => {
|
|||
|
||||
// since the request is deleted, we need to remove the saved responses as well
|
||||
possibleTab.value.document.request.responses = {}
|
||||
|
||||
// remove inherited properties
|
||||
possibleTab.value.document.inheritedProperties = undefined
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -231,6 +231,9 @@ function resetSaveContextForAffectedRequests(folderPath: string) {
|
|||
if (tab.value.document.type === "request") {
|
||||
// since the request is deleted, we need to remove the saved responses as well
|
||||
tab.value.document.request.responses = {}
|
||||
|
||||
// remove inherited properties
|
||||
tab.value.document.inheritedProperties = undefined
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -261,6 +264,9 @@ export async function resetTeamRequestsContext() {
|
|||
if (tab.value.document.type === "request") {
|
||||
// since the request is deleted, we need to remove the saved responses as well
|
||||
tab.value.document.request.responses = {}
|
||||
|
||||
// remove inherited properties
|
||||
tab.value.document.inheritedProperties = undefined
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ import {
|
|||
} from "@codemirror/view"
|
||||
import { StreamSubscriberFunc } from "@composables/stream"
|
||||
import {
|
||||
HoppRESTRequestVariables,
|
||||
parseTemplateStringE,
|
||||
HoppRESTRequestVariables,
|
||||
} from "@hoppscotch/data"
|
||||
import * as E from "fp-ts/Either"
|
||||
import { Ref, watch } from "vue"
|
||||
|
|
@ -124,9 +124,12 @@ const cursorTooltipField = (aggregateEnvs: AggregateEnvironment[]) =>
|
|||
const envName = tooltipEnv?.sourceEnv ?? "Choose an Environment"
|
||||
|
||||
let envInitialValue = tooltipEnv?.initialValue
|
||||
// If the environment is not a request variable, get the current value from the current environment service
|
||||
|
||||
// If the environment is not a request variable or collection variable, get the current value from the current environment service
|
||||
// For collection variables and request variables, use the value directly from tooltipEnv
|
||||
let envCurrentValue =
|
||||
tooltipEnv?.sourceEnv !== "RequestVariable"
|
||||
tooltipEnv?.sourceEnv !== "RequestVariable" &&
|
||||
tooltipEnv?.sourceEnv !== "CollectionVariable"
|
||||
? currentEnvironmentValueService.getEnvironmentByKey(
|
||||
tooltipEnv?.sourceEnv !== "Global"
|
||||
? currentSelectedEnvironment.id
|
||||
|
|
@ -398,25 +401,36 @@ export class HoppEnvironmentPlugin {
|
|||
subscribeToStream: StreamSubscriberFunc,
|
||||
private editorView: Ref<EditorView | undefined>
|
||||
) {
|
||||
const aggregateEnvs = getAggregateEnvsWithCurrentValue()
|
||||
const currentTab = restTabs.currentActiveTab.value
|
||||
const currentTabRequest =
|
||||
currentTab.document.type === "example-response"
|
||||
? currentTab.document.response.originalRequest
|
||||
: currentTab.document.request
|
||||
const currentTabInheritedProperty = currentTab.document.inheritedProperties
|
||||
|
||||
if (!currentTabRequest || !currentTabInheritedProperty) return
|
||||
|
||||
// Watch the current active tab to update the variables accordingly
|
||||
watch(
|
||||
[currentTabRequest, currentTabInheritedProperty],
|
||||
([request, document]) => {
|
||||
() => restTabs.currentActiveTab.value,
|
||||
(currentTab) => {
|
||||
const request =
|
||||
currentTab.document.type === "example-response"
|
||||
? currentTab.document.response.originalRequest
|
||||
: currentTab.document.request
|
||||
|
||||
const inheritedProperties = currentTab.document.inheritedProperties
|
||||
|
||||
// Extract collection variables safely, handling undefined or non-inherited-property types
|
||||
const collectionVariables =
|
||||
inheritedProperties && "variables" in inheritedProperties
|
||||
? inheritedProperties.variables
|
||||
: []
|
||||
|
||||
// Get request variables if available, otherwise use empty array
|
||||
const requestVariables =
|
||||
request && "requestVariables" in request
|
||||
? request.requestVariables
|
||||
: []
|
||||
|
||||
const requestAndCollVars = getRequestAndCollectionVariables(
|
||||
request.requestVariables,
|
||||
document.variables
|
||||
requestVariables,
|
||||
collectionVariables
|
||||
)
|
||||
|
||||
this.envs = [...requestAndCollVars, ...aggregateEnvs]
|
||||
const currentAggregateEnvs = getAggregateEnvsWithCurrentValue()
|
||||
this.envs = [...requestAndCollVars, ...currentAggregateEnvs]
|
||||
|
||||
this.editorView.value?.dispatch({
|
||||
effects: this.compartment.reconfigure([
|
||||
|
|
@ -428,13 +442,25 @@ export class HoppEnvironmentPlugin {
|
|||
{ immediate: true, deep: true }
|
||||
)
|
||||
|
||||
const requestAndCollVars = getRequestAndCollectionVariables(
|
||||
currentTabRequest.requestVariables,
|
||||
currentTabInheritedProperty.variables
|
||||
)
|
||||
|
||||
subscribeToStream(aggregateEnvsWithCurrentValue$, (envs) => {
|
||||
this.envs = [...requestAndCollVars, ...envs]
|
||||
// Recompute request and collection variables from current tab to avoid stale closure values
|
||||
const tab = restTabs.currentActiveTab.value
|
||||
const request =
|
||||
tab.document.type === "example-response"
|
||||
? tab.document.response.originalRequest
|
||||
: tab.document.request
|
||||
const inheritedProperties = tab.document.inheritedProperties
|
||||
|
||||
// Get request variables if available, otherwise use empty array
|
||||
const requestVariables =
|
||||
request && "requestVariables" in request ? request.requestVariables : []
|
||||
|
||||
const freshRequestAndCollVars = getRequestAndCollectionVariables(
|
||||
requestVariables,
|
||||
inheritedProperties?.variables ?? []
|
||||
)
|
||||
|
||||
this.envs = [...freshRequestAndCollVars, ...envs]
|
||||
|
||||
this.editorView.value?.dispatch({
|
||||
effects: this.compartment.reconfigure([
|
||||
|
|
|
|||
Loading…
Reference in a new issue