@grafana/scenes 4.17.2--canary.723.8999827741.0 → 4.18.0--canary.724.9001989710.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
@@ -3325,7 +3325,6 @@ function AdHocFilterRenderer({ filter, model }) {
3325
3325
  const valueValue = keyLabelToOption(filter.value, filter.valueLabel);
3326
3326
  const valueSelect = /* @__PURE__ */ React__default["default"].createElement(ui.Select, {
3327
3327
  allowCustomValue: true,
3328
- isValidNewOption: (inputValue) => inputValue.trim().length > 0,
3329
3328
  allowCreateWhileLoading: true,
3330
3329
  formatCreateLabel: (inputValue) => `Use custom value: ${inputValue}`,
3331
3330
  disabled: model.state.readOnly,
@@ -3746,23 +3745,46 @@ function toSelectableValue({ text, value }) {
3746
3745
  };
3747
3746
  }
3748
3747
 
3749
- function mergeMultipleDataLayers(layers) {
3750
- const resultStreams = layers.map((l) => l.getResultsStream());
3751
- const resultsMap = /* @__PURE__ */ new Map();
3752
- const deactivationHandlers = [];
3753
- for (const layer of layers) {
3754
- deactivationHandlers.push(layer.activate());
3748
+ class DataLayersMerger {
3749
+ constructor() {
3750
+ this._resultsMap = /* @__PURE__ */ new Map();
3751
+ this._prevLayers = [];
3752
+ }
3753
+ getMergedStream(layers) {
3754
+ if (areDifferentLayers(layers, this._prevLayers)) {
3755
+ this._resultsMap = /* @__PURE__ */ new Map();
3756
+ this._prevLayers = layers;
3757
+ }
3758
+ const resultStreams = layers.map((l) => l.getResultsStream());
3759
+ const deactivationHandlers = [];
3760
+ for (const layer of layers) {
3761
+ deactivationHandlers.push(layer.activate());
3762
+ }
3763
+ return rxjs.merge(resultStreams).pipe(
3764
+ rxjs.mergeAll(),
3765
+ rxjs.filter((v) => {
3766
+ return this._resultsMap.get(v.origin.state.key) !== v;
3767
+ }),
3768
+ rxjs.map((v) => {
3769
+ this._resultsMap.set(v.origin.state.key, v);
3770
+ return this._resultsMap.values();
3771
+ }),
3772
+ rxjs.finalize(() => {
3773
+ deactivationHandlers.forEach((handler) => handler());
3774
+ })
3775
+ );
3755
3776
  }
3756
- return rxjs.merge(resultStreams).pipe(
3757
- rxjs.mergeAll(),
3758
- rxjs.map((v) => {
3759
- resultsMap.set(v.origin.state.key, v);
3760
- return resultsMap.values();
3761
- }),
3762
- rxjs.finalize(() => {
3763
- deactivationHandlers.forEach((handler) => handler());
3764
- })
3765
- );
3777
+ }
3778
+ function areDifferentLayers(a, b) {
3779
+ if (a.length !== b.length) {
3780
+ return true;
3781
+ }
3782
+ for (let i = 0; i < a.length; i++) {
3783
+ if (a[i] !== b[i]) {
3784
+ return true;
3785
+ }
3786
+ }
3787
+ return false;
3766
3788
  }
3767
3789
 
3768
3790
  var __defProp$w = Object.defineProperty;
@@ -3791,6 +3813,7 @@ function getNextRequestId$1() {
3791
3813
  class SceneQueryRunner extends SceneObjectBase {
3792
3814
  constructor(initialState) {
3793
3815
  super(initialState);
3816
+ this._dataLayersMerger = new DataLayersMerger();
3794
3817
  this._variableValueRecorder = new VariableValueRecorder();
3795
3818
  this._results = new rxjs.ReplaySubject(1);
3796
3819
  this._scopedVars = { __sceneObject: { value: this, text: "__sceneObject" } };
@@ -3905,10 +3928,10 @@ class SceneQueryRunner extends SceneObjectBase {
3905
3928
  if (dataLayers.length === 0) {
3906
3929
  return;
3907
3930
  }
3908
- this._dataLayersSub = mergeMultipleDataLayers(dataLayers).subscribe(this._onLayersReceived.bind(this));
3931
+ this._dataLayersSub = this._dataLayersMerger.getMergedStream(dataLayers).subscribe(this._onLayersReceived.bind(this));
3909
3932
  }
3910
3933
  _onLayersReceived(results) {
3911
- var _a, _b, _c, _d;
3934
+ var _a, _b, _c, _d, _e;
3912
3935
  const timeRange = sceneGraph.getTimeRange(this);
3913
3936
  const { dataLayerFilter } = this.state;
3914
3937
  let annotations = [];
@@ -3940,12 +3963,15 @@ class SceneQueryRunner extends SceneObjectBase {
3940
3963
  }
3941
3964
  }
3942
3965
  }
3943
- const baseStateUpdate = this.state.data ? this.state.data : __spreadProps$k(__spreadValues$w({}, emptyPanelData), { timeRange: timeRange.state.value });
3966
+ if (alertState === ((_c = this.state.data) == null ? void 0 : _c.alertState) && allFramesEmpty(annotations) && allFramesEmpty(this._layerAnnotations)) {
3967
+ return;
3968
+ }
3944
3969
  this._layerAnnotations = annotations;
3970
+ const baseStateUpdate = this.state.data ? this.state.data : __spreadProps$k(__spreadValues$w({}, emptyPanelData), { timeRange: timeRange.state.value });
3945
3971
  this.setState({
3946
3972
  data: __spreadProps$k(__spreadValues$w({}, baseStateUpdate), {
3947
- annotations: [...(_c = this._resultAnnotations) != null ? _c : [], ...annotations],
3948
- alertState: alertState != null ? alertState : (_d = this.state.data) == null ? void 0 : _d.alertState
3973
+ annotations: [...(_d = this._resultAnnotations) != null ? _d : [], ...annotations],
3974
+ alertState: alertState != null ? alertState : (_e = this.state.data) == null ? void 0 : _e.alertState
3949
3975
  })
3950
3976
  });
3951
3977
  }
@@ -4181,6 +4207,17 @@ function findFirstDatasource(targets) {
4181
4207
  var _a, _b;
4182
4208
  return (_b = (_a = targets.find((t) => t.datasource !== null)) == null ? void 0 : _a.datasource) != null ? _b : void 0;
4183
4209
  }
4210
+ function allFramesEmpty(frames) {
4211
+ if (!frames) {
4212
+ return true;
4213
+ }
4214
+ for (let i = 0; i < frames.length; i++) {
4215
+ if (frames[i].length > 0) {
4216
+ return false;
4217
+ }
4218
+ }
4219
+ return true;
4220
+ }
4184
4221
 
4185
4222
  function isVariableValueEqual(a, b) {
4186
4223
  if (a === b) {
@@ -5249,7 +5286,7 @@ class SceneDataLayerBase extends SceneObjectBase {
5249
5286
  super(__spreadValues$r({
5250
5287
  isEnabled: true
5251
5288
  }, initialState));
5252
- this._results = new rxjs.ReplaySubject();
5289
+ this._results = new rxjs.ReplaySubject(1);
5253
5290
  this.isDataLayer = true;
5254
5291
  this._variableValueRecorder = new VariableValueRecorder();
5255
5292
  this._variableDependency = new VariableDependencyConfig(this, {
@@ -5973,11 +6010,12 @@ class SceneDataLayerSetBase extends SceneObjectBase {
5973
6010
  constructor() {
5974
6011
  super(...arguments);
5975
6012
  this.isDataLayer = true;
5976
- this._results = new rxjs.ReplaySubject();
6013
+ this._results = new rxjs.ReplaySubject(1);
6014
+ this._dataLayersMerger = new DataLayersMerger();
5977
6015
  }
5978
6016
  subscribeToAllLayers(layers) {
5979
6017
  if (layers.length > 0) {
5980
- this.querySub = mergeMultipleDataLayers(layers).subscribe(this._onLayerUpdateReceived.bind(this));
6018
+ this.querySub = this._dataLayersMerger.getMergedStream(layers).subscribe(this._onLayerUpdateReceived.bind(this));
5981
6019
  } else {
5982
6020
  this._results.next({ origin: this, data: emptyPanelData });
5983
6021
  this.setStateHelper({ data: emptyPanelData });