@grafana/scenes 6.47.1--canary.1303.19372012709.0 → 6.47.1--canary.1303.19493819306.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,6 +2,8 @@ import { isEqual } from 'lodash';
2
2
  import { sceneGraph } from '../core/sceneGraph/index.js';
3
3
  import { SceneQueryRunner } from '../querying/SceneQueryRunner.js';
4
4
  import { css } from '@emotion/css';
5
+ import { getDataSource } from '../utils/getDataSource.js';
6
+ import { wrapInSafeSerializableSceneObject } from '../utils/wrapInSafeSerializableSceneObject.js';
5
7
 
6
8
  function isVariableValueEqual(a, b) {
7
9
  if (a === b) {
@@ -185,6 +187,50 @@ function getNonApplicablePillStyles(theme) {
185
187
  })
186
188
  };
187
189
  }
190
+ function verifyDrilldownApplicability(sourceObject, queriesDataSource, drilldownDatasource, isApplicabilityEnabled) {
191
+ const datasourceUid = sceneGraph.interpolate(sourceObject, queriesDataSource == null ? void 0 : queriesDataSource.uid);
192
+ return Boolean(
193
+ isApplicabilityEnabled && datasourceUid === sceneGraph.interpolate(sourceObject, drilldownDatasource == null ? void 0 : drilldownDatasource.uid)
194
+ );
195
+ }
196
+ async function getDrilldownApplicability(queryRunner, filtersVar, groupByVar) {
197
+ var _a, _b, _c, _d, _e, _f;
198
+ if (!filtersVar && !groupByVar) {
199
+ return;
200
+ }
201
+ const datasource = queryRunner.state.datasource;
202
+ const queries = (_b = (_a = queryRunner.state.data) == null ? void 0 : _a.request) == null ? void 0 : _b.targets;
203
+ const ds = await getDataSource(datasource, {
204
+ __sceneObject: wrapInSafeSerializableSceneObject(queryRunner)
205
+ });
206
+ if (!ds.getDrilldownsApplicability) {
207
+ return;
208
+ }
209
+ const dsUid = sceneGraph.interpolate(queryRunner, datasource == null ? void 0 : datasource.uid);
210
+ const timeRange = sceneGraph.getTimeRange(queryRunner).state.value;
211
+ const groupByKeys = [];
212
+ const filters = [];
213
+ const hasGroupByApplicability = groupByVar && dsUid === sceneGraph.interpolate(groupByVar, (_c = groupByVar == null ? void 0 : groupByVar.state.datasource) == null ? void 0 : _c.uid);
214
+ const hasFiltersApplicability = filtersVar && dsUid === sceneGraph.interpolate(filtersVar, (_e = (_d = filtersVar.state) == null ? void 0 : _d.datasource) == null ? void 0 : _e.uid);
215
+ if (!hasGroupByApplicability && !hasFiltersApplicability) {
216
+ return;
217
+ }
218
+ if (hasGroupByApplicability) {
219
+ groupByKeys.push(
220
+ ...Array.isArray(groupByVar.state.value) ? groupByVar.state.value.map((v) => String(v)) : groupByVar.state.value ? [String(groupByVar.state.value)] : []
221
+ );
222
+ }
223
+ if (hasFiltersApplicability) {
224
+ filters.push(...filtersVar.state.filters, ...(_f = filtersVar.state.originFilters) != null ? _f : []);
225
+ }
226
+ return await ds.getDrilldownsApplicability({
227
+ groupByKeys,
228
+ filters,
229
+ queries,
230
+ timeRange,
231
+ scopes: sceneGraph.getScopes(queryRunner)
232
+ });
233
+ }
188
234
 
189
- export { dataFromResponse, escapeLabelValueInExactSelector, escapeLabelValueInRegexSelector, escapeOriginFilterUrlDelimiters, escapeURLDelimiters, escapeUrlCommaDelimiters, escapeUrlHashDelimiters, escapeUrlPipeDelimiters, getNonApplicablePillStyles, getQueriesForVariables, handleOptionGroups, isVariableValueEqual, renderPrometheusLabelFilters, responseHasError, safeStringifyValue, toUrlCommaDelimitedString, unescapeUrlDelimiters };
235
+ export { dataFromResponse, escapeLabelValueInExactSelector, escapeLabelValueInRegexSelector, escapeOriginFilterUrlDelimiters, escapeURLDelimiters, escapeUrlCommaDelimiters, escapeUrlHashDelimiters, escapeUrlPipeDelimiters, getDrilldownApplicability, getNonApplicablePillStyles, getQueriesForVariables, handleOptionGroups, isVariableValueEqual, renderPrometheusLabelFilters, responseHasError, safeStringifyValue, toUrlCommaDelimitedString, unescapeUrlDelimiters, verifyDrilldownApplicability };
190
236
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sources":["../../../src/variables/utils.ts"],"sourcesContent":["import { isEqual } from 'lodash';\nimport { VariableValue } from './types';\nimport {\n AdHocVariableFilter,\n DataQueryError,\n GetTagResponse,\n GrafanaTheme2,\n MetricFindValue,\n SelectableValue,\n} from '@grafana/data';\nimport { sceneGraph } from '../core/sceneGraph';\nimport { SceneDataQuery, SceneObject, SceneObjectState } from '../core/types';\nimport { SceneQueryRunner } from '../querying/SceneQueryRunner';\nimport { DataSourceRef } from '@grafana/schema';\nimport { css } from '@emotion/css';\n\nexport function isVariableValueEqual(a: VariableValue | null | undefined, b: VariableValue | null | undefined) {\n if (a === b) {\n return true;\n }\n\n return isEqual(a, b);\n}\n\nexport function safeStringifyValue(value: unknown) {\n // Avoid circular references ignoring those references\n const getCircularReplacer = () => {\n const seen = new WeakSet();\n return (_: string, value: object | null) => {\n if (typeof value === 'object' && value !== null) {\n if (seen.has(value)) {\n return;\n }\n seen.add(value);\n }\n return value;\n };\n };\n\n try {\n return JSON.stringify(value, getCircularReplacer());\n } catch (error) {\n console.error(error);\n }\n\n return '';\n}\n\nexport function renderPrometheusLabelFilters(filters: AdHocVariableFilter[]) {\n return filters.map((filter) => renderFilter(filter)).join(',');\n}\n\nfunction renderFilter(filter: AdHocVariableFilter) {\n let value = '';\n let operator = filter.operator;\n\n // map \"one of\" operator to regex\n if (operator === '=|') {\n operator = '=~';\n // TODO remove when we're on the latest version of @grafana/data\n // @ts-expect-error\n value = filter.values?.map(escapeLabelValueInRegexSelector).join('|');\n } else if (operator === '!=|') {\n operator = '!~';\n // TODO remove when we're on the latest version of @grafana/data\n // @ts-expect-error\n value = filter.values?.map(escapeLabelValueInRegexSelector).join('|');\n } else if (operator === '=~' || operator === '!~') {\n value = escapeLabelValueInRegexSelector(filter.value);\n } else {\n value = escapeLabelValueInExactSelector(filter.value);\n }\n\n return `${filter.key}${operator}\"${value}\"`;\n}\n\n// based on the openmetrics-documentation, the 3 symbols we have to handle are:\n// - \\n ... the newline character\n// - \\ ... the backslash character\n// - \" ... the double-quote character\nexport function escapeLabelValueInExactSelector(labelValue: string): string {\n return labelValue.replace(/\\\\/g, '\\\\\\\\').replace(/\\n/g, '\\\\n').replace(/\"/g, '\\\\\"');\n}\n\nexport function escapeLabelValueInRegexSelector(labelValue: string): string {\n return escapeLabelValueInExactSelector(escapeLokiRegexp(labelValue));\n}\n\nexport function isRegexSelector(selector?: string) {\n if (selector && (selector.includes('=~') || selector.includes('!~'))) {\n return true;\n }\n return false;\n}\n\n// Loki regular-expressions use the RE2 syntax (https://github.com/google/re2/wiki/Syntax),\n// so every character that matches something in that list has to be escaped.\n// the list of meta characters is: *+?()|\\.[]{}^$\n// we make a javascript regular expression that matches those characters:\nconst RE2_METACHARACTERS = /[*+?()|\\\\.\\[\\]{}^$]/g;\nfunction escapeLokiRegexp(value: string): string {\n return value.replace(RE2_METACHARACTERS, '\\\\$&');\n}\n\n/**\n * Get all queries in the scene that have the same datasource as provided source object\n */\nexport function getQueriesForVariables(\n sourceObject: SceneObject<SceneObjectState & { datasource: DataSourceRef | null }>\n) {\n const runners = sceneGraph.findAllObjects(\n sourceObject.getRoot(),\n (o) => o instanceof SceneQueryRunner\n ) as SceneQueryRunner[];\n\n const interpolatedDsUuid = sceneGraph.interpolate(sourceObject, sourceObject.state.datasource?.uid);\n\n const applicableRunners = filterOutInactiveRunnerDuplicates(runners).filter((r) => {\n const interpolatedQueryDsUuid = sceneGraph.interpolate(sourceObject, r.state.datasource?.uid);\n\n return interpolatedQueryDsUuid === interpolatedDsUuid;\n });\n\n if (applicableRunners.length === 0) {\n return [];\n }\n\n const result: SceneDataQuery[] = [];\n applicableRunners.forEach((r) => {\n result.push(\n ...r.state.queries.filter((q) => {\n if (!q.datasource || !q.datasource.uid) {\n return true;\n }\n\n const interpolatedQueryDsUuid = sceneGraph.interpolate(sourceObject, q.datasource.uid);\n return interpolatedQueryDsUuid === interpolatedDsUuid;\n })\n );\n });\n\n return result;\n}\n\n// Filters out inactive runner duplicates, keeping only the ones that are currently active.\n// This is needed for scnearios whan a query runner is cloned and the original is not removed but de-activated.\n// Can happen i.e. when editing a panel in Grafana Core dashboards.\nfunction filterOutInactiveRunnerDuplicates(runners: SceneQueryRunner[]) {\n // Group items by key\n const groupedItems: { [key: string]: SceneQueryRunner[] } = {};\n\n for (const item of runners) {\n if (item.state.key) {\n if (!(item.state.key in groupedItems)) {\n groupedItems[item.state.key] = [];\n }\n groupedItems[item.state.key].push(item);\n }\n }\n\n // Filter out inactive items and concatenate active items\n return Object.values(groupedItems).flatMap((group) => {\n const activeItems = group.filter((item) => item.isActive);\n // Keep inactive items if there's only one item with the key\n if (activeItems.length === 0 && group.length === 1) {\n return group;\n }\n return activeItems;\n });\n}\n\nexport function escapeUrlPipeDelimiters(value: string | undefined): string {\n if (value === null || value === undefined) {\n return '';\n }\n\n // Replace the pipe due to using it as a filter separator\n return (value = /\\|/g[Symbol.replace](value, '__gfp__'));\n}\n\nexport function escapeUrlCommaDelimiters(value: string | undefined): string {\n if (value === null || value === undefined) {\n return '';\n }\n\n // Replace the comma due to using it as a value/label separator\n return /,/g[Symbol.replace](value, '__gfc__');\n}\n\nexport function escapeUrlHashDelimiters(value: string | undefined): string {\n if (value === null || value === undefined) {\n return '';\n }\n\n // Replace the hash due to using it as a value/label separator\n return /#/g[Symbol.replace](value, '__gfh__');\n}\n\nexport function escapeOriginFilterUrlDelimiters(value: string | undefined): string {\n return escapeUrlHashDelimiters(escapeUrlPipeDelimiters(value));\n}\n\nexport function escapeURLDelimiters(value: string | undefined): string {\n return escapeUrlCommaDelimiters(escapeUrlPipeDelimiters(value));\n}\n\nexport function unescapeUrlDelimiters(value: string | undefined): string {\n if (value === null || value === undefined) {\n return '';\n }\n\n value = /__gfp__/g[Symbol.replace](value, '|');\n value = /__gfc__/g[Symbol.replace](value, ',');\n value = /__gfh__/g[Symbol.replace](value, '#');\n\n return value;\n}\n\nexport function toUrlCommaDelimitedString(key: string, label?: string): string {\n // Omit for identical key/label or when label is not set at all\n if (!label || key === label) {\n return escapeUrlCommaDelimiters(key);\n }\n\n return [key, label].map(escapeUrlCommaDelimiters).join(',');\n}\n\nexport function dataFromResponse(response: GetTagResponse | MetricFindValue[]) {\n return Array.isArray(response) ? response : response.data;\n}\n\nexport function responseHasError(\n response: GetTagResponse | MetricFindValue[]\n): response is GetTagResponse & { error: DataQueryError } {\n return !Array.isArray(response) && Boolean(response.error);\n}\n\n// Collect a flat list of SelectableValues with a `group` property into a hierarchical list with groups\nexport function handleOptionGroups(values: SelectableValue[]): Array<SelectableValue<string>> {\n const result: Array<SelectableValue<string>> = [];\n const groupedResults = new Map<string, Array<SelectableValue<string>>>();\n\n for (const value of values) {\n const groupLabel = value.group;\n if (groupLabel) {\n let group = groupedResults.get(groupLabel);\n\n if (!group) {\n group = [];\n groupedResults.set(groupLabel, group);\n result.push({ label: groupLabel, options: group });\n }\n\n group.push(value);\n } else {\n result.push(value);\n }\n }\n\n return result;\n}\n\nexport function getNonApplicablePillStyles(theme: GrafanaTheme2) {\n return {\n disabledPill: css({\n background: theme.colors.action.selected,\n color: theme.colors.text.disabled,\n border: 0,\n '&:hover': {\n background: theme.colors.action.selected,\n },\n }),\n strikethrough: css({\n textDecoration: 'line-through',\n }),\n };\n}\n"],"names":["value","_a"],"mappings":";;;;;AAgBgB,SAAA,oBAAA,CAAqB,GAAqC,CAAqC,EAAA;AAC7G,EAAA,IAAI,MAAM,CAAG,EAAA;AACX,IAAO,OAAA,IAAA;AAAA;AAGT,EAAO,OAAA,OAAA,CAAQ,GAAG,CAAC,CAAA;AACrB;AAEO,SAAS,mBAAmB,KAAgB,EAAA;AAEjD,EAAA,MAAM,sBAAsB,MAAM;AAChC,IAAM,MAAA,IAAA,uBAAW,OAAQ,EAAA;AACzB,IAAO,OAAA,CAAC,GAAWA,MAAyB,KAAA;AAC1C,MAAA,IAAI,OAAOA,MAAAA,KAAU,QAAYA,IAAAA,MAAAA,KAAU,IAAM,EAAA;AAC/C,QAAI,IAAA,IAAA,CAAK,GAAIA,CAAAA,MAAK,CAA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KAAK,CAAA;AAAA,KACX,MAAA;AACL,MAAA,MAAA,CAAO,KAAK,KAAK,CAAA;AAAA;AACnB;AAGF,EAAO,OAAA,MAAA;AACT;AAEO,SAAS,2BAA2B,KAAsB,EAAA;AAC/D,EAAO,OAAA;AAAA,IACL,cAAc,GAAI,CAAA;AAAA,MAChB,UAAA,EAAY,KAAM,CAAA,MAAA,CAAO,MAAO,CAAA,QAAA;AAAA,MAChC,KAAA,EAAO,KAAM,CAAA,MAAA,CAAO,IAAK,CAAA,QAAA;AAAA,MACzB,MAAQ,EAAA,CAAA;AAAA,MACR,SAAW,EAAA;AAAA,QACT,UAAA,EAAY,KAAM,CAAA,MAAA,CAAO,MAAO,CAAA;AAAA;AAClC,KACD,CAAA;AAAA,IACD,eAAe,GAAI,CAAA;AAAA,MACjB,cAAgB,EAAA;AAAA,KACjB;AAAA,GACH;AACF;;;;"}
1
+ {"version":3,"file":"utils.js","sources":["../../../src/variables/utils.ts"],"sourcesContent":["import { isEqual } from 'lodash';\nimport { VariableValue } from './types';\nimport {\n AdHocVariableFilter,\n DataQueryError,\n GetTagResponse,\n GrafanaTheme2,\n MetricFindValue,\n // @ts-expect-error (temporary till we update grafana/data)\n DrilldownsApplicability,\n SelectableValue,\n} from '@grafana/data';\nimport { sceneGraph } from '../core/sceneGraph';\nimport { SceneDataQuery, SceneObject, SceneObjectState } from '../core/types';\nimport { SceneQueryRunner } from '../querying/SceneQueryRunner';\nimport { DataSourceRef } from '@grafana/schema';\nimport { css } from '@emotion/css';\nimport { getDataSource } from '../utils/getDataSource';\nimport { wrapInSafeSerializableSceneObject } from '../utils/wrapInSafeSerializableSceneObject';\nimport { AdHocFiltersVariable } from './adhoc/AdHocFiltersVariable';\nimport { GroupByVariable } from './groupby/GroupByVariable';\n\nexport function isVariableValueEqual(a: VariableValue | null | undefined, b: VariableValue | null | undefined) {\n if (a === b) {\n return true;\n }\n\n return isEqual(a, b);\n}\n\nexport function safeStringifyValue(value: unknown) {\n // Avoid circular references ignoring those references\n const getCircularReplacer = () => {\n const seen = new WeakSet();\n return (_: string, value: object | null) => {\n if (typeof value === 'object' && value !== null) {\n if (seen.has(value)) {\n return;\n }\n seen.add(value);\n }\n return value;\n };\n };\n\n try {\n return JSON.stringify(value, getCircularReplacer());\n } catch (error) {\n console.error(error);\n }\n\n return '';\n}\n\nexport function renderPrometheusLabelFilters(filters: AdHocVariableFilter[]) {\n return filters.map((filter) => renderFilter(filter)).join(',');\n}\n\nfunction renderFilter(filter: AdHocVariableFilter) {\n let value = '';\n let operator = filter.operator;\n\n // map \"one of\" operator to regex\n if (operator === '=|') {\n operator = '=~';\n // TODO remove when we're on the latest version of @grafana/data\n // @ts-expect-error\n value = filter.values?.map(escapeLabelValueInRegexSelector).join('|');\n } else if (operator === '!=|') {\n operator = '!~';\n // TODO remove when we're on the latest version of @grafana/data\n // @ts-expect-error\n value = filter.values?.map(escapeLabelValueInRegexSelector).join('|');\n } else if (operator === '=~' || operator === '!~') {\n value = escapeLabelValueInRegexSelector(filter.value);\n } else {\n value = escapeLabelValueInExactSelector(filter.value);\n }\n\n return `${filter.key}${operator}\"${value}\"`;\n}\n\n// based on the openmetrics-documentation, the 3 symbols we have to handle are:\n// - \\n ... the newline character\n// - \\ ... the backslash character\n// - \" ... the double-quote character\nexport function escapeLabelValueInExactSelector(labelValue: string): string {\n return labelValue.replace(/\\\\/g, '\\\\\\\\').replace(/\\n/g, '\\\\n').replace(/\"/g, '\\\\\"');\n}\n\nexport function escapeLabelValueInRegexSelector(labelValue: string): string {\n return escapeLabelValueInExactSelector(escapeLokiRegexp(labelValue));\n}\n\nexport function isRegexSelector(selector?: string) {\n if (selector && (selector.includes('=~') || selector.includes('!~'))) {\n return true;\n }\n return false;\n}\n\n// Loki regular-expressions use the RE2 syntax (https://github.com/google/re2/wiki/Syntax),\n// so every character that matches something in that list has to be escaped.\n// the list of meta characters is: *+?()|\\.[]{}^$\n// we make a javascript regular expression that matches those characters:\nconst RE2_METACHARACTERS = /[*+?()|\\\\.\\[\\]{}^$]/g;\nfunction escapeLokiRegexp(value: string): string {\n return value.replace(RE2_METACHARACTERS, '\\\\$&');\n}\n\n/**\n * Get all queries in the scene that have the same datasource as provided source object\n */\nexport function getQueriesForVariables(\n sourceObject: SceneObject<SceneObjectState & { datasource: DataSourceRef | null }>\n) {\n const runners = sceneGraph.findAllObjects(\n sourceObject.getRoot(),\n (o) => o instanceof SceneQueryRunner\n ) as SceneQueryRunner[];\n\n const interpolatedDsUuid = sceneGraph.interpolate(sourceObject, sourceObject.state.datasource?.uid);\n\n const applicableRunners = filterOutInactiveRunnerDuplicates(runners).filter((r) => {\n const interpolatedQueryDsUuid = sceneGraph.interpolate(sourceObject, r.state.datasource?.uid);\n\n return interpolatedQueryDsUuid === interpolatedDsUuid;\n });\n\n if (applicableRunners.length === 0) {\n return [];\n }\n\n const result: SceneDataQuery[] = [];\n applicableRunners.forEach((r) => {\n result.push(\n ...r.state.queries.filter((q) => {\n if (!q.datasource || !q.datasource.uid) {\n return true;\n }\n\n const interpolatedQueryDsUuid = sceneGraph.interpolate(sourceObject, q.datasource.uid);\n return interpolatedQueryDsUuid === interpolatedDsUuid;\n })\n );\n });\n\n return result;\n}\n\n// Filters out inactive runner duplicates, keeping only the ones that are currently active.\n// This is needed for scnearios whan a query runner is cloned and the original is not removed but de-activated.\n// Can happen i.e. when editing a panel in Grafana Core dashboards.\nfunction filterOutInactiveRunnerDuplicates(runners: SceneQueryRunner[]) {\n // Group items by key\n const groupedItems: { [key: string]: SceneQueryRunner[] } = {};\n\n for (const item of runners) {\n if (item.state.key) {\n if (!(item.state.key in groupedItems)) {\n groupedItems[item.state.key] = [];\n }\n groupedItems[item.state.key].push(item);\n }\n }\n\n // Filter out inactive items and concatenate active items\n return Object.values(groupedItems).flatMap((group) => {\n const activeItems = group.filter((item) => item.isActive);\n // Keep inactive items if there's only one item with the key\n if (activeItems.length === 0 && group.length === 1) {\n return group;\n }\n return activeItems;\n });\n}\n\nexport function escapeUrlPipeDelimiters(value: string | undefined): string {\n if (value === null || value === undefined) {\n return '';\n }\n\n // Replace the pipe due to using it as a filter separator\n return (value = /\\|/g[Symbol.replace](value, '__gfp__'));\n}\n\nexport function escapeUrlCommaDelimiters(value: string | undefined): string {\n if (value === null || value === undefined) {\n return '';\n }\n\n // Replace the comma due to using it as a value/label separator\n return /,/g[Symbol.replace](value, '__gfc__');\n}\n\nexport function escapeUrlHashDelimiters(value: string | undefined): string {\n if (value === null || value === undefined) {\n return '';\n }\n\n // Replace the hash due to using it as a value/label separator\n return /#/g[Symbol.replace](value, '__gfh__');\n}\n\nexport function escapeOriginFilterUrlDelimiters(value: string | undefined): string {\n return escapeUrlHashDelimiters(escapeUrlPipeDelimiters(value));\n}\n\nexport function escapeURLDelimiters(value: string | undefined): string {\n return escapeUrlCommaDelimiters(escapeUrlPipeDelimiters(value));\n}\n\nexport function unescapeUrlDelimiters(value: string | undefined): string {\n if (value === null || value === undefined) {\n return '';\n }\n\n value = /__gfp__/g[Symbol.replace](value, '|');\n value = /__gfc__/g[Symbol.replace](value, ',');\n value = /__gfh__/g[Symbol.replace](value, '#');\n\n return value;\n}\n\nexport function toUrlCommaDelimitedString(key: string, label?: string): string {\n // Omit for identical key/label or when label is not set at all\n if (!label || key === label) {\n return escapeUrlCommaDelimiters(key);\n }\n\n return [key, label].map(escapeUrlCommaDelimiters).join(',');\n}\n\nexport function dataFromResponse(response: GetTagResponse | MetricFindValue[]) {\n return Array.isArray(response) ? response : response.data;\n}\n\nexport function responseHasError(\n response: GetTagResponse | MetricFindValue[]\n): response is GetTagResponse & { error: DataQueryError } {\n return !Array.isArray(response) && Boolean(response.error);\n}\n\n// Collect a flat list of SelectableValues with a `group` property into a hierarchical list with groups\nexport function handleOptionGroups(values: SelectableValue[]): Array<SelectableValue<string>> {\n const result: Array<SelectableValue<string>> = [];\n const groupedResults = new Map<string, Array<SelectableValue<string>>>();\n\n for (const value of values) {\n const groupLabel = value.group;\n if (groupLabel) {\n let group = groupedResults.get(groupLabel);\n\n if (!group) {\n group = [];\n groupedResults.set(groupLabel, group);\n result.push({ label: groupLabel, options: group });\n }\n\n group.push(value);\n } else {\n result.push(value);\n }\n }\n\n return result;\n}\n\nexport function getNonApplicablePillStyles(theme: GrafanaTheme2) {\n return {\n disabledPill: css({\n background: theme.colors.action.selected,\n color: theme.colors.text.disabled,\n border: 0,\n '&:hover': {\n background: theme.colors.action.selected,\n },\n }),\n strikethrough: css({\n textDecoration: 'line-through',\n }),\n };\n}\n\nexport function verifyDrilldownApplicability(\n sourceObject: SceneObject,\n queriesDataSource: DataSourceRef | undefined,\n drilldownDatasource: DataSourceRef | null,\n isApplicabilityEnabled?: boolean\n): boolean {\n const datasourceUid = sceneGraph.interpolate(sourceObject, queriesDataSource?.uid);\n\n return Boolean(\n isApplicabilityEnabled && datasourceUid === sceneGraph.interpolate(sourceObject, drilldownDatasource?.uid)\n );\n}\n\nexport async function getDrilldownApplicability(\n queryRunner: SceneQueryRunner,\n filtersVar?: AdHocFiltersVariable,\n groupByVar?: GroupByVariable\n): Promise<DrilldownsApplicability[] | undefined> {\n //if no drilldown vars return\n if (!filtersVar && !groupByVar) {\n return;\n }\n\n const datasource = queryRunner.state.datasource;\n const queries = queryRunner.state.data?.request?.targets;\n\n const ds = await getDataSource(datasource, {\n __sceneObject: wrapInSafeSerializableSceneObject(queryRunner),\n });\n\n // return if method not implemented\n // @ts-expect-error (temporary till we update grafana/data)\n if (!ds.getDrilldownsApplicability) {\n return;\n }\n\n const dsUid = sceneGraph.interpolate(queryRunner, datasource?.uid);\n const timeRange = sceneGraph.getTimeRange(queryRunner).state.value;\n const groupByKeys = [];\n const filters = [];\n\n const hasGroupByApplicability =\n groupByVar && dsUid === sceneGraph.interpolate(groupByVar, groupByVar?.state.datasource?.uid);\n const hasFiltersApplicability =\n filtersVar && dsUid === sceneGraph.interpolate(filtersVar, filtersVar.state?.datasource?.uid);\n\n // if neither vars use the ds from the queries, return\n if (!hasGroupByApplicability && !hasFiltersApplicability) {\n return;\n }\n\n if (hasGroupByApplicability) {\n groupByKeys.push(\n ...(Array.isArray(groupByVar.state.value)\n ? groupByVar.state.value.map((v) => String(v))\n : groupByVar.state.value\n ? [String(groupByVar.state.value)]\n : [])\n );\n }\n\n if (hasFiltersApplicability) {\n filters.push(...filtersVar.state.filters, ...(filtersVar.state.originFilters ?? []));\n }\n\n // @ts-expect-error (temporary till we update grafana/data)\n return await ds.getDrilldownsApplicability({\n groupByKeys,\n filters,\n queries,\n timeRange,\n scopes: sceneGraph.getScopes(queryRunner),\n });\n}\n"],"names":["value","_a"],"mappings":";;;;;;;AAsBgB,SAAA,oBAAA,CAAqB,GAAqC,CAAqC,EAAA;AAC7G,EAAA,IAAI,MAAM,CAAG,EAAA;AACX,IAAO,OAAA,IAAA;AAAA;AAGT,EAAO,OAAA,OAAA,CAAQ,GAAG,CAAC,CAAA;AACrB;AAEO,SAAS,mBAAmB,KAAgB,EAAA;AAEjD,EAAA,MAAM,sBAAsB,MAAM;AAChC,IAAM,MAAA,IAAA,uBAAW,OAAQ,EAAA;AACzB,IAAO,OAAA,CAAC,GAAWA,MAAyB,KAAA;AAC1C,MAAA,IAAI,OAAOA,MAAAA,KAAU,QAAYA,IAAAA,MAAAA,KAAU,IAAM,EAAA;AAC/C,QAAI,IAAA,IAAA,CAAK,GAAIA,CAAAA,MAAK,CAAG,EAAA;AACnB,UAAA;AAAA;AAEF,QAAA,IAAA,CAAK,IAAIA,MAAK,CAAA;AAAA;AAEhB,MAAOA,OAAAA,MAAAA;AAAA,KACT;AAAA,GACF;AAEA,EAAI,IAAA;AACF,IAAA,OAAO,IAAK,CAAA,SAAA,CAAU,KAAO,EAAA,mBAAA,EAAqB,CAAA;AAAA,WAC3C,KAAO,EAAA;AACd,IAAA,OAAA,CAAQ,MAAM,KAAK,CAAA;AAAA;AAGrB,EAAO,OAAA,EAAA;AACT;AAEO,SAAS,6BAA6B,OAAgC,EAAA;AAC3E,EAAO,OAAA,OAAA,CAAQ,IAAI,CAAC,M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AAG,0BAA2B,CAAA;AAAA,IACzC,WAAA;AAAA,IACA,OAAA;AAAA,IACA,OAAA;AAAA,IACA,SAAA;AAAA,IACA,MAAA,EAAQ,UAAW,CAAA,SAAA,CAAU,WAAW;AAAA,GACzC,CAAA;AACH;;;;"}
package/dist/index.d.ts CHANGED
@@ -988,11 +988,90 @@ interface MacroVariableConstructor {
988
988
  */
989
989
  declare function registerVariableMacro(name: string, macro: MacroVariableConstructor, replace?: boolean): () => void;
990
990
 
991
- declare function renderPrometheusLabelFilters(filters: AdHocVariableFilter[]): string;
992
- declare function escapeLabelValueInExactSelector(labelValue: string): string;
993
- declare function escapeLabelValueInRegexSelector(labelValue: string): string;
994
- declare function escapeUrlPipeDelimiters(value: string | undefined): string;
995
- declare function escapeURLDelimiters(value: string | undefined): string;
991
+ interface QueryRunnerState extends SceneObjectState {
992
+ data?: PanelData;
993
+ queries: SceneDataQuery[];
994
+ datasource?: DataSourceRef;
995
+ minInterval?: string;
996
+ maxDataPoints?: number;
997
+ liveStreaming?: boolean;
998
+ maxDataPointsFromWidth?: boolean;
999
+ cacheTimeout?: DataQueryRequest['cacheTimeout'];
1000
+ queryCachingTTL?: DataQueryRequest['queryCachingTTL'];
1001
+ /**
1002
+ * When set to auto (the default) query runner will issue queries on activate (when variable dependencies are ready) or when time range change.
1003
+ * Set to manual to have full manual control over when queries are issued. Try not to set this. This is mainly useful for unit tests, or special edge case workflows.
1004
+ */
1005
+ runQueriesMode?: 'auto' | 'manual';
1006
+ dataLayerFilter?: DataLayerFilter;
1007
+ _hasFetchedData?: boolean;
1008
+ }
1009
+ declare class SceneQueryRunner extends SceneObjectBase<QueryRunnerState> implements SceneDataProvider {
1010
+ private _querySub?;
1011
+ private _dataLayersSub?;
1012
+ private _dataLayersMerger;
1013
+ private _timeSub?;
1014
+ private _timeSubRange?;
1015
+ private _containerWidth?;
1016
+ private _variableValueRecorder;
1017
+ private _results;
1018
+ private _scopedVars;
1019
+ private _layerAnnotations?;
1020
+ private _resultAnnotations?;
1021
+ private _isInView;
1022
+ private _bypassIsInView;
1023
+ private _queryNotExecutedWhenOutOfView;
1024
+ getResultsStream(): ReplaySubject<SceneDataProviderResult>;
1025
+ protected _variableDependency: VariableDependencyConfig<QueryRunnerState>;
1026
+ private _drilldownDependenciesManager;
1027
+ constructor(initialState: QueryRunnerState);
1028
+ private _onActivate;
1029
+ private _handleDataLayers;
1030
+ private _onLayersReceived;
1031
+ /**
1032
+ * This tries to start a new query whenever a variable completes or is changed.
1033
+ *
1034
+ * We care about variable update completions even when the variable has not changed and even when it is not a direct dependency.
1035
+ * Example: Variables A and B (B depends on A). A update depends on time range. So when time change query runner will
1036
+ * find that variable A is loading which is a dependency on of variable B so will set _isWaitingForVariables to true and
1037
+ * not issue any query.
1038
+ *
1039
+ * When A completes it's loading (with no value change, so B never updates) it will cause a call of this function letting
1040
+ * the query runner know that A has completed, and in case _isWaitingForVariables we try to run the query. The query will
1041
+ * only run if all variables are in a non loading state so in other scenarios where a query depends on many variables this will
1042
+ * be called many times until all dependencies are in a non loading state. *
1043
+ */
1044
+ private onVariableUpdatesCompleted;
1045
+ /**
1046
+ * Check if value changed is a adhoc filter o group by variable that did not exist when we issued the last query
1047
+ */
1048
+ private onAnyVariableChanged;
1049
+ private _isRelevantAutoVariable;
1050
+ private shouldRunQueriesOnActivate;
1051
+ private _isDataTimeRangeStale;
1052
+ private _onDeactivate;
1053
+ setContainerWidth(width: number): void;
1054
+ isDataReadyToDisplay(): boolean;
1055
+ private subscribeToTimeRangeChanges;
1056
+ runQueries(): void;
1057
+ private getMaxDataPoints;
1058
+ cancelQuery(): void;
1059
+ private runWithTimeRange;
1060
+ clone(withState?: Partial<QueryRunnerState>): this;
1061
+ private prepareRequests;
1062
+ private onDataReceived;
1063
+ private _combineDataLayers;
1064
+ private _setNoDataState;
1065
+ /**
1066
+ * Walk up the scene graph and find any ExtraQueryProviders.
1067
+ *
1068
+ * This will return an array of the closest provider of each type.
1069
+ */
1070
+ private getClosestExtraQueryProviders;
1071
+ private isQueryModeAuto;
1072
+ isInViewChanged(isInView: boolean): void;
1073
+ bypassIsInViewChanged(bypassIsInView: boolean): void;
1074
+ }
996
1075
 
997
1076
  declare class AdHocFiltersVariableUrlSyncHandler implements SceneObjectUrlSyncHandler {
998
1077
  private _variable;
@@ -1003,10 +1082,6 @@ declare class AdHocFiltersVariableUrlSyncHandler implements SceneObjectUrlSyncHa
1003
1082
  updateFromUrl(values: SceneObjectUrlValues): void;
1004
1083
  }
1005
1084
 
1006
- interface DrilldownApplicabilitySupport {
1007
- isApplicabilityEnabled: () => boolean;
1008
- }
1009
-
1010
1085
  interface AdHocFilterWithLabels<M extends Record<string, any> = {}> extends AdHocVariableFilter {
1011
1086
  keyLabel?: string;
1012
1087
  valueLabels?: string[];
@@ -1098,6 +1173,10 @@ interface AdHocFiltersVariableState extends SceneVariableState {
1098
1173
  * Allows custom formatting of a value before saving to filter state
1099
1174
  */
1100
1175
  onAddCustomValue?: OnAddCustomValueFn;
1176
+ /**
1177
+ * state for checking whether drilldown applicability is enabled
1178
+ */
1179
+ applicabilityEnabled?: boolean;
1101
1180
  }
1102
1181
  type AdHocVariableExpressionBuilderFn = (filters: AdHocFilterWithLabels[]) => string;
1103
1182
  type OnAddCustomValueFn = (item: SelectableValue<string> & {
@@ -1120,13 +1199,12 @@ type OperatorDefinition = {
1120
1199
  isMulti?: Boolean;
1121
1200
  isRegex?: Boolean;
1122
1201
  };
1123
- declare class AdHocFiltersVariable extends SceneObjectBase<AdHocFiltersVariableState> implements SceneVariable<AdHocFiltersVariableState>, DrilldownApplicabilitySupport {
1202
+ declare class AdHocFiltersVariable extends SceneObjectBase<AdHocFiltersVariableState> implements SceneVariable<AdHocFiltersVariableState> {
1124
1203
  static Component: typeof AdHocFiltersVariableRenderer;
1125
1204
  private _scopedVars;
1126
1205
  private _dataSourceSrv;
1127
1206
  private _originalValues;
1128
1207
  private _prevScopes;
1129
- private _applicabilityEnabled;
1130
1208
  /** Needed for scopes dependency */
1131
1209
  protected _variableDependency: VariableDependencyConfig<AdHocFiltersVariableState>;
1132
1210
  protected _urlSync: AdHocFiltersVariableUrlSyncHandler;
@@ -1151,7 +1229,6 @@ declare class AdHocFiltersVariable extends SceneObjectBase<AdHocFiltersVariableS
1151
1229
  _removeFilter(filter: AdHocFilterWithLabels): void;
1152
1230
  _removeLastFilter(): void;
1153
1231
  _handleComboboxBackspace(filter: AdHocFilterWithLabels): void;
1154
- isApplicabilityEnabled(): boolean;
1155
1232
  getFiltersApplicabilityForQueries(filters: AdHocFilterWithLabels[], queries: SceneDataQuery[]): Promise<DrilldownsApplicability[] | undefined>;
1156
1233
  _verifyApplicability(): Promise<void>;
1157
1234
  /**
@@ -1167,20 +1244,6 @@ declare class AdHocFiltersVariable extends SceneObjectBase<AdHocFiltersVariableS
1167
1244
  }
1168
1245
  declare function AdHocFiltersVariableRenderer({ model }: SceneComponentProps<AdHocFiltersVariable>): React__default.JSX.Element;
1169
1246
 
1170
- interface ConstantVariableState extends SceneVariableState {
1171
- value: VariableValue;
1172
- }
1173
- declare class ConstantVariable extends SceneObjectBase<ConstantVariableState> implements SceneVariable<ConstantVariableState> {
1174
- protected _variableDependency: VariableDependencyConfig<ConstantVariableState>;
1175
- private _prevValue;
1176
- constructor(initialState: Partial<ConstantVariableState>);
1177
- /**
1178
- * This function is called on when SceneVariableSet is activated or when a dependency changes.
1179
- */
1180
- validateAndUpdate(): Observable<ValidateAndUpdateResult>;
1181
- getValue(): VariableValue;
1182
- }
1183
-
1184
1247
  interface MultiValueVariableState extends SceneVariableState {
1185
1248
  value: VariableValue;
1186
1249
  text: VariableValue;
@@ -1255,6 +1318,108 @@ declare abstract class MultiValueVariable<TState extends MultiValueVariableState
1255
1318
  onSearchChange?(searchFilter: string): void;
1256
1319
  }
1257
1320
 
1321
+ interface GroupByVariableState extends MultiValueVariableState {
1322
+ /** Defaults to "Group" */
1323
+ name: string;
1324
+ /** The visible keys to group on */
1325
+ defaultOptions?: MetricFindValue[];
1326
+ /** Base filters to always apply when looking up keys */
1327
+ baseFilters?: AdHocVariableFilter[];
1328
+ /** Datasource to use for getTagKeys and also controls which scene queries the group by should apply to */
1329
+ datasource: DataSourceRef | null;
1330
+ /** Default value set for this groupBy. When this field is set, changing value will allow the user to restore back to this default value */
1331
+ defaultValue?: {
1332
+ text: VariableValue;
1333
+ value: VariableValue;
1334
+ };
1335
+ /** Needed for url sync when passing flag to another dashboard */
1336
+ restorable?: boolean;
1337
+ /** Controls if the group by can be changed */
1338
+ readOnly?: boolean;
1339
+ /**
1340
+ * @experimental
1341
+ * Controls the layout and design of the label.
1342
+ * Vertical layout does not yet support operator selector.
1343
+ */
1344
+ layout?: ControlsLayout;
1345
+ /**
1346
+ * Defaults to same-datasource which means group by will automatically be applied to all queries with the same data source as this GroupBySet.
1347
+ * In manual mode no queries are re-run on changes, and you have to manually apply the filter to whatever queries you want.
1348
+ */
1349
+ applyMode?: 'auto' | 'manual';
1350
+ /**
1351
+ * Filter out the keys that do not match the regex.
1352
+ */
1353
+ tagKeyRegexFilter?: RegExp;
1354
+ /**
1355
+ * Extension hook for customizing the key lookup.
1356
+ * Return replace: true if you want to override the default lookup
1357
+ * Return replace: false if you want to combine the results with the default lookup
1358
+ */
1359
+ getTagKeysProvider?: getTagKeysProvider;
1360
+ /**
1361
+ * Holds the applicability for each of the selected keys
1362
+ */
1363
+ keysApplicability?: DrilldownsApplicability[];
1364
+ /**
1365
+ * state for checking whether drilldown applicability is enabled
1366
+ */
1367
+ applicabilityEnabled?: boolean;
1368
+ }
1369
+ type getTagKeysProvider = (set: GroupByVariable, currentKey: string | null) => Promise<{
1370
+ replace?: boolean;
1371
+ values: MetricFindValue[] | GetTagResponse;
1372
+ }>;
1373
+ declare class GroupByVariable extends MultiValueVariable<GroupByVariableState> {
1374
+ static Component: typeof GroupByVariableRenderer;
1375
+ isLazy: boolean;
1376
+ protected _urlSync: SceneObjectUrlSyncHandler;
1377
+ validateAndUpdate(): Observable<ValidateAndUpdateResult>;
1378
+ private _updateValueGivenNewOptions;
1379
+ getValueOptions(args: VariableGetOptionsArgs): Observable<VariableValueOption[]>;
1380
+ constructor(initialState: Partial<GroupByVariableState>);
1381
+ private _activationHandler;
1382
+ getApplicableKeys(): VariableValue;
1383
+ getGroupByApplicabilityForQueries(value: VariableValue, queries: SceneDataQuery[]): Promise<DrilldownsApplicability[] | undefined>;
1384
+ _verifyApplicability(): Promise<void>;
1385
+ checkIfRestorable(values: VariableValue): boolean;
1386
+ restoreDefaultValues(): void;
1387
+ /**
1388
+ * Get possible keys given current filters. Do not call from plugins directly
1389
+ */
1390
+ _getKeys: (ds: DataSourceApi) => Promise<GetTagResponse | MetricFindValue[]>;
1391
+ /**
1392
+ * Allows clearing the value of the variable to an empty value. Overrides default behavior of a MultiValueVariable
1393
+ */
1394
+ getDefaultMultiState(options: VariableValueOption[]): {
1395
+ value: VariableValueSingle[];
1396
+ text: string[];
1397
+ };
1398
+ }
1399
+ declare function GroupByVariableRenderer({ model }: SceneComponentProps<GroupByVariable>): React__default.JSX.Element;
1400
+
1401
+ declare function renderPrometheusLabelFilters(filters: AdHocVariableFilter[]): string;
1402
+ declare function escapeLabelValueInExactSelector(labelValue: string): string;
1403
+ declare function escapeLabelValueInRegexSelector(labelValue: string): string;
1404
+ declare function escapeUrlPipeDelimiters(value: string | undefined): string;
1405
+ declare function escapeURLDelimiters(value: string | undefined): string;
1406
+ declare function verifyDrilldownApplicability(sourceObject: SceneObject, queriesDataSource: DataSourceRef | undefined, drilldownDatasource: DataSourceRef | null, isApplicabilityEnabled?: boolean): boolean;
1407
+ declare function getDrilldownApplicability(queryRunner: SceneQueryRunner, filtersVar?: AdHocFiltersVariable, groupByVar?: GroupByVariable): Promise<DrilldownsApplicability[] | undefined>;
1408
+
1409
+ interface ConstantVariableState extends SceneVariableState {
1410
+ value: VariableValue;
1411
+ }
1412
+ declare class ConstantVariable extends SceneObjectBase<ConstantVariableState> implements SceneVariable<ConstantVariableState> {
1413
+ protected _variableDependency: VariableDependencyConfig<ConstantVariableState>;
1414
+ private _prevValue;
1415
+ constructor(initialState: Partial<ConstantVariableState>);
1416
+ /**
1417
+ * This function is called on when SceneVariableSet is activated or when a dependency changes.
1418
+ */
1419
+ validateAndUpdate(): Observable<ValidateAndUpdateResult>;
1420
+ getValue(): VariableValue;
1421
+ }
1422
+
1258
1423
  interface CustomVariableState extends MultiValueVariableState {
1259
1424
  query: string;
1260
1425
  }
@@ -1348,84 +1513,6 @@ declare class QueryVariable extends MultiValueVariable<QueryVariableState> {
1348
1513
  static Component: ({ model }: SceneComponentProps<MultiValueVariable>) => React__default.JSX.Element;
1349
1514
  }
1350
1515
 
1351
- interface GroupByVariableState extends MultiValueVariableState {
1352
- /** Defaults to "Group" */
1353
- name: string;
1354
- /** The visible keys to group on */
1355
- defaultOptions?: MetricFindValue[];
1356
- /** Base filters to always apply when looking up keys */
1357
- baseFilters?: AdHocVariableFilter[];
1358
- /** Datasource to use for getTagKeys and also controls which scene queries the group by should apply to */
1359
- datasource: DataSourceRef | null;
1360
- /** Default value set for this groupBy. When this field is set, changing value will allow the user to restore back to this default value */
1361
- defaultValue?: {
1362
- text: VariableValue;
1363
- value: VariableValue;
1364
- };
1365
- /** Needed for url sync when passing flag to another dashboard */
1366
- restorable?: boolean;
1367
- /** Controls if the group by can be changed */
1368
- readOnly?: boolean;
1369
- /**
1370
- * @experimental
1371
- * Controls the layout and design of the label.
1372
- * Vertical layout does not yet support operator selector.
1373
- */
1374
- layout?: ControlsLayout;
1375
- /**
1376
- * Defaults to same-datasource which means group by will automatically be applied to all queries with the same data source as this GroupBySet.
1377
- * In manual mode no queries are re-run on changes, and you have to manually apply the filter to whatever queries you want.
1378
- */
1379
- applyMode?: 'auto' | 'manual';
1380
- /**
1381
- * Filter out the keys that do not match the regex.
1382
- */
1383
- tagKeyRegexFilter?: RegExp;
1384
- /**
1385
- * Extension hook for customizing the key lookup.
1386
- * Return replace: true if you want to override the default lookup
1387
- * Return replace: false if you want to combine the results with the default lookup
1388
- */
1389
- getTagKeysProvider?: getTagKeysProvider;
1390
- /**
1391
- * Holds the applicability for each of the selected keys
1392
- */
1393
- keysApplicability?: DrilldownsApplicability[];
1394
- }
1395
- type getTagKeysProvider = (set: GroupByVariable, currentKey: string | null) => Promise<{
1396
- replace?: boolean;
1397
- values: MetricFindValue[] | GetTagResponse;
1398
- }>;
1399
- declare class GroupByVariable extends MultiValueVariable<GroupByVariableState> implements DrilldownApplicabilitySupport {
1400
- static Component: typeof GroupByVariableRenderer;
1401
- isLazy: boolean;
1402
- protected _urlSync: SceneObjectUrlSyncHandler;
1403
- private _applicabilityEnabled;
1404
- validateAndUpdate(): Observable<ValidateAndUpdateResult>;
1405
- private _updateValueGivenNewOptions;
1406
- getValueOptions(args: VariableGetOptionsArgs): Observable<VariableValueOption[]>;
1407
- constructor(initialState: Partial<GroupByVariableState>);
1408
- private _activationHandler;
1409
- getApplicableKeys(): VariableValue;
1410
- isApplicabilityEnabled(): boolean;
1411
- getGroupByApplicabilityForQueries(value: VariableValue, queries: SceneDataQuery[]): Promise<DrilldownsApplicability[] | undefined>;
1412
- _verifyApplicability(): Promise<void>;
1413
- checkIfRestorable(values: VariableValue): boolean;
1414
- restoreDefaultValues(): void;
1415
- /**
1416
- * Get possible keys given current filters. Do not call from plugins directly
1417
- */
1418
- _getKeys: (ds: DataSourceApi) => Promise<GetTagResponse | MetricFindValue[]>;
1419
- /**
1420
- * Allows clearing the value of the variable to an empty value. Overrides default behavior of a MultiValueVariable
1421
- */
1422
- getDefaultMultiState(options: VariableValueOption[]): {
1423
- value: VariableValueSingle[];
1424
- text: string[];
1425
- };
1426
- }
1427
- declare function GroupByVariableRenderer({ model }: SceneComponentProps<GroupByVariable>): React__default.JSX.Element;
1428
-
1429
1516
  interface SwitchVariableState extends SceneVariableState {
1430
1517
  value: string;
1431
1518
  enabledValue: string;
@@ -2088,91 +2175,6 @@ declare class SceneTimeZoneOverride extends SceneTimeRangeTransformerBase<SceneT
2088
2175
  onTimeZoneChange(timeZone: string): void;
2089
2176
  }
2090
2177
 
2091
- interface QueryRunnerState extends SceneObjectState {
2092
- data?: PanelData;
2093
- queries: SceneDataQuery[];
2094
- datasource?: DataSourceRef;
2095
- minInterval?: string;
2096
- maxDataPoints?: number;
2097
- liveStreaming?: boolean;
2098
- maxDataPointsFromWidth?: boolean;
2099
- cacheTimeout?: DataQueryRequest['cacheTimeout'];
2100
- queryCachingTTL?: DataQueryRequest['queryCachingTTL'];
2101
- /**
2102
- * When set to auto (the default) query runner will issue queries on activate (when variable dependencies are ready) or when time range change.
2103
- * Set to manual to have full manual control over when queries are issued. Try not to set this. This is mainly useful for unit tests, or special edge case workflows.
2104
- */
2105
- runQueriesMode?: 'auto' | 'manual';
2106
- dataLayerFilter?: DataLayerFilter;
2107
- _hasFetchedData?: boolean;
2108
- }
2109
- declare class SceneQueryRunner extends SceneObjectBase<QueryRunnerState> implements SceneDataProvider {
2110
- private _querySub?;
2111
- private _dataLayersSub?;
2112
- private _dataLayersMerger;
2113
- private _timeSub?;
2114
- private _timeSubRange?;
2115
- private _containerWidth?;
2116
- private _variableValueRecorder;
2117
- private _results;
2118
- private _scopedVars;
2119
- private _layerAnnotations?;
2120
- private _resultAnnotations?;
2121
- private _isInView;
2122
- private _bypassIsInView;
2123
- private _queryNotExecutedWhenOutOfView;
2124
- getResultsStream(): ReplaySubject<SceneDataProviderResult>;
2125
- protected _variableDependency: VariableDependencyConfig<QueryRunnerState>;
2126
- private _drilldownDependenciesManager;
2127
- constructor(initialState: QueryRunnerState);
2128
- private _onActivate;
2129
- private _handleDataLayers;
2130
- private _onLayersReceived;
2131
- /**
2132
- * This tries to start a new query whenever a variable completes or is changed.
2133
- *
2134
- * We care about variable update completions even when the variable has not changed and even when it is not a direct dependency.
2135
- * Example: Variables A and B (B depends on A). A update depends on time range. So when time change query runner will
2136
- * find that variable A is loading which is a dependency on of variable B so will set _isWaitingForVariables to true and
2137
- * not issue any query.
2138
- *
2139
- * When A completes it's loading (with no value change, so B never updates) it will cause a call of this function letting
2140
- * the query runner know that A has completed, and in case _isWaitingForVariables we try to run the query. The query will
2141
- * only run if all variables are in a non loading state so in other scenarios where a query depends on many variables this will
2142
- * be called many times until all dependencies are in a non loading state. *
2143
- */
2144
- private onVariableUpdatesCompleted;
2145
- /**
2146
- * Check if value changed is a adhoc filter o group by variable that did not exist when we issued the last query
2147
- */
2148
- private onAnyVariableChanged;
2149
- private _isRelevantAutoVariable;
2150
- private shouldRunQueriesOnActivate;
2151
- private _isDataTimeRangeStale;
2152
- private _onDeactivate;
2153
- setContainerWidth(width: number): void;
2154
- isDataReadyToDisplay(): boolean;
2155
- private subscribeToTimeRangeChanges;
2156
- runQueries(): void;
2157
- private getMaxDataPoints;
2158
- cancelQuery(): void;
2159
- private runWithTimeRange;
2160
- clone(withState?: Partial<QueryRunnerState>): this;
2161
- private prepareRequests;
2162
- private onDataReceived;
2163
- private _combineDataLayers;
2164
- private _setNoDataState;
2165
- /**
2166
- * Walk up the scene graph and find any ExtraQueryProviders.
2167
- *
2168
- * This will return an array of the closest provider of each type.
2169
- */
2170
- private getClosestExtraQueryProviders;
2171
- private isQueryModeAuto;
2172
- isInViewChanged(isInView: boolean): void;
2173
- bypassIsInViewChanged(bypassIsInView: boolean): void;
2174
- }
2175
-
2176
2178
  interface DataProviderSharerState extends SceneDataState {
2177
2179
  source: SceneObjectRef<SceneDataProvider>;
2178
2180
  }
@@ -3594,6 +3596,8 @@ declare const sceneUtils: {
3594
3596
  isSwitchVariable: typeof isSwitchVariable;
3595
3597
  isRepeatCloneOrChildOf: typeof isRepeatCloneOrChildOf;
3596
3598
  buildPathIdFor: typeof buildPathIdFor;
3599
+ verifyDrilldownApplicability: typeof verifyDrilldownApplicability;
3600
+ getDrilldownApplicability: typeof getDrilldownApplicability;
3597
3601
  };
3598
3602
 
3599
3603
  export { AdHocFiltersComboboxRenderer, AdHocFiltersVariable, AdHocFiltersVariableController, ConstantVariable, ControlsLabel, CustomVariable, DataProviderProxy, DataSourceVariable, EmbeddedScene, FieldConfigBuilder, FieldConfigBuilders, FieldConfigOverridesBuilder, GroupByVariable, IntervalVariable, LazyLoader, LocalValueVariable, MultiOrSingleValueSelect, MultiValueVariable, NestedScene, NewSceneObjectAddedEvent, PATH_ID_SEPARATOR, PanelBuilders, PanelOptionsBuilders, QueryVariable, RuntimeDataSource, SafeSerializableSceneObject, SceneApp, SceneAppPage, SceneByFrameRepeater, SceneByVariableRepeater, SceneCSSGridItem, SceneCSSGridLayout, SceneCanvasText, SceneControlsSpacer, SceneDataLayerBase, SceneDataLayerControls, SceneDataLayerSet, SceneDataLayerSetBase, SceneDataNode, SceneDataTransformer, SceneDebugger, SceneFlexItem, SceneFlexLayout, SceneGridItem, SceneGridLayout, SceneGridLayoutDragStartEvent, SceneGridRow, SceneObjectBase, SceneObjectRef, SceneObjectStateChangedEvent, SceneObjectUrlSyncConfig, SceneQueryRunner, SceneReactObject, SceneRefreshPicker, SceneTimePicker, SceneTimeRange, SceneTimeRangeCompare, SceneTimeRangeTransformerBase, SceneTimeZoneOverride, SceneToolbarButton, SceneToolbarInput, SceneVariableSet, SceneVariableValueChangedEvent, ScopesVariable, SplitLayout, SwitchVariable, TestVariable, TextBoxVariable, UrlSyncContextProvider, UrlSyncManager, UserActionEvent, VariableDependencyConfig, VariableValueControl, VariableValueSelectWrapper, VariableValueSelectors, VizConfigBuilder, VizConfigBuilders, VizPanel, VizPanelBuilder, VizPanelExploreButton, VizPanelMenu, index$2 as behaviors, index as dataLayers, escapeUrlPipeDelimiters, formatRegistry, getExploreURL, isCustomVariableValue, isDataLayer, isDataRequestEnricher, isFiltersRequestEnricher, isSceneObject, loadResources, index$1 as performanceUtils, registerQueryWithController, registerRuntimeDataSource, sceneGraph, sceneUtils, useSceneApp, useSceneObjectState, useUrlSync, writePerformanceLog };