@grafana/scenes 6.33.1--canary.1235.17401388269.0 → 6.33.1--canary.1235.17408464975.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.
package/dist/index.js CHANGED
@@ -3140,49 +3140,6 @@ function getEnrichedDataRequest(sourceRunner) {
3140
3140
  return null;
3141
3141
  }
3142
3142
 
3143
- let originalGetAdhocFilters = void 0;
3144
- let allActiveFilterSets = /* @__PURE__ */ new Set();
3145
- function patchGetAdhocFilters(filterVar) {
3146
- filterVar.addActivationHandler(() => {
3147
- allActiveFilterSets.add(filterVar);
3148
- return () => allActiveFilterSets.delete(filterVar);
3149
- });
3150
- if (originalGetAdhocFilters) {
3151
- return;
3152
- }
3153
- const templateSrv = runtime.getTemplateSrv();
3154
- if (!(templateSrv == null ? void 0 : templateSrv.getAdhocFilters)) {
3155
- console.log("Failed to patch getAdhocFilters");
3156
- return;
3157
- }
3158
- originalGetAdhocFilters = templateSrv.getAdhocFilters;
3159
- templateSrv.getAdhocFilters = function getAdhocFiltersScenePatch(dsName) {
3160
- var _a;
3161
- if (allActiveFilterSets.size === 0) {
3162
- return originalGetAdhocFilters.call(templateSrv, dsName);
3163
- }
3164
- const ds = runtime.getDataSourceSrv().getInstanceSettings(dsName);
3165
- if (!ds) {
3166
- return [];
3167
- }
3168
- for (const filter of allActiveFilterSets.values()) {
3169
- if (((_a = filter.state.datasource) == null ? void 0 : _a.uid) === ds.uid) {
3170
- return filter.state.filters;
3171
- }
3172
- }
3173
- return [];
3174
- }.bind(templateSrv);
3175
- }
3176
- function findActiveAdHocFilterVariableByUid(dsUid) {
3177
- var _a;
3178
- for (const filter of allActiveFilterSets.values()) {
3179
- if (interpolate(filter, (_a = filter.state.datasource) == null ? void 0 : _a.uid) === dsUid) {
3180
- return filter;
3181
- }
3182
- }
3183
- return void 0;
3184
- }
3185
-
3186
3143
  const allActiveGroupByVariables = /* @__PURE__ */ new Set();
3187
3144
  function findActiveGroupByVariablesByUid(dsUid) {
3188
3145
  var _a;
@@ -3851,13 +3808,13 @@ class GroupByVariable extends MultiValueVariable {
3851
3808
  const ds = await getDataSource(this.state.datasource, {
3852
3809
  __sceneObject: wrapInSafeSerializableSceneObject(this)
3853
3810
  });
3854
- if (!ds.getFiltersApplicability) {
3811
+ if (!ds.getDrilldownsApplicability) {
3855
3812
  return;
3856
3813
  }
3857
3814
  const queries = getQueriesForVariables(this);
3858
3815
  const timeRange = sceneGraph.getTimeRange(this).state.value;
3859
3816
  const value = this.state.value;
3860
- const response = await ds.getFiltersApplicability({
3817
+ const response = await ds.getDrilldownsApplicability({
3861
3818
  groupByKeys: Array.isArray(value) ? value.map((v) => String(v)) : value ? [String(value)] : [],
3862
3819
  queries,
3863
3820
  timeRange,
@@ -3994,12 +3951,11 @@ function GroupByVariableRenderer({ model }) {
3994
3951
  if (restorable !== model.state.restorable) {
3995
3952
  model.setState({ restorable });
3996
3953
  }
3954
+ model._verifyApplicability();
3997
3955
  },
3998
3956
  onChange: (newValue, action) => {
3999
3957
  if (action.action === "clear" && noValueOnClear) {
4000
3958
  model.changeValueTo([], void 0, true);
4001
- } else {
4002
- model._verifyApplicability();
4003
3959
  }
4004
3960
  setUncommittedValue(newValue);
4005
3961
  },
@@ -4081,6 +4037,49 @@ function toSelectableValue$1(input) {
4081
4037
  return result;
4082
4038
  }
4083
4039
 
4040
+ let originalGetAdhocFilters = void 0;
4041
+ const allActiveFilterSets = /* @__PURE__ */ new Set();
4042
+ function patchGetAdhocFilters(filterVar) {
4043
+ filterVar.addActivationHandler(() => {
4044
+ allActiveFilterSets.add(filterVar);
4045
+ return () => allActiveFilterSets.delete(filterVar);
4046
+ });
4047
+ if (originalGetAdhocFilters) {
4048
+ return;
4049
+ }
4050
+ const templateSrv = runtime.getTemplateSrv();
4051
+ if (!(templateSrv == null ? void 0 : templateSrv.getAdhocFilters)) {
4052
+ console.log("Failed to patch getAdhocFilters");
4053
+ return;
4054
+ }
4055
+ originalGetAdhocFilters = templateSrv.getAdhocFilters;
4056
+ templateSrv.getAdhocFilters = function getAdhocFiltersScenePatch(dsName) {
4057
+ var _a;
4058
+ if (allActiveFilterSets.size === 0) {
4059
+ return originalGetAdhocFilters.call(templateSrv, dsName);
4060
+ }
4061
+ const ds = runtime.getDataSourceSrv().getInstanceSettings(dsName);
4062
+ if (!ds) {
4063
+ return [];
4064
+ }
4065
+ for (const filter of allActiveFilterSets.values()) {
4066
+ if (((_a = filter.state.datasource) == null ? void 0 : _a.uid) === ds.uid) {
4067
+ return filter.state.filters;
4068
+ }
4069
+ }
4070
+ return [];
4071
+ }.bind(templateSrv);
4072
+ }
4073
+ function findActiveAdHocFilterVariableByUid(dsUid) {
4074
+ var _a;
4075
+ for (const filter of allActiveFilterSets.values()) {
4076
+ if (interpolate(filter, (_a = filter.state.datasource) == null ? void 0 : _a.uid) === dsUid) {
4077
+ return filter;
4078
+ }
4079
+ }
4080
+ return void 0;
4081
+ }
4082
+
4084
4083
  function LoadingIndicator(props) {
4085
4084
  return /* @__PURE__ */ React__default.default.createElement(ui.Tooltip, { content: i18n.t("grafana-scenes.utils.loading-indicator.content-cancel-query", "Cancel query") }, /* @__PURE__ */ React__default.default.createElement(
4086
4085
  ui.Icon,
@@ -6431,7 +6430,7 @@ class AdHocFiltersVariable extends SceneObjectBase {
6431
6430
  var _a, _b, _c;
6432
6431
  const filters = [...this.state.filters, ...(_a = this.state.originFilters) != null ? _a : []];
6433
6432
  const ds = await this._dataSourceSrv.get(this.state.datasource, this._scopedVars);
6434
- if (!ds || !ds.getFiltersApplicability) {
6433
+ if (!ds || !ds.getDrilldownsApplicability) {
6435
6434
  return;
6436
6435
  }
6437
6436
  if (!filters) {
@@ -6439,7 +6438,7 @@ class AdHocFiltersVariable extends SceneObjectBase {
6439
6438
  }
6440
6439
  const timeRange = sceneGraph.getTimeRange(this).state.value;
6441
6440
  const queries = this.state.useQueriesAsFilterForOptions ? getQueriesForVariables(this) : void 0;
6442
- const response = await ds.getFiltersApplicability({
6441
+ const response = await ds.getDrilldownsApplicability({
6443
6442
  filters,
6444
6443
  queries,
6445
6444
  timeRange,
@@ -6682,6 +6681,60 @@ function areDifferentLayers(a, b) {
6682
6681
  return false;
6683
6682
  }
6684
6683
 
6684
+ class DrilldownDependenciesManager {
6685
+ constructor(variableDependency) {
6686
+ this._variableDependency = variableDependency;
6687
+ }
6688
+ /**
6689
+ * Walk up scene graph and find the closest filterset with matching data source
6690
+ */
6691
+ findAndSubscribeToDrilldowns(interpolatedUid) {
6692
+ const filtersVar = findActiveAdHocFilterVariableByUid(interpolatedUid);
6693
+ const groupByVar = findActiveGroupByVariablesByUid(interpolatedUid);
6694
+ let hasChanges = false;
6695
+ if (this._adhocFiltersVar !== filtersVar) {
6696
+ this._adhocFiltersVar = filtersVar;
6697
+ hasChanges = true;
6698
+ }
6699
+ if (this._groupByVar !== groupByVar) {
6700
+ this._groupByVar = groupByVar;
6701
+ hasChanges = true;
6702
+ }
6703
+ if (hasChanges) {
6704
+ this._updateExplicitDrilldownVariableDependencies();
6705
+ }
6706
+ }
6707
+ _updateExplicitDrilldownVariableDependencies() {
6708
+ const explicitDependencies = [];
6709
+ if (this._adhocFiltersVar) {
6710
+ explicitDependencies.push(this._adhocFiltersVar.state.name);
6711
+ }
6712
+ if (this._groupByVar) {
6713
+ explicitDependencies.push(this._groupByVar.state.name);
6714
+ }
6715
+ this._variableDependency.setVariableNames(explicitDependencies);
6716
+ }
6717
+ get adHocFiltersVar() {
6718
+ return this._adhocFiltersVar;
6719
+ }
6720
+ get groupByVar() {
6721
+ return this._groupByVar;
6722
+ }
6723
+ getFilters() {
6724
+ var _a;
6725
+ return this._adhocFiltersVar ? [...(_a = this._adhocFiltersVar.state.originFilters) != null ? _a : [], ...this._adhocFiltersVar.state.filters].filter(
6726
+ (f) => isFilterComplete(f) && isFilterApplicable(f)
6727
+ ) : void 0;
6728
+ }
6729
+ getGroupByKeys() {
6730
+ return this._groupByVar ? this._groupByVar.getApplicableKeys() : void 0;
6731
+ }
6732
+ cleanup() {
6733
+ this._adhocFiltersVar = void 0;
6734
+ this._groupByVar = void 0;
6735
+ }
6736
+ }
6737
+
6685
6738
  let counter$1 = 100;
6686
6739
  function getNextRequestId$1() {
6687
6740
  return "SQR" + counter$1++;
@@ -6699,6 +6752,7 @@ class SceneQueryRunner extends SceneObjectBase {
6699
6752
  onAnyVariableChanged: this.onAnyVariableChanged.bind(this),
6700
6753
  dependsOnScopes: true
6701
6754
  });
6755
+ this._drilldownDependenciesManager = new DrilldownDependenciesManager(this._variableDependency);
6702
6756
  this.onDataReceived = (data$1) => {
6703
6757
  const preProcessedData = data.preProcessPanelData(data$1, this.state.data);
6704
6758
  this._resultAnnotations = data$1.annotations;
@@ -6814,7 +6868,7 @@ class SceneQueryRunner extends SceneObjectBase {
6814
6868
  * Check if value changed is a adhoc filter o group by variable that did not exist when we issued the last query
6815
6869
  */
6816
6870
  onAnyVariableChanged(variable) {
6817
- if (this._adhocFiltersVar === variable || this._groupByVar === variable || !this.isQueryModeAuto()) {
6871
+ if (this._drilldownDependenciesManager.adHocFiltersVar === variable || this._drilldownDependenciesManager.groupByVar === variable || !this.isQueryModeAuto()) {
6818
6872
  return;
6819
6873
  }
6820
6874
  if (variable instanceof AdHocFiltersVariable && this._isRelevantAutoVariable(variable)) {
@@ -6868,8 +6922,7 @@ class SceneQueryRunner extends SceneObjectBase {
6868
6922
  (_a = this._timeSub) == null ? void 0 : _a.unsubscribe();
6869
6923
  this._timeSub = void 0;
6870
6924
  this._timeSubRange = void 0;
6871
- this._adhocFiltersVar = void 0;
6872
- this._groupByVar = void 0;
6925
+ this._drilldownDependenciesManager.cleanup();
6873
6926
  }
6874
6927
  setContainerWidth(width) {
6875
6928
  if (!this._containerWidth && width > 0) {
@@ -6950,7 +7003,7 @@ class SceneQueryRunner extends SceneObjectBase {
6950
7003
  try {
6951
7004
  const datasource = (_c = this.state.datasource) != null ? _c : findFirstDatasource(queries);
6952
7005
  const ds = await getDataSource(datasource, this._scopedVars);
6953
- this.findAndSubscribeToAdHocFilters(ds.uid);
7006
+ this._drilldownDependenciesManager.findAndSubscribeToDrilldowns(ds.uid);
6954
7007
  const runRequest = runtime.getRunRequest();
6955
7008
  const { primary, secondaries, processors } = this.prepareRequests(timeRange, ds);
6956
7009
  writeSceneLog("SceneQueryRunner", "Starting runRequest", this.state.key);
@@ -6994,7 +7047,7 @@ class SceneQueryRunner extends SceneObjectBase {
6994
7047
  return clone;
6995
7048
  }
6996
7049
  prepareRequests(timeRange, ds) {
6997
- var _a, _b;
7050
+ var _a;
6998
7051
  const { minInterval, queries } = this.state;
6999
7052
  let request = {
7000
7053
  app: "scenes",
@@ -7018,14 +7071,13 @@ class SceneQueryRunner extends SceneObjectBase {
7018
7071
  // This asks the scene root to provide context properties like app, panel and dashboardUID
7019
7072
  ...getEnrichedDataRequest(this)
7020
7073
  };
7021
- if (this._adhocFiltersVar) {
7022
- request.filters = [
7023
- ...(_a = this._adhocFiltersVar.state.originFilters) != null ? _a : [],
7024
- ...this._adhocFiltersVar.state.filters
7025
- ].filter((f) => isFilterComplete(f) && isFilterApplicable(f));
7074
+ const filters = this._drilldownDependenciesManager.getFilters();
7075
+ const groupByKeys = this._drilldownDependenciesManager.getGroupByKeys();
7076
+ if (filters) {
7077
+ request.filters = filters;
7026
7078
  }
7027
- if (this._groupByVar) {
7028
- request.groupByKeys = this._groupByVar.getApplicableKeys();
7079
+ if (groupByKeys) {
7080
+ request.groupByKeys = groupByKeys;
7029
7081
  }
7030
7082
  request.targets = request.targets.map((query) => {
7031
7083
  var _a2;
@@ -7045,7 +7097,7 @@ class SceneQueryRunner extends SceneObjectBase {
7045
7097
  const primaryTimeRange = timeRange.state.value;
7046
7098
  let secondaryRequests = [];
7047
7099
  let secondaryProcessors = /* @__PURE__ */ new Map();
7048
- for (const provider of (_b = this.getClosestExtraQueryProviders()) != null ? _b : []) {
7100
+ for (const provider of (_a = this.getClosestExtraQueryProviders()) != null ? _a : []) {
7049
7101
  for (const { req, processor } of provider.getExtraQueries(request)) {
7050
7102
  const requestId = getNextRequestId$1();
7051
7103
  secondaryRequests.push({ ...req, requestId });
@@ -7092,31 +7144,6 @@ class SceneQueryRunner extends SceneObjectBase {
7092
7144
  });
7093
7145
  return Array.from(found.values());
7094
7146
  }
7095
- /**
7096
- * Walk up scene graph and find the closest filterset with matching data source
7097
- */
7098
- findAndSubscribeToAdHocFilters(interpolatedUid) {
7099
- const filtersVar = findActiveAdHocFilterVariableByUid(interpolatedUid);
7100
- if (this._adhocFiltersVar !== filtersVar) {
7101
- this._adhocFiltersVar = filtersVar;
7102
- this._updateExplicitVariableDependencies();
7103
- }
7104
- const groupByVar = findActiveGroupByVariablesByUid(interpolatedUid);
7105
- if (this._groupByVar !== groupByVar) {
7106
- this._groupByVar = groupByVar;
7107
- this._updateExplicitVariableDependencies();
7108
- }
7109
- }
7110
- _updateExplicitVariableDependencies() {
7111
- const explicitDependencies = [];
7112
- if (this._adhocFiltersVar) {
7113
- explicitDependencies.push(this._adhocFiltersVar.state.name);
7114
- }
7115
- if (this._groupByVar) {
7116
- explicitDependencies.push(this._groupByVar.state.name);
7117
- }
7118
- this._variableDependency.setVariableNames(explicitDependencies);
7119
- }
7120
7147
  isQueryModeAuto() {
7121
7148
  var _a;
7122
7149
  return ((_a = this.state.runQueriesMode) != null ? _a : "auto") === "auto";
@@ -10070,7 +10097,7 @@ let counter = 100;
10070
10097
  function getNextRequestId() {
10071
10098
  return "AQ" + counter++;
10072
10099
  }
10073
- function executeAnnotationQuery(datasource, timeRange, query, layer) {
10100
+ function executeAnnotationQuery(datasource, timeRange, query, layer, filters, groupByKeys) {
10074
10101
  var _a;
10075
10102
  if (datasource.annotationQuery && shouldUseLegacyRunner(datasource)) {
10076
10103
  console.warn("Using deprecated annotationQuery method, please upgrade your datasource");
@@ -10137,6 +10164,8 @@ function executeAnnotationQuery(datasource, timeRange, query, layer) {
10137
10164
  }
10138
10165
  ],
10139
10166
  scopes: sceneGraph.getScopes(layer),
10167
+ filters,
10168
+ groupByKeys,
10140
10169
  ...getEnrichedDataRequest(layer)
10141
10170
  };
10142
10171
  const runRequest = runtime.getRunRequest();
@@ -10235,6 +10264,7 @@ class AnnotationsDataLayer extends SceneDataLayerBase {
10235
10264
  this._scopedVars = {
10236
10265
  __sceneObject: wrapInSafeSerializableSceneObject(this)
10237
10266
  };
10267
+ this._drilldownDependenciesManager = new DrilldownDependenciesManager(this._variableDependency);
10238
10268
  }
10239
10269
  onEnable() {
10240
10270
  this.publishEvent(new runtime.RefreshEvent(), true);
@@ -10266,10 +10296,12 @@ class AnnotationsDataLayer extends SceneDataLayerBase {
10266
10296
  this.runWithTimeRange(timeRange);
10267
10297
  }
10268
10298
  async runWithTimeRange(timeRange) {
10299
+ var _a;
10269
10300
  const { query } = this.state;
10270
10301
  if (!query.enable) {
10271
10302
  return;
10272
10303
  }
10304
+ this._drilldownDependenciesManager.findAndSubscribeToDrilldowns((_a = query.datasource) == null ? void 0 : _a.uid);
10273
10305
  if (this.querySub) {
10274
10306
  this.querySub.unsubscribe();
10275
10307
  }
@@ -10279,7 +10311,14 @@ class AnnotationsDataLayer extends SceneDataLayerBase {
10279
10311
  }
10280
10312
  try {
10281
10313
  const ds = await this.resolveDataSource(query);
10282
- let stream = executeAnnotationQuery(ds, timeRange, query, this).pipe(
10314
+ let stream = executeAnnotationQuery(
10315
+ ds,
10316
+ timeRange,
10317
+ query,
10318
+ this,
10319
+ this._drilldownDependenciesManager.getFilters(),
10320
+ this._drilldownDependenciesManager.getGroupByKeys()
10321
+ ).pipe(
10283
10322
  registerQueryWithController({
10284
10323
  type: "AnnotationsDataLayer/annotationsLoading",
10285
10324
  origin: this,