@@ -33,6 +33,7 @@ import {getOrg} from 'src/organizations/selectors'
3333import { getLabels , getStatus } from 'src/resources/selectors'
3434import { currentContext } from 'src/shared/selectors/currentContext'
3535import { event } from 'src/cloud/utils/reporting'
36+ import { isFlagEnabled } from 'src/shared/utils/featureFlag'
3637
3738// Constants
3839import * as copy from 'src/shared/copy/notifications'
@@ -56,8 +57,12 @@ import {
5657 EditorAction ,
5758} from 'src/variables/actions/creators'
5859import { RouterAction } from 'connected-react-router'
59- import { filterUnusedVars } from 'src/shared/utils/filterUnusedVars'
60+ import {
61+ filterUnusedVars ,
62+ filterUnusedVarsBasedOnQuery ,
63+ } from 'src/shared/utils/filterUnusedVars'
6064import { getActiveTimeMachine } from 'src/timeMachine/selectors'
65+ import { getActiveQuery } from 'src/timeMachine/selectors'
6166
6267type Action = VariableAction | EditorAction | NotifyAction
6368
@@ -156,7 +161,17 @@ export const hydrateVariables = (
156161 const org = getOrg ( state )
157162 const vars = getVariablesFromState ( state )
158163 const views = getActiveView ( state )
159- const usedVars = views . length ? filterUnusedVars ( vars , views ) : vars
164+ const activeQuery = getActiveQuery ( state )
165+
166+ let usedVars = vars
167+ if ( views . length ) {
168+ usedVars = filterUnusedVars ( vars , views )
169+ } else if (
170+ isFlagEnabled ( 'hydrateRelevantDashboardVariables' ) &&
171+ activeQuery . text
172+ ) {
173+ usedVars = filterUnusedVarsBasedOnQuery ( vars , [ activeQuery . text ] )
174+ }
160175
161176 const hydration = hydrateVars ( usedVars , getAllVariablesFromState ( state ) , {
162177 orgID : org . id ,
0 commit comments