@grafana/scenes 0.0.12 → 0.0.14

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.
Files changed (46) hide show
  1. package/dist/esm/components/EmbeddedScene.js +3 -2
  2. package/dist/esm/components/EmbeddedScene.js.map +1 -1
  3. package/dist/esm/components/SceneApp/SceneApp.js +164 -0
  4. package/dist/esm/components/SceneApp/SceneApp.js.map +1 -0
  5. package/dist/esm/components/SceneApp/utils.js +38 -0
  6. package/dist/esm/components/SceneApp/utils.js.map +1 -0
  7. package/dist/esm/components/SceneTimePicker.js +2 -1
  8. package/dist/esm/components/SceneTimePicker.js.map +1 -1
  9. package/dist/esm/components/VizPanel/VizPanelRenderer.js +6 -0
  10. package/dist/esm/components/VizPanel/VizPanelRenderer.js.map +1 -1
  11. package/dist/esm/core/SceneObjectBase.js +10 -4
  12. package/dist/esm/core/SceneObjectBase.js.map +1 -1
  13. package/dist/esm/core/SceneTimeRange.js +0 -2
  14. package/dist/esm/core/SceneTimeRange.js.map +1 -1
  15. package/dist/esm/core/sceneGraph.js +19 -2
  16. package/dist/esm/core/sceneGraph.js.map +1 -1
  17. package/dist/esm/core/types.js.map +1 -1
  18. package/dist/esm/index.js +1 -0
  19. package/dist/esm/index.js.map +1 -1
  20. package/dist/esm/querying/SceneQueryRunner.js +32 -3
  21. package/dist/esm/querying/SceneQueryRunner.js.map +1 -1
  22. package/dist/esm/utils/writeSceneLog.js +8 -0
  23. package/dist/esm/utils/writeSceneLog.js.map +1 -0
  24. package/dist/esm/variables/VariableDependencyConfig.js +19 -8
  25. package/dist/esm/variables/VariableDependencyConfig.js.map +1 -1
  26. package/dist/esm/variables/VariableValueRecorder.js +56 -0
  27. package/dist/esm/variables/VariableValueRecorder.js.map +1 -0
  28. package/dist/esm/variables/components/VariableValueSelectors.js +34 -8
  29. package/dist/esm/variables/components/VariableValueSelectors.js.map +1 -1
  30. package/dist/esm/variables/interpolation/defaults.js +14 -3
  31. package/dist/esm/variables/interpolation/defaults.js.map +1 -1
  32. package/dist/esm/variables/interpolation/sceneInterpolator.js +2 -18
  33. package/dist/esm/variables/interpolation/sceneInterpolator.js.map +1 -1
  34. package/dist/esm/variables/lookupVariable.js +20 -0
  35. package/dist/esm/variables/lookupVariable.js.map +1 -0
  36. package/dist/esm/variables/sets/SceneVariableSet.js +28 -29
  37. package/dist/esm/variables/sets/SceneVariableSet.js.map +1 -1
  38. package/dist/esm/variables/types.js.map +1 -1
  39. package/dist/esm/variables/utils.js +11 -0
  40. package/dist/esm/variables/utils.js.map +1 -0
  41. package/dist/esm/variables/variants/query/QueryVariable.js +1 -3
  42. package/dist/esm/variables/variants/query/QueryVariable.js.map +1 -1
  43. package/dist/index.d.ts +82 -11
  44. package/dist/index.js +785 -431
  45. package/dist/index.js.map +1 -1
  46. package/package.json +6 -3
package/dist/index.js CHANGED
@@ -15,6 +15,7 @@ var reactUse = require('react-use');
15
15
  var experimental = require('@grafana/experimental');
16
16
  var ReactGridLayout = require('react-grid-layout');
17
17
  var AutoSizer = require('react-virtualized-auto-sizer');
18
+ var reactRouterDom = require('react-router-dom');
18
19
 
19
20
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
20
21
 
@@ -30,21 +31,21 @@ class SceneObjectStateChangedEvent extends data.BusEventWithPayload {
30
31
  }
31
32
  SceneObjectStateChangedEvent.type = "scene-object-state-change";
32
33
 
33
- var __defProp$e = Object.defineProperty;
34
+ var __defProp$f = Object.defineProperty;
34
35
  var __defProps$5 = Object.defineProperties;
35
36
  var __getOwnPropDescs$5 = Object.getOwnPropertyDescriptors;
36
- var __getOwnPropSymbols$e = Object.getOwnPropertySymbols;
37
- var __hasOwnProp$e = Object.prototype.hasOwnProperty;
38
- var __propIsEnum$e = Object.prototype.propertyIsEnumerable;
39
- var __defNormalProp$e = (obj, key, value) => key in obj ? __defProp$e(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
40
- var __spreadValues$e = (a, b) => {
37
+ var __getOwnPropSymbols$f = Object.getOwnPropertySymbols;
38
+ var __hasOwnProp$f = Object.prototype.hasOwnProperty;
39
+ var __propIsEnum$f = Object.prototype.propertyIsEnumerable;
40
+ var __defNormalProp$f = (obj, key, value) => key in obj ? __defProp$f(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
41
+ var __spreadValues$f = (a, b) => {
41
42
  for (var prop in b || (b = {}))
42
- if (__hasOwnProp$e.call(b, prop))
43
- __defNormalProp$e(a, prop, b[prop]);
44
- if (__getOwnPropSymbols$e)
45
- for (var prop of __getOwnPropSymbols$e(b)) {
46
- if (__propIsEnum$e.call(b, prop))
47
- __defNormalProp$e(a, prop, b[prop]);
43
+ if (__hasOwnProp$f.call(b, prop))
44
+ __defNormalProp$f(a, prop, b[prop]);
45
+ if (__getOwnPropSymbols$f)
46
+ for (var prop of __getOwnPropSymbols$f(b)) {
47
+ if (__propIsEnum$f.call(b, prop))
48
+ __defNormalProp$f(a, prop, b[prop]);
48
49
  }
49
50
  return a;
50
51
  };
@@ -52,11 +53,11 @@ var __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
52
53
  var __objRest = (source, exclude) => {
53
54
  var target = {};
54
55
  for (var prop in source)
55
- if (__hasOwnProp$e.call(source, prop) && exclude.indexOf(prop) < 0)
56
+ if (__hasOwnProp$f.call(source, prop) && exclude.indexOf(prop) < 0)
56
57
  target[prop] = source[prop];
57
- if (source != null && __getOwnPropSymbols$e)
58
- for (var prop of __getOwnPropSymbols$e(source)) {
59
- if (exclude.indexOf(prop) < 0 && __propIsEnum$e.call(source, prop))
58
+ if (source != null && __getOwnPropSymbols$f)
59
+ for (var prop of __getOwnPropSymbols$f(source)) {
60
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$f.call(source, prop))
60
61
  target[prop] = source[prop];
61
62
  }
62
63
  return target;
@@ -71,7 +72,7 @@ function SceneComponentWrapper(_a) {
71
72
  ]);
72
73
  var _a2;
73
74
  const Component = (_a2 = model.constructor["Component"]) != null ? _a2 : EmptyRenderer;
74
- const inner = /* @__PURE__ */ React__default["default"].createElement(Component, __spreadProps$5(__spreadValues$e({}, otherProps), {
75
+ const inner = /* @__PURE__ */ React__default["default"].createElement(Component, __spreadProps$5(__spreadValues$f({}, otherProps), {
75
76
  model,
76
77
  isEditing
77
78
  }));
@@ -110,19 +111,19 @@ function getSceneEditor$1(sceneObject) {
110
111
  throw new Error("No editor found in scene tree");
111
112
  }
112
113
 
113
- var __defProp$d = Object.defineProperty;
114
- var __getOwnPropSymbols$d = Object.getOwnPropertySymbols;
115
- var __hasOwnProp$d = Object.prototype.hasOwnProperty;
116
- var __propIsEnum$d = Object.prototype.propertyIsEnumerable;
117
- var __defNormalProp$d = (obj, key, value) => key in obj ? __defProp$d(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
118
- var __spreadValues$d = (a, b) => {
114
+ var __defProp$e = Object.defineProperty;
115
+ var __getOwnPropSymbols$e = Object.getOwnPropertySymbols;
116
+ var __hasOwnProp$e = Object.prototype.hasOwnProperty;
117
+ var __propIsEnum$e = Object.prototype.propertyIsEnumerable;
118
+ var __defNormalProp$e = (obj, key, value) => key in obj ? __defProp$e(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
119
+ var __spreadValues$e = (a, b) => {
119
120
  for (var prop in b || (b = {}))
120
- if (__hasOwnProp$d.call(b, prop))
121
- __defNormalProp$d(a, prop, b[prop]);
122
- if (__getOwnPropSymbols$d)
123
- for (var prop of __getOwnPropSymbols$d(b)) {
124
- if (__propIsEnum$d.call(b, prop))
125
- __defNormalProp$d(a, prop, b[prop]);
121
+ if (__hasOwnProp$e.call(b, prop))
122
+ __defNormalProp$e(a, prop, b[prop]);
123
+ if (__getOwnPropSymbols$e)
124
+ for (var prop of __getOwnPropSymbols$e(b)) {
125
+ if (__propIsEnum$e.call(b, prop))
126
+ __defNormalProp$e(a, prop, b[prop]);
126
127
  }
127
128
  return a;
128
129
  };
@@ -141,7 +142,7 @@ function forEachSceneObjectInState(state, callback) {
141
142
  }
142
143
  }
143
144
  function cloneSceneObject(sceneObject, withState) {
144
- const clonedState = __spreadValues$d({}, sceneObject.state);
145
+ const clonedState = __spreadValues$e({}, sceneObject.state);
145
146
  for (const key in clonedState) {
146
147
  const propValue = clonedState[key];
147
148
  if (propValue instanceof SceneObjectBase) {
@@ -163,19 +164,19 @@ function cloneSceneObject(sceneObject, withState) {
163
164
  return new sceneObject.constructor(clonedState);
164
165
  }
165
166
 
166
- var __defProp$c = Object.defineProperty;
167
- var __getOwnPropSymbols$c = Object.getOwnPropertySymbols;
168
- var __hasOwnProp$c = Object.prototype.hasOwnProperty;
169
- var __propIsEnum$c = Object.prototype.propertyIsEnumerable;
170
- var __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$c(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
171
- var __spreadValues$c = (a, b) => {
167
+ var __defProp$d = Object.defineProperty;
168
+ var __getOwnPropSymbols$d = Object.getOwnPropertySymbols;
169
+ var __hasOwnProp$d = Object.prototype.hasOwnProperty;
170
+ var __propIsEnum$d = Object.prototype.propertyIsEnumerable;
171
+ var __defNormalProp$d = (obj, key, value) => key in obj ? __defProp$d(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
172
+ var __spreadValues$d = (a, b) => {
172
173
  for (var prop in b || (b = {}))
173
- if (__hasOwnProp$c.call(b, prop))
174
- __defNormalProp$c(a, prop, b[prop]);
175
- if (__getOwnPropSymbols$c)
176
- for (var prop of __getOwnPropSymbols$c(b)) {
177
- if (__propIsEnum$c.call(b, prop))
178
- __defNormalProp$c(a, prop, b[prop]);
174
+ if (__hasOwnProp$d.call(b, prop))
175
+ __defNormalProp$d(a, prop, b[prop]);
176
+ if (__getOwnPropSymbols$d)
177
+ for (var prop of __getOwnPropSymbols$d(b)) {
178
+ if (__propIsEnum$d.call(b, prop))
179
+ __defNormalProp$d(a, prop, b[prop]);
179
180
  }
180
181
  return a;
181
182
  };
@@ -226,7 +227,7 @@ class SceneObjectBase {
226
227
  }
227
228
  setState(update) {
228
229
  const prevState = this._state;
229
- const newState = __spreadValues$c(__spreadValues$c({}, this._state), update);
230
+ const newState = __spreadValues$d(__spreadValues$d({}, this._state), update);
230
231
  this._state = Object.freeze(newState);
231
232
  this.setParent();
232
233
  this._subject.next(newState);
@@ -251,17 +252,23 @@ class SceneObjectBase {
251
252
  }
252
253
  activate() {
253
254
  this._isActive = true;
254
- const { $data, $variables } = this.state;
255
- if ($data && !$data.isActive) {
256
- $data.activate();
255
+ const { $data, $variables, $timeRange } = this.state;
256
+ if ($timeRange && !$timeRange.isActive) {
257
+ $timeRange.activate();
257
258
  }
258
259
  if ($variables && !$variables.isActive) {
259
260
  $variables.activate();
260
261
  }
262
+ if ($data && !$data.isActive) {
263
+ $data.activate();
264
+ }
261
265
  }
262
266
  deactivate() {
263
267
  this._isActive = false;
264
- const { $data, $variables } = this.state;
268
+ const { $data, $variables, $timeRange } = this.state;
269
+ if ($timeRange && $timeRange.isActive) {
270
+ $timeRange.deactivate();
271
+ }
265
272
  if ($data && $data.isActive) {
266
273
  $data.deactivate();
267
274
  }
@@ -312,19 +319,19 @@ class SceneObjectUrlSyncConfig {
312
319
  }
313
320
  }
314
321
 
315
- var __defProp$b = Object.defineProperty;
316
- var __getOwnPropSymbols$b = Object.getOwnPropertySymbols;
317
- var __hasOwnProp$b = Object.prototype.hasOwnProperty;
318
- var __propIsEnum$b = Object.prototype.propertyIsEnumerable;
319
- var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
320
- var __spreadValues$b = (a, b) => {
322
+ var __defProp$c = Object.defineProperty;
323
+ var __getOwnPropSymbols$c = Object.getOwnPropertySymbols;
324
+ var __hasOwnProp$c = Object.prototype.hasOwnProperty;
325
+ var __propIsEnum$c = Object.prototype.propertyIsEnumerable;
326
+ var __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$c(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
327
+ var __spreadValues$c = (a, b) => {
321
328
  for (var prop in b || (b = {}))
322
- if (__hasOwnProp$b.call(b, prop))
323
- __defNormalProp$b(a, prop, b[prop]);
324
- if (__getOwnPropSymbols$b)
325
- for (var prop of __getOwnPropSymbols$b(b)) {
326
- if (__propIsEnum$b.call(b, prop))
327
- __defNormalProp$b(a, prop, b[prop]);
329
+ if (__hasOwnProp$c.call(b, prop))
330
+ __defNormalProp$c(a, prop, b[prop]);
331
+ if (__getOwnPropSymbols$c)
332
+ for (var prop of __getOwnPropSymbols$c(b)) {
333
+ if (__propIsEnum$c.call(b, prop))
334
+ __defNormalProp$c(a, prop, b[prop]);
328
335
  }
329
336
  return a;
330
337
  };
@@ -335,7 +342,7 @@ class SceneTimeRange extends SceneObjectBase {
335
342
  const to = (_b = state.to) != null ? _b : "now";
336
343
  const timeZone = (_c = state.timeZone) != null ? _c : data.getTimeZone();
337
344
  const value = evaluateTimeRange(from, to, timeZone);
338
- super(__spreadValues$b({ from, to, timeZone, value }, state));
345
+ super(__spreadValues$c({ from, to, timeZone, value }, state));
339
346
  this._urlSync = new SceneObjectUrlSyncConfig(this, { keys: ["from", "to"] });
340
347
  this.onTimeRangeChange = (timeRange) => {
341
348
  const update = {};
@@ -355,8 +362,6 @@ class SceneTimeRange extends SceneObjectBase {
355
362
  this.onRefresh = () => {
356
363
  this.setState({ value: evaluateTimeRange(this.state.from, this.state.to, this.state.timeZone) });
357
364
  };
358
- this.onIntervalChanged = (_) => {
359
- };
360
365
  }
361
366
  getUrlState(state) {
362
367
  return { from: state.from, to: state.to };
@@ -414,176 +419,6 @@ function evaluateTimeRange(from, to, timeZone, fiscalYearStartMonth) {
414
419
  };
415
420
  }
416
421
 
417
- class SceneVariableValueChangedEvent extends data.BusEventWithPayload {
418
- }
419
- SceneVariableValueChangedEvent.type = "scene-variable-changed-value";
420
-
421
- class SceneVariableSet extends SceneObjectBase {
422
- constructor() {
423
- super(...arguments);
424
- this._variablesThatHaveChanged = /* @__PURE__ */ new Set();
425
- this._variablesToUpdate = /* @__PURE__ */ new Set();
426
- this._updating = /* @__PURE__ */ new Map();
427
- }
428
- getByName(name) {
429
- return this.state.variables.find((x) => x.state.name === name);
430
- }
431
- activate() {
432
- super.activate();
433
- this._subs.add(
434
- this.subscribeToEvent(SceneVariableValueChangedEvent, (event) => this.handleVariableValueChanged(event.payload))
435
- );
436
- this.checkForVariablesThatChangedWhileInactive();
437
- for (const variable of this.state.variables) {
438
- if (this.variableNeedsUpdate(variable)) {
439
- this._variablesToUpdate.add(variable);
440
- }
441
- }
442
- this.updateNextBatch();
443
- }
444
- checkForVariablesThatChangedWhileInactive() {
445
- if (!this._validValuesWhenDeactivated) {
446
- return;
447
- }
448
- for (const variable of this.state.variables) {
449
- if (this._validValuesWhenDeactivated.has(variable)) {
450
- const value = this._validValuesWhenDeactivated.get(variable);
451
- if (!isVariableValueEqual(value, variable.getValue())) {
452
- writeVariableTraceLog(variable, "Changed while in-active");
453
- this.handleVariableValueChanged(variable);
454
- }
455
- }
456
- }
457
- }
458
- variableNeedsUpdate(variable) {
459
- if (!variable.validateAndUpdate) {
460
- return false;
461
- }
462
- if (this._validValuesWhenDeactivated && this._validValuesWhenDeactivated.has(variable)) {
463
- const value = this._validValuesWhenDeactivated.get(variable);
464
- if (isVariableValueEqual(value, variable.getValue())) {
465
- writeVariableTraceLog(variable, "Skipping updateAndValidate current value valid");
466
- return false;
467
- }
468
- }
469
- return true;
470
- }
471
- deactivate() {
472
- var _a;
473
- super.deactivate();
474
- for (const update of this._updating.values()) {
475
- (_a = update.subscription) == null ? void 0 : _a.unsubscribe();
476
- }
477
- this._validValuesWhenDeactivated = /* @__PURE__ */ new Map();
478
- for (const variable of this.state.variables) {
479
- if (!this._variablesToUpdate.has(variable) || !this._updating.has(variable)) {
480
- this._validValuesWhenDeactivated.set(variable, variable.getValue());
481
- }
482
- }
483
- this._variablesToUpdate.clear();
484
- this._updating.clear();
485
- }
486
- updateNextBatch() {
487
- if (this._variablesToUpdate.size === 0 && this._variablesThatHaveChanged.size > 0) {
488
- this.notifyDependentSceneObjects();
489
- return;
490
- }
491
- for (const variable of this._variablesToUpdate) {
492
- if (!variable.validateAndUpdate) {
493
- throw new Error("Variable added to variablesToUpdate but does not have validateAndUpdate");
494
- }
495
- if (this._updating.has(variable)) {
496
- continue;
497
- }
498
- if (this.hasDependendencyInUpdateQueue(variable)) {
499
- continue;
500
- }
501
- const variableToUpdate = {
502
- variable
503
- };
504
- this._updating.set(variable, variableToUpdate);
505
- writeVariableTraceLog(variable, "updateAndValidate started");
506
- variableToUpdate.subscription = variable.validateAndUpdate().subscribe({
507
- next: () => this.validateAndUpdateCompleted(variable),
508
- error: (err) => this.handleVariableError(variable, err)
509
- });
510
- }
511
- }
512
- validateAndUpdateCompleted(variable) {
513
- var _a;
514
- const update = this._updating.get(variable);
515
- (_a = update == null ? void 0 : update.subscription) == null ? void 0 : _a.unsubscribe();
516
- this._updating.delete(variable);
517
- this._variablesToUpdate.delete(variable);
518
- writeVariableTraceLog(variable, "updateAndValidate completed");
519
- this.updateNextBatch();
520
- }
521
- handleVariableError(variable, err) {
522
- var _a;
523
- const update = this._updating.get(variable);
524
- (_a = update == null ? void 0 : update.subscription) == null ? void 0 : _a.unsubscribe();
525
- this._updating.delete(variable);
526
- this._variablesToUpdate.delete(variable);
527
- variable.setState({ loading: false, error: err });
528
- writeVariableTraceLog(variable, "updateAndValidate error", err);
529
- }
530
- hasDependendencyInUpdateQueue(variable) {
531
- var _a;
532
- if (!variable.variableDependency) {
533
- return false;
534
- }
535
- for (const otherVariable of this._variablesToUpdate.values()) {
536
- if ((_a = variable.variableDependency) == null ? void 0 : _a.hasDependencyOn(otherVariable.state.name)) {
537
- return true;
538
- }
539
- }
540
- return false;
541
- }
542
- handleVariableValueChanged(variableThatChanged) {
543
- this._variablesThatHaveChanged.add(variableThatChanged);
544
- if (this._updating.has(variableThatChanged)) {
545
- return;
546
- }
547
- for (const otherVariable of this.state.variables) {
548
- if (otherVariable.variableDependency) {
549
- if (otherVariable.variableDependency.hasDependencyOn(variableThatChanged.state.name)) {
550
- writeVariableTraceLog(otherVariable, "Added to update quee, dependant variable value changed");
551
- this._variablesToUpdate.add(otherVariable);
552
- }
553
- }
554
- }
555
- this.updateNextBatch();
556
- }
557
- notifyDependentSceneObjects() {
558
- if (!this.parent) {
559
- return;
560
- }
561
- this.traverseSceneAndNotify(this.parent);
562
- this._variablesThatHaveChanged.clear();
563
- }
564
- traverseSceneAndNotify(sceneObject) {
565
- if (this === sceneObject) {
566
- return;
567
- }
568
- if (sceneObject.variableDependency) {
569
- sceneObject.variableDependency.variableValuesChanged(this._variablesThatHaveChanged);
570
- }
571
- forEachSceneObjectInState(sceneObject.state, (child) => this.traverseSceneAndNotify(child));
572
- }
573
- }
574
- function writeVariableTraceLog(variable, message, err) {
575
- if (window.grafanaLoggingSceneVariables) {
576
- console.log(`Variable[${variable.state.name}]: ${message}`, err);
577
- }
578
- }
579
- function isVariableValueEqual(a, b) {
580
- if (a === b) {
581
- return true;
582
- }
583
- return lodash.isEqual(a, b);
584
- }
585
-
586
- const EmptyVariableSet = new SceneVariableSet({ variables: [] });
587
422
  const EmptyDataNode = new SceneDataNode({
588
423
  data: {
589
424
  state: data.LoadingState.Done,
@@ -592,6 +427,18 @@ const EmptyDataNode = new SceneDataNode({
592
427
  }
593
428
  });
594
429
  const DefaultTimeRange = new SceneTimeRange();
430
+ class EmptyVariableSetImpl extends SceneObjectBase {
431
+ constructor() {
432
+ super({ variables: [] });
433
+ }
434
+ getByName(name) {
435
+ return void 0;
436
+ }
437
+ isVariableLoadingOrWaitingToUpdate(variable) {
438
+ return false;
439
+ }
440
+ }
441
+ const EmptyVariableSet = new EmptyVariableSetImpl();
595
442
 
596
443
  const _ScopedVarsVariable = class {
597
444
  constructor(name, value) {
@@ -920,31 +767,11 @@ function formatQueryParameter(name, value) {
920
767
  return `var-${name}=${encodeURIComponentStrict(value)}`;
921
768
  }
922
769
 
923
- function sceneInterpolator(sceneObject, target, scopedVars, format) {
924
- if (!target) {
925
- return target != null ? target : "";
926
- }
927
- VARIABLE_REGEX.lastIndex = 0;
928
- return target.replace(VARIABLE_REGEX, (match, var1, var2, fmt2, var3, fieldPath, fmt3) => {
929
- const variableName = var1 || var2 || var3;
930
- const fmt = fmt2 || fmt3 || format;
931
- let variable;
932
- if (scopedVars && scopedVars[variableName]) {
933
- variable = getSceneVariableForScopedVar(variableName, scopedVars[variableName]);
934
- } else {
935
- variable = lookupSceneVariable(variableName, sceneObject);
936
- }
937
- if (!variable) {
938
- return match;
939
- }
940
- return formatValue(variable, variable.getValue(fieldPath), fmt);
941
- });
942
- }
943
- function lookupSceneVariable(name, sceneObject) {
770
+ function lookupVariable(name, sceneObject) {
944
771
  const variables = sceneObject.state.$variables;
945
772
  if (!variables) {
946
773
  if (sceneObject.parent) {
947
- return lookupSceneVariable(name, sceneObject.parent);
774
+ return lookupVariable(name, sceneObject.parent);
948
775
  } else {
949
776
  return null;
950
777
  }
@@ -953,10 +780,31 @@ function lookupSceneVariable(name, sceneObject) {
953
780
  if (found) {
954
781
  return found;
955
782
  } else if (sceneObject.parent) {
956
- return lookupSceneVariable(name, sceneObject.parent);
783
+ return lookupVariable(name, sceneObject.parent);
957
784
  }
958
785
  return null;
959
786
  }
787
+
788
+ function sceneInterpolator(sceneObject, target, scopedVars, format) {
789
+ if (!target) {
790
+ return target != null ? target : "";
791
+ }
792
+ VARIABLE_REGEX.lastIndex = 0;
793
+ return target.replace(VARIABLE_REGEX, (match, var1, var2, fmt2, var3, fieldPath, fmt3) => {
794
+ const variableName = var1 || var2 || var3;
795
+ const fmt = fmt2 || fmt3 || format;
796
+ let variable;
797
+ if (scopedVars && scopedVars[variableName]) {
798
+ variable = getSceneVariableForScopedVar(variableName, scopedVars[variableName]);
799
+ } else {
800
+ variable = lookupVariable(variableName, sceneObject);
801
+ }
802
+ if (!variable) {
803
+ return match;
804
+ }
805
+ return formatValue(variable, variable.getValue(fieldPath), fmt);
806
+ });
807
+ }
960
808
  function formatValue(variable, value, formatNameOrFn) {
961
809
  if (value === null || value === void 0) {
962
810
  return "";
@@ -1047,13 +895,29 @@ function interpolate(sceneObject, value, scopedVars, format) {
1047
895
  }
1048
896
  return sceneInterpolator(sceneObject, value, scopedVars, format);
1049
897
  }
898
+ function hasVariableDependencyInLoadingState(sceneObject) {
899
+ if (!sceneObject.variableDependency) {
900
+ return false;
901
+ }
902
+ for (const name of sceneObject.variableDependency.getNames()) {
903
+ const variable = lookupVariable(name, sceneObject);
904
+ if (!variable) {
905
+ continue;
906
+ }
907
+ const set = variable.parent;
908
+ return set.isVariableLoadingOrWaitingToUpdate(variable);
909
+ }
910
+ return false;
911
+ }
1050
912
  const sceneGraph = {
1051
913
  getVariables,
1052
914
  getData,
1053
915
  getTimeRange,
1054
916
  getSceneEditor,
1055
917
  getLayout,
1056
- interpolate
918
+ interpolate,
919
+ lookupVariable,
920
+ hasVariableDependencyInLoadingState
1057
921
  };
1058
922
 
1059
923
  async function getDataSource(datasource, scopedVars) {
@@ -1064,26 +928,37 @@ async function getDataSource(datasource, scopedVars) {
1064
928
  }
1065
929
 
1066
930
  class VariableDependencyConfig {
1067
- constructor(_sceneObject, options) {
931
+ constructor(_sceneObject, _options) {
1068
932
  this._sceneObject = _sceneObject;
933
+ this._options = _options;
1069
934
  this._dependencies = /* @__PURE__ */ new Set();
1070
935
  this.scanCount = 0;
1071
936
  this.defaultHandlerReferencedVariableValueChanged = () => {
1072
937
  this._sceneObject.forceRender();
1073
938
  };
1074
- var _a;
1075
- this._statePaths = options.statePaths;
1076
- this._onReferencedVariableValueChanged = (_a = options.onReferencedVariableValueChanged) != null ? _a : this.defaultHandlerReferencedVariableValueChanged;
939
+ this._statePaths = _options.statePaths;
1077
940
  }
1078
941
  hasDependencyOn(name) {
1079
942
  return this.getNames().has(name);
1080
943
  }
1081
- variableValuesChanged(variables) {
944
+ variableUpdatesCompleted(changedVariables) {
1082
945
  const deps = this.getNames();
1083
- for (const variable of variables) {
946
+ let dependencyChanged = false;
947
+ for (const variable of changedVariables) {
1084
948
  if (deps.has(variable.state.name)) {
1085
- this._onReferencedVariableValueChanged();
1086
- return;
949
+ dependencyChanged = true;
950
+ break;
951
+ }
952
+ }
953
+ if (this._options.onVariableUpdatesCompleted) {
954
+ this._options.onVariableUpdatesCompleted(changedVariables, dependencyChanged);
955
+ return;
956
+ }
957
+ if (dependencyChanged) {
958
+ if (this._options.onReferencedVariableValueChanged) {
959
+ this._options.onReferencedVariableValueChanged();
960
+ } else {
961
+ this.defaultHandlerReferencedVariableValueChanged();
1087
962
  }
1088
963
  }
1089
964
  }
@@ -1145,21 +1020,85 @@ const safeStringifyValue = (value) => {
1145
1020
  return "";
1146
1021
  };
1147
1022
 
1148
- var __defProp$a = Object.defineProperty;
1023
+ function writeSceneLog(logger, message, ...rest) {
1024
+ if (window.grafanaSceneLogging) {
1025
+ console.log(`${logger}: `, message, ...rest);
1026
+ }
1027
+ }
1028
+
1029
+ function isVariableValueEqual(a, b) {
1030
+ if (a === b) {
1031
+ return true;
1032
+ }
1033
+ return lodash.isEqual(a, b);
1034
+ }
1035
+
1036
+ class VariableValueRecorder {
1037
+ constructor() {
1038
+ this._values = /* @__PURE__ */ new Map();
1039
+ }
1040
+ recordCurrentDependencyValuesForSceneObject(sceneObject) {
1041
+ this.clearValues();
1042
+ for (const variableName of sceneObject.variableDependency.getNames()) {
1043
+ const variable = sceneGraph.lookupVariable(variableName, sceneObject);
1044
+ if (variable) {
1045
+ this._values.set(variable, variable.getValue());
1046
+ }
1047
+ }
1048
+ }
1049
+ clearValues() {
1050
+ this._values.clear();
1051
+ }
1052
+ hasValues() {
1053
+ return !!this._values;
1054
+ }
1055
+ recordCurrentValue(variable) {
1056
+ this._values.set(variable, variable.getValue());
1057
+ }
1058
+ hasRecordedValue(variable) {
1059
+ return this._values.has(variable);
1060
+ }
1061
+ hasValueChanged(variable) {
1062
+ if (this._values.has(variable)) {
1063
+ const value = this._values.get(variable);
1064
+ if (!isVariableValueEqual(value, variable.getValue())) {
1065
+ return true;
1066
+ }
1067
+ }
1068
+ return false;
1069
+ }
1070
+ hasDependenciesChanged(sceneObject) {
1071
+ if (!this._values) {
1072
+ return false;
1073
+ }
1074
+ for (const variableName of sceneObject.variableDependency.getNames()) {
1075
+ const variable = sceneGraph.lookupVariable(variableName, sceneObject);
1076
+ if (variable && this._values.has(variable)) {
1077
+ const value = this._values.get(variable);
1078
+ if (!isVariableValueEqual(value, variable.getValue())) {
1079
+ return true;
1080
+ }
1081
+ }
1082
+ }
1083
+ return false;
1084
+ }
1085
+ }
1086
+
1087
+ var __defProp$b = Object.defineProperty;
1149
1088
  var __defProps$4 = Object.defineProperties;
1150
1089
  var __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors;
1151
- var __getOwnPropSymbols$a = Object.getOwnPropertySymbols;
1152
- var __hasOwnProp$a = Object.prototype.hasOwnProperty;
1153
- var __propIsEnum$a = Object.prototype.propertyIsEnumerable;
1154
- var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1155
- var __spreadValues$a = (a, b) => {
1090
+ var __getOwnPropSymbols$b = Object.getOwnPropertySymbols;
1091
+ var __hasOwnProp$b = Object.prototype.hasOwnProperty;
1092
+ var __propIsEnum$b = Object.prototype.propertyIsEnumerable;
1093
+ var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1094
+ var __spreadValues$b = (a, b) => {
1156
1095
  for (var prop in b || (b = {}))
1157
- if (__hasOwnProp$a.call(b, prop))
1158
- __defNormalProp$a(a, prop, b[prop]);
1159
- if (__getOwnPropSymbols$a)
1160
- for (var prop of __getOwnPropSymbols$a(b)) {
1161
- if (__propIsEnum$a.call(b, prop))
1162
- __defNormalProp$a(a, prop, b[prop]);
1096
+ if (__hasOwnProp$b.call(b, prop))
1097
+ __defNormalProp$b(a, prop, b[prop]);
1098
+ if (__getOwnPropSymbols$b)
1099
+ for (var prop of __getOwnPropSymbols$b(b)) {
1100
+ if (__propIsEnum$b.call(b, prop))
1101
+ __defNormalProp$b(a, prop, b[prop]);
1163
1102
  }
1164
1103
  return a;
1165
1104
  };
@@ -1171,9 +1110,10 @@ function getNextRequestId() {
1171
1110
  class SceneQueryRunner extends SceneObjectBase {
1172
1111
  constructor() {
1173
1112
  super(...arguments);
1113
+ this._variableValueRecorder = new VariableValueRecorder();
1174
1114
  this._variableDependency = new VariableDependencyConfig(this, {
1175
1115
  statePaths: ["queries", "datasource"],
1176
- onReferencedVariableValueChanged: () => this.runQueries()
1116
+ onVariableUpdatesCompleted: (variables, dependencyChanged) => this.onVariableUpdatesCompleted(variables, dependencyChanged)
1177
1117
  });
1178
1118
  this.onDataReceived = (data) => {
1179
1119
  this.setState({ data });
@@ -1193,11 +1133,27 @@ class SceneQueryRunner extends SceneObjectBase {
1193
1133
  this.runQueries();
1194
1134
  }
1195
1135
  }
1136
+ onVariableUpdatesCompleted(_variablesThatHaveChanged, dependencyChanged) {
1137
+ if (this.state.isWaitingForVariables && this.shouldRunQueriesOnActivate()) {
1138
+ this.runQueries();
1139
+ return;
1140
+ }
1141
+ if (dependencyChanged) {
1142
+ this.runQueries();
1143
+ }
1144
+ }
1196
1145
  shouldRunQueriesOnActivate() {
1197
- if (this.state.data) {
1146
+ if (!this.state.maxDataPoints && this.state.maxDataPointsFromWidth && !this._containerWidth) {
1198
1147
  return false;
1199
1148
  }
1200
- if (!this.state.maxDataPoints && this.state.maxDataPointsFromWidth && !this._containerWidth) {
1149
+ if (this._variableValueRecorder.hasDependenciesChanged(this)) {
1150
+ writeSceneLog(
1151
+ "SceneQueryRunner",
1152
+ "Variable dependency changed while inactive, shouldRunQueriesOnActivate returns true"
1153
+ );
1154
+ return true;
1155
+ }
1156
+ if (this.state.data) {
1201
1157
  return false;
1202
1158
  }
1203
1159
  return true;
@@ -1208,6 +1164,7 @@ class SceneQueryRunner extends SceneObjectBase {
1208
1164
  this._querySub.unsubscribe();
1209
1165
  this._querySub = void 0;
1210
1166
  }
1167
+ this._variableValueRecorder.recordCurrentDependencyValuesForSceneObject(this);
1211
1168
  }
1212
1169
  setContainerWidth(width) {
1213
1170
  if (!this._containerWidth && width > 0) {
@@ -1234,6 +1191,14 @@ class SceneQueryRunner extends SceneObjectBase {
1234
1191
  return (_b = (_a = this.state.maxDataPoints) != null ? _a : this._containerWidth) != null ? _b : 500;
1235
1192
  }
1236
1193
  async runWithTimeRange(timeRange) {
1194
+ if (sceneGraph.hasVariableDependencyInLoadingState(this)) {
1195
+ writeSceneLog("SceneQueryRunner", "Variable dependency is in loading state, skipping query execution");
1196
+ this.setState({ isWaitingForVariables: true });
1197
+ return;
1198
+ }
1199
+ if (this.state.isWaitingForVariables) {
1200
+ this.setState({ isWaitingForVariables: false });
1201
+ }
1237
1202
  const { datasource, minInterval, queries } = this.state;
1238
1203
  const sceneObjectScopedVar = {
1239
1204
  __sceneObject: { text: "__sceneObject", value: this }
@@ -1269,6 +1234,7 @@ class SceneQueryRunner extends SceneObjectBase {
1269
1234
  request.interval = norm.interval;
1270
1235
  request.intervalMs = norm.intervalMs;
1271
1236
  const runRequest = runtime.getRunRequest();
1237
+ writeSceneLog("SceneQueryRunner", "Starting runRequest", this.state.key);
1272
1238
  this._querySub = runRequest(ds, request).pipe(getTransformationsStream(this, this.state.transformations)).subscribe({
1273
1239
  next: this.onDataReceived
1274
1240
  });
@@ -1289,7 +1255,7 @@ const getTransformationsStream = (sceneObject, transformations) => (inputStream)
1289
1255
  return sceneGraph.interpolate(sceneObject, value, (_a = data$1 == null ? void 0 : data$1.request) == null ? void 0 : _a.scopedVars);
1290
1256
  }
1291
1257
  };
1292
- return data.transformDataFrame(transformations, data$1.series, ctx).pipe(rxjs.map((series) => __spreadProps$4(__spreadValues$a({}, data$1), { series })));
1258
+ return data.transformDataFrame(transformations, data$1.series, ctx).pipe(rxjs.map((series) => __spreadProps$4(__spreadValues$b({}, data$1), { series })));
1293
1259
  })
1294
1260
  );
1295
1261
  };
@@ -1337,30 +1303,40 @@ class SceneDataTransformer extends SceneObjectBase {
1337
1303
  }
1338
1304
  }
1339
1305
 
1306
+ class SceneVariableValueChangedEvent extends data.BusEventWithPayload {
1307
+ }
1308
+ SceneVariableValueChangedEvent.type = "scene-variable-changed-value";
1309
+
1340
1310
  class VariableValueSelectors extends SceneObjectBase {
1341
1311
  }
1342
1312
  VariableValueSelectors.Component = VariableValueSelectorsRenderer;
1343
1313
  function VariableValueSelectorsRenderer({ model }) {
1344
1314
  const variables = sceneGraph.getVariables(model).useState();
1315
+ const styles = ui.useStyles2(getStyles$2);
1345
1316
  return /* @__PURE__ */ React__default["default"].createElement(React__default["default"].Fragment, null, variables.variables.map((variable) => /* @__PURE__ */ React__default["default"].createElement(VariableValueSelectWrapper, {
1346
1317
  key: variable.state.key,
1347
- variable
1318
+ variable,
1319
+ styles
1348
1320
  })));
1349
1321
  }
1350
- function VariableValueSelectWrapper({ variable }) {
1322
+ function VariableValueSelectWrapper({
1323
+ variable,
1324
+ styles
1325
+ }) {
1351
1326
  const state = variable.useState();
1352
1327
  if (state.hide === data.VariableHide.hideVariable) {
1353
1328
  return null;
1354
1329
  }
1355
1330
  return /* @__PURE__ */ React__default["default"].createElement("div", {
1356
- className: "gf-form"
1331
+ className: styles.container
1357
1332
  }, /* @__PURE__ */ React__default["default"].createElement(VariableLabel, {
1358
- state
1333
+ state,
1334
+ styles
1359
1335
  }), /* @__PURE__ */ React__default["default"].createElement(variable.Component, {
1360
1336
  model: variable
1361
1337
  }));
1362
1338
  }
1363
- function VariableLabel({ state }) {
1339
+ function VariableLabel({ state, styles }) {
1364
1340
  var _a;
1365
1341
  if (state.hide === data.VariableHide.hideLabel) {
1366
1342
  return null;
@@ -1372,37 +1348,219 @@ function VariableLabel({ state }) {
1372
1348
  content: state.description,
1373
1349
  placement: "bottom"
1374
1350
  }, /* @__PURE__ */ React__default["default"].createElement("label", {
1375
- className: "gf-form-label gf-form-label--variable",
1351
+ className: styles.variableLabel,
1376
1352
  "data-testid": e2eSelectors.selectors.pages.Dashboard.SubMenu.submenuItemLabels(labelOrName),
1377
1353
  htmlFor: elementId
1378
1354
  }, labelOrName));
1379
1355
  }
1380
1356
  return /* @__PURE__ */ React__default["default"].createElement("label", {
1381
- className: "gf-form-label gf-form-label--variable",
1357
+ className: styles.variableLabel,
1382
1358
  "data-testid": e2eSelectors.selectors.pages.Dashboard.SubMenu.submenuItemLabels(labelOrName),
1383
1359
  htmlFor: elementId
1384
1360
  }, labelOrName);
1385
1361
  }
1362
+ const getStyles$2 = (theme) => ({
1363
+ container: css.css({
1364
+ display: "flex"
1365
+ }),
1366
+ variableLabel: css.css({
1367
+ background: theme.isDark ? theme.colors.background.primary : theme.colors.background.secondary,
1368
+ display: `flex`,
1369
+ alignItems: "center",
1370
+ padding: theme.spacing(0, 1),
1371
+ fontWeight: theme.typography.fontWeightMedium,
1372
+ fontSize: theme.typography.bodySmall.fontSize,
1373
+ height: theme.spacing(theme.components.height.md),
1374
+ lineHeight: theme.spacing(theme.components.height.md),
1375
+ borderRadius: theme.shape.borderRadius(1),
1376
+ border: `1px solid ${theme.components.input.borderColor}`,
1377
+ position: "relative",
1378
+ right: -1
1379
+ })
1380
+ });
1386
1381
 
1387
- var __defProp$9 = Object.defineProperty;
1388
- var __getOwnPropSymbols$9 = Object.getOwnPropertySymbols;
1389
- var __hasOwnProp$9 = Object.prototype.hasOwnProperty;
1390
- var __propIsEnum$9 = Object.prototype.propertyIsEnumerable;
1391
- var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1392
- var __spreadValues$9 = (a, b) => {
1382
+ class SceneVariableSet extends SceneObjectBase {
1383
+ constructor() {
1384
+ super(...arguments);
1385
+ this._variablesThatHaveChanged = /* @__PURE__ */ new Set();
1386
+ this._variablesToUpdate = /* @__PURE__ */ new Set();
1387
+ this._updating = /* @__PURE__ */ new Map();
1388
+ this._variableValueRecorder = new VariableValueRecorder();
1389
+ }
1390
+ getByName(name) {
1391
+ return this.state.variables.find((x) => x.state.name === name);
1392
+ }
1393
+ activate() {
1394
+ super.activate();
1395
+ this._subs.add(
1396
+ this.subscribeToEvent(SceneVariableValueChangedEvent, (event) => this.handleVariableValueChanged(event.payload))
1397
+ );
1398
+ this.checkForVariablesThatChangedWhileInactive();
1399
+ for (const variable of this.state.variables) {
1400
+ if (this.variableNeedsUpdate(variable)) {
1401
+ this._variablesToUpdate.add(variable);
1402
+ }
1403
+ }
1404
+ this.updateNextBatch();
1405
+ }
1406
+ checkForVariablesThatChangedWhileInactive() {
1407
+ if (!this._variableValueRecorder.hasValues()) {
1408
+ return;
1409
+ }
1410
+ for (const variable of this.state.variables) {
1411
+ if (this._variableValueRecorder.hasValueChanged(variable)) {
1412
+ writeVariableTraceLog(variable, "Changed while in-active");
1413
+ this.addDependentVariablesToUpdateQueue(variable);
1414
+ }
1415
+ }
1416
+ }
1417
+ variableNeedsUpdate(variable) {
1418
+ if (!variable.validateAndUpdate) {
1419
+ return false;
1420
+ }
1421
+ if (this._variableValueRecorder.hasRecordedValue(variable)) {
1422
+ writeVariableTraceLog(variable, "Skipping updateAndValidate current value valid");
1423
+ return false;
1424
+ }
1425
+ return true;
1426
+ }
1427
+ deactivate() {
1428
+ var _a;
1429
+ super.deactivate();
1430
+ for (const update of this._updating.values()) {
1431
+ (_a = update.subscription) == null ? void 0 : _a.unsubscribe();
1432
+ }
1433
+ for (const variable of this.state.variables) {
1434
+ if (!this._variablesToUpdate.has(variable) && !this._updating.has(variable)) {
1435
+ this._variableValueRecorder.recordCurrentValue(variable);
1436
+ }
1437
+ }
1438
+ this._variablesToUpdate.clear();
1439
+ this._updating.clear();
1440
+ }
1441
+ updateNextBatch() {
1442
+ if (this._variablesToUpdate.size === 0) {
1443
+ this.notifyDependentSceneObjects();
1444
+ return;
1445
+ }
1446
+ for (const variable of this._variablesToUpdate) {
1447
+ if (!variable.validateAndUpdate) {
1448
+ throw new Error("Variable added to variablesToUpdate but does not have validateAndUpdate");
1449
+ }
1450
+ if (this._updating.has(variable)) {
1451
+ continue;
1452
+ }
1453
+ if (this.hasDependendencyInUpdateQueue(variable)) {
1454
+ continue;
1455
+ }
1456
+ const variableToUpdate = {
1457
+ variable
1458
+ };
1459
+ this._updating.set(variable, variableToUpdate);
1460
+ writeVariableTraceLog(variable, "updateAndValidate started");
1461
+ variableToUpdate.subscription = variable.validateAndUpdate().subscribe({
1462
+ next: () => this.validateAndUpdateCompleted(variable),
1463
+ error: (err) => this.handleVariableError(variable, err)
1464
+ });
1465
+ }
1466
+ }
1467
+ validateAndUpdateCompleted(variable) {
1468
+ var _a;
1469
+ const update = this._updating.get(variable);
1470
+ (_a = update == null ? void 0 : update.subscription) == null ? void 0 : _a.unsubscribe();
1471
+ this._updating.delete(variable);
1472
+ this._variablesToUpdate.delete(variable);
1473
+ writeVariableTraceLog(variable, "updateAndValidate completed");
1474
+ this.updateNextBatch();
1475
+ }
1476
+ handleVariableError(variable, err) {
1477
+ var _a;
1478
+ const update = this._updating.get(variable);
1479
+ (_a = update == null ? void 0 : update.subscription) == null ? void 0 : _a.unsubscribe();
1480
+ this._updating.delete(variable);
1481
+ this._variablesToUpdate.delete(variable);
1482
+ variable.setState({ loading: false, error: err });
1483
+ writeVariableTraceLog(variable, "updateAndValidate error", err);
1484
+ }
1485
+ hasDependendencyInUpdateQueue(variable) {
1486
+ var _a;
1487
+ if (!variable.variableDependency) {
1488
+ return false;
1489
+ }
1490
+ for (const otherVariable of this._variablesToUpdate.values()) {
1491
+ if ((_a = variable.variableDependency) == null ? void 0 : _a.hasDependencyOn(otherVariable.state.name)) {
1492
+ return true;
1493
+ }
1494
+ }
1495
+ return false;
1496
+ }
1497
+ handleVariableValueChanged(variableThatChanged) {
1498
+ this._variablesThatHaveChanged.add(variableThatChanged);
1499
+ if (this._updating.has(variableThatChanged)) {
1500
+ return;
1501
+ }
1502
+ this.addDependentVariablesToUpdateQueue(variableThatChanged);
1503
+ this.updateNextBatch();
1504
+ }
1505
+ addDependentVariablesToUpdateQueue(variableThatChanged) {
1506
+ for (const otherVariable of this.state.variables) {
1507
+ if (otherVariable.variableDependency) {
1508
+ if (otherVariable.variableDependency.hasDependencyOn(variableThatChanged.state.name)) {
1509
+ writeVariableTraceLog(otherVariable, "Added to update quee, dependant variable value changed");
1510
+ this._variablesToUpdate.add(otherVariable);
1511
+ }
1512
+ }
1513
+ }
1514
+ }
1515
+ notifyDependentSceneObjects() {
1516
+ if (!this.parent) {
1517
+ return;
1518
+ }
1519
+ this.traverseSceneAndNotify(this.parent);
1520
+ this._variablesThatHaveChanged.clear();
1521
+ }
1522
+ traverseSceneAndNotify(sceneObject) {
1523
+ if (this === sceneObject) {
1524
+ return;
1525
+ }
1526
+ if (!sceneObject.isActive) {
1527
+ return;
1528
+ }
1529
+ if (sceneObject.variableDependency) {
1530
+ sceneObject.variableDependency.variableUpdatesCompleted(this._variablesThatHaveChanged);
1531
+ }
1532
+ forEachSceneObjectInState(sceneObject.state, (child) => this.traverseSceneAndNotify(child));
1533
+ }
1534
+ isVariableLoadingOrWaitingToUpdate(variable) {
1535
+ if (!this.isActive) {
1536
+ return true;
1537
+ }
1538
+ return this._variablesToUpdate.has(variable) || this._updating.has(variable);
1539
+ }
1540
+ }
1541
+ function writeVariableTraceLog(variable, message, err) {
1542
+ writeSceneLog("SceneVariableSet", `Variable[${variable.state.name}]: ${message}`, err);
1543
+ }
1544
+
1545
+ var __defProp$a = Object.defineProperty;
1546
+ var __getOwnPropSymbols$a = Object.getOwnPropertySymbols;
1547
+ var __hasOwnProp$a = Object.prototype.hasOwnProperty;
1548
+ var __propIsEnum$a = Object.prototype.propertyIsEnumerable;
1549
+ var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1550
+ var __spreadValues$a = (a, b) => {
1393
1551
  for (var prop in b || (b = {}))
1394
- if (__hasOwnProp$9.call(b, prop))
1395
- __defNormalProp$9(a, prop, b[prop]);
1396
- if (__getOwnPropSymbols$9)
1397
- for (var prop of __getOwnPropSymbols$9(b)) {
1398
- if (__propIsEnum$9.call(b, prop))
1399
- __defNormalProp$9(a, prop, b[prop]);
1552
+ if (__hasOwnProp$a.call(b, prop))
1553
+ __defNormalProp$a(a, prop, b[prop]);
1554
+ if (__getOwnPropSymbols$a)
1555
+ for (var prop of __getOwnPropSymbols$a(b)) {
1556
+ if (__propIsEnum$a.call(b, prop))
1557
+ __defNormalProp$a(a, prop, b[prop]);
1400
1558
  }
1401
1559
  return a;
1402
1560
  };
1403
1561
  class ConstantVariable extends SceneObjectBase {
1404
1562
  constructor(initialState) {
1405
- super(__spreadValues$9({
1563
+ super(__spreadValues$a({
1406
1564
  type: "constant",
1407
1565
  value: "",
1408
1566
  name: ""
@@ -1640,25 +1798,25 @@ class MultiValueUrlSyncHandler {
1640
1798
  }
1641
1799
  }
1642
1800
 
1643
- var __defProp$8 = Object.defineProperty;
1644
- var __getOwnPropSymbols$8 = Object.getOwnPropertySymbols;
1645
- var __hasOwnProp$8 = Object.prototype.hasOwnProperty;
1646
- var __propIsEnum$8 = Object.prototype.propertyIsEnumerable;
1647
- var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1648
- var __spreadValues$8 = (a, b) => {
1801
+ var __defProp$9 = Object.defineProperty;
1802
+ var __getOwnPropSymbols$9 = Object.getOwnPropertySymbols;
1803
+ var __hasOwnProp$9 = Object.prototype.hasOwnProperty;
1804
+ var __propIsEnum$9 = Object.prototype.propertyIsEnumerable;
1805
+ var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1806
+ var __spreadValues$9 = (a, b) => {
1649
1807
  for (var prop in b || (b = {}))
1650
- if (__hasOwnProp$8.call(b, prop))
1651
- __defNormalProp$8(a, prop, b[prop]);
1652
- if (__getOwnPropSymbols$8)
1653
- for (var prop of __getOwnPropSymbols$8(b)) {
1654
- if (__propIsEnum$8.call(b, prop))
1655
- __defNormalProp$8(a, prop, b[prop]);
1808
+ if (__hasOwnProp$9.call(b, prop))
1809
+ __defNormalProp$9(a, prop, b[prop]);
1810
+ if (__getOwnPropSymbols$9)
1811
+ for (var prop of __getOwnPropSymbols$9(b)) {
1812
+ if (__propIsEnum$9.call(b, prop))
1813
+ __defNormalProp$9(a, prop, b[prop]);
1656
1814
  }
1657
1815
  return a;
1658
1816
  };
1659
1817
  class CustomVariable extends MultiValueVariable {
1660
1818
  constructor(initialState) {
1661
- super(__spreadValues$8({
1819
+ super(__spreadValues$9({
1662
1820
  type: "custom",
1663
1821
  query: "",
1664
1822
  value: "",
@@ -1691,25 +1849,25 @@ CustomVariable.Component = ({ model }) => {
1691
1849
  return renderSelectForVariable(model);
1692
1850
  };
1693
1851
 
1694
- var __defProp$7 = Object.defineProperty;
1695
- var __getOwnPropSymbols$7 = Object.getOwnPropertySymbols;
1696
- var __hasOwnProp$7 = Object.prototype.hasOwnProperty;
1697
- var __propIsEnum$7 = Object.prototype.propertyIsEnumerable;
1698
- var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1699
- var __spreadValues$7 = (a, b) => {
1852
+ var __defProp$8 = Object.defineProperty;
1853
+ var __getOwnPropSymbols$8 = Object.getOwnPropertySymbols;
1854
+ var __hasOwnProp$8 = Object.prototype.hasOwnProperty;
1855
+ var __propIsEnum$8 = Object.prototype.propertyIsEnumerable;
1856
+ var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1857
+ var __spreadValues$8 = (a, b) => {
1700
1858
  for (var prop in b || (b = {}))
1701
- if (__hasOwnProp$7.call(b, prop))
1702
- __defNormalProp$7(a, prop, b[prop]);
1703
- if (__getOwnPropSymbols$7)
1704
- for (var prop of __getOwnPropSymbols$7(b)) {
1705
- if (__propIsEnum$7.call(b, prop))
1706
- __defNormalProp$7(a, prop, b[prop]);
1859
+ if (__hasOwnProp$8.call(b, prop))
1860
+ __defNormalProp$8(a, prop, b[prop]);
1861
+ if (__getOwnPropSymbols$8)
1862
+ for (var prop of __getOwnPropSymbols$8(b)) {
1863
+ if (__propIsEnum$8.call(b, prop))
1864
+ __defNormalProp$8(a, prop, b[prop]);
1707
1865
  }
1708
1866
  return a;
1709
1867
  };
1710
1868
  class DataSourceVariable extends MultiValueVariable {
1711
1869
  constructor(initialState) {
1712
- super(__spreadValues$7({
1870
+ super(__spreadValues$8({
1713
1871
  type: "datasource",
1714
1872
  value: "",
1715
1873
  text: "",
@@ -1787,21 +1945,21 @@ const hasStandardVariableSupport = (datasource) => {
1787
1945
  return "toDataQuery" in variableSupport && Boolean(variableSupport.toDataQuery);
1788
1946
  };
1789
1947
 
1790
- var __defProp$6 = Object.defineProperty;
1948
+ var __defProp$7 = Object.defineProperty;
1791
1949
  var __defProps$3 = Object.defineProperties;
1792
1950
  var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
1793
- var __getOwnPropSymbols$6 = Object.getOwnPropertySymbols;
1794
- var __hasOwnProp$6 = Object.prototype.hasOwnProperty;
1795
- var __propIsEnum$6 = Object.prototype.propertyIsEnumerable;
1796
- var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1797
- var __spreadValues$6 = (a, b) => {
1951
+ var __getOwnPropSymbols$7 = Object.getOwnPropertySymbols;
1952
+ var __hasOwnProp$7 = Object.prototype.hasOwnProperty;
1953
+ var __propIsEnum$7 = Object.prototype.propertyIsEnumerable;
1954
+ var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1955
+ var __spreadValues$7 = (a, b) => {
1798
1956
  for (var prop in b || (b = {}))
1799
- if (__hasOwnProp$6.call(b, prop))
1800
- __defNormalProp$6(a, prop, b[prop]);
1801
- if (__getOwnPropSymbols$6)
1802
- for (var prop of __getOwnPropSymbols$6(b)) {
1803
- if (__propIsEnum$6.call(b, prop))
1804
- __defNormalProp$6(a, prop, b[prop]);
1957
+ if (__hasOwnProp$7.call(b, prop))
1958
+ __defNormalProp$7(a, prop, b[prop]);
1959
+ if (__getOwnPropSymbols$7)
1960
+ for (var prop of __getOwnPropSymbols$7(b)) {
1961
+ if (__propIsEnum$7.call(b, prop))
1962
+ __defNormalProp$7(a, prop, b[prop]);
1805
1963
  }
1806
1964
  return a;
1807
1965
  };
@@ -1842,7 +2000,7 @@ class LegacyQueryRunner {
1842
2000
  return getEmptyMetricFindValueObservable();
1843
2001
  }
1844
2002
  return rxjs.from(
1845
- this.datasource.metricFindQuery(variable.state.query, __spreadProps$3(__spreadValues$6({}, request), {
2003
+ this.datasource.metricFindQuery(variable.state.query, __spreadProps$3(__spreadValues$7({}, request), {
1846
2004
  variable: {
1847
2005
  name: variable.state.name,
1848
2006
  type: variable.state.type
@@ -2049,25 +2207,25 @@ function areMetricFindValues(data$1) {
2049
2207
  return false;
2050
2208
  }
2051
2209
 
2052
- var __defProp$5 = Object.defineProperty;
2053
- var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
2054
- var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
2055
- var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
2056
- var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2057
- var __spreadValues$5 = (a, b) => {
2210
+ var __defProp$6 = Object.defineProperty;
2211
+ var __getOwnPropSymbols$6 = Object.getOwnPropertySymbols;
2212
+ var __hasOwnProp$6 = Object.prototype.hasOwnProperty;
2213
+ var __propIsEnum$6 = Object.prototype.propertyIsEnumerable;
2214
+ var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2215
+ var __spreadValues$6 = (a, b) => {
2058
2216
  for (var prop in b || (b = {}))
2059
- if (__hasOwnProp$5.call(b, prop))
2060
- __defNormalProp$5(a, prop, b[prop]);
2061
- if (__getOwnPropSymbols$5)
2062
- for (var prop of __getOwnPropSymbols$5(b)) {
2063
- if (__propIsEnum$5.call(b, prop))
2064
- __defNormalProp$5(a, prop, b[prop]);
2217
+ if (__hasOwnProp$6.call(b, prop))
2218
+ __defNormalProp$6(a, prop, b[prop]);
2219
+ if (__getOwnPropSymbols$6)
2220
+ for (var prop of __getOwnPropSymbols$6(b)) {
2221
+ if (__propIsEnum$6.call(b, prop))
2222
+ __defNormalProp$6(a, prop, b[prop]);
2065
2223
  }
2066
2224
  return a;
2067
2225
  };
2068
2226
  class QueryVariable extends MultiValueVariable {
2069
2227
  constructor(initialState) {
2070
- super(__spreadValues$5({
2228
+ super(__spreadValues$6({
2071
2229
  type: "query",
2072
2230
  name: "",
2073
2231
  value: "",
@@ -2101,14 +2259,12 @@ class QueryVariable extends MultiValueVariable {
2101
2259
  if (this.updateSubscription) {
2102
2260
  this.updateSubscription.unsubscribe();
2103
2261
  }
2104
- if (this.dataSourceSubject) {
2105
- this.dataSourceSubject.unsubscribe();
2106
- }
2107
2262
  }
2108
2263
  getValueOptions(args) {
2109
2264
  if (this.state.query === "" || !this.state.datasource) {
2110
2265
  return rxjs.of([]);
2111
2266
  }
2267
+ this.setState({ loading: true });
2112
2268
  return rxjs.from(
2113
2269
  getDataSource(this.state.datasource, {
2114
2270
  __sceneObject: { text: "__sceneObject", value: this }
@@ -2221,25 +2377,25 @@ function queryMetricTree(query) {
2221
2377
  return queryTree(children, query.split("."), 0);
2222
2378
  }
2223
2379
 
2224
- var __defProp$4 = Object.defineProperty;
2225
- var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
2226
- var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
2227
- var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
2228
- var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2229
- var __spreadValues$4 = (a, b) => {
2380
+ var __defProp$5 = Object.defineProperty;
2381
+ var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
2382
+ var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
2383
+ var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
2384
+ var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2385
+ var __spreadValues$5 = (a, b) => {
2230
2386
  for (var prop in b || (b = {}))
2231
- if (__hasOwnProp$4.call(b, prop))
2232
- __defNormalProp$4(a, prop, b[prop]);
2233
- if (__getOwnPropSymbols$4)
2234
- for (var prop of __getOwnPropSymbols$4(b)) {
2235
- if (__propIsEnum$4.call(b, prop))
2236
- __defNormalProp$4(a, prop, b[prop]);
2387
+ if (__hasOwnProp$5.call(b, prop))
2388
+ __defNormalProp$5(a, prop, b[prop]);
2389
+ if (__getOwnPropSymbols$5)
2390
+ for (var prop of __getOwnPropSymbols$5(b)) {
2391
+ if (__propIsEnum$5.call(b, prop))
2392
+ __defNormalProp$5(a, prop, b[prop]);
2237
2393
  }
2238
2394
  return a;
2239
2395
  };
2240
2396
  class TestVariable extends MultiValueVariable {
2241
2397
  constructor(initialState) {
2242
- super(__spreadValues$4({
2398
+ super(__spreadValues$5({
2243
2399
  type: "custom",
2244
2400
  name: "Test",
2245
2401
  value: "Value",
@@ -2456,7 +2612,7 @@ function getStyles$1(theme) {
2456
2612
  container: css.css({
2457
2613
  flexGrow: 1,
2458
2614
  display: "flex",
2459
- gap: "8px",
2615
+ gap: theme.spacing(2),
2460
2616
  minHeight: "100%",
2461
2617
  flexDirection: "column"
2462
2618
  }),
@@ -2468,7 +2624,8 @@ function getStyles$1(theme) {
2468
2624
  controls: css.css({
2469
2625
  display: "flex",
2470
2626
  gap: theme.spacing(1),
2471
- alignItems: "center"
2627
+ alignItems: "center",
2628
+ flexWrap: "wrap"
2472
2629
  })
2473
2630
  };
2474
2631
  }
@@ -2518,6 +2675,12 @@ function VizPanelRenderer({ model }) {
2518
2675
  if ($data instanceof SceneQueryRunner) {
2519
2676
  $data.setContainerWidth(width);
2520
2677
  }
2678
+ const titleItems = isDraggable ? [dragHandle] : [];
2679
+ if (model.state.$timeRange) {
2680
+ titleItems.push(/* @__PURE__ */ React__default["default"].createElement(model.state.$timeRange.Component, {
2681
+ model: model.state.$timeRange
2682
+ }));
2683
+ }
2521
2684
  return /* @__PURE__ */ React__default["default"].createElement("div", {
2522
2685
  ref,
2523
2686
  style: { position: "absolute", width: "100%", height: "100%" }
@@ -2554,25 +2717,25 @@ function VizPanelRenderer({ model }) {
2554
2717
  }
2555
2718
  VizPanelRenderer.displayName = "ScenePanelRenderer";
2556
2719
 
2557
- var __defProp$3 = Object.defineProperty;
2558
- var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
2559
- var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
2560
- var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
2561
- var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2562
- var __spreadValues$3 = (a, b) => {
2720
+ var __defProp$4 = Object.defineProperty;
2721
+ var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
2722
+ var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
2723
+ var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
2724
+ var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2725
+ var __spreadValues$4 = (a, b) => {
2563
2726
  for (var prop in b || (b = {}))
2564
- if (__hasOwnProp$3.call(b, prop))
2565
- __defNormalProp$3(a, prop, b[prop]);
2566
- if (__getOwnPropSymbols$3)
2567
- for (var prop of __getOwnPropSymbols$3(b)) {
2568
- if (__propIsEnum$3.call(b, prop))
2569
- __defNormalProp$3(a, prop, b[prop]);
2727
+ if (__hasOwnProp$4.call(b, prop))
2728
+ __defNormalProp$4(a, prop, b[prop]);
2729
+ if (__getOwnPropSymbols$4)
2730
+ for (var prop of __getOwnPropSymbols$4(b)) {
2731
+ if (__propIsEnum$4.call(b, prop))
2732
+ __defNormalProp$4(a, prop, b[prop]);
2570
2733
  }
2571
2734
  return a;
2572
2735
  };
2573
2736
  class VizPanel extends SceneObjectBase {
2574
2737
  constructor(state) {
2575
- super(__spreadValues$3({
2738
+ super(__spreadValues$4({
2576
2739
  options: {},
2577
2740
  fieldConfig: { defaults: {}, overrides: [] },
2578
2741
  title: "Title",
@@ -2642,21 +2805,21 @@ class VizPanel extends SceneObjectBase {
2642
2805
  }
2643
2806
  VizPanel.Component = VizPanelRenderer;
2644
2807
 
2645
- var __defProp$2 = Object.defineProperty;
2808
+ var __defProp$3 = Object.defineProperty;
2646
2809
  var __defProps$2 = Object.defineProperties;
2647
2810
  var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
2648
- var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
2649
- var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
2650
- var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
2651
- var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2652
- var __spreadValues$2 = (a, b) => {
2811
+ var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
2812
+ var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
2813
+ var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
2814
+ var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2815
+ var __spreadValues$3 = (a, b) => {
2653
2816
  for (var prop in b || (b = {}))
2654
- if (__hasOwnProp$2.call(b, prop))
2655
- __defNormalProp$2(a, prop, b[prop]);
2656
- if (__getOwnPropSymbols$2)
2657
- for (var prop of __getOwnPropSymbols$2(b)) {
2658
- if (__propIsEnum$2.call(b, prop))
2659
- __defNormalProp$2(a, prop, b[prop]);
2817
+ if (__hasOwnProp$3.call(b, prop))
2818
+ __defNormalProp$3(a, prop, b[prop]);
2819
+ if (__getOwnPropSymbols$3)
2820
+ for (var prop of __getOwnPropSymbols$3(b)) {
2821
+ if (__propIsEnum$3.call(b, prop))
2822
+ __defNormalProp$3(a, prop, b[prop]);
2660
2823
  }
2661
2824
  return a;
2662
2825
  };
@@ -2667,7 +2830,7 @@ class NestedScene extends SceneObjectBase {
2667
2830
  this.onToggle = () => {
2668
2831
  this.setState({
2669
2832
  isCollapsed: !this.state.isCollapsed,
2670
- placement: __spreadProps$2(__spreadValues$2({}, this.state.placement), {
2833
+ placement: __spreadProps$2(__spreadValues$3({}, this.state.placement), {
2671
2834
  ySizing: this.state.isCollapsed ? "fill" : "content"
2672
2835
  })
2673
2836
  });
@@ -2838,7 +3001,8 @@ function SceneTimePickerRenderer({ model }) {
2838
3001
  }
2839
3002
  }), /* @__PURE__ */ React__default["default"].createElement(ui.RefreshPicker, {
2840
3003
  onRefresh: timeRange.onRefresh,
2841
- onIntervalChanged: timeRange.onIntervalChanged
3004
+ onIntervalChanged: () => {
3005
+ }
2842
3006
  }));
2843
3007
  }
2844
3008
 
@@ -2979,31 +3143,31 @@ const GRID_CELL_HEIGHT = 30;
2979
3143
  const GRID_CELL_VMARGIN = 8;
2980
3144
  const GRID_COLUMN_COUNT = 24;
2981
3145
 
2982
- var __defProp$1 = Object.defineProperty;
3146
+ var __defProp$2 = Object.defineProperty;
2983
3147
  var __defProps$1 = Object.defineProperties;
2984
3148
  var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
2985
- var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
2986
- var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
2987
- var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
2988
- var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2989
- var __spreadValues$1 = (a, b) => {
3149
+ var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
3150
+ var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
3151
+ var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
3152
+ var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3153
+ var __spreadValues$2 = (a, b) => {
2990
3154
  for (var prop in b || (b = {}))
2991
- if (__hasOwnProp$1.call(b, prop))
2992
- __defNormalProp$1(a, prop, b[prop]);
2993
- if (__getOwnPropSymbols$1)
2994
- for (var prop of __getOwnPropSymbols$1(b)) {
2995
- if (__propIsEnum$1.call(b, prop))
2996
- __defNormalProp$1(a, prop, b[prop]);
3155
+ if (__hasOwnProp$2.call(b, prop))
3156
+ __defNormalProp$2(a, prop, b[prop]);
3157
+ if (__getOwnPropSymbols$2)
3158
+ for (var prop of __getOwnPropSymbols$2(b)) {
3159
+ if (__propIsEnum$2.call(b, prop))
3160
+ __defNormalProp$2(a, prop, b[prop]);
2997
3161
  }
2998
3162
  return a;
2999
3163
  };
3000
3164
  var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
3001
3165
  class SceneGridRow extends SceneObjectBase {
3002
3166
  constructor(state) {
3003
- super(__spreadProps$1(__spreadValues$1({
3167
+ super(__spreadProps$1(__spreadValues$2({
3004
3168
  isCollapsible: true
3005
3169
  }, state), {
3006
- placement: __spreadProps$1(__spreadValues$1({
3170
+ placement: __spreadProps$1(__spreadValues$2({
3007
3171
  isResizable: false,
3008
3172
  isDraggable: true
3009
3173
  }, state.placement), {
@@ -3091,29 +3255,29 @@ const getSceneGridRowStyles = (theme) => {
3091
3255
  };
3092
3256
  };
3093
3257
 
3094
- var __defProp = Object.defineProperty;
3258
+ var __defProp$1 = Object.defineProperty;
3095
3259
  var __defProps = Object.defineProperties;
3096
3260
  var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
3097
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3098
- var __hasOwnProp = Object.prototype.hasOwnProperty;
3099
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
3100
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3101
- var __spreadValues = (a, b) => {
3261
+ var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
3262
+ var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
3263
+ var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
3264
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3265
+ var __spreadValues$1 = (a, b) => {
3102
3266
  for (var prop in b || (b = {}))
3103
- if (__hasOwnProp.call(b, prop))
3104
- __defNormalProp(a, prop, b[prop]);
3105
- if (__getOwnPropSymbols)
3106
- for (var prop of __getOwnPropSymbols(b)) {
3107
- if (__propIsEnum.call(b, prop))
3108
- __defNormalProp(a, prop, b[prop]);
3267
+ if (__hasOwnProp$1.call(b, prop))
3268
+ __defNormalProp$1(a, prop, b[prop]);
3269
+ if (__getOwnPropSymbols$1)
3270
+ for (var prop of __getOwnPropSymbols$1(b)) {
3271
+ if (__propIsEnum$1.call(b, prop))
3272
+ __defNormalProp$1(a, prop, b[prop]);
3109
3273
  }
3110
3274
  return a;
3111
3275
  };
3112
3276
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
3113
3277
  class SceneGridLayout extends SceneObjectBase {
3114
3278
  constructor(state) {
3115
- super(__spreadProps(__spreadValues({}, state), {
3116
- placement: __spreadValues({
3279
+ super(__spreadProps(__spreadValues$1({}, state), {
3280
+ placement: __spreadValues$1({
3117
3281
  isDraggable: true
3118
3282
  }, state.placement),
3119
3283
  children: sortChildrenByPosition(state.children)
@@ -3134,7 +3298,7 @@ class SceneGridLayout extends SceneObjectBase {
3134
3298
  };
3135
3299
  if (!isItemSizeEqual(child.state.placement, nextSize)) {
3136
3300
  child.setState({
3137
- placement: __spreadValues(__spreadValues({}, child.state.placement), nextSize)
3301
+ placement: __spreadValues$1(__spreadValues$1({}, child.state.placement), nextSize)
3138
3302
  });
3139
3303
  }
3140
3304
  }
@@ -3143,7 +3307,7 @@ class SceneGridLayout extends SceneObjectBase {
3143
3307
  this.onResizeStop = (_, o, n) => {
3144
3308
  const child = this.getSceneLayoutChild(n.i);
3145
3309
  child.setState({
3146
- placement: __spreadProps(__spreadValues({}, child.state.placement), {
3310
+ placement: __spreadProps(__spreadValues$1({}, child.state.placement), {
3147
3311
  width: n.w,
3148
3312
  height: n.h
3149
3313
  })
@@ -3158,7 +3322,7 @@ class SceneGridLayout extends SceneObjectBase {
3158
3322
  const childSize = child.state.placement;
3159
3323
  if ((childSize == null ? void 0 : childSize.x) !== gridItem.x || (childSize == null ? void 0 : childSize.y) !== gridItem.y) {
3160
3324
  child.setState({
3161
- placement: __spreadProps(__spreadValues({}, child.state.placement), {
3325
+ placement: __spreadProps(__spreadValues$1({}, child.state.placement), {
3162
3326
  x: gridItem.x,
3163
3327
  y: gridItem.y
3164
3328
  })
@@ -3194,7 +3358,7 @@ class SceneGridLayout extends SceneObjectBase {
3194
3358
  const yDiff = firstPanelYPos - (rowY + 1);
3195
3359
  let yMax = rowY;
3196
3360
  for (const panel of rowChildren) {
3197
- const newSize = __spreadValues({}, panel.state.placement);
3361
+ const newSize = __spreadValues$1({}, panel.state.placement);
3198
3362
  newSize.y = (_d = newSize.y) != null ? _d : rowY;
3199
3363
  newSize.y -= yDiff;
3200
3364
  if (newSize.y > ((_e = panel.state.placement) == null ? void 0 : _e.y)) {
@@ -3236,7 +3400,7 @@ class SceneGridLayout extends SceneObjectBase {
3236
3400
  pushChildDown(child, amount) {
3237
3401
  var _a;
3238
3402
  child.setState({
3239
- placement: __spreadProps(__spreadValues({}, child.state.placement), {
3403
+ placement: __spreadProps(__spreadValues$1({}, child.state.placement), {
3240
3404
  y: ((_a = child.state.placement) == null ? void 0 : _a.y) + amount
3241
3405
  })
3242
3406
  });
@@ -3304,7 +3468,7 @@ class SceneGridLayout extends SceneObjectBase {
3304
3468
  cells = sortGridLayout(cells);
3305
3469
  if (width < 768) {
3306
3470
  this._skipOnLayoutChange = true;
3307
- return cells.map((cell) => __spreadProps(__spreadValues({}, cell), { w: 24 }));
3471
+ return cells.map((cell) => __spreadProps(__spreadValues$1({}, cell), { w: 24 }));
3308
3472
  }
3309
3473
  this._skipOnLayoutChange = false;
3310
3474
  return cells;
@@ -3370,6 +3534,194 @@ function sortGridLayout(layout) {
3370
3534
  return [...layout].sort((a, b) => a.y - b.y || a.x - b.x);
3371
3535
  }
3372
3536
 
3537
+ var __defProp = Object.defineProperty;
3538
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3539
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
3540
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
3541
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3542
+ var __spreadValues = (a, b) => {
3543
+ for (var prop in b || (b = {}))
3544
+ if (__hasOwnProp.call(b, prop))
3545
+ __defNormalProp(a, prop, b[prop]);
3546
+ if (__getOwnPropSymbols)
3547
+ for (var prop of __getOwnPropSymbols(b)) {
3548
+ if (__propIsEnum.call(b, prop))
3549
+ __defNormalProp(a, prop, b[prop]);
3550
+ }
3551
+ return a;
3552
+ };
3553
+ function useAppQueryParams() {
3554
+ const location = reactRouterDom.useLocation();
3555
+ return runtime.locationSearchToObject(location.search || "");
3556
+ }
3557
+ function getLinkUrlWithAppUrlState(path, params, preserveParams) {
3558
+ const paramsCopy = __spreadValues({}, params);
3559
+ if (preserveParams) {
3560
+ for (const key of Object.keys(paramsCopy)) {
3561
+ if (!preserveParams.includes(key)) {
3562
+ delete paramsCopy[key];
3563
+ }
3564
+ }
3565
+ }
3566
+ return data.urlUtil.renderUrl(path, paramsCopy);
3567
+ }
3568
+
3569
+ const sceneCache = /* @__PURE__ */ new Map();
3570
+ class SceneApp extends SceneObjectBase {
3571
+ }
3572
+ SceneApp.Component = ({ model }) => {
3573
+ const { pages } = model.useState();
3574
+ return /* @__PURE__ */ React__default["default"].createElement(reactRouterDom.Switch, null, pages.map((page) => /* @__PURE__ */ React__default["default"].createElement(reactRouterDom.Route, {
3575
+ key: page.state.url,
3576
+ exact: false,
3577
+ path: page.state.url,
3578
+ render: () => {
3579
+ return page && /* @__PURE__ */ React__default["default"].createElement(page.Component, {
3580
+ model: page
3581
+ });
3582
+ }
3583
+ })));
3584
+ };
3585
+ class SceneAppPage extends SceneObjectBase {
3586
+ }
3587
+ SceneAppPage.Component = SceneAppPageRenderer;
3588
+ function SceneAppPageRenderer({ model }) {
3589
+ var _a;
3590
+ const { tabs, drilldowns, url, routePath } = model.state;
3591
+ const routes = [];
3592
+ if (tabs) {
3593
+ for (const page2 of tabs) {
3594
+ routes.push(
3595
+ /* @__PURE__ */ React__default["default"].createElement(reactRouterDom.Route, {
3596
+ exact: true,
3597
+ key: page2.state.url,
3598
+ path: (_a = page2.state.routePath) != null ? _a : page2.state.url,
3599
+ render: () => {
3600
+ return /* @__PURE__ */ React__default["default"].createElement(page2.Component, {
3601
+ model: page2
3602
+ });
3603
+ }
3604
+ })
3605
+ );
3606
+ if (page2.state.drilldowns) {
3607
+ for (const drilldown of page2.state.drilldowns) {
3608
+ routes.push(
3609
+ /* @__PURE__ */ React__default["default"].createElement(reactRouterDom.Route, {
3610
+ exact: false,
3611
+ key: drilldown.routePath,
3612
+ path: drilldown.routePath,
3613
+ render: () => {
3614
+ return /* @__PURE__ */ React__default["default"].createElement(SceneAppDrilldownViewRender, {
3615
+ drilldown,
3616
+ parent: page2
3617
+ });
3618
+ }
3619
+ })
3620
+ );
3621
+ }
3622
+ }
3623
+ }
3624
+ return /* @__PURE__ */ React__default["default"].createElement(reactRouterDom.Switch, null, routes);
3625
+ }
3626
+ if (drilldowns) {
3627
+ for (const drilldown of drilldowns) {
3628
+ routes.push(
3629
+ /* @__PURE__ */ React__default["default"].createElement(reactRouterDom.Route, {
3630
+ key: drilldown.routePath,
3631
+ exact: false,
3632
+ path: drilldown.routePath,
3633
+ render: () => {
3634
+ return /* @__PURE__ */ React__default["default"].createElement(SceneAppDrilldownViewRender, {
3635
+ drilldown,
3636
+ parent: model
3637
+ });
3638
+ }
3639
+ })
3640
+ );
3641
+ }
3642
+ }
3643
+ let page = /* @__PURE__ */ React__default["default"].createElement(ScenePageRenderer, {
3644
+ page: model
3645
+ });
3646
+ if (model.parent instanceof SceneAppPage) {
3647
+ page = /* @__PURE__ */ React__default["default"].createElement(ScenePageRenderer, {
3648
+ page: model.parent,
3649
+ activeTab: model,
3650
+ tabs: model.parent.state.tabs
3651
+ });
3652
+ }
3653
+ return /* @__PURE__ */ React__default["default"].createElement(reactRouterDom.Switch, null, /* @__PURE__ */ React__default["default"].createElement(reactRouterDom.Route, {
3654
+ key: url,
3655
+ exact: true,
3656
+ path: routePath != null ? routePath : url,
3657
+ render: () => {
3658
+ return page;
3659
+ }
3660
+ }), routes);
3661
+ }
3662
+ function ScenePageRenderer({ page, tabs, activeTab }) {
3663
+ const [isInitialized, setIsInitialized] = React.useState(false);
3664
+ const params = useAppQueryParams();
3665
+ const routeMatch = reactRouterDom.useRouteMatch();
3666
+ let scene = sceneCache.get(routeMatch.url);
3667
+ if (!scene) {
3668
+ scene = activeTab ? activeTab.state.getScene(routeMatch) : page.state.getScene(routeMatch);
3669
+ sceneCache.set(routeMatch.url, scene);
3670
+ }
3671
+ React.useEffect(() => {
3672
+ if (!isInitialized && scene) {
3673
+ scene.initUrlSync();
3674
+ setIsInitialized(true);
3675
+ }
3676
+ }, [isInitialized, scene]);
3677
+ if (!isInitialized) {
3678
+ return null;
3679
+ }
3680
+ const pageNav = {
3681
+ text: page.state.title,
3682
+ subTitle: page.state.subTitle,
3683
+ url: getLinkUrlWithAppUrlState(page.state.url, params, page.state.preserveUrlKeys),
3684
+ hideFromBreadcrumbs: page.state.hideFromBreadcrumbs,
3685
+ parentItem: getParentBreadcrumbs(page.state.getParentPage ? page.state.getParentPage() : page.parent, params)
3686
+ };
3687
+ if (tabs) {
3688
+ pageNav.children = tabs.map((tab) => {
3689
+ return {
3690
+ text: tab.state.title,
3691
+ active: activeTab === tab,
3692
+ url: getLinkUrlWithAppUrlState(tab.state.url, params, tab.state.preserveUrlKeys),
3693
+ parentItem: pageNav
3694
+ };
3695
+ });
3696
+ }
3697
+ return /* @__PURE__ */ React__default["default"].createElement(runtime.PluginPage, {
3698
+ pageNav
3699
+ }, /* @__PURE__ */ React__default["default"].createElement(scene.Component, {
3700
+ model: scene
3701
+ }));
3702
+ }
3703
+ function SceneAppDrilldownViewRender(props) {
3704
+ const routeMatch = reactRouterDom.useRouteMatch();
3705
+ const scene = props.drilldown.getPage(routeMatch, props.parent);
3706
+ return /* @__PURE__ */ React__default["default"].createElement(scene.Component, {
3707
+ model: scene
3708
+ });
3709
+ }
3710
+ function getParentBreadcrumbs(parent, params) {
3711
+ if (parent instanceof SceneAppPage) {
3712
+ return {
3713
+ text: parent.state.title,
3714
+ url: getLinkUrlWithAppUrlState(parent.state.url, params, parent.state.preserveUrlKeys),
3715
+ hideFromBreadcrumbs: parent.state.hideFromBreadcrumbs,
3716
+ parentItem: getParentBreadcrumbs(
3717
+ parent.state.getParentPage ? parent.state.getParentPage() : parent.parent,
3718
+ params
3719
+ )
3720
+ };
3721
+ }
3722
+ return void 0;
3723
+ }
3724
+
3373
3725
  exports.ConstantVariable = ConstantVariable;
3374
3726
  exports.CustomVariable = CustomVariable;
3375
3727
  exports.DataSourceVariable = DataSourceVariable;
@@ -3377,6 +3729,8 @@ exports.EmbeddedScene = EmbeddedScene;
3377
3729
  exports.FormatRegistryID = FormatRegistryID;
3378
3730
  exports.NestedScene = NestedScene;
3379
3731
  exports.QueryVariable = QueryVariable;
3732
+ exports.SceneApp = SceneApp;
3733
+ exports.SceneAppPage = SceneAppPage;
3380
3734
  exports.SceneByFrameRepeater = SceneByFrameRepeater;
3381
3735
  exports.SceneCanvasText = SceneCanvasText;
3382
3736
  exports.SceneControlsSpacer = SceneControlsSpacer;