@grafana/scenes 6.32.1--canary.1233.17398013859.0 → 6.33.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.d.ts CHANGED
@@ -1659,6 +1659,7 @@ declare class AnnotationsDataLayer extends SceneDataLayerBase<AnnotationsDataLay
1659
1659
  static Component: typeof AnnotationsDataLayerRenderer;
1660
1660
  private _scopedVars;
1661
1661
  private _timeRangeSub;
1662
+ private _drilldownDependenciesManager;
1662
1663
  constructor(initialState: AnnotationsDataLayerState);
1663
1664
  onEnable(): void;
1664
1665
  onDisable(): void;
@@ -1780,10 +1781,9 @@ declare class SceneQueryRunner extends SceneObjectBase<QueryRunnerState> impleme
1780
1781
  private _scopedVars;
1781
1782
  private _layerAnnotations?;
1782
1783
  private _resultAnnotations?;
1783
- private _adhocFiltersVar?;
1784
- private _groupByVar?;
1785
1784
  getResultsStream(): ReplaySubject<SceneDataProviderResult>;
1786
1785
  protected _variableDependency: VariableDependencyConfig<QueryRunnerState>;
1786
+ private _drilldownDependenciesManager;
1787
1787
  constructor(initialState: QueryRunnerState);
1788
1788
  private _onActivate;
1789
1789
  private _handleDataLayers;
@@ -1828,11 +1828,6 @@ declare class SceneQueryRunner extends SceneObjectBase<QueryRunnerState> impleme
1828
1828
  * This will return an array of the closest provider of each type.
1829
1829
  */
1830
1830
  private getClosestExtraQueryProviders;
1831
- /**
1832
- * Walk up scene graph and find the closest filterset with matching data source
1833
- */
1834
- private findAndSubscribeToAdHocFilters;
1835
- private _updateExplicitVariableDependencies;
1836
1831
  private isQueryModeAuto;
1837
1832
  }
1838
1833
 
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;
@@ -3808,6 +3765,49 @@ function toSelectableValue$1(input) {
3808
3765
  return result;
3809
3766
  }
3810
3767
 
3768
+ let originalGetAdhocFilters = void 0;
3769
+ const allActiveFilterSets = /* @__PURE__ */ new Set();
3770
+ function patchGetAdhocFilters(filterVar) {
3771
+ filterVar.addActivationHandler(() => {
3772
+ allActiveFilterSets.add(filterVar);
3773
+ return () => allActiveFilterSets.delete(filterVar);
3774
+ });
3775
+ if (originalGetAdhocFilters) {
3776
+ return;
3777
+ }
3778
+ const templateSrv = runtime.getTemplateSrv();
3779
+ if (!(templateSrv == null ? void 0 : templateSrv.getAdhocFilters)) {
3780
+ console.log("Failed to patch getAdhocFilters");
3781
+ return;
3782
+ }
3783
+ originalGetAdhocFilters = templateSrv.getAdhocFilters;
3784
+ templateSrv.getAdhocFilters = function getAdhocFiltersScenePatch(dsName) {
3785
+ var _a;
3786
+ if (allActiveFilterSets.size === 0) {
3787
+ return originalGetAdhocFilters.call(templateSrv, dsName);
3788
+ }
3789
+ const ds = runtime.getDataSourceSrv().getInstanceSettings(dsName);
3790
+ if (!ds) {
3791
+ return [];
3792
+ }
3793
+ for (const filter of allActiveFilterSets.values()) {
3794
+ if (((_a = filter.state.datasource) == null ? void 0 : _a.uid) === ds.uid) {
3795
+ return filter.state.filters;
3796
+ }
3797
+ }
3798
+ return [];
3799
+ }.bind(templateSrv);
3800
+ }
3801
+ function findActiveAdHocFilterVariableByUid(dsUid) {
3802
+ var _a;
3803
+ for (const filter of allActiveFilterSets.values()) {
3804
+ if (interpolate(filter, (_a = filter.state.datasource) == null ? void 0 : _a.uid) === dsUid) {
3805
+ return filter;
3806
+ }
3807
+ }
3808
+ return void 0;
3809
+ }
3810
+
3811
3811
  function LoadingIndicator(props) {
3812
3812
  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
3813
  ui.Icon,
@@ -6409,6 +6409,60 @@ function areDifferentLayers(a, b) {
6409
6409
  return false;
6410
6410
  }
6411
6411
 
6412
+ class DrilldownDependenciesManager {
6413
+ constructor(variableDependency) {
6414
+ this._variableDependency = variableDependency;
6415
+ }
6416
+ /**
6417
+ * Walk up scene graph and find the closest filterset with matching data source
6418
+ */
6419
+ findAndSubscribeToDrilldowns(interpolatedUid) {
6420
+ const filtersVar = findActiveAdHocFilterVariableByUid(interpolatedUid);
6421
+ const groupByVar = findActiveGroupByVariablesByUid(interpolatedUid);
6422
+ let hasChanges = false;
6423
+ if (this._adhocFiltersVar !== filtersVar) {
6424
+ this._adhocFiltersVar = filtersVar;
6425
+ hasChanges = true;
6426
+ }
6427
+ if (this._groupByVar !== groupByVar) {
6428
+ this._groupByVar = groupByVar;
6429
+ hasChanges = true;
6430
+ }
6431
+ if (hasChanges) {
6432
+ this._updateExplicitDrilldownVariableDependencies();
6433
+ }
6434
+ }
6435
+ _updateExplicitDrilldownVariableDependencies() {
6436
+ const explicitDependencies = [];
6437
+ if (this._adhocFiltersVar) {
6438
+ explicitDependencies.push(this._adhocFiltersVar.state.name);
6439
+ }
6440
+ if (this._groupByVar) {
6441
+ explicitDependencies.push(this._groupByVar.state.name);
6442
+ }
6443
+ this._variableDependency.setVariableNames(explicitDependencies);
6444
+ }
6445
+ get adHocFiltersVar() {
6446
+ return this._adhocFiltersVar;
6447
+ }
6448
+ get groupByVar() {
6449
+ return this._groupByVar;
6450
+ }
6451
+ getFilters() {
6452
+ var _a;
6453
+ return this._adhocFiltersVar ? [...(_a = this._adhocFiltersVar.state.originFilters) != null ? _a : [], ...this._adhocFiltersVar.state.filters].filter(
6454
+ (f) => isFilterComplete(f) && isFilterApplicable(f)
6455
+ ) : void 0;
6456
+ }
6457
+ getGroupByKeys() {
6458
+ return this._groupByVar ? this._groupByVar.getApplicableKeys() : void 0;
6459
+ }
6460
+ cleanup() {
6461
+ this._adhocFiltersVar = void 0;
6462
+ this._groupByVar = void 0;
6463
+ }
6464
+ }
6465
+
6412
6466
  let counter$1 = 100;
6413
6467
  function getNextRequestId$1() {
6414
6468
  return "SQR" + counter$1++;
@@ -6426,6 +6480,7 @@ class SceneQueryRunner extends SceneObjectBase {
6426
6480
  onAnyVariableChanged: this.onAnyVariableChanged.bind(this),
6427
6481
  dependsOnScopes: true
6428
6482
  });
6483
+ this._drilldownDependenciesManager = new DrilldownDependenciesManager(this._variableDependency);
6429
6484
  this.onDataReceived = (data$1) => {
6430
6485
  const preProcessedData = data.preProcessPanelData(data$1, this.state.data);
6431
6486
  this._resultAnnotations = data$1.annotations;
@@ -6541,7 +6596,7 @@ class SceneQueryRunner extends SceneObjectBase {
6541
6596
  * Check if value changed is a adhoc filter o group by variable that did not exist when we issued the last query
6542
6597
  */
6543
6598
  onAnyVariableChanged(variable) {
6544
- if (this._adhocFiltersVar === variable || this._groupByVar === variable || !this.isQueryModeAuto()) {
6599
+ if (this._drilldownDependenciesManager.adHocFiltersVar === variable || this._drilldownDependenciesManager.groupByVar === variable || !this.isQueryModeAuto()) {
6545
6600
  return;
6546
6601
  }
6547
6602
  if (variable instanceof AdHocFiltersVariable && this._isRelevantAutoVariable(variable)) {
@@ -6595,8 +6650,7 @@ class SceneQueryRunner extends SceneObjectBase {
6595
6650
  (_a = this._timeSub) == null ? void 0 : _a.unsubscribe();
6596
6651
  this._timeSub = void 0;
6597
6652
  this._timeSubRange = void 0;
6598
- this._adhocFiltersVar = void 0;
6599
- this._groupByVar = void 0;
6653
+ this._drilldownDependenciesManager.cleanup();
6600
6654
  }
6601
6655
  setContainerWidth(width) {
6602
6656
  if (!this._containerWidth && width > 0) {
@@ -6677,7 +6731,7 @@ class SceneQueryRunner extends SceneObjectBase {
6677
6731
  try {
6678
6732
  const datasource = (_c = this.state.datasource) != null ? _c : findFirstDatasource(queries);
6679
6733
  const ds = await getDataSource(datasource, this._scopedVars);
6680
- this.findAndSubscribeToAdHocFilters(ds.uid);
6734
+ this._drilldownDependenciesManager.findAndSubscribeToDrilldowns(ds.uid);
6681
6735
  const runRequest = runtime.getRunRequest();
6682
6736
  const { primary, secondaries, processors } = this.prepareRequests(timeRange, ds);
6683
6737
  writeSceneLog("SceneQueryRunner", "Starting runRequest", this.state.key);
@@ -6721,7 +6775,7 @@ class SceneQueryRunner extends SceneObjectBase {
6721
6775
  return clone;
6722
6776
  }
6723
6777
  prepareRequests(timeRange, ds) {
6724
- var _a, _b;
6778
+ var _a;
6725
6779
  const { minInterval, queries } = this.state;
6726
6780
  let request = {
6727
6781
  app: "scenes",
@@ -6745,14 +6799,13 @@ class SceneQueryRunner extends SceneObjectBase {
6745
6799
  // This asks the scene root to provide context properties like app, panel and dashboardUID
6746
6800
  ...getEnrichedDataRequest(this)
6747
6801
  };
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));
6802
+ const filters = this._drilldownDependenciesManager.getFilters();
6803
+ const groupByKeys = this._drilldownDependenciesManager.getGroupByKeys();
6804
+ if (filters) {
6805
+ request.filters = filters;
6753
6806
  }
6754
- if (this._groupByVar) {
6755
- request.groupByKeys = this._groupByVar.getApplicableKeys();
6807
+ if (groupByKeys) {
6808
+ request.groupByKeys = groupByKeys;
6756
6809
  }
6757
6810
  request.targets = request.targets.map((query) => {
6758
6811
  var _a2;
@@ -6772,7 +6825,7 @@ class SceneQueryRunner extends SceneObjectBase {
6772
6825
  const primaryTimeRange = timeRange.state.value;
6773
6826
  let secondaryRequests = [];
6774
6827
  let secondaryProcessors = /* @__PURE__ */ new Map();
6775
- for (const provider of (_b = this.getClosestExtraQueryProviders()) != null ? _b : []) {
6828
+ for (const provider of (_a = this.getClosestExtraQueryProviders()) != null ? _a : []) {
6776
6829
  for (const { req, processor } of provider.getExtraQueries(request)) {
6777
6830
  const requestId = getNextRequestId$1();
6778
6831
  secondaryRequests.push({ ...req, requestId });
@@ -6819,31 +6872,6 @@ class SceneQueryRunner extends SceneObjectBase {
6819
6872
  });
6820
6873
  return Array.from(found.values());
6821
6874
  }
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
6875
  isQueryModeAuto() {
6848
6876
  var _a;
6849
6877
  return ((_a = this.state.runQueriesMode) != null ? _a : "auto") === "auto";
@@ -9797,7 +9825,7 @@ let counter = 100;
9797
9825
  function getNextRequestId() {
9798
9826
  return "AQ" + counter++;
9799
9827
  }
9800
- function executeAnnotationQuery(datasource, timeRange, query, layer) {
9828
+ function executeAnnotationQuery(datasource, timeRange, query, layer, filters, groupByKeys) {
9801
9829
  var _a;
9802
9830
  if (datasource.annotationQuery && shouldUseLegacyRunner(datasource)) {
9803
9831
  console.warn("Using deprecated annotationQuery method, please upgrade your datasource");
@@ -9864,6 +9892,8 @@ function executeAnnotationQuery(datasource, timeRange, query, layer) {
9864
9892
  }
9865
9893
  ],
9866
9894
  scopes: sceneGraph.getScopes(layer),
9895
+ filters,
9896
+ groupByKeys,
9867
9897
  ...getEnrichedDataRequest(layer)
9868
9898
  };
9869
9899
  const runRequest = runtime.getRunRequest();
@@ -9962,6 +9992,7 @@ class AnnotationsDataLayer extends SceneDataLayerBase {
9962
9992
  this._scopedVars = {
9963
9993
  __sceneObject: wrapInSafeSerializableSceneObject(this)
9964
9994
  };
9995
+ this._drilldownDependenciesManager = new DrilldownDependenciesManager(this._variableDependency);
9965
9996
  }
9966
9997
  onEnable() {
9967
9998
  this.publishEvent(new runtime.RefreshEvent(), true);
@@ -9993,10 +10024,12 @@ class AnnotationsDataLayer extends SceneDataLayerBase {
9993
10024
  this.runWithTimeRange(timeRange);
9994
10025
  }
9995
10026
  async runWithTimeRange(timeRange) {
10027
+ var _a;
9996
10028
  const { query } = this.state;
9997
10029
  if (!query.enable) {
9998
10030
  return;
9999
10031
  }
10032
+ this._drilldownDependenciesManager.findAndSubscribeToDrilldowns((_a = query.datasource) == null ? void 0 : _a.uid);
10000
10033
  if (this.querySub) {
10001
10034
  this.querySub.unsubscribe();
10002
10035
  }
@@ -10006,7 +10039,14 @@ class AnnotationsDataLayer extends SceneDataLayerBase {
10006
10039
  }
10007
10040
  try {
10008
10041
  const ds = await this.resolveDataSource(query);
10009
- let stream = executeAnnotationQuery(ds, timeRange, query, this).pipe(
10042
+ let stream = executeAnnotationQuery(
10043
+ ds,
10044
+ timeRange,
10045
+ query,
10046
+ this,
10047
+ this._drilldownDependenciesManager.getFilters(),
10048
+ this._drilldownDependenciesManager.getGroupByKeys()
10049
+ ).pipe(
10010
10050
  registerQueryWithController({
10011
10051
  type: "AnnotationsDataLayer/annotationsLoading",
10012
10052
  origin: this,