@grafana/scenes 6.32.1--canary.1233.17382026725.0 → 6.33.0--canary.1232.17398095824.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
@@ -2868,49 +2868,6 @@ function getEnrichedDataRequest(sourceRunner) {
2868
2868
  return null;
2869
2869
  }
2870
2870
 
2871
- let originalGetAdhocFilters = void 0;
2872
- let allActiveFilterSets = /* @__PURE__ */ new Set();
2873
- function patchGetAdhocFilters(filterVar) {
2874
- filterVar.addActivationHandler(() => {
2875
- allActiveFilterSets.add(filterVar);
2876
- return () => allActiveFilterSets.delete(filterVar);
2877
- });
2878
- if (originalGetAdhocFilters) {
2879
- return;
2880
- }
2881
- const templateSrv = runtime.getTemplateSrv();
2882
- if (!(templateSrv == null ? void 0 : templateSrv.getAdhocFilters)) {
2883
- console.log("Failed to patch getAdhocFilters");
2884
- return;
2885
- }
2886
- originalGetAdhocFilters = templateSrv.getAdhocFilters;
2887
- templateSrv.getAdhocFilters = function getAdhocFiltersScenePatch(dsName) {
2888
- var _a;
2889
- if (allActiveFilterSets.size === 0) {
2890
- return originalGetAdhocFilters.call(templateSrv, dsName);
2891
- }
2892
- const ds = runtime.getDataSourceSrv().getInstanceSettings(dsName);
2893
- if (!ds) {
2894
- return [];
2895
- }
2896
- for (const filter of allActiveFilterSets.values()) {
2897
- if (((_a = filter.state.datasource) == null ? void 0 : _a.uid) === ds.uid) {
2898
- return filter.state.filters;
2899
- }
2900
- }
2901
- return [];
2902
- }.bind(templateSrv);
2903
- }
2904
- function findActiveAdHocFilterVariableByUid(dsUid) {
2905
- var _a;
2906
- for (const filter of allActiveFilterSets.values()) {
2907
- if (interpolate(filter, (_a = filter.state.datasource) == null ? void 0 : _a.uid) === dsUid) {
2908
- return filter;
2909
- }
2910
- }
2911
- return void 0;
2912
- }
2913
-
2914
2871
  const allActiveGroupByVariables = /* @__PURE__ */ new Set();
2915
2872
  function findActiveGroupByVariablesByUid(dsUid) {
2916
2873
  var _a;
@@ -3579,13 +3536,13 @@ class GroupByVariable extends MultiValueVariable {
3579
3536
  const ds = await getDataSource(this.state.datasource, {
3580
3537
  __sceneObject: wrapInSafeSerializableSceneObject(this)
3581
3538
  });
3582
- if (!ds.getDrilldownsApplicability) {
3539
+ if (!ds.getFiltersApplicability) {
3583
3540
  return;
3584
3541
  }
3585
3542
  const queries = getQueriesForVariables(this);
3586
3543
  const timeRange = sceneGraph.getTimeRange(this).state.value;
3587
3544
  const value = this.state.value;
3588
- const response = await ds.getDrilldownsApplicability({
3545
+ const response = await ds.getFiltersApplicability({
3589
3546
  groupByKeys: Array.isArray(value) ? value.map((v) => String(v)) : value ? [String(value)] : [],
3590
3547
  queries,
3591
3548
  timeRange,
@@ -3722,11 +3679,12 @@ function GroupByVariableRenderer({ model }) {
3722
3679
  if (restorable !== model.state.restorable) {
3723
3680
  model.setState({ restorable });
3724
3681
  }
3725
- model._verifyApplicability();
3726
3682
  },
3727
3683
  onChange: (newValue, action) => {
3728
3684
  if (action.action === "clear" && noValueOnClear) {
3729
3685
  model.changeValueTo([], void 0, true);
3686
+ } else {
3687
+ model._verifyApplicability();
3730
3688
  }
3731
3689
  setUncommittedValue(newValue);
3732
3690
  },
@@ -3808,6 +3766,49 @@ function toSelectableValue$1(input) {
3808
3766
  return result;
3809
3767
  }
3810
3768
 
3769
+ let originalGetAdhocFilters = void 0;
3770
+ const allActiveFilterSets = /* @__PURE__ */ new Set();
3771
+ function patchGetAdhocFilters(filterVar) {
3772
+ filterVar.addActivationHandler(() => {
3773
+ allActiveFilterSets.add(filterVar);
3774
+ return () => allActiveFilterSets.delete(filterVar);
3775
+ });
3776
+ if (originalGetAdhocFilters) {
3777
+ return;
3778
+ }
3779
+ const templateSrv = runtime.getTemplateSrv();
3780
+ if (!(templateSrv == null ? void 0 : templateSrv.getAdhocFilters)) {
3781
+ console.log("Failed to patch getAdhocFilters");
3782
+ return;
3783
+ }
3784
+ originalGetAdhocFilters = templateSrv.getAdhocFilters;
3785
+ templateSrv.getAdhocFilters = function getAdhocFiltersScenePatch(dsName) {
3786
+ var _a;
3787
+ if (allActiveFilterSets.size === 0) {
3788
+ return originalGetAdhocFilters.call(templateSrv, dsName);
3789
+ }
3790
+ const ds = runtime.getDataSourceSrv().getInstanceSettings(dsName);
3791
+ if (!ds) {
3792
+ return [];
3793
+ }
3794
+ for (const filter of allActiveFilterSets.values()) {
3795
+ if (((_a = filter.state.datasource) == null ? void 0 : _a.uid) === ds.uid) {
3796
+ return filter.state.filters;
3797
+ }
3798
+ }
3799
+ return [];
3800
+ }.bind(templateSrv);
3801
+ }
3802
+ function findActiveAdHocFilterVariableByUid(dsUid) {
3803
+ var _a;
3804
+ for (const filter of allActiveFilterSets.values()) {
3805
+ if (interpolate(filter, (_a = filter.state.datasource) == null ? void 0 : _a.uid) === dsUid) {
3806
+ return filter;
3807
+ }
3808
+ }
3809
+ return void 0;
3810
+ }
3811
+
3811
3812
  function LoadingIndicator(props) {
3812
3813
  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(
3813
3814
  ui.Icon,
@@ -6158,7 +6159,7 @@ class AdHocFiltersVariable extends SceneObjectBase {
6158
6159
  var _a, _b, _c;
6159
6160
  const filters = [...this.state.filters, ...(_a = this.state.originFilters) != null ? _a : []];
6160
6161
  const ds = await this._dataSourceSrv.get(this.state.datasource, this._scopedVars);
6161
- if (!ds || !ds.getDrilldownsApplicability) {
6162
+ if (!ds || !ds.getFiltersApplicability) {
6162
6163
  return;
6163
6164
  }
6164
6165
  if (!filters) {
@@ -6166,7 +6167,7 @@ class AdHocFiltersVariable extends SceneObjectBase {
6166
6167
  }
6167
6168
  const timeRange = sceneGraph.getTimeRange(this).state.value;
6168
6169
  const queries = this.state.useQueriesAsFilterForOptions ? getQueriesForVariables(this) : void 0;
6169
- const response = await ds.getDrilldownsApplicability({
6170
+ const response = await ds.getFiltersApplicability({
6170
6171
  filters,
6171
6172
  queries,
6172
6173
  timeRange,
@@ -6409,6 +6410,60 @@ function areDifferentLayers(a, b) {
6409
6410
  return false;
6410
6411
  }
6411
6412
 
6413
+ class DrilldownDependenciesManager {
6414
+ constructor(variableDependency) {
6415
+ this._variableDependency = variableDependency;
6416
+ }
6417
+ /**
6418
+ * Walk up scene graph and find the closest filterset with matching data source
6419
+ */
6420
+ findAndSubscribeToDrilldowns(interpolatedUid) {
6421
+ const filtersVar = findActiveAdHocFilterVariableByUid(interpolatedUid);
6422
+ const groupByVar = findActiveGroupByVariablesByUid(interpolatedUid);
6423
+ let hasChanges = false;
6424
+ if (this._adhocFiltersVar !== filtersVar) {
6425
+ this._adhocFiltersVar = filtersVar;
6426
+ hasChanges = true;
6427
+ }
6428
+ if (this._groupByVar !== groupByVar) {
6429
+ this._groupByVar = groupByVar;
6430
+ hasChanges = true;
6431
+ }
6432
+ if (hasChanges) {
6433
+ this._updateExplicitDrilldownVariableDependencies();
6434
+ }
6435
+ }
6436
+ _updateExplicitDrilldownVariableDependencies() {
6437
+ const explicitDependencies = [];
6438
+ if (this._adhocFiltersVar) {
6439
+ explicitDependencies.push(this._adhocFiltersVar.state.name);
6440
+ }
6441
+ if (this._groupByVar) {
6442
+ explicitDependencies.push(this._groupByVar.state.name);
6443
+ }
6444
+ this._variableDependency.setVariableNames(explicitDependencies);
6445
+ }
6446
+ get adHocFiltersVar() {
6447
+ return this._adhocFiltersVar;
6448
+ }
6449
+ get groupByVar() {
6450
+ return this._groupByVar;
6451
+ }
6452
+ getFilters() {
6453
+ var _a;
6454
+ return this._adhocFiltersVar ? [...(_a = this._adhocFiltersVar.state.originFilters) != null ? _a : [], ...this._adhocFiltersVar.state.filters].filter(
6455
+ (f) => isFilterComplete(f) && isFilterApplicable(f)
6456
+ ) : void 0;
6457
+ }
6458
+ getGroupByKeys() {
6459
+ return this._groupByVar ? this._groupByVar.getApplicableKeys() : void 0;
6460
+ }
6461
+ cleanup() {
6462
+ this._adhocFiltersVar = void 0;
6463
+ this._groupByVar = void 0;
6464
+ }
6465
+ }
6466
+
6412
6467
  let counter$1 = 100;
6413
6468
  function getNextRequestId$1() {
6414
6469
  return "SQR" + counter$1++;
@@ -6426,6 +6481,7 @@ class SceneQueryRunner extends SceneObjectBase {
6426
6481
  onAnyVariableChanged: this.onAnyVariableChanged.bind(this),
6427
6482
  dependsOnScopes: true
6428
6483
  });
6484
+ this._drilldownDependenciesManager = new DrilldownDependenciesManager(this._variableDependency);
6429
6485
  this.onDataReceived = (data$1) => {
6430
6486
  const preProcessedData = data.preProcessPanelData(data$1, this.state.data);
6431
6487
  this._resultAnnotations = data$1.annotations;
@@ -6541,7 +6597,7 @@ class SceneQueryRunner extends SceneObjectBase {
6541
6597
  * Check if value changed is a adhoc filter o group by variable that did not exist when we issued the last query
6542
6598
  */
6543
6599
  onAnyVariableChanged(variable) {
6544
- if (this._adhocFiltersVar === variable || this._groupByVar === variable || !this.isQueryModeAuto()) {
6600
+ if (this._drilldownDependenciesManager.adHocFiltersVar === variable || this._drilldownDependenciesManager.groupByVar === variable || !this.isQueryModeAuto()) {
6545
6601
  return;
6546
6602
  }
6547
6603
  if (variable instanceof AdHocFiltersVariable && this._isRelevantAutoVariable(variable)) {
@@ -6595,8 +6651,7 @@ class SceneQueryRunner extends SceneObjectBase {
6595
6651
  (_a = this._timeSub) == null ? void 0 : _a.unsubscribe();
6596
6652
  this._timeSub = void 0;
6597
6653
  this._timeSubRange = void 0;
6598
- this._adhocFiltersVar = void 0;
6599
- this._groupByVar = void 0;
6654
+ this._drilldownDependenciesManager.cleanup();
6600
6655
  }
6601
6656
  setContainerWidth(width) {
6602
6657
  if (!this._containerWidth && width > 0) {
@@ -6677,7 +6732,7 @@ class SceneQueryRunner extends SceneObjectBase {
6677
6732
  try {
6678
6733
  const datasource = (_c = this.state.datasource) != null ? _c : findFirstDatasource(queries);
6679
6734
  const ds = await getDataSource(datasource, this._scopedVars);
6680
- this.findAndSubscribeToAdHocFilters(ds.uid);
6735
+ this._drilldownDependenciesManager.findAndSubscribeToDrilldowns(ds.uid);
6681
6736
  const runRequest = runtime.getRunRequest();
6682
6737
  const { primary, secondaries, processors } = this.prepareRequests(timeRange, ds);
6683
6738
  writeSceneLog("SceneQueryRunner", "Starting runRequest", this.state.key);
@@ -6721,7 +6776,7 @@ class SceneQueryRunner extends SceneObjectBase {
6721
6776
  return clone;
6722
6777
  }
6723
6778
  prepareRequests(timeRange, ds) {
6724
- var _a, _b;
6779
+ var _a;
6725
6780
  const { minInterval, queries } = this.state;
6726
6781
  let request = {
6727
6782
  app: "scenes",
@@ -6745,14 +6800,13 @@ class SceneQueryRunner extends SceneObjectBase {
6745
6800
  // This asks the scene root to provide context properties like app, panel and dashboardUID
6746
6801
  ...getEnrichedDataRequest(this)
6747
6802
  };
6748
- if (this._adhocFiltersVar) {
6749
- request.filters = [
6750
- ...(_a = this._adhocFiltersVar.state.originFilters) != null ? _a : [],
6751
- ...this._adhocFiltersVar.state.filters
6752
- ].filter((f) => isFilterComplete(f) && isFilterApplicable(f));
6803
+ const filters = this._drilldownDependenciesManager.getFilters();
6804
+ const groupByKeys = this._drilldownDependenciesManager.getGroupByKeys();
6805
+ if (filters) {
6806
+ request.filters = filters;
6753
6807
  }
6754
- if (this._groupByVar) {
6755
- request.groupByKeys = this._groupByVar.getApplicableKeys();
6808
+ if (groupByKeys) {
6809
+ request.groupByKeys = groupByKeys;
6756
6810
  }
6757
6811
  request.targets = request.targets.map((query) => {
6758
6812
  var _a2;
@@ -6772,7 +6826,7 @@ class SceneQueryRunner extends SceneObjectBase {
6772
6826
  const primaryTimeRange = timeRange.state.value;
6773
6827
  let secondaryRequests = [];
6774
6828
  let secondaryProcessors = /* @__PURE__ */ new Map();
6775
- for (const provider of (_b = this.getClosestExtraQueryProviders()) != null ? _b : []) {
6829
+ for (const provider of (_a = this.getClosestExtraQueryProviders()) != null ? _a : []) {
6776
6830
  for (const { req, processor } of provider.getExtraQueries(request)) {
6777
6831
  const requestId = getNextRequestId$1();
6778
6832
  secondaryRequests.push({ ...req, requestId });
@@ -6819,31 +6873,6 @@ class SceneQueryRunner extends SceneObjectBase {
6819
6873
  });
6820
6874
  return Array.from(found.values());
6821
6875
  }
6822
- /**
6823
- * Walk up scene graph and find the closest filterset with matching data source
6824
- */
6825
- findAndSubscribeToAdHocFilters(interpolatedUid) {
6826
- const filtersVar = findActiveAdHocFilterVariableByUid(interpolatedUid);
6827
- if (this._adhocFiltersVar !== filtersVar) {
6828
- this._adhocFiltersVar = filtersVar;
6829
- this._updateExplicitVariableDependencies();
6830
- }
6831
- const groupByVar = findActiveGroupByVariablesByUid(interpolatedUid);
6832
- if (this._groupByVar !== groupByVar) {
6833
- this._groupByVar = groupByVar;
6834
- this._updateExplicitVariableDependencies();
6835
- }
6836
- }
6837
- _updateExplicitVariableDependencies() {
6838
- const explicitDependencies = [];
6839
- if (this._adhocFiltersVar) {
6840
- explicitDependencies.push(this._adhocFiltersVar.state.name);
6841
- }
6842
- if (this._groupByVar) {
6843
- explicitDependencies.push(this._groupByVar.state.name);
6844
- }
6845
- this._variableDependency.setVariableNames(explicitDependencies);
6846
- }
6847
6876
  isQueryModeAuto() {
6848
6877
  var _a;
6849
6878
  return ((_a = this.state.runQueriesMode) != null ? _a : "auto") === "auto";
@@ -9797,7 +9826,7 @@ let counter = 100;
9797
9826
  function getNextRequestId() {
9798
9827
  return "AQ" + counter++;
9799
9828
  }
9800
- function executeAnnotationQuery(datasource, timeRange, query, layer) {
9829
+ function executeAnnotationQuery(datasource, timeRange, query, layer, filters, groupByKeys) {
9801
9830
  var _a;
9802
9831
  if (datasource.annotationQuery && shouldUseLegacyRunner(datasource)) {
9803
9832
  console.warn("Using deprecated annotationQuery method, please upgrade your datasource");
@@ -9864,6 +9893,8 @@ function executeAnnotationQuery(datasource, timeRange, query, layer) {
9864
9893
  }
9865
9894
  ],
9866
9895
  scopes: sceneGraph.getScopes(layer),
9896
+ filters,
9897
+ groupByKeys,
9867
9898
  ...getEnrichedDataRequest(layer)
9868
9899
  };
9869
9900
  const runRequest = runtime.getRunRequest();
@@ -9962,6 +9993,7 @@ class AnnotationsDataLayer extends SceneDataLayerBase {
9962
9993
  this._scopedVars = {
9963
9994
  __sceneObject: wrapInSafeSerializableSceneObject(this)
9964
9995
  };
9996
+ this._drilldownDependenciesManager = new DrilldownDependenciesManager(this._variableDependency);
9965
9997
  }
9966
9998
  onEnable() {
9967
9999
  this.publishEvent(new runtime.RefreshEvent(), true);
@@ -9993,10 +10025,12 @@ class AnnotationsDataLayer extends SceneDataLayerBase {
9993
10025
  this.runWithTimeRange(timeRange);
9994
10026
  }
9995
10027
  async runWithTimeRange(timeRange) {
10028
+ var _a;
9996
10029
  const { query } = this.state;
9997
10030
  if (!query.enable) {
9998
10031
  return;
9999
10032
  }
10033
+ this._drilldownDependenciesManager.findAndSubscribeToDrilldowns((_a = query.datasource) == null ? void 0 : _a.uid);
10000
10034
  if (this.querySub) {
10001
10035
  this.querySub.unsubscribe();
10002
10036
  }
@@ -10006,7 +10040,14 @@ class AnnotationsDataLayer extends SceneDataLayerBase {
10006
10040
  }
10007
10041
  try {
10008
10042
  const ds = await this.resolveDataSource(query);
10009
- let stream = executeAnnotationQuery(ds, timeRange, query, this).pipe(
10043
+ let stream = executeAnnotationQuery(
10044
+ ds,
10045
+ timeRange,
10046
+ query,
10047
+ this,
10048
+ this._drilldownDependenciesManager.getFilters(),
10049
+ this._drilldownDependenciesManager.getGroupByKeys()
10050
+ ).pipe(
10010
10051
  registerQueryWithController({
10011
10052
  type: "AnnotationsDataLayer/annotationsLoading",
10012
10053
  origin: this,