@grafana/scenes 0.0.10 → 0.0.12
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/esm/components/VizPanel/VizPanel.js.map +1 -1
- package/dist/esm/components/VizPanel/VizPanelRenderer.js +8 -5
- package/dist/esm/components/VizPanel/VizPanelRenderer.js.map +1 -1
- package/dist/esm/components/layout/SceneFlexLayout.js +10 -2
- package/dist/esm/components/layout/SceneFlexLayout.js.map +1 -1
- package/dist/esm/querying/SceneQueryRunner.js +3 -1
- package/dist/esm/querying/SceneQueryRunner.js.map +1 -1
- package/dist/esm/variables/interpolation/sceneInterpolator.js.map +1 -1
- package/dist/esm/variables/sets/SceneVariableSet.js +88 -41
- package/dist/esm/variables/sets/SceneVariableSet.js.map +1 -1
- package/dist/index.d.ts +13 -13
- package/dist/index.js +108 -49
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -421,53 +421,78 @@ SceneVariableValueChangedEvent.type = "scene-variable-changed-value";
|
|
|
421
421
|
class SceneVariableSet extends SceneObjectBase {
|
|
422
422
|
constructor() {
|
|
423
423
|
super(...arguments);
|
|
424
|
-
this.
|
|
425
|
-
this.
|
|
426
|
-
this.
|
|
427
|
-
this.onVariableValueChanged = (event) => {
|
|
428
|
-
const variableThatChanged = event.payload;
|
|
429
|
-
this.variablesThatHaveChanged.add(variableThatChanged);
|
|
430
|
-
if (this.updating.has(variableThatChanged)) {
|
|
431
|
-
return;
|
|
432
|
-
}
|
|
433
|
-
for (const otherVariable of this.state.variables) {
|
|
434
|
-
if (otherVariable.variableDependency) {
|
|
435
|
-
if (otherVariable.variableDependency.hasDependencyOn(variableThatChanged.state.name)) {
|
|
436
|
-
this.variablesToUpdate.add(otherVariable);
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
this.updateNextBatch();
|
|
441
|
-
};
|
|
424
|
+
this._variablesThatHaveChanged = /* @__PURE__ */ new Set();
|
|
425
|
+
this._variablesToUpdate = /* @__PURE__ */ new Set();
|
|
426
|
+
this._updating = /* @__PURE__ */ new Map();
|
|
442
427
|
}
|
|
443
428
|
getByName(name) {
|
|
444
429
|
return this.state.variables.find((x) => x.state.name === name);
|
|
445
430
|
}
|
|
446
431
|
activate() {
|
|
447
432
|
super.activate();
|
|
448
|
-
this._subs.add(
|
|
449
|
-
|
|
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;
|
|
450
470
|
}
|
|
451
471
|
deactivate() {
|
|
452
472
|
var _a;
|
|
453
473
|
super.deactivate();
|
|
454
|
-
for (const update of this.
|
|
474
|
+
for (const update of this._updating.values()) {
|
|
455
475
|
(_a = update.subscription) == null ? void 0 : _a.unsubscribe();
|
|
456
476
|
}
|
|
457
|
-
this.
|
|
458
|
-
this.
|
|
459
|
-
|
|
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();
|
|
460
485
|
}
|
|
461
486
|
updateNextBatch() {
|
|
462
|
-
if (this.
|
|
487
|
+
if (this._variablesToUpdate.size === 0 && this._variablesThatHaveChanged.size > 0) {
|
|
463
488
|
this.notifyDependentSceneObjects();
|
|
464
489
|
return;
|
|
465
490
|
}
|
|
466
|
-
for (const variable of this.
|
|
491
|
+
for (const variable of this._variablesToUpdate) {
|
|
467
492
|
if (!variable.validateAndUpdate) {
|
|
468
493
|
throw new Error("Variable added to variablesToUpdate but does not have validateAndUpdate");
|
|
469
494
|
}
|
|
470
|
-
if (this.
|
|
495
|
+
if (this._updating.has(variable)) {
|
|
471
496
|
continue;
|
|
472
497
|
}
|
|
473
498
|
if (this.hasDependendencyInUpdateQueue(variable)) {
|
|
@@ -476,7 +501,8 @@ class SceneVariableSet extends SceneObjectBase {
|
|
|
476
501
|
const variableToUpdate = {
|
|
477
502
|
variable
|
|
478
503
|
};
|
|
479
|
-
this.
|
|
504
|
+
this._updating.set(variable, variableToUpdate);
|
|
505
|
+
writeVariableTraceLog(variable, "updateAndValidate started");
|
|
480
506
|
variableToUpdate.subscription = variable.validateAndUpdate().subscribe({
|
|
481
507
|
next: () => this.validateAndUpdateCompleted(variable),
|
|
482
508
|
error: (err) => this.handleVariableError(variable, err)
|
|
@@ -485,36 +511,45 @@ class SceneVariableSet extends SceneObjectBase {
|
|
|
485
511
|
}
|
|
486
512
|
validateAndUpdateCompleted(variable) {
|
|
487
513
|
var _a;
|
|
488
|
-
const update = this.
|
|
514
|
+
const update = this._updating.get(variable);
|
|
489
515
|
(_a = update == null ? void 0 : update.subscription) == null ? void 0 : _a.unsubscribe();
|
|
490
|
-
this.
|
|
491
|
-
this.
|
|
516
|
+
this._updating.delete(variable);
|
|
517
|
+
this._variablesToUpdate.delete(variable);
|
|
518
|
+
writeVariableTraceLog(variable, "updateAndValidate completed");
|
|
492
519
|
this.updateNextBatch();
|
|
493
520
|
}
|
|
494
521
|
handleVariableError(variable, err) {
|
|
495
522
|
var _a;
|
|
496
|
-
const update = this.
|
|
523
|
+
const update = this._updating.get(variable);
|
|
497
524
|
(_a = update == null ? void 0 : update.subscription) == null ? void 0 : _a.unsubscribe();
|
|
498
|
-
this.
|
|
499
|
-
this.
|
|
525
|
+
this._updating.delete(variable);
|
|
526
|
+
this._variablesToUpdate.delete(variable);
|
|
500
527
|
variable.setState({ loading: false, error: err });
|
|
528
|
+
writeVariableTraceLog(variable, "updateAndValidate error", err);
|
|
501
529
|
}
|
|
502
530
|
hasDependendencyInUpdateQueue(variable) {
|
|
503
531
|
var _a;
|
|
504
532
|
if (!variable.variableDependency) {
|
|
505
533
|
return false;
|
|
506
534
|
}
|
|
507
|
-
for (const otherVariable of this.
|
|
535
|
+
for (const otherVariable of this._variablesToUpdate.values()) {
|
|
508
536
|
if ((_a = variable.variableDependency) == null ? void 0 : _a.hasDependencyOn(otherVariable.state.name)) {
|
|
509
537
|
return true;
|
|
510
538
|
}
|
|
511
539
|
}
|
|
512
540
|
return false;
|
|
513
541
|
}
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
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
|
+
}
|
|
518
553
|
}
|
|
519
554
|
}
|
|
520
555
|
this.updateNextBatch();
|
|
@@ -524,18 +559,29 @@ class SceneVariableSet extends SceneObjectBase {
|
|
|
524
559
|
return;
|
|
525
560
|
}
|
|
526
561
|
this.traverseSceneAndNotify(this.parent);
|
|
527
|
-
this.
|
|
562
|
+
this._variablesThatHaveChanged.clear();
|
|
528
563
|
}
|
|
529
564
|
traverseSceneAndNotify(sceneObject) {
|
|
530
565
|
if (this === sceneObject) {
|
|
531
566
|
return;
|
|
532
567
|
}
|
|
533
568
|
if (sceneObject.variableDependency) {
|
|
534
|
-
sceneObject.variableDependency.variableValuesChanged(this.
|
|
569
|
+
sceneObject.variableDependency.variableValuesChanged(this._variablesThatHaveChanged);
|
|
535
570
|
}
|
|
536
571
|
forEachSceneObjectInState(sceneObject.state, (child) => this.traverseSceneAndNotify(child));
|
|
537
572
|
}
|
|
538
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
|
+
}
|
|
539
585
|
|
|
540
586
|
const EmptyVariableSet = new SceneVariableSet({ variables: [] });
|
|
541
587
|
const EmptyDataNode = new SceneDataNode({
|
|
@@ -1174,7 +1220,9 @@ class SceneQueryRunner extends SceneObjectBase {
|
|
|
1174
1220
|
}, 0);
|
|
1175
1221
|
}
|
|
1176
1222
|
} else {
|
|
1177
|
-
|
|
1223
|
+
if (width > 0) {
|
|
1224
|
+
this._containerWidth = width;
|
|
1225
|
+
}
|
|
1178
1226
|
}
|
|
1179
1227
|
}
|
|
1180
1228
|
runQueries() {
|
|
@@ -2442,10 +2490,10 @@ function VizPanelRenderer({ model }) {
|
|
|
2442
2490
|
var _a;
|
|
2443
2491
|
const theme = ui.useTheme2();
|
|
2444
2492
|
const replace = React.useMemo(
|
|
2445
|
-
() => (value, scoped) => sceneGraph.interpolate(model, value, scoped),
|
|
2493
|
+
() => (value, scoped, format) => sceneGraph.interpolate(model, value, scoped, format),
|
|
2446
2494
|
[model]
|
|
2447
2495
|
);
|
|
2448
|
-
const { title, options, fieldConfig, pluginId, pluginLoadError, $data, placement } = model.useState();
|
|
2496
|
+
const { title, description, options, fieldConfig, pluginId, pluginLoadError, $data, placement } = model.useState();
|
|
2449
2497
|
const [ref, { width, height }] = reactUse.useMeasure();
|
|
2450
2498
|
const plugin = model.getPlugin();
|
|
2451
2499
|
const { data: data$1 } = sceneGraph.getData(model).useState();
|
|
@@ -2454,7 +2502,7 @@ function VizPanelRenderer({ model }) {
|
|
|
2454
2502
|
const dragHandle = /* @__PURE__ */ React__default["default"].createElement(SceneDragHandle, {
|
|
2455
2503
|
layoutKey: parentLayout.state.key
|
|
2456
2504
|
});
|
|
2457
|
-
const titleInterpolated =
|
|
2505
|
+
const titleInterpolated = replace(title, void 0, "text");
|
|
2458
2506
|
const timeZone = sceneGraph.getTimeRange(model).state.timeZone;
|
|
2459
2507
|
const dataWithOverrides = data.useFieldOverrides(plugin, fieldConfig, data$1, timeZone, theme, replace);
|
|
2460
2508
|
if (pluginLoadError) {
|
|
@@ -2475,9 +2523,12 @@ function VizPanelRenderer({ model }) {
|
|
|
2475
2523
|
style: { position: "absolute", width: "100%", height: "100%" }
|
|
2476
2524
|
}, /* @__PURE__ */ React__default["default"].createElement(ui.PanelChrome, {
|
|
2477
2525
|
title: titleInterpolated,
|
|
2526
|
+
description: description ? () => replace(description) : "",
|
|
2527
|
+
loadingState: dataWithOverrides == null ? void 0 : dataWithOverrides.state,
|
|
2528
|
+
statusMessage: (dataWithOverrides == null ? void 0 : dataWithOverrides.error) ? dataWithOverrides.error.message : "",
|
|
2478
2529
|
width,
|
|
2479
2530
|
height,
|
|
2480
|
-
|
|
2531
|
+
titleItems: isDraggable ? [dragHandle] : []
|
|
2481
2532
|
}, (innerWidth, innerHeight) => /* @__PURE__ */ React__default["default"].createElement(React__default["default"].Fragment, null, !dataWithOverrides && /* @__PURE__ */ React__default["default"].createElement("div", null, "No data..."), dataWithOverrides && /* @__PURE__ */ React__default["default"].createElement(ui.ErrorBoundaryAlert, {
|
|
2482
2533
|
dependencies: [plugin, data$1]
|
|
2483
2534
|
}, /* @__PURE__ */ React__default["default"].createElement(data.PluginContextProvider, {
|
|
@@ -2494,7 +2545,7 @@ function VizPanelRenderer({ model }) {
|
|
|
2494
2545
|
width: innerWidth,
|
|
2495
2546
|
height: innerHeight,
|
|
2496
2547
|
renderCounter: 0,
|
|
2497
|
-
replaceVariables:
|
|
2548
|
+
replaceVariables: replace,
|
|
2498
2549
|
onOptionsChange: model.onOptionsChange,
|
|
2499
2550
|
onFieldConfigChange: model.onFieldConfigChange,
|
|
2500
2551
|
onChangeTimeRange: model.onChangeTimeRange,
|
|
@@ -2843,9 +2894,17 @@ class SceneFlexLayout extends SceneObjectBase {
|
|
|
2843
2894
|
SceneFlexLayout.Component = FlexLayoutRenderer;
|
|
2844
2895
|
SceneFlexLayout.Editor = FlexLayoutEditor;
|
|
2845
2896
|
function FlexLayoutRenderer({ model, isEditing }) {
|
|
2846
|
-
const { direction = "row", children } = model.useState();
|
|
2897
|
+
const { direction = "row", children, wrap } = model.useState();
|
|
2898
|
+
const style = {
|
|
2899
|
+
flexGrow: 1,
|
|
2900
|
+
flexDirection: direction,
|
|
2901
|
+
display: "flex",
|
|
2902
|
+
gap: "8px",
|
|
2903
|
+
flexWrap: wrap,
|
|
2904
|
+
alignContent: "baseline"
|
|
2905
|
+
};
|
|
2847
2906
|
return /* @__PURE__ */ React__default["default"].createElement("div", {
|
|
2848
|
-
style
|
|
2907
|
+
style
|
|
2849
2908
|
}, children.map((item) => /* @__PURE__ */ React__default["default"].createElement(FlexLayoutChildComponent, {
|
|
2850
2909
|
key: item.state.key,
|
|
2851
2910
|
item,
|