@grafana/scenes 6.29.0--canary.1197.16645626691.0 → 6.29.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
@@ -4690,6 +4690,10 @@ const AdHocCombobox = React.forwardRef(function AdHocCombobox2({ filter, model,
4690
4690
  if (reason && ["outside-press", "escape-key"].includes(reason)) {
4691
4691
  if (isMultiValueEdit) {
4692
4692
  handleMultiValueFilterCommit(model, filter, filterMultiValues);
4693
+ } else {
4694
+ if (filter && filter.origin && inputValue === "") {
4695
+ model.updateToMatchAll(filter);
4696
+ }
4693
4697
  }
4694
4698
  handleResetWip();
4695
4699
  handleChangeViewMode == null ? void 0 : handleChangeViewMode();
@@ -4701,6 +4705,7 @@ const AdHocCombobox = React.forwardRef(function AdHocCombobox2({ filter, model,
4701
4705
  handleChangeViewMode,
4702
4706
  handleMultiValueFilterCommit,
4703
4707
  handleResetWip,
4708
+ inputValue,
4704
4709
  isMultiValueEdit,
4705
4710
  model
4706
4711
  ]
@@ -8508,6 +8513,253 @@ const createProperty = (color) => {
8508
8513
  };
8509
8514
  };
8510
8515
 
8516
+ class SceneDataLayerSetBase extends SceneObjectBase {
8517
+ constructor() {
8518
+ super(...arguments);
8519
+ /** Mark it as a data layer */
8520
+ this.isDataLayer = true;
8521
+ /**
8522
+ * Subject to emit results to.
8523
+ */
8524
+ this._results = new rxjs.ReplaySubject(1);
8525
+ this._dataLayersMerger = new DataLayersMerger();
8526
+ }
8527
+ subscribeToAllLayers(layers) {
8528
+ if (layers.length > 0) {
8529
+ this.querySub = this._dataLayersMerger.getMergedStream(layers).subscribe(this._onLayerUpdateReceived.bind(this));
8530
+ } else {
8531
+ this._results.next({ origin: this, data: emptyPanelData });
8532
+ this.setStateHelper({ data: emptyPanelData });
8533
+ }
8534
+ }
8535
+ _onLayerUpdateReceived(results) {
8536
+ var _a;
8537
+ let series = [];
8538
+ for (const result of results) {
8539
+ if ((_a = result.data) == null ? void 0 : _a.series) {
8540
+ series = series.concat(result.data.series);
8541
+ }
8542
+ }
8543
+ const combinedData = { ...emptyPanelData, series };
8544
+ this._results.next({ origin: this, data: combinedData });
8545
+ this.setStateHelper({ data: combinedData });
8546
+ }
8547
+ getResultsStream() {
8548
+ return this._results;
8549
+ }
8550
+ cancelQuery() {
8551
+ var _a;
8552
+ (_a = this.querySub) == null ? void 0 : _a.unsubscribe();
8553
+ }
8554
+ /**
8555
+ * This helper function is to counter the contravariance of setState
8556
+ */
8557
+ setStateHelper(state) {
8558
+ setBaseClassState(this, state);
8559
+ }
8560
+ }
8561
+ class SceneDataLayerSet extends SceneDataLayerSetBase {
8562
+ constructor(state) {
8563
+ var _a, _b;
8564
+ super({
8565
+ name: (_a = state.name) != null ? _a : "Data layers",
8566
+ layers: (_b = state.layers) != null ? _b : []
8567
+ });
8568
+ this.addActivationHandler(() => this._onActivate());
8569
+ }
8570
+ _onActivate() {
8571
+ this._subs.add(
8572
+ this.subscribeToState((newState, oldState) => {
8573
+ var _a;
8574
+ if (newState.layers !== oldState.layers) {
8575
+ (_a = this.querySub) == null ? void 0 : _a.unsubscribe();
8576
+ this.subscribeToAllLayers(newState.layers);
8577
+ }
8578
+ })
8579
+ );
8580
+ this.subscribeToAllLayers(this.state.layers);
8581
+ return () => {
8582
+ var _a;
8583
+ (_a = this.querySub) == null ? void 0 : _a.unsubscribe();
8584
+ };
8585
+ }
8586
+ }
8587
+ SceneDataLayerSet.Component = ({ model }) => {
8588
+ const { layers } = model.useState();
8589
+ 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 })));
8590
+ };
8591
+
8592
+ class SceneDataTransformer extends SceneObjectBase {
8593
+ constructor(state) {
8594
+ super(state);
8595
+ this._results = new rxjs.ReplaySubject(1);
8596
+ /**
8597
+ * Scan transformations for variable usage and re-process transforms when a variable values change
8598
+ */
8599
+ this._variableDependency = new VariableDependencyConfig(
8600
+ this,
8601
+ {
8602
+ statePaths: ["transformations"],
8603
+ onReferencedVariableValueChanged: () => this.reprocessTransformations()
8604
+ }
8605
+ );
8606
+ this.addActivationHandler(() => this.activationHandler());
8607
+ }
8608
+ activationHandler() {
8609
+ const sourceData = this.getSourceData();
8610
+ this._subs.add(sourceData.subscribeToState((state) => this.transform(state.data)));
8611
+ if (sourceData.state.data) {
8612
+ this.transform(sourceData.state.data);
8613
+ }
8614
+ return () => {
8615
+ if (this._transformSub) {
8616
+ this._transformSub.unsubscribe();
8617
+ }
8618
+ };
8619
+ }
8620
+ getSourceData() {
8621
+ if (this.state.$data) {
8622
+ if (this.state.$data instanceof SceneDataLayerSet) {
8623
+ throw new Error("SceneDataLayerSet can not be used as data provider for SceneDataTransformer.");
8624
+ }
8625
+ return this.state.$data;
8626
+ }
8627
+ if (!this.parent || !this.parent.parent) {
8628
+ throw new Error("SceneDataTransformer must either have $data set on it or have a parent.parent with $data");
8629
+ }
8630
+ return sceneGraph.getData(this.parent.parent);
8631
+ }
8632
+ setContainerWidth(width) {
8633
+ if (this.state.$data && this.state.$data.setContainerWidth) {
8634
+ this.state.$data.setContainerWidth(width);
8635
+ }
8636
+ }
8637
+ isDataReadyToDisplay() {
8638
+ const dataObject = this.getSourceData();
8639
+ if (dataObject.isDataReadyToDisplay) {
8640
+ return dataObject.isDataReadyToDisplay();
8641
+ }
8642
+ return true;
8643
+ }
8644
+ reprocessTransformations() {
8645
+ this.transform(this.getSourceData().state.data, true);
8646
+ }
8647
+ cancelQuery() {
8648
+ var _a, _b;
8649
+ (_b = (_a = this.getSourceData()).cancelQuery) == null ? void 0 : _b.call(_a);
8650
+ }
8651
+ getResultsStream() {
8652
+ return this._results;
8653
+ }
8654
+ clone(withState) {
8655
+ const clone = super.clone(withState);
8656
+ if (this._prevDataFromSource) {
8657
+ clone["_prevDataFromSource"] = this._prevDataFromSource;
8658
+ }
8659
+ return clone;
8660
+ }
8661
+ haveAlreadyTransformedData(data) {
8662
+ if (!this._prevDataFromSource) {
8663
+ return false;
8664
+ }
8665
+ if (data === this._prevDataFromSource) {
8666
+ return true;
8667
+ }
8668
+ const { series, annotations } = this._prevDataFromSource;
8669
+ if (data.series === series && data.annotations === annotations) {
8670
+ if (this.state.data && data.state !== this.state.data.state) {
8671
+ this.setState({ data: { ...this.state.data, state: data.state } });
8672
+ }
8673
+ return true;
8674
+ }
8675
+ return false;
8676
+ }
8677
+ transform(data$1, force = false) {
8678
+ var _a;
8679
+ if (this.state.transformations.length === 0 || !data$1) {
8680
+ this._prevDataFromSource = data$1;
8681
+ this.setState({ data: data$1 });
8682
+ if (data$1) {
8683
+ this._results.next({ origin: this, data: data$1 });
8684
+ }
8685
+ return;
8686
+ }
8687
+ if (!force && this.haveAlreadyTransformedData(data$1)) {
8688
+ return;
8689
+ }
8690
+ let interpolatedTransformations = this._interpolateVariablesInTransformationConfigs(data$1);
8691
+ const seriesTransformations = interpolatedTransformations.filter((transformation) => {
8692
+ if ("options" in transformation || "topic" in transformation) {
8693
+ return transformation.topic == null || transformation.topic === data.DataTopic.Series;
8694
+ }
8695
+ return true;
8696
+ }).map((transformation) => "operator" in transformation ? transformation.operator : transformation);
8697
+ const annotationsTransformations = interpolatedTransformations.filter((transformation) => {
8698
+ if ("options" in transformation || "topic" in transformation) {
8699
+ return transformation.topic === data.DataTopic.Annotations;
8700
+ }
8701
+ return false;
8702
+ }).map((transformation) => "operator" in transformation ? transformation.operator : transformation);
8703
+ if (this._transformSub) {
8704
+ this._transformSub.unsubscribe();
8705
+ }
8706
+ const ctx = {
8707
+ interpolate: (value) => {
8708
+ var _a2;
8709
+ return sceneGraph.interpolate(this, value, (_a2 = data$1.request) == null ? void 0 : _a2.scopedVars);
8710
+ }
8711
+ };
8712
+ let streams = [data.transformDataFrame(seriesTransformations, data$1.series, ctx)];
8713
+ if (data$1.annotations && data$1.annotations.length > 0 && annotationsTransformations.length > 0) {
8714
+ streams.push(data.transformDataFrame(annotationsTransformations, (_a = data$1.annotations) != null ? _a : []));
8715
+ }
8716
+ this._transformSub = rxjs.forkJoin(streams).pipe(
8717
+ rxjs.map((values) => {
8718
+ const transformedSeries = values[0];
8719
+ const transformedAnnotations = values[1];
8720
+ return {
8721
+ ...data$1,
8722
+ series: transformedSeries,
8723
+ annotations: transformedAnnotations != null ? transformedAnnotations : data$1.annotations
8724
+ };
8725
+ }),
8726
+ rxjs.catchError((err) => {
8727
+ var _a2;
8728
+ console.error("Error transforming data: ", err);
8729
+ const sourceErr = ((_a2 = this.getSourceData().state.data) == null ? void 0 : _a2.errors) || [];
8730
+ const transformationError = runtime.toDataQueryError(err);
8731
+ transformationError.message = `Error transforming data: ${transformationError.message}`;
8732
+ const result = {
8733
+ ...data$1,
8734
+ state: data.LoadingState.Error,
8735
+ // Combine transformation error with upstream errors
8736
+ errors: [...sourceErr, transformationError]
8737
+ };
8738
+ return rxjs.of(result);
8739
+ })
8740
+ ).subscribe((transformedData) => {
8741
+ this.setState({ data: transformedData });
8742
+ this._results.next({ origin: this, data: transformedData });
8743
+ this._prevDataFromSource = data$1;
8744
+ });
8745
+ }
8746
+ _interpolateVariablesInTransformationConfigs(data) {
8747
+ var _a;
8748
+ const transformations = this.state.transformations;
8749
+ if (this._variableDependency.getNames().size === 0) {
8750
+ return transformations;
8751
+ }
8752
+ const onlyObjects = transformations.every((t) => typeof t === "object");
8753
+ if (onlyObjects) {
8754
+ return JSON.parse(sceneGraph.interpolate(this, JSON.stringify(transformations), (_a = data.request) == null ? void 0 : _a.scopedVars));
8755
+ }
8756
+ return transformations.map((t) => {
8757
+ var _a2;
8758
+ return typeof t === "object" ? JSON.parse(sceneGraph.interpolate(this, JSON.stringify(t), (_a2 = data.request) == null ? void 0 : _a2.scopedVars)) : t;
8759
+ });
8760
+ }
8761
+ }
8762
+
8511
8763
  class VizPanel extends SceneObjectBase {
8512
8764
  constructor(state) {
8513
8765
  var _a;
@@ -8746,6 +8998,18 @@ class VizPanel extends SceneObjectBase {
8746
8998
  if (plugin.onPanelMigration && currentVersion !== pluginVersion && !isAfterPluginChange) {
8747
8999
  panel.options = await plugin.onPanelMigration(panel);
8748
9000
  }
9001
+ let $data = this.state.$data;
9002
+ if (panel.transformations && $data) {
9003
+ if ($data instanceof SceneDataTransformer) {
9004
+ $data.setState({ transformations: panel.transformations });
9005
+ } else if ($data instanceof SceneQueryRunner) {
9006
+ $data.clearParent();
9007
+ $data = new SceneDataTransformer({
9008
+ transformations: panel.transformations,
9009
+ $data
9010
+ });
9011
+ }
9012
+ }
8749
9013
  const withDefaults = data.getPanelOptionsWithDefaults({
8750
9014
  plugin,
8751
9015
  currentOptions: panel.options,
@@ -8754,6 +9018,7 @@ class VizPanel extends SceneObjectBase {
8754
9018
  });
8755
9019
  this._plugin = plugin;
8756
9020
  this.setState({
9021
+ $data,
8757
9022
  options: withDefaults.options,
8758
9023
  fieldConfig: withDefaults.fieldConfig,
8759
9024
  pluginVersion: currentVersion,
@@ -9653,253 +9918,6 @@ class DataProviderProxy extends SceneObjectBase {
9653
9918
  }
9654
9919
  }
9655
9920
 
9656
- class SceneDataLayerSetBase extends SceneObjectBase {
9657
- constructor() {
9658
- super(...arguments);
9659
- /** Mark it as a data layer */
9660
- this.isDataLayer = true;
9661
- /**
9662
- * Subject to emit results to.
9663
- */
9664
- this._results = new rxjs.ReplaySubject(1);
9665
- this._dataLayersMerger = new DataLayersMerger();
9666
- }
9667
- subscribeToAllLayers(layers) {
9668
- if (layers.length > 0) {
9669
- this.querySub = this._dataLayersMerger.getMergedStream(layers).subscribe(this._onLayerUpdateReceived.bind(this));
9670
- } else {
9671
- this._results.next({ origin: this, data: emptyPanelData });
9672
- this.setStateHelper({ data: emptyPanelData });
9673
- }
9674
- }
9675
- _onLayerUpdateReceived(results) {
9676
- var _a;
9677
- let series = [];
9678
- for (const result of results) {
9679
- if ((_a = result.data) == null ? void 0 : _a.series) {
9680
- series = series.concat(result.data.series);
9681
- }
9682
- }
9683
- const combinedData = { ...emptyPanelData, series };
9684
- this._results.next({ origin: this, data: combinedData });
9685
- this.setStateHelper({ data: combinedData });
9686
- }
9687
- getResultsStream() {
9688
- return this._results;
9689
- }
9690
- cancelQuery() {
9691
- var _a;
9692
- (_a = this.querySub) == null ? void 0 : _a.unsubscribe();
9693
- }
9694
- /**
9695
- * This helper function is to counter the contravariance of setState
9696
- */
9697
- setStateHelper(state) {
9698
- setBaseClassState(this, state);
9699
- }
9700
- }
9701
- class SceneDataLayerSet extends SceneDataLayerSetBase {
9702
- constructor(state) {
9703
- var _a, _b;
9704
- super({
9705
- name: (_a = state.name) != null ? _a : "Data layers",
9706
- layers: (_b = state.layers) != null ? _b : []
9707
- });
9708
- this.addActivationHandler(() => this._onActivate());
9709
- }
9710
- _onActivate() {
9711
- this._subs.add(
9712
- this.subscribeToState((newState, oldState) => {
9713
- var _a;
9714
- if (newState.layers !== oldState.layers) {
9715
- (_a = this.querySub) == null ? void 0 : _a.unsubscribe();
9716
- this.subscribeToAllLayers(newState.layers);
9717
- }
9718
- })
9719
- );
9720
- this.subscribeToAllLayers(this.state.layers);
9721
- return () => {
9722
- var _a;
9723
- (_a = this.querySub) == null ? void 0 : _a.unsubscribe();
9724
- };
9725
- }
9726
- }
9727
- SceneDataLayerSet.Component = ({ model }) => {
9728
- const { layers } = model.useState();
9729
- 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 })));
9730
- };
9731
-
9732
- class SceneDataTransformer extends SceneObjectBase {
9733
- constructor(state) {
9734
- super(state);
9735
- this._results = new rxjs.ReplaySubject(1);
9736
- /**
9737
- * Scan transformations for variable usage and re-process transforms when a variable values change
9738
- */
9739
- this._variableDependency = new VariableDependencyConfig(
9740
- this,
9741
- {
9742
- statePaths: ["transformations"],
9743
- onReferencedVariableValueChanged: () => this.reprocessTransformations()
9744
- }
9745
- );
9746
- this.addActivationHandler(() => this.activationHandler());
9747
- }
9748
- activationHandler() {
9749
- const sourceData = this.getSourceData();
9750
- this._subs.add(sourceData.subscribeToState((state) => this.transform(state.data)));
9751
- if (sourceData.state.data) {
9752
- this.transform(sourceData.state.data);
9753
- }
9754
- return () => {
9755
- if (this._transformSub) {
9756
- this._transformSub.unsubscribe();
9757
- }
9758
- };
9759
- }
9760
- getSourceData() {
9761
- if (this.state.$data) {
9762
- if (this.state.$data instanceof SceneDataLayerSet) {
9763
- throw new Error("SceneDataLayerSet can not be used as data provider for SceneDataTransformer.");
9764
- }
9765
- return this.state.$data;
9766
- }
9767
- if (!this.parent || !this.parent.parent) {
9768
- throw new Error("SceneDataTransformer must either have $data set on it or have a parent.parent with $data");
9769
- }
9770
- return sceneGraph.getData(this.parent.parent);
9771
- }
9772
- setContainerWidth(width) {
9773
- if (this.state.$data && this.state.$data.setContainerWidth) {
9774
- this.state.$data.setContainerWidth(width);
9775
- }
9776
- }
9777
- isDataReadyToDisplay() {
9778
- const dataObject = this.getSourceData();
9779
- if (dataObject.isDataReadyToDisplay) {
9780
- return dataObject.isDataReadyToDisplay();
9781
- }
9782
- return true;
9783
- }
9784
- reprocessTransformations() {
9785
- this.transform(this.getSourceData().state.data, true);
9786
- }
9787
- cancelQuery() {
9788
- var _a, _b;
9789
- (_b = (_a = this.getSourceData()).cancelQuery) == null ? void 0 : _b.call(_a);
9790
- }
9791
- getResultsStream() {
9792
- return this._results;
9793
- }
9794
- clone(withState) {
9795
- const clone = super.clone(withState);
9796
- if (this._prevDataFromSource) {
9797
- clone["_prevDataFromSource"] = this._prevDataFromSource;
9798
- }
9799
- return clone;
9800
- }
9801
- haveAlreadyTransformedData(data) {
9802
- if (!this._prevDataFromSource) {
9803
- return false;
9804
- }
9805
- if (data === this._prevDataFromSource) {
9806
- return true;
9807
- }
9808
- const { series, annotations } = this._prevDataFromSource;
9809
- if (data.series === series && data.annotations === annotations) {
9810
- if (this.state.data && data.state !== this.state.data.state) {
9811
- this.setState({ data: { ...this.state.data, state: data.state } });
9812
- }
9813
- return true;
9814
- }
9815
- return false;
9816
- }
9817
- transform(data$1, force = false) {
9818
- var _a;
9819
- if (this.state.transformations.length === 0 || !data$1) {
9820
- this._prevDataFromSource = data$1;
9821
- this.setState({ data: data$1 });
9822
- if (data$1) {
9823
- this._results.next({ origin: this, data: data$1 });
9824
- }
9825
- return;
9826
- }
9827
- if (!force && this.haveAlreadyTransformedData(data$1)) {
9828
- return;
9829
- }
9830
- let interpolatedTransformations = this._interpolateVariablesInTransformationConfigs(data$1);
9831
- const seriesTransformations = interpolatedTransformations.filter((transformation) => {
9832
- if ("options" in transformation || "topic" in transformation) {
9833
- return transformation.topic == null || transformation.topic === data.DataTopic.Series;
9834
- }
9835
- return true;
9836
- }).map((transformation) => "operator" in transformation ? transformation.operator : transformation);
9837
- const annotationsTransformations = interpolatedTransformations.filter((transformation) => {
9838
- if ("options" in transformation || "topic" in transformation) {
9839
- return transformation.topic === data.DataTopic.Annotations;
9840
- }
9841
- return false;
9842
- }).map((transformation) => "operator" in transformation ? transformation.operator : transformation);
9843
- if (this._transformSub) {
9844
- this._transformSub.unsubscribe();
9845
- }
9846
- const ctx = {
9847
- interpolate: (value) => {
9848
- var _a2;
9849
- return sceneGraph.interpolate(this, value, (_a2 = data$1.request) == null ? void 0 : _a2.scopedVars);
9850
- }
9851
- };
9852
- let streams = [data.transformDataFrame(seriesTransformations, data$1.series, ctx)];
9853
- if (data$1.annotations && data$1.annotations.length > 0 && annotationsTransformations.length > 0) {
9854
- streams.push(data.transformDataFrame(annotationsTransformations, (_a = data$1.annotations) != null ? _a : []));
9855
- }
9856
- this._transformSub = rxjs.forkJoin(streams).pipe(
9857
- rxjs.map((values) => {
9858
- const transformedSeries = values[0];
9859
- const transformedAnnotations = values[1];
9860
- return {
9861
- ...data$1,
9862
- series: transformedSeries,
9863
- annotations: transformedAnnotations != null ? transformedAnnotations : data$1.annotations
9864
- };
9865
- }),
9866
- rxjs.catchError((err) => {
9867
- var _a2;
9868
- console.error("Error transforming data: ", err);
9869
- const sourceErr = ((_a2 = this.getSourceData().state.data) == null ? void 0 : _a2.errors) || [];
9870
- const transformationError = runtime.toDataQueryError(err);
9871
- transformationError.message = `Error transforming data: ${transformationError.message}`;
9872
- const result = {
9873
- ...data$1,
9874
- state: data.LoadingState.Error,
9875
- // Combine transformation error with upstream errors
9876
- errors: [...sourceErr, transformationError]
9877
- };
9878
- return rxjs.of(result);
9879
- })
9880
- ).subscribe((transformedData) => {
9881
- this.setState({ data: transformedData });
9882
- this._results.next({ origin: this, data: transformedData });
9883
- this._prevDataFromSource = data$1;
9884
- });
9885
- }
9886
- _interpolateVariablesInTransformationConfigs(data) {
9887
- var _a;
9888
- const transformations = this.state.transformations;
9889
- if (this._variableDependency.getNames().size === 0) {
9890
- return transformations;
9891
- }
9892
- const onlyObjects = transformations.every((t) => typeof t === "object");
9893
- if (onlyObjects) {
9894
- return JSON.parse(sceneGraph.interpolate(this, JSON.stringify(transformations), (_a = data.request) == null ? void 0 : _a.scopedVars));
9895
- }
9896
- return transformations.map((t) => {
9897
- var _a2;
9898
- return typeof t === "object" ? JSON.parse(sceneGraph.interpolate(this, JSON.stringify(t), (_a2 = data.request) == null ? void 0 : _a2.scopedVars)) : t;
9899
- });
9900
- }
9901
- }
9902
-
9903
9921
  class VariableValueSelectors extends SceneObjectBase {
9904
9922
  }
9905
9923
  VariableValueSelectors.Component = VariableValueSelectorsRenderer;