Skip to content

Commit

Permalink
fix(insight-variables): don't always add all variables (PostHog#27876)
Browse files Browse the repository at this point in the history
  • Loading branch information
EDsCODE authored Jan 24, 2025
1 parent 23b89fa commit 16bc627
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export const variablesLogic = kea<variablesLogicType>([
}),
setEditorQuery: (query: string) => ({ query }),
updateSourceQuery: true,
resetVariables: true,
})),
propsChanged(({ props, actions }, oldProps) => {
if (oldProps.queryInput !== props.queryInput) {
Expand Down Expand Up @@ -103,6 +104,9 @@ export const variablesLogic = kea<variablesLogicType>([

return stateCopy
},
resetVariables: () => {
return []
},
},
],
editorQuery: [
Expand Down Expand Up @@ -191,6 +195,11 @@ export const variablesLogic = kea<variablesLogicType>([
editorQuery: (query: string) => {
const queryVariableMatches = getVariablesFromQuery(query)

if (!queryVariableMatches.length) {
actions.resetVariables()
return
}

queryVariableMatches?.forEach((match) => {
if (match === null) {
return
Expand All @@ -212,10 +221,16 @@ export const variablesLogic = kea<variablesLogicType>([
return
}

const queryVariableMatches = getVariablesFromQuery(query.source.query)

const variables = Object.values(query.source.variables ?? {})

if (variables.length) {
actions.addVariables(variables)
variables.forEach((variable) => {
if (queryVariableMatches.includes(variable.code_name)) {
actions.addVariable(variable)
}
})
}
},
})),
Expand Down

0 comments on commit 16bc627

Please sign in to comment.