@grafana/scenes 3.14.0 → 3.14.1--canary.655.8371909776.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
@@ -13,8 +13,8 @@ var schema = require('@grafana/schema');
13
13
  var reactUse = require('react-use');
14
14
  var ui = require('@grafana/ui');
15
15
  var css = require('@emotion/css');
16
- var operators = require('rxjs/operators');
17
16
  var e2eSelectors = require('@grafana/e2e-selectors');
17
+ var operators = require('rxjs/operators');
18
18
  var ReactGridLayout = require('react-grid-layout');
19
19
  var AutoSizer = require('react-virtualized-auto-sizer');
20
20
  var BarChartPanelCfg_types_gen = require('@grafana/schema/dist/esm/raw/composable/barchart/panelcfg/x/BarChartPanelCfg_types.gen');
@@ -1357,21 +1357,14 @@ function formatValue(variable, value, formatNameOrFn) {
1357
1357
  return formatter.formatter(value, args, variable);
1358
1358
  }
1359
1359
 
1360
- class SceneDataLayers extends SceneObjectBase {
1361
- constructor(state) {
1362
- super(state);
1363
- this.addActivationHandler(() => this._onActivate());
1364
- }
1365
- _onActivate() {
1366
- const { layers } = this.state;
1367
- const deactivationHandlers = [];
1368
- for (const layer of layers) {
1369
- deactivationHandlers.push(layer.activate());
1370
- }
1371
- return () => {
1372
- deactivationHandlers.forEach((handler) => handler());
1373
- };
1374
- }
1360
+ function isSceneObject(obj) {
1361
+ return obj.useState !== void 0;
1362
+ }
1363
+ function isDataRequestEnricher(obj) {
1364
+ return "enrichDataRequest" in obj;
1365
+ }
1366
+ function isDataLayer(obj) {
1367
+ return "isDataLayer" in obj;
1375
1368
  }
1376
1369
 
1377
1370
  var __accessCheck = (obj, member, msg) => {
@@ -1506,25 +1499,25 @@ function findAllObjects(scene, check) {
1506
1499
  return found;
1507
1500
  }
1508
1501
  function getDataLayers(sceneObject, localOnly = false) {
1509
- let parent = sceneObject;
1502
+ let currentLevel = sceneObject;
1510
1503
  let collected = [];
1511
- let source;
1512
- while (parent) {
1513
- if (parent.state.$data && !(parent.state.$data instanceof SceneDataLayers)) {
1514
- if (parent.state.$data.state.$data instanceof SceneDataLayers) {
1515
- source = parent.state.$data.state.$data;
1516
- }
1517
- }
1518
- if (parent.state.$data && parent.state.$data instanceof SceneDataLayers) {
1519
- source = parent.state.$data;
1504
+ while (currentLevel) {
1505
+ const dataProvider = currentLevel.state.$data;
1506
+ if (!dataProvider) {
1507
+ currentLevel = currentLevel.parent;
1508
+ continue;
1520
1509
  }
1521
- if (source) {
1522
- collected = collected.concat(source.state.layers);
1523
- if (localOnly) {
1524
- break;
1510
+ if (isDataLayer(dataProvider)) {
1511
+ collected = collected.concat(dataProvider);
1512
+ } else {
1513
+ if (dataProvider.state.$data && isDataLayer(dataProvider.state.$data)) {
1514
+ collected = collected.concat(dataProvider.state.$data);
1525
1515
  }
1526
1516
  }
1527
- parent = parent.parent;
1517
+ if (localOnly && collected.length > 0) {
1518
+ break;
1519
+ }
1520
+ currentLevel = currentLevel.parent;
1528
1521
  }
1529
1522
  return collected;
1530
1523
  }
@@ -2047,13 +2040,6 @@ function isGroupByVariable(variable) {
2047
2040
  return variable.state.type === "groupby";
2048
2041
  }
2049
2042
 
2050
- function isSceneObject(obj) {
2051
- return obj.useState !== void 0;
2052
- }
2053
- function isDataRequestEnricher(obj) {
2054
- return "enrichDataRequest" in obj;
2055
- }
2056
-
2057
2043
  const sceneGraph = {
2058
2044
  getVariables,
2059
2045
  getData,
@@ -3242,6 +3228,7 @@ class SceneDataLayerBase extends SceneObjectBase {
3242
3228
  isEnabled: true
3243
3229
  }, initialState));
3244
3230
  this._results = new rxjs.ReplaySubject();
3231
+ this.isDataLayer = true;
3245
3232
  this._variableValueRecorder = new VariableValueRecorder();
3246
3233
  this._variableDependency = new VariableDependencyConfig(this, {
3247
3234
  onVariableUpdateCompleted: this.onVariableUpdateCompleted.bind(this)
@@ -3261,14 +3248,8 @@ class SceneDataLayerBase extends SceneObjectBase {
3261
3248
  this.querySub.unsubscribe();
3262
3249
  this.querySub = void 0;
3263
3250
  this.onDisable();
3264
- this._results.next({
3265
- origin: this,
3266
- data: emptyPanelData,
3267
- topic: this.topic
3268
- });
3269
- this.setStateHelper({
3270
- data: emptyPanelData
3271
- });
3251
+ this._results.next({ origin: this, data: emptyPanelData });
3252
+ this.setStateHelper({ data: emptyPanelData });
3272
3253
  }
3273
3254
  if (n.isEnabled && !p.isEnabled) {
3274
3255
  this.onEnable();
@@ -3294,19 +3275,13 @@ class SceneDataLayerBase extends SceneObjectBase {
3294
3275
  if (this.querySub) {
3295
3276
  this.querySub.unsubscribe();
3296
3277
  this.querySub = void 0;
3297
- this.publishResults(emptyPanelData, this.topic);
3278
+ this.publishResults(emptyPanelData);
3298
3279
  }
3299
3280
  }
3300
- publishResults(data, topic) {
3281
+ publishResults(data) {
3301
3282
  if (this.state.isEnabled) {
3302
- this._results.next({
3303
- origin: this,
3304
- data,
3305
- topic
3306
- });
3307
- this.setStateHelper({
3308
- data
3309
- });
3283
+ this._results.next({ origin: this, data });
3284
+ this.setStateHelper({ data });
3310
3285
  }
3311
3286
  }
3312
3287
  getResultsStream() {
@@ -3333,6 +3308,156 @@ class SceneDataLayerBase extends SceneObjectBase {
3333
3308
  }
3334
3309
  }
3335
3310
 
3311
+ function LoadingIndicator(props) {
3312
+ return /* @__PURE__ */ React__default["default"].createElement(ui.Tooltip, {
3313
+ content: "Cancel query"
3314
+ }, /* @__PURE__ */ React__default["default"].createElement(ui.Icon, {
3315
+ className: "spin-clockwise",
3316
+ name: "sync",
3317
+ size: "xs",
3318
+ role: "button",
3319
+ onMouseDown: (e) => {
3320
+ props.onCancel(e);
3321
+ }
3322
+ }));
3323
+ }
3324
+
3325
+ function ControlsLabel(props) {
3326
+ const styles = ui.useStyles2(getStyles$9);
3327
+ const theme = ui.useTheme2();
3328
+ const isVertical = props.layout === "vertical";
3329
+ const loadingIndicator = Boolean(props.isLoading) ? /* @__PURE__ */ React__default["default"].createElement("div", {
3330
+ style: { marginLeft: theme.spacing(1), marginTop: "-1px" },
3331
+ "aria-label": e2eSelectors.selectors.components.LoadingIndicator.icon
3332
+ }, /* @__PURE__ */ React__default["default"].createElement(LoadingIndicator, {
3333
+ onCancel: (e) => {
3334
+ var _a;
3335
+ e.preventDefault();
3336
+ e.stopPropagation();
3337
+ (_a = props.onCancel) == null ? void 0 : _a.call(props);
3338
+ }
3339
+ })) : null;
3340
+ let errorIndicator = null;
3341
+ if (props.error) {
3342
+ errorIndicator = /* @__PURE__ */ React__default["default"].createElement(ui.Tooltip, {
3343
+ content: props.error,
3344
+ placement: "bottom"
3345
+ }, /* @__PURE__ */ React__default["default"].createElement(ui.Icon, {
3346
+ className: styles.errorIcon,
3347
+ name: "exclamation-triangle"
3348
+ }));
3349
+ }
3350
+ const testId = typeof props.label === "string" ? e2eSelectors.selectors.pages.Dashboard.SubMenu.submenuItemLabels(props.label) : "";
3351
+ let labelElement;
3352
+ if (isVertical) {
3353
+ labelElement = /* @__PURE__ */ React__default["default"].createElement("label", {
3354
+ className: styles.verticalLabel,
3355
+ "data-testid": testId,
3356
+ htmlFor: props.htmlFor
3357
+ }, props.label, errorIndicator, props.icon && /* @__PURE__ */ React__default["default"].createElement(ui.Icon, {
3358
+ name: props.icon,
3359
+ className: styles.normalIcon
3360
+ }), loadingIndicator, props.onRemove && /* @__PURE__ */ React__default["default"].createElement(ui.IconButton, {
3361
+ variant: "secondary",
3362
+ size: "xs",
3363
+ name: "times",
3364
+ onClick: props.onRemove,
3365
+ tooltip: "Remove"
3366
+ }));
3367
+ } else {
3368
+ labelElement = /* @__PURE__ */ React__default["default"].createElement("label", {
3369
+ className: styles.horizontalLabel,
3370
+ "data-testid": testId,
3371
+ htmlFor: props.htmlFor
3372
+ }, errorIndicator, props.icon && /* @__PURE__ */ React__default["default"].createElement(ui.Icon, {
3373
+ name: props.icon,
3374
+ className: styles.normalIcon
3375
+ }), props.label, loadingIndicator);
3376
+ }
3377
+ if (props.description) {
3378
+ return /* @__PURE__ */ React__default["default"].createElement(ui.Tooltip, {
3379
+ content: props.description,
3380
+ placement: isVertical ? "top" : "bottom"
3381
+ }, labelElement);
3382
+ }
3383
+ return labelElement;
3384
+ }
3385
+ const getStyles$9 = (theme) => ({
3386
+ horizontalLabel: css.css({
3387
+ background: theme.isDark ? theme.colors.background.primary : theme.colors.background.secondary,
3388
+ display: `flex`,
3389
+ alignItems: "center",
3390
+ padding: theme.spacing(0, 1),
3391
+ fontWeight: theme.typography.fontWeightMedium,
3392
+ fontSize: theme.typography.bodySmall.fontSize,
3393
+ height: theme.spacing(theme.components.height.md),
3394
+ lineHeight: theme.spacing(theme.components.height.md),
3395
+ borderRadius: theme.shape.borderRadius(1),
3396
+ border: `1px solid ${theme.components.input.borderColor}`,
3397
+ position: "relative",
3398
+ right: -1,
3399
+ whiteSpace: "nowrap",
3400
+ gap: theme.spacing(0.5)
3401
+ }),
3402
+ verticalLabel: css.css({
3403
+ display: `flex`,
3404
+ alignItems: "center",
3405
+ fontWeight: theme.typography.fontWeightMedium,
3406
+ fontSize: theme.typography.bodySmall.fontSize,
3407
+ lineHeight: theme.typography.bodySmall.lineHeight,
3408
+ whiteSpace: "nowrap",
3409
+ marginBottom: theme.spacing(0.5),
3410
+ gap: theme.spacing(1)
3411
+ }),
3412
+ errorIcon: css.css({
3413
+ color: theme.colors.error.text
3414
+ }),
3415
+ normalIcon: css.css({
3416
+ color: theme.colors.text.secondary
3417
+ })
3418
+ });
3419
+
3420
+ class SceneDataLayerControls extends SceneObjectBase {
3421
+ constructor() {
3422
+ super({});
3423
+ }
3424
+ }
3425
+ SceneDataLayerControls.Component = SceneDataLayerControlsRenderer;
3426
+ function SceneDataLayerControlsRenderer({ model }) {
3427
+ const layers = sceneGraph.getDataLayers(model, true);
3428
+ if (layers.length === 0) {
3429
+ return null;
3430
+ }
3431
+ return /* @__PURE__ */ React__default["default"].createElement(React__default["default"].Fragment, null, layers.map((layer) => /* @__PURE__ */ React__default["default"].createElement(layer.Component, {
3432
+ model: layer,
3433
+ key: layer.state.key
3434
+ })));
3435
+ }
3436
+ function DataLayerControlSwitch({ layer }) {
3437
+ var _a, _b;
3438
+ const elementId = `data-layer-${layer.state.key}`;
3439
+ const { data, isEnabled } = layer.useState();
3440
+ const showLoading = Boolean(data && data.state === schema.LoadingState.Loading);
3441
+ return /* @__PURE__ */ React__default["default"].createElement("div", {
3442
+ className: containerStyle$1
3443
+ }, /* @__PURE__ */ React__default["default"].createElement(ControlsLabel, {
3444
+ htmlFor: elementId,
3445
+ isLoading: showLoading,
3446
+ onCancel: () => {
3447
+ var _a2;
3448
+ return (_a2 = layer.cancelQuery) == null ? void 0 : _a2.call(layer);
3449
+ },
3450
+ label: layer.state.name,
3451
+ description: layer.state.description,
3452
+ error: (_b = (_a = layer.state.data) == null ? void 0 : _a.errors) == null ? void 0 : _b[0].message
3453
+ }), /* @__PURE__ */ React__default["default"].createElement(ui.InlineSwitch, {
3454
+ id: elementId,
3455
+ value: isEnabled,
3456
+ onChange: () => layer.setState({ isEnabled: !isEnabled })
3457
+ }));
3458
+ }
3459
+ const containerStyle$1 = css.css({ display: "flex" });
3460
+
3336
3461
  var __defProp$w = Object.defineProperty;
3337
3462
  var __defProps$k = Object.defineProperties;
3338
3463
  var __getOwnPropDescs$k = Object.getOwnPropertyDescriptors;
@@ -3752,7 +3877,6 @@ class AnnotationsDataLayer extends SceneDataLayerBase {
3752
3877
  ["query"]
3753
3878
  );
3754
3879
  this._scopedVars = { __sceneObject: { value: this, text: "__sceneObject" } };
3755
- this.topic = data.DataTopic.Annotations;
3756
3880
  }
3757
3881
  onEnable() {
3758
3882
  const timeRange = sceneGraph.getTimeRange(this);
@@ -3792,20 +3916,17 @@ class AnnotationsDataLayer extends SceneDataLayerBase {
3792
3916
  })
3793
3917
  );
3794
3918
  this.querySub = stream.subscribe((stateUpdate) => {
3795
- this.publishResults(stateUpdate, data.DataTopic.Annotations);
3919
+ this.publishResults(stateUpdate);
3796
3920
  });
3797
3921
  } catch (e) {
3798
- this.publishResults(
3799
- __spreadProps$i(__spreadValues$t({}, emptyPanelData), {
3800
- state: schema.LoadingState.Error,
3801
- errors: [
3802
- {
3803
- message: getMessageFromError(e)
3804
- }
3805
- ]
3806
- }),
3807
- data.DataTopic.Annotations
3808
- );
3922
+ this.publishResults(__spreadProps$i(__spreadValues$t({}, emptyPanelData), {
3923
+ state: schema.LoadingState.Error,
3924
+ errors: [
3925
+ {
3926
+ message: getMessageFromError(e)
3927
+ }
3928
+ ]
3929
+ }));
3809
3930
  console.error("AnnotationsDataLayer error", e);
3810
3931
  }
3811
3932
  }
@@ -3820,10 +3941,20 @@ class AnnotationsDataLayer extends SceneDataLayerBase {
3820
3941
  df.meta = __spreadProps$i(__spreadValues$t({}, df.meta), {
3821
3942
  dataTopic: data.DataTopic.Annotations
3822
3943
  });
3823
- stateUpdate.annotations = [df];
3944
+ stateUpdate.series = [df];
3824
3945
  return stateUpdate;
3825
3946
  }
3826
3947
  }
3948
+ AnnotationsDataLayer.Component = AnnotationsDataLayerRenderer;
3949
+ function AnnotationsDataLayerRenderer({ model }) {
3950
+ const { isHidden } = model.useState();
3951
+ if (isHidden) {
3952
+ return null;
3953
+ }
3954
+ return /* @__PURE__ */ React__default["default"].createElement(DataLayerControlSwitch, {
3955
+ layer: model
3956
+ });
3957
+ }
3827
3958
 
3828
3959
  var index = /*#__PURE__*/Object.freeze({
3829
3960
  __proto__: null,
@@ -4040,7 +4171,7 @@ class SceneTimeRangeCompare extends SceneObjectBase {
4040
4171
  SceneTimeRangeCompare.Component = SceneTimeRangeCompareRenderer;
4041
4172
  function SceneTimeRangeCompareRenderer({ model }) {
4042
4173
  var _a;
4043
- const styles = ui.useStyles2(getStyles$9);
4174
+ const styles = ui.useStyles2(getStyles$8);
4044
4175
  const { compareWith, compareOptions } = model.useState();
4045
4176
  const [previousCompare, setPreviousCompare] = React__default["default"].useState(compareWith);
4046
4177
  const previousValue = (_a = compareOptions.find(({ value: value2 }) => value2 === previousCompare)) != null ? _a : PREVIOUS_PERIOD_COMPARE_OPTION;
@@ -4080,7 +4211,7 @@ function SceneTimeRangeCompareRenderer({ model }) {
4080
4211
  isOpen: false
4081
4212
  }, previousValue.label));
4082
4213
  }
4083
- function getStyles$9(theme) {
4214
+ function getStyles$8(theme) {
4084
4215
  return {
4085
4216
  previewButton: css.css({
4086
4217
  "&:disabled": {
@@ -4735,115 +4866,6 @@ function GroupByVariableRenderer({ model }) {
4735
4866
  return renderSelectForVariable(model);
4736
4867
  }
4737
4868
 
4738
- function LoadingIndicator(props) {
4739
- return /* @__PURE__ */ React__default["default"].createElement(ui.Tooltip, {
4740
- content: "Cancel query"
4741
- }, /* @__PURE__ */ React__default["default"].createElement(ui.Icon, {
4742
- className: "spin-clockwise",
4743
- name: "sync",
4744
- size: "xs",
4745
- role: "button",
4746
- onMouseDown: (e) => {
4747
- props.onCancel(e);
4748
- }
4749
- }));
4750
- }
4751
-
4752
- function ControlsLabel(props) {
4753
- const styles = ui.useStyles2(getStyles$8);
4754
- const theme = ui.useTheme2();
4755
- const isVertical = props.layout === "vertical";
4756
- const loadingIndicator = Boolean(props.isLoading) ? /* @__PURE__ */ React__default["default"].createElement("div", {
4757
- style: { marginLeft: theme.spacing(1), marginTop: "-1px" },
4758
- "aria-label": e2eSelectors.selectors.components.LoadingIndicator.icon
4759
- }, /* @__PURE__ */ React__default["default"].createElement(LoadingIndicator, {
4760
- onCancel: (e) => {
4761
- var _a;
4762
- e.preventDefault();
4763
- e.stopPropagation();
4764
- (_a = props.onCancel) == null ? void 0 : _a.call(props);
4765
- }
4766
- })) : null;
4767
- let errorIndicator = null;
4768
- if (props.error) {
4769
- errorIndicator = /* @__PURE__ */ React__default["default"].createElement(ui.Tooltip, {
4770
- content: props.error,
4771
- placement: "bottom"
4772
- }, /* @__PURE__ */ React__default["default"].createElement(ui.Icon, {
4773
- className: styles.errorIcon,
4774
- name: "exclamation-triangle"
4775
- }));
4776
- }
4777
- const testId = typeof props.label === "string" ? e2eSelectors.selectors.pages.Dashboard.SubMenu.submenuItemLabels(props.label) : "";
4778
- let labelElement;
4779
- if (isVertical) {
4780
- labelElement = /* @__PURE__ */ React__default["default"].createElement("label", {
4781
- className: styles.verticalLabel,
4782
- "data-testid": testId,
4783
- htmlFor: props.htmlFor
4784
- }, props.label, errorIndicator, props.icon && /* @__PURE__ */ React__default["default"].createElement(ui.Icon, {
4785
- name: props.icon,
4786
- className: styles.normalIcon
4787
- }), loadingIndicator, props.onRemove && /* @__PURE__ */ React__default["default"].createElement(ui.IconButton, {
4788
- variant: "secondary",
4789
- size: "xs",
4790
- name: "times",
4791
- onClick: props.onRemove,
4792
- tooltip: "Remove"
4793
- }));
4794
- } else {
4795
- labelElement = /* @__PURE__ */ React__default["default"].createElement("label", {
4796
- className: styles.horizontalLabel,
4797
- "data-testid": testId,
4798
- htmlFor: props.htmlFor
4799
- }, errorIndicator, props.icon && /* @__PURE__ */ React__default["default"].createElement(ui.Icon, {
4800
- name: props.icon,
4801
- className: styles.normalIcon
4802
- }), props.label, loadingIndicator);
4803
- }
4804
- if (props.description) {
4805
- return /* @__PURE__ */ React__default["default"].createElement(ui.Tooltip, {
4806
- content: props.description,
4807
- placement: isVertical ? "top" : "bottom"
4808
- }, labelElement);
4809
- }
4810
- return labelElement;
4811
- }
4812
- const getStyles$8 = (theme) => ({
4813
- horizontalLabel: css.css({
4814
- background: theme.isDark ? theme.colors.background.primary : theme.colors.background.secondary,
4815
- display: `flex`,
4816
- alignItems: "center",
4817
- padding: theme.spacing(0, 1),
4818
- fontWeight: theme.typography.fontWeightMedium,
4819
- fontSize: theme.typography.bodySmall.fontSize,
4820
- height: theme.spacing(theme.components.height.md),
4821
- lineHeight: theme.spacing(theme.components.height.md),
4822
- borderRadius: theme.shape.borderRadius(1),
4823
- border: `1px solid ${theme.components.input.borderColor}`,
4824
- position: "relative",
4825
- right: -1,
4826
- whiteSpace: "nowrap",
4827
- gap: theme.spacing(0.5)
4828
- }),
4829
- verticalLabel: css.css({
4830
- display: `flex`,
4831
- alignItems: "center",
4832
- fontWeight: theme.typography.fontWeightMedium,
4833
- fontSize: theme.typography.bodySmall.fontSize,
4834
- lineHeight: theme.typography.bodySmall.lineHeight,
4835
- whiteSpace: "nowrap",
4836
- marginBottom: theme.spacing(0.5),
4837
- gap: theme.spacing(1)
4838
- }),
4839
- errorIcon: css.css({
4840
- color: theme.colors.error.text
4841
- }),
4842
- normalIcon: css.css({
4843
- color: theme.colors.text.secondary
4844
- })
4845
- });
4846
-
4847
4869
  var __defProp$n = Object.defineProperty;
4848
4870
  var __defProps$d = Object.defineProperties;
4849
4871
  var __getOwnPropDescs$d = Object.getOwnPropertyDescriptors;
@@ -5293,6 +5315,25 @@ function toSelectableValue({ text, value }) {
5293
5315
  };
5294
5316
  }
5295
5317
 
5318
+ function mergeMultipleDataLayers(layers) {
5319
+ const resultStreams = layers.map((l) => l.getResultsStream());
5320
+ const resultsMap = /* @__PURE__ */ new Map();
5321
+ const deactivationHandlers = [];
5322
+ for (const layer of layers) {
5323
+ deactivationHandlers.push(layer.activate());
5324
+ }
5325
+ return rxjs.merge(resultStreams).pipe(
5326
+ rxjs.mergeAll(),
5327
+ rxjs.map((v) => {
5328
+ resultsMap.set(v.origin.state.key, v);
5329
+ return resultsMap.values();
5330
+ }),
5331
+ rxjs.finalize(() => {
5332
+ deactivationHandlers.forEach((handler) => handler());
5333
+ })
5334
+ );
5335
+ }
5336
+
5296
5337
  var __defProp$l = Object.defineProperty;
5297
5338
  var __defProps$b = Object.defineProperties;
5298
5339
  var __getOwnPropDescs$b = Object.getOwnPropertyDescriptors;
@@ -5433,44 +5474,28 @@ class SceneQueryRunner extends SceneObjectBase {
5433
5474
  }
5434
5475
  _handleDataLayers() {
5435
5476
  const dataLayers = sceneGraph.getDataLayers(this);
5436
- const observables = [];
5437
- const resultsMap = /* @__PURE__ */ new Map();
5438
- if (dataLayers.length > 0) {
5439
- dataLayers.forEach((layer) => {
5440
- observables.push(layer.getResultsStream());
5441
- });
5442
- this._dataLayersSub = rxjs.merge(observables).pipe(
5443
- rxjs.mergeAll(),
5444
- rxjs.map((v) => {
5445
- resultsMap.set(v.origin.state.key, v.data);
5446
- return resultsMap;
5447
- })
5448
- ).subscribe((result) => {
5449
- this._onLayersReceived(result);
5450
- });
5477
+ if (dataLayers.length === 0) {
5478
+ return;
5451
5479
  }
5480
+ this._dataLayersSub = mergeMultipleDataLayers(dataLayers).subscribe(this._onLayersReceived.bind(this));
5452
5481
  }
5453
5482
  _onLayersReceived(results) {
5454
- var _a, _b;
5483
+ var _a, _b, _c, _d;
5455
5484
  const timeRange = sceneGraph.getTimeRange(this);
5456
- const dataLayers = sceneGraph.getDataLayers(this);
5457
5485
  const { dataLayerFilter } = this.state;
5458
5486
  let annotations = [];
5459
5487
  let alertStates = [];
5460
5488
  let alertState;
5461
- const layerKeys = Array.from(results.keys());
5462
- Array.from(results.values()).forEach((result, i) => {
5463
- const layerKey = layerKeys[i];
5464
- const layer = dataLayers.find((l) => l.state.key === layerKey);
5465
- if (layer) {
5466
- if (layer.topic === data.DataTopic.Annotations && result[data.DataTopic.Annotations]) {
5467
- annotations = annotations.concat(result[data.DataTopic.Annotations]);
5489
+ for (const result of results) {
5490
+ for (let frame of result.data.series) {
5491
+ if (((_a = frame.meta) == null ? void 0 : _a.dataTopic) === data.DataTopic.Annotations) {
5492
+ annotations = annotations.concat(frame);
5468
5493
  }
5469
- if (layer.topic === "alertStates") {
5470
- alertStates = alertStates.concat(result.series);
5494
+ if (((_b = frame.meta) == null ? void 0 : _b.dataTopic) === data.DataTopic.AlertStates) {
5495
+ alertStates = alertStates.concat(frame);
5471
5496
  }
5472
5497
  }
5473
- });
5498
+ }
5474
5499
  if (dataLayerFilter == null ? void 0 : dataLayerFilter.panelId) {
5475
5500
  if (annotations.length > 0) {
5476
5501
  annotations = filterAnnotations(annotations, dataLayerFilter);
@@ -5491,8 +5516,8 @@ class SceneQueryRunner extends SceneObjectBase {
5491
5516
  this._layerAnnotations = annotations;
5492
5517
  this.setState({
5493
5518
  data: __spreadProps$b(__spreadValues$l({}, baseStateUpdate), {
5494
- annotations: [...(_a = this._resultAnnotations) != null ? _a : [], ...annotations],
5495
- alertState: alertState != null ? alertState : (_b = this.state.data) == null ? void 0 : _b.alertState
5519
+ annotations: [...(_c = this._resultAnnotations) != null ? _c : [], ...annotations],
5520
+ alertState: alertState != null ? alertState : (_d = this.state.data) == null ? void 0 : _d.alertState
5496
5521
  })
5497
5522
  });
5498
5523
  }
@@ -5720,64 +5745,76 @@ var __spreadValues$k = (a, b) => {
5720
5745
  return a;
5721
5746
  };
5722
5747
  var __spreadProps$a = (a, b) => __defProps$a(a, __getOwnPropDescs$a(b));
5723
- class SceneDataLayerControls extends SceneObjectBase {
5748
+ class SceneDataLayerSetBase extends SceneObjectBase {
5724
5749
  constructor() {
5725
- super({ layersMap: {} });
5726
- this.addActivationHandler(() => this._onActivate());
5750
+ super(...arguments);
5751
+ this.isDataLayer = true;
5752
+ this._results = new rxjs.ReplaySubject();
5727
5753
  }
5728
- _onActivate() {
5729
- const layers = sceneGraph.getDataLayers(this, true);
5730
- this.setState({ layersMap: layers.reduce((acc, l) => __spreadProps$a(__spreadValues$k({}, acc), { [l.state.key]: l.state.isEnabled }), {}) });
5754
+ subscribeToAllLayers(layers) {
5755
+ if (layers.length > 0) {
5756
+ this.querySub = mergeMultipleDataLayers(layers).subscribe(this._onLayerUpdateReceived.bind(this));
5757
+ } else {
5758
+ this._results.next({ origin: this, data: emptyPanelData });
5759
+ this.setStateHelper({ data: emptyPanelData });
5760
+ }
5731
5761
  }
5732
- toggleLayer(l) {
5733
- this.setState({ layersMap: __spreadProps$a(__spreadValues$k({}, this.state.layersMap), { [l.state.key]: !l.state.isEnabled }) });
5734
- l.setState({ isEnabled: !l.state.isEnabled });
5762
+ _onLayerUpdateReceived(results) {
5763
+ var _a;
5764
+ let series = [];
5765
+ for (const result of results) {
5766
+ if ((_a = result.data) == null ? void 0 : _a.series) {
5767
+ series = series.concat(result.data.series);
5768
+ }
5769
+ }
5770
+ const combinedData = __spreadProps$a(__spreadValues$k({}, emptyPanelData), { series });
5771
+ this._results.next({ origin: this, data: combinedData });
5772
+ this.setStateHelper({ data: combinedData });
5735
5773
  }
5736
- }
5737
- SceneDataLayerControls.Component = SceneDataLayerControlsRenderer;
5738
- function SceneDataLayerControlsRenderer({ model }) {
5739
- const { layersMap } = model.useState();
5740
- const layers = sceneGraph.getDataLayers(model, true);
5741
- if (layers.length === 0) {
5742
- return null;
5774
+ getResultsStream() {
5775
+ return this._results;
5776
+ }
5777
+ cancelQuery() {
5778
+ var _a;
5779
+ (_a = this.querySub) == null ? void 0 : _a.unsubscribe();
5780
+ }
5781
+ setStateHelper(state) {
5782
+ setBaseClassState(this, state);
5743
5783
  }
5744
- return /* @__PURE__ */ React__default["default"].createElement(React__default["default"].Fragment, null, layers.map((l) => {
5745
- const elementId = `data-layer-${l.state.key}`;
5746
- if (l.state.isHidden) {
5747
- return null;
5748
- }
5749
- return /* @__PURE__ */ React__default["default"].createElement(SceneDataLayerControl, {
5750
- key: elementId,
5751
- layer: l,
5752
- onToggleLayer: () => model.toggleLayer(l),
5753
- isEnabled: layersMap[l.state.key]
5754
- });
5755
- }));
5756
5784
  }
5757
- function SceneDataLayerControl({ layer, isEnabled, onToggleLayer }) {
5758
- var _a, _b;
5759
- const elementId = `data-layer-${layer.state.key}`;
5760
- const { data } = layer.useState();
5761
- const showLoading = Boolean(data && data.state === schema.LoadingState.Loading);
5762
- return /* @__PURE__ */ React__default["default"].createElement("div", {
5763
- className: containerStyle$1
5764
- }, /* @__PURE__ */ React__default["default"].createElement(ControlsLabel, {
5765
- htmlFor: elementId,
5766
- isLoading: showLoading,
5767
- onCancel: () => {
5768
- var _a2;
5769
- return (_a2 = layer.cancelQuery) == null ? void 0 : _a2.call(layer);
5770
- },
5771
- label: layer.state.name,
5772
- description: layer.state.description,
5773
- error: (_b = (_a = layer.state.data) == null ? void 0 : _a.errors) == null ? void 0 : _b[0].message
5774
- }), /* @__PURE__ */ React__default["default"].createElement(ui.InlineSwitch, {
5775
- id: elementId,
5776
- value: isEnabled,
5777
- onChange: onToggleLayer
5778
- }));
5785
+ class SceneDataLayerSet extends SceneDataLayerSetBase {
5786
+ constructor(state) {
5787
+ var _a, _b;
5788
+ super({
5789
+ name: (_a = state.name) != null ? _a : "Data layers",
5790
+ layers: (_b = state.layers) != null ? _b : []
5791
+ });
5792
+ this.addActivationHandler(() => this._onActivate());
5793
+ }
5794
+ _onActivate() {
5795
+ this._subs.add(
5796
+ this.subscribeToState((newState, oldState) => {
5797
+ var _a;
5798
+ if (newState.layers !== oldState.layers) {
5799
+ (_a = this.querySub) == null ? void 0 : _a.unsubscribe();
5800
+ this.subscribeToAllLayers(newState.layers);
5801
+ }
5802
+ })
5803
+ );
5804
+ this.subscribeToAllLayers(this.state.layers);
5805
+ return () => {
5806
+ var _a;
5807
+ (_a = this.querySub) == null ? void 0 : _a.unsubscribe();
5808
+ };
5809
+ }
5779
5810
  }
5780
- const containerStyle$1 = css.css({ display: "flex" });
5811
+ SceneDataLayerSet.Component = ({ model }) => {
5812
+ const { layers } = model.useState();
5813
+ return /* @__PURE__ */ React__default["default"].createElement(React__default["default"].Fragment, null, layers.map((layer) => /* @__PURE__ */ React__default["default"].createElement(layer.Component, {
5814
+ model: layer,
5815
+ key: layer.state.key
5816
+ })));
5817
+ };
5781
5818
 
5782
5819
  var __defProp$j = Object.defineProperty;
5783
5820
  var __defProps$9 = Object.defineProperties;
@@ -5825,8 +5862,8 @@ class SceneDataTransformer extends SceneObjectBase {
5825
5862
  }
5826
5863
  getSourceData() {
5827
5864
  if (this.state.$data) {
5828
- if (this.state.$data instanceof SceneDataLayers) {
5829
- throw new Error("SceneDataLayers can not be used as data provider for SceneDataTransformer.");
5865
+ if (this.state.$data instanceof SceneDataLayerSet) {
5866
+ throw new Error("SceneDataLayerSet can not be used as data provider for SceneDataTransformer.");
5830
5867
  }
5831
5868
  return this.state.$data;
5832
5869
  }
@@ -10374,7 +10411,8 @@ exports.SceneCanvasText = SceneCanvasText;
10374
10411
  exports.SceneControlsSpacer = SceneControlsSpacer;
10375
10412
  exports.SceneDataLayerBase = SceneDataLayerBase;
10376
10413
  exports.SceneDataLayerControls = SceneDataLayerControls;
10377
- exports.SceneDataLayers = SceneDataLayers;
10414
+ exports.SceneDataLayerSet = SceneDataLayerSet;
10415
+ exports.SceneDataLayerSetBase = SceneDataLayerSetBase;
10378
10416
  exports.SceneDataNode = SceneDataNode;
10379
10417
  exports.SceneDataTransformer = SceneDataTransformer;
10380
10418
  exports.SceneDebugger = SceneDebugger;
@@ -10415,6 +10453,7 @@ exports.dataLayers = index;
10415
10453
  exports.formatRegistry = formatRegistry;
10416
10454
  exports.getUrlSyncManager = getUrlSyncManager;
10417
10455
  exports.isCustomVariableValue = isCustomVariableValue;
10456
+ exports.isDataLayer = isDataLayer;
10418
10457
  exports.isDataRequestEnricher = isDataRequestEnricher;
10419
10458
  exports.isSceneObject = isSceneObject;
10420
10459
  exports.registerQueryWithController = registerQueryWithController;