@grafana/scenes 6.26.1--canary.1173.15996686844.0 → 6.26.1

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
@@ -8378,253 +8378,6 @@ const createProperty = (color) => {
8378
8378
  };
8379
8379
  };
8380
8380
 
8381
- class SceneDataLayerSetBase extends SceneObjectBase {
8382
- constructor() {
8383
- super(...arguments);
8384
- /** Mark it as a data layer */
8385
- this.isDataLayer = true;
8386
- /**
8387
- * Subject to emit results to.
8388
- */
8389
- this._results = new rxjs.ReplaySubject(1);
8390
- this._dataLayersMerger = new DataLayersMerger();
8391
- }
8392
- subscribeToAllLayers(layers) {
8393
- if (layers.length > 0) {
8394
- this.querySub = this._dataLayersMerger.getMergedStream(layers).subscribe(this._onLayerUpdateReceived.bind(this));
8395
- } else {
8396
- this._results.next({ origin: this, data: emptyPanelData });
8397
- this.setStateHelper({ data: emptyPanelData });
8398
- }
8399
- }
8400
- _onLayerUpdateReceived(results) {
8401
- var _a;
8402
- let series = [];
8403
- for (const result of results) {
8404
- if ((_a = result.data) == null ? void 0 : _a.series) {
8405
- series = series.concat(result.data.series);
8406
- }
8407
- }
8408
- const combinedData = { ...emptyPanelData, series };
8409
- this._results.next({ origin: this, data: combinedData });
8410
- this.setStateHelper({ data: combinedData });
8411
- }
8412
- getResultsStream() {
8413
- return this._results;
8414
- }
8415
- cancelQuery() {
8416
- var _a;
8417
- (_a = this.querySub) == null ? void 0 : _a.unsubscribe();
8418
- }
8419
- /**
8420
- * This helper function is to counter the contravariance of setState
8421
- */
8422
- setStateHelper(state) {
8423
- setBaseClassState(this, state);
8424
- }
8425
- }
8426
- class SceneDataLayerSet extends SceneDataLayerSetBase {
8427
- constructor(state) {
8428
- var _a, _b;
8429
- super({
8430
- name: (_a = state.name) != null ? _a : "Data layers",
8431
- layers: (_b = state.layers) != null ? _b : []
8432
- });
8433
- this.addActivationHandler(() => this._onActivate());
8434
- }
8435
- _onActivate() {
8436
- this._subs.add(
8437
- this.subscribeToState((newState, oldState) => {
8438
- var _a;
8439
- if (newState.layers !== oldState.layers) {
8440
- (_a = this.querySub) == null ? void 0 : _a.unsubscribe();
8441
- this.subscribeToAllLayers(newState.layers);
8442
- }
8443
- })
8444
- );
8445
- this.subscribeToAllLayers(this.state.layers);
8446
- return () => {
8447
- var _a;
8448
- (_a = this.querySub) == null ? void 0 : _a.unsubscribe();
8449
- };
8450
- }
8451
- }
8452
- SceneDataLayerSet.Component = ({ model }) => {
8453
- const { layers } = model.useState();
8454
- return /* @__PURE__ */ React__default.default.createElement(React__default.default.Fragment, null, layers.map((layer) => /* @__PURE__ */ React__default.default.createElement(layer.Component, { model: layer, key: layer.state.key })));
8455
- };
8456
-
8457
- class SceneDataTransformer extends SceneObjectBase {
8458
- constructor(state) {
8459
- super(state);
8460
- this._results = new rxjs.ReplaySubject(1);
8461
- /**
8462
- * Scan transformations for variable usage and re-process transforms when a variable values change
8463
- */
8464
- this._variableDependency = new VariableDependencyConfig(
8465
- this,
8466
- {
8467
- statePaths: ["transformations"],
8468
- onReferencedVariableValueChanged: () => this.reprocessTransformations()
8469
- }
8470
- );
8471
- this.addActivationHandler(() => this.activationHandler());
8472
- }
8473
- activationHandler() {
8474
- const sourceData = this.getSourceData();
8475
- this._subs.add(sourceData.subscribeToState((state) => this.transform(state.data)));
8476
- if (sourceData.state.data) {
8477
- this.transform(sourceData.state.data);
8478
- }
8479
- return () => {
8480
- if (this._transformSub) {
8481
- this._transformSub.unsubscribe();
8482
- }
8483
- };
8484
- }
8485
- getSourceData() {
8486
- if (this.state.$data) {
8487
- if (this.state.$data instanceof SceneDataLayerSet) {
8488
- throw new Error("SceneDataLayerSet can not be used as data provider for SceneDataTransformer.");
8489
- }
8490
- return this.state.$data;
8491
- }
8492
- if (!this.parent || !this.parent.parent) {
8493
- throw new Error("SceneDataTransformer must either have $data set on it or have a parent.parent with $data");
8494
- }
8495
- return sceneGraph.getData(this.parent.parent);
8496
- }
8497
- setContainerWidth(width) {
8498
- if (this.state.$data && this.state.$data.setContainerWidth) {
8499
- this.state.$data.setContainerWidth(width);
8500
- }
8501
- }
8502
- isDataReadyToDisplay() {
8503
- const dataObject = this.getSourceData();
8504
- if (dataObject.isDataReadyToDisplay) {
8505
- return dataObject.isDataReadyToDisplay();
8506
- }
8507
- return true;
8508
- }
8509
- reprocessTransformations() {
8510
- this.transform(this.getSourceData().state.data, true);
8511
- }
8512
- cancelQuery() {
8513
- var _a, _b;
8514
- (_b = (_a = this.getSourceData()).cancelQuery) == null ? void 0 : _b.call(_a);
8515
- }
8516
- getResultsStream() {
8517
- return this._results;
8518
- }
8519
- clone(withState) {
8520
- const clone = super.clone(withState);
8521
- if (this._prevDataFromSource) {
8522
- clone["_prevDataFromSource"] = this._prevDataFromSource;
8523
- }
8524
- return clone;
8525
- }
8526
- haveAlreadyTransformedData(data) {
8527
- if (!this._prevDataFromSource) {
8528
- return false;
8529
- }
8530
- if (data === this._prevDataFromSource) {
8531
- return true;
8532
- }
8533
- const { series, annotations } = this._prevDataFromSource;
8534
- if (data.series === series && data.annotations === annotations) {
8535
- if (this.state.data && data.state !== this.state.data.state) {
8536
- this.setState({ data: { ...this.state.data, state: data.state } });
8537
- }
8538
- return true;
8539
- }
8540
- return false;
8541
- }
8542
- transform(data$1, force = false) {
8543
- var _a;
8544
- if (this.state.transformations.length === 0 || !data$1) {
8545
- this._prevDataFromSource = data$1;
8546
- this.setState({ data: data$1 });
8547
- if (data$1) {
8548
- this._results.next({ origin: this, data: data$1 });
8549
- }
8550
- return;
8551
- }
8552
- if (!force && this.haveAlreadyTransformedData(data$1)) {
8553
- return;
8554
- }
8555
- let interpolatedTransformations = this._interpolateVariablesInTransformationConfigs(data$1);
8556
- const seriesTransformations = interpolatedTransformations.filter((transformation) => {
8557
- if ("options" in transformation || "topic" in transformation) {
8558
- return transformation.topic == null || transformation.topic === data.DataTopic.Series;
8559
- }
8560
- return true;
8561
- }).map((transformation) => "operator" in transformation ? transformation.operator : transformation);
8562
- const annotationsTransformations = interpolatedTransformations.filter((transformation) => {
8563
- if ("options" in transformation || "topic" in transformation) {
8564
- return transformation.topic === data.DataTopic.Annotations;
8565
- }
8566
- return false;
8567
- }).map((transformation) => "operator" in transformation ? transformation.operator : transformation);
8568
- if (this._transformSub) {
8569
- this._transformSub.unsubscribe();
8570
- }
8571
- const ctx = {
8572
- interpolate: (value) => {
8573
- var _a2;
8574
- return sceneGraph.interpolate(this, value, (_a2 = data$1.request) == null ? void 0 : _a2.scopedVars);
8575
- }
8576
- };
8577
- let streams = [data.transformDataFrame(seriesTransformations, data$1.series, ctx)];
8578
- if (data$1.annotations && data$1.annotations.length > 0 && annotationsTransformations.length > 0) {
8579
- streams.push(data.transformDataFrame(annotationsTransformations, (_a = data$1.annotations) != null ? _a : []));
8580
- }
8581
- this._transformSub = rxjs.forkJoin(streams).pipe(
8582
- rxjs.map((values) => {
8583
- const transformedSeries = values[0];
8584
- const transformedAnnotations = values[1];
8585
- return {
8586
- ...data$1,
8587
- series: transformedSeries,
8588
- annotations: transformedAnnotations != null ? transformedAnnotations : data$1.annotations
8589
- };
8590
- }),
8591
- rxjs.catchError((err) => {
8592
- var _a2;
8593
- console.error("Error transforming data: ", err);
8594
- const sourceErr = ((_a2 = this.getSourceData().state.data) == null ? void 0 : _a2.errors) || [];
8595
- const transformationError = runtime.toDataQueryError(err);
8596
- transformationError.message = `Error transforming data: ${transformationError.message}`;
8597
- const result = {
8598
- ...data$1,
8599
- state: data.LoadingState.Error,
8600
- // Combine transformation error with upstream errors
8601
- errors: [...sourceErr, transformationError]
8602
- };
8603
- return rxjs.of(result);
8604
- })
8605
- ).subscribe((transformedData) => {
8606
- this.setState({ data: transformedData });
8607
- this._results.next({ origin: this, data: transformedData });
8608
- this._prevDataFromSource = data$1;
8609
- });
8610
- }
8611
- _interpolateVariablesInTransformationConfigs(data) {
8612
- var _a;
8613
- const transformations = this.state.transformations;
8614
- if (this._variableDependency.getNames().size === 0) {
8615
- return transformations;
8616
- }
8617
- const onlyObjects = transformations.every((t) => typeof t === "object");
8618
- if (onlyObjects) {
8619
- return JSON.parse(sceneGraph.interpolate(this, JSON.stringify(transformations), (_a = data.request) == null ? void 0 : _a.scopedVars));
8620
- }
8621
- return transformations.map((t) => {
8622
- var _a2;
8623
- return typeof t === "object" ? JSON.parse(sceneGraph.interpolate(this, JSON.stringify(t), (_a2 = data.request) == null ? void 0 : _a2.scopedVars)) : t;
8624
- });
8625
- }
8626
- }
8627
-
8628
8381
  class VizPanel extends SceneObjectBase {
8629
8382
  constructor(state) {
8630
8383
  var _a;
@@ -8863,17 +8616,6 @@ class VizPanel extends SceneObjectBase {
8863
8616
  if (plugin.onPanelMigration && currentVersion !== pluginVersion && !isAfterPluginChange) {
8864
8617
  panel.options = await plugin.onPanelMigration(panel);
8865
8618
  }
8866
- let $data = this.state.$data;
8867
- if (panel.transformations && $data) {
8868
- if ($data instanceof SceneDataTransformer) {
8869
- $data.setState({ transformations: panel.transformations });
8870
- } else if ($data instanceof SceneQueryRunner) {
8871
- $data = new SceneDataTransformer({
8872
- transformations: panel.transformations,
8873
- $data
8874
- });
8875
- }
8876
- }
8877
8619
  const withDefaults = data.getPanelOptionsWithDefaults({
8878
8620
  plugin,
8879
8621
  currentOptions: panel.options,
@@ -8882,7 +8624,6 @@ class VizPanel extends SceneObjectBase {
8882
8624
  });
8883
8625
  this._plugin = plugin;
8884
8626
  this.setState({
8885
- $data,
8886
8627
  options: withDefaults.options,
8887
8628
  fieldConfig: withDefaults.fieldConfig,
8888
8629
  pluginVersion: currentVersion,
@@ -9606,6 +9347,9 @@ class AnnotationsDataLayer extends SceneDataLayerBase {
9606
9347
  }
9607
9348
  async runWithTimeRange(timeRange) {
9608
9349
  const { query } = this.state;
9350
+ if (!query.enable) {
9351
+ return;
9352
+ }
9609
9353
  if (this.querySub) {
9610
9354
  this.querySub.unsubscribe();
9611
9355
  }
@@ -9779,6 +9523,253 @@ class DataProviderProxy extends SceneObjectBase {
9779
9523
  }
9780
9524
  }
9781
9525
 
9526
+ class SceneDataLayerSetBase extends SceneObjectBase {
9527
+ constructor() {
9528
+ super(...arguments);
9529
+ /** Mark it as a data layer */
9530
+ this.isDataLayer = true;
9531
+ /**
9532
+ * Subject to emit results to.
9533
+ */
9534
+ this._results = new rxjs.ReplaySubject(1);
9535
+ this._dataLayersMerger = new DataLayersMerger();
9536
+ }
9537
+ subscribeToAllLayers(layers) {
9538
+ if (layers.length > 0) {
9539
+ this.querySub = this._dataLayersMerger.getMergedStream(layers).subscribe(this._onLayerUpdateReceived.bind(this));
9540
+ } else {
9541
+ this._results.next({ origin: this, data: emptyPanelData });
9542
+ this.setStateHelper({ data: emptyPanelData });
9543
+ }
9544
+ }
9545
+ _onLayerUpdateReceived(results) {
9546
+ var _a;
9547
+ let series = [];
9548
+ for (const result of results) {
9549
+ if ((_a = result.data) == null ? void 0 : _a.series) {
9550
+ series = series.concat(result.data.series);
9551
+ }
9552
+ }
9553
+ const combinedData = { ...emptyPanelData, series };
9554
+ this._results.next({ origin: this, data: combinedData });
9555
+ this.setStateHelper({ data: combinedData });
9556
+ }
9557
+ getResultsStream() {
9558
+ return this._results;
9559
+ }
9560
+ cancelQuery() {
9561
+ var _a;
9562
+ (_a = this.querySub) == null ? void 0 : _a.unsubscribe();
9563
+ }
9564
+ /**
9565
+ * This helper function is to counter the contravariance of setState
9566
+ */
9567
+ setStateHelper(state) {
9568
+ setBaseClassState(this, state);
9569
+ }
9570
+ }
9571
+ class SceneDataLayerSet extends SceneDataLayerSetBase {
9572
+ constructor(state) {
9573
+ var _a, _b;
9574
+ super({
9575
+ name: (_a = state.name) != null ? _a : "Data layers",
9576
+ layers: (_b = state.layers) != null ? _b : []
9577
+ });
9578
+ this.addActivationHandler(() => this._onActivate());
9579
+ }
9580
+ _onActivate() {
9581
+ this._subs.add(
9582
+ this.subscribeToState((newState, oldState) => {
9583
+ var _a;
9584
+ if (newState.layers !== oldState.layers) {
9585
+ (_a = this.querySub) == null ? void 0 : _a.unsubscribe();
9586
+ this.subscribeToAllLayers(newState.layers);
9587
+ }
9588
+ })
9589
+ );
9590
+ this.subscribeToAllLayers(this.state.layers);
9591
+ return () => {
9592
+ var _a;
9593
+ (_a = this.querySub) == null ? void 0 : _a.unsubscribe();
9594
+ };
9595
+ }
9596
+ }
9597
+ SceneDataLayerSet.Component = ({ model }) => {
9598
+ const { layers } = model.useState();
9599
+ return /* @__PURE__ */ React__default.default.createElement(React__default.default.Fragment, null, layers.map((layer) => /* @__PURE__ */ React__default.default.createElement(layer.Component, { model: layer, key: layer.state.key })));
9600
+ };
9601
+
9602
+ class SceneDataTransformer extends SceneObjectBase {
9603
+ constructor(state) {
9604
+ super(state);
9605
+ this._results = new rxjs.ReplaySubject(1);
9606
+ /**
9607
+ * Scan transformations for variable usage and re-process transforms when a variable values change
9608
+ */
9609
+ this._variableDependency = new VariableDependencyConfig(
9610
+ this,
9611
+ {
9612
+ statePaths: ["transformations"],
9613
+ onReferencedVariableValueChanged: () => this.reprocessTransformations()
9614
+ }
9615
+ );
9616
+ this.addActivationHandler(() => this.activationHandler());
9617
+ }
9618
+ activationHandler() {
9619
+ const sourceData = this.getSourceData();
9620
+ this._subs.add(sourceData.subscribeToState((state) => this.transform(state.data)));
9621
+ if (sourceData.state.data) {
9622
+ this.transform(sourceData.state.data);
9623
+ }
9624
+ return () => {
9625
+ if (this._transformSub) {
9626
+ this._transformSub.unsubscribe();
9627
+ }
9628
+ };
9629
+ }
9630
+ getSourceData() {
9631
+ if (this.state.$data) {
9632
+ if (this.state.$data instanceof SceneDataLayerSet) {
9633
+ throw new Error("SceneDataLayerSet can not be used as data provider for SceneDataTransformer.");
9634
+ }
9635
+ return this.state.$data;
9636
+ }
9637
+ if (!this.parent || !this.parent.parent) {
9638
+ throw new Error("SceneDataTransformer must either have $data set on it or have a parent.parent with $data");
9639
+ }
9640
+ return sceneGraph.getData(this.parent.parent);
9641
+ }
9642
+ setContainerWidth(width) {
9643
+ if (this.state.$data && this.state.$data.setContainerWidth) {
9644
+ this.state.$data.setContainerWidth(width);
9645
+ }
9646
+ }
9647
+ isDataReadyToDisplay() {
9648
+ const dataObject = this.getSourceData();
9649
+ if (dataObject.isDataReadyToDisplay) {
9650
+ return dataObject.isDataReadyToDisplay();
9651
+ }
9652
+ return true;
9653
+ }
9654
+ reprocessTransformations() {
9655
+ this.transform(this.getSourceData().state.data, true);
9656
+ }
9657
+ cancelQuery() {
9658
+ var _a, _b;
9659
+ (_b = (_a = this.getSourceData()).cancelQuery) == null ? void 0 : _b.call(_a);
9660
+ }
9661
+ getResultsStream() {
9662
+ return this._results;
9663
+ }
9664
+ clone(withState) {
9665
+ const clone = super.clone(withState);
9666
+ if (this._prevDataFromSource) {
9667
+ clone["_prevDataFromSource"] = this._prevDataFromSource;
9668
+ }
9669
+ return clone;
9670
+ }
9671
+ haveAlreadyTransformedData(data) {
9672
+ if (!this._prevDataFromSource) {
9673
+ return false;
9674
+ }
9675
+ if (data === this._prevDataFromSource) {
9676
+ return true;
9677
+ }
9678
+ const { series, annotations } = this._prevDataFromSource;
9679
+ if (data.series === series && data.annotations === annotations) {
9680
+ if (this.state.data && data.state !== this.state.data.state) {
9681
+ this.setState({ data: { ...this.state.data, state: data.state } });
9682
+ }
9683
+ return true;
9684
+ }
9685
+ return false;
9686
+ }
9687
+ transform(data$1, force = false) {
9688
+ var _a;
9689
+ if (this.state.transformations.length === 0 || !data$1) {
9690
+ this._prevDataFromSource = data$1;
9691
+ this.setState({ data: data$1 });
9692
+ if (data$1) {
9693
+ this._results.next({ origin: this, data: data$1 });
9694
+ }
9695
+ return;
9696
+ }
9697
+ if (!force && this.haveAlreadyTransformedData(data$1)) {
9698
+ return;
9699
+ }
9700
+ let interpolatedTransformations = this._interpolateVariablesInTransformationConfigs(data$1);
9701
+ const seriesTransformations = interpolatedTransformations.filter((transformation) => {
9702
+ if ("options" in transformation || "topic" in transformation) {
9703
+ return transformation.topic == null || transformation.topic === data.DataTopic.Series;
9704
+ }
9705
+ return true;
9706
+ }).map((transformation) => "operator" in transformation ? transformation.operator : transformation);
9707
+ const annotationsTransformations = interpolatedTransformations.filter((transformation) => {
9708
+ if ("options" in transformation || "topic" in transformation) {
9709
+ return transformation.topic === data.DataTopic.Annotations;
9710
+ }
9711
+ return false;
9712
+ }).map((transformation) => "operator" in transformation ? transformation.operator : transformation);
9713
+ if (this._transformSub) {
9714
+ this._transformSub.unsubscribe();
9715
+ }
9716
+ const ctx = {
9717
+ interpolate: (value) => {
9718
+ var _a2;
9719
+ return sceneGraph.interpolate(this, value, (_a2 = data$1.request) == null ? void 0 : _a2.scopedVars);
9720
+ }
9721
+ };
9722
+ let streams = [data.transformDataFrame(seriesTransformations, data$1.series, ctx)];
9723
+ if (data$1.annotations && data$1.annotations.length > 0 && annotationsTransformations.length > 0) {
9724
+ streams.push(data.transformDataFrame(annotationsTransformations, (_a = data$1.annotations) != null ? _a : []));
9725
+ }
9726
+ this._transformSub = rxjs.forkJoin(streams).pipe(
9727
+ rxjs.map((values) => {
9728
+ const transformedSeries = values[0];
9729
+ const transformedAnnotations = values[1];
9730
+ return {
9731
+ ...data$1,
9732
+ series: transformedSeries,
9733
+ annotations: transformedAnnotations != null ? transformedAnnotations : data$1.annotations
9734
+ };
9735
+ }),
9736
+ rxjs.catchError((err) => {
9737
+ var _a2;
9738
+ console.error("Error transforming data: ", err);
9739
+ const sourceErr = ((_a2 = this.getSourceData().state.data) == null ? void 0 : _a2.errors) || [];
9740
+ const transformationError = runtime.toDataQueryError(err);
9741
+ transformationError.message = `Error transforming data: ${transformationError.message}`;
9742
+ const result = {
9743
+ ...data$1,
9744
+ state: data.LoadingState.Error,
9745
+ // Combine transformation error with upstream errors
9746
+ errors: [...sourceErr, transformationError]
9747
+ };
9748
+ return rxjs.of(result);
9749
+ })
9750
+ ).subscribe((transformedData) => {
9751
+ this.setState({ data: transformedData });
9752
+ this._results.next({ origin: this, data: transformedData });
9753
+ this._prevDataFromSource = data$1;
9754
+ });
9755
+ }
9756
+ _interpolateVariablesInTransformationConfigs(data) {
9757
+ var _a;
9758
+ const transformations = this.state.transformations;
9759
+ if (this._variableDependency.getNames().size === 0) {
9760
+ return transformations;
9761
+ }
9762
+ const onlyObjects = transformations.every((t) => typeof t === "object");
9763
+ if (onlyObjects) {
9764
+ return JSON.parse(sceneGraph.interpolate(this, JSON.stringify(transformations), (_a = data.request) == null ? void 0 : _a.scopedVars));
9765
+ }
9766
+ return transformations.map((t) => {
9767
+ var _a2;
9768
+ return typeof t === "object" ? JSON.parse(sceneGraph.interpolate(this, JSON.stringify(t), (_a2 = data.request) == null ? void 0 : _a2.scopedVars)) : t;
9769
+ });
9770
+ }
9771
+ }
9772
+
9782
9773
  class VariableValueSelectors extends SceneObjectBase {
9783
9774
  }
9784
9775
  VariableValueSelectors.Component = VariableValueSelectorsRenderer;