@grafana/scenes 0.0.16 → 0.0.18
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/SceneCanvasText.js.map +1 -1
- package/dist/esm/components/SceneDragHandle.js +2 -2
- package/dist/esm/components/SceneDragHandle.js.map +1 -1
- package/dist/esm/components/VizPanel/VizPanelRenderer.js +7 -7
- package/dist/esm/components/VizPanel/VizPanelRenderer.js.map +1 -1
- package/dist/esm/components/layout/SceneFlexLayout.js +3 -0
- package/dist/esm/components/layout/SceneFlexLayout.js.map +1 -1
- package/dist/esm/components/layout/SceneGridLayout.js +13 -3
- package/dist/esm/components/layout/SceneGridLayout.js.map +1 -1
- package/dist/esm/components/layout/SceneGridRow.js +9 -8
- package/dist/esm/components/layout/SceneGridRow.js.map +1 -1
- package/dist/esm/core/sceneGraph.js +1 -1
- package/dist/esm/core/sceneGraph.js.map +1 -1
- package/dist/esm/core/types.js.map +1 -1
- package/dist/esm/querying/SceneQueryRunner.js +20 -17
- package/dist/esm/querying/SceneQueryRunner.js.map +1 -1
- package/dist/esm/variables/interpolation/formatRegistry.js +3 -0
- package/dist/esm/variables/interpolation/formatRegistry.js.map +1 -1
- package/dist/esm/variables/variants/TextBoxVariable.js.map +1 -1
- package/dist/esm/variables/variants/query/createQueryVariableRunner.js +25 -1
- package/dist/esm/variables/variants/query/createQueryVariableRunner.js.map +1 -1
- package/dist/esm/variables/variants/query/guards.js +11 -1
- package/dist/esm/variables/variants/query/guards.js.map +1 -1
- package/dist/index.d.ts +24 -4
- package/dist/index.js +102 -46
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -628,6 +628,9 @@ const formatRegistry = new data.Registry(() => {
|
|
|
628
628
|
name: "JSON",
|
|
629
629
|
description: "JSON stringify value",
|
|
630
630
|
formatter: (value) => {
|
|
631
|
+
if (typeof value === "string") {
|
|
632
|
+
return value;
|
|
633
|
+
}
|
|
631
634
|
return JSON.stringify(value);
|
|
632
635
|
}
|
|
633
636
|
},
|
|
@@ -880,7 +883,7 @@ function getSceneEditor(sceneObject) {
|
|
|
880
883
|
throw new Error("No editor found in scene tree");
|
|
881
884
|
}
|
|
882
885
|
function getLayout(scene) {
|
|
883
|
-
if (
|
|
886
|
+
if ("isDraggable" in scene) {
|
|
884
887
|
return scene;
|
|
885
888
|
}
|
|
886
889
|
if (scene.parent) {
|
|
@@ -1234,7 +1237,7 @@ class SceneQueryRunner extends SceneObjectBase {
|
|
|
1234
1237
|
request.intervalMs = norm.intervalMs;
|
|
1235
1238
|
const runRequest = runtime.getRunRequest();
|
|
1236
1239
|
writeSceneLog("SceneQueryRunner", "Starting runRequest", this.state.key);
|
|
1237
|
-
this._querySub = runRequest(ds, request).pipe(getTransformationsStream(this, this.state.transformations)).subscribe({
|
|
1240
|
+
this._querySub = runRequest(ds, request).pipe(getTransformationsStream(this, this.state.transformations, this.state.data)).subscribe({
|
|
1238
1241
|
next: this.onDataReceived
|
|
1239
1242
|
});
|
|
1240
1243
|
} catch (err) {
|
|
@@ -1242,22 +1245,25 @@ class SceneQueryRunner extends SceneObjectBase {
|
|
|
1242
1245
|
}
|
|
1243
1246
|
}
|
|
1244
1247
|
}
|
|
1245
|
-
|
|
1246
|
-
return inputStream
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
interpolate: (value) => {
|
|
1253
|
-
var _a;
|
|
1254
|
-
return sceneGraph.interpolate(sceneObject, value, (_a = data$1 == null ? void 0 : data$1.request) == null ? void 0 : _a.scopedVars);
|
|
1248
|
+
function getTransformationsStream(sceneObject, transformations, lastResult) {
|
|
1249
|
+
return (inputStream) => {
|
|
1250
|
+
return inputStream.pipe(
|
|
1251
|
+
rxjs.mergeMap((data$1) => {
|
|
1252
|
+
const preProcessedData = data.preProcessPanelData(data$1, lastResult);
|
|
1253
|
+
if (!transformations || transformations.length === 0) {
|
|
1254
|
+
return rxjs.of(preProcessedData);
|
|
1255
1255
|
}
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
}
|
|
1256
|
+
const ctx = {
|
|
1257
|
+
interpolate: (value) => {
|
|
1258
|
+
var _a;
|
|
1259
|
+
return sceneGraph.interpolate(sceneObject, value, (_a = preProcessedData == null ? void 0 : preProcessedData.request) == null ? void 0 : _a.scopedVars);
|
|
1260
|
+
}
|
|
1261
|
+
};
|
|
1262
|
+
return data.transformDataFrame(transformations, data$1.series, ctx).pipe(rxjs.map((series) => __spreadProps$5(__spreadValues$d({}, data$1), { series })));
|
|
1263
|
+
})
|
|
1264
|
+
);
|
|
1265
|
+
};
|
|
1266
|
+
}
|
|
1261
1267
|
|
|
1262
1268
|
class SceneDataTransformer extends SceneObjectBase {
|
|
1263
1269
|
activate() {
|
|
@@ -1943,6 +1949,16 @@ const hasStandardVariableSupport = (datasource) => {
|
|
|
1943
1949
|
const variableSupport = datasource.variables;
|
|
1944
1950
|
return "toDataQuery" in variableSupport && Boolean(variableSupport.toDataQuery);
|
|
1945
1951
|
};
|
|
1952
|
+
const hasCustomVariableSupport = (datasource) => {
|
|
1953
|
+
if (!datasource.variables) {
|
|
1954
|
+
return false;
|
|
1955
|
+
}
|
|
1956
|
+
if (datasource.variables.getType() !== data.VariableSupportType.Custom) {
|
|
1957
|
+
return false;
|
|
1958
|
+
}
|
|
1959
|
+
const variableSupport = datasource.variables;
|
|
1960
|
+
return "query" in variableSupport && "editor" in variableSupport && Boolean(variableSupport.query) && Boolean(variableSupport.editor);
|
|
1961
|
+
};
|
|
1946
1962
|
|
|
1947
1963
|
var __defProp$9 = Object.defineProperty;
|
|
1948
1964
|
var __defProps$4 = Object.defineProperties;
|
|
@@ -2016,6 +2032,27 @@ class LegacyQueryRunner {
|
|
|
2016
2032
|
);
|
|
2017
2033
|
}
|
|
2018
2034
|
}
|
|
2035
|
+
class CustomQueryRunner {
|
|
2036
|
+
constructor(datasource, _runRequest = runtime.getRunRequest()) {
|
|
2037
|
+
this.datasource = datasource;
|
|
2038
|
+
this._runRequest = _runRequest;
|
|
2039
|
+
}
|
|
2040
|
+
getTarget(variable) {
|
|
2041
|
+
if (hasCustomVariableSupport(this.datasource)) {
|
|
2042
|
+
return variable.state.query;
|
|
2043
|
+
}
|
|
2044
|
+
throw new Error("Couldn't create a target with supplied arguments.");
|
|
2045
|
+
}
|
|
2046
|
+
runRequest(_, request) {
|
|
2047
|
+
if (!hasCustomVariableSupport(this.datasource)) {
|
|
2048
|
+
return getEmptyMetricFindValueObservable();
|
|
2049
|
+
}
|
|
2050
|
+
if (!this.datasource.variables.query) {
|
|
2051
|
+
return this._runRequest(this.datasource, request);
|
|
2052
|
+
}
|
|
2053
|
+
return this._runRequest(this.datasource, request, this.datasource.variables.query);
|
|
2054
|
+
}
|
|
2055
|
+
}
|
|
2019
2056
|
function getEmptyMetricFindValueObservable() {
|
|
2020
2057
|
return rxjs.of({ state: data.LoadingState.Done, series: [], timeRange: data.getDefaultTimeRange() });
|
|
2021
2058
|
}
|
|
@@ -2026,6 +2063,9 @@ function createQueryVariableRunnerFactory(datasource) {
|
|
|
2026
2063
|
if (hasLegacyVariableSupport(datasource)) {
|
|
2027
2064
|
return new LegacyQueryRunner(datasource);
|
|
2028
2065
|
}
|
|
2066
|
+
if (hasCustomVariableSupport(datasource)) {
|
|
2067
|
+
return new CustomQueryRunner(datasource);
|
|
2068
|
+
}
|
|
2029
2069
|
throw new Error(`Couldn't create a query runner for datasource ${datasource.type}`);
|
|
2030
2070
|
}
|
|
2031
2071
|
let createQueryVariableRunner = createQueryVariableRunnerFactory;
|
|
@@ -2707,19 +2747,6 @@ function getStyles$1(theme) {
|
|
|
2707
2747
|
};
|
|
2708
2748
|
}
|
|
2709
2749
|
|
|
2710
|
-
function SceneDragHandle({ layoutKey, className }) {
|
|
2711
|
-
return /* @__PURE__ */ React__default["default"].createElement("div", {
|
|
2712
|
-
className: `${className} grid-drag-handle-${layoutKey}`,
|
|
2713
|
-
style: {
|
|
2714
|
-
width: "20px",
|
|
2715
|
-
height: "20px",
|
|
2716
|
-
cursor: "move"
|
|
2717
|
-
}
|
|
2718
|
-
}, /* @__PURE__ */ React__default["default"].createElement(ui.Icon, {
|
|
2719
|
-
name: "draggabledots"
|
|
2720
|
-
}));
|
|
2721
|
-
}
|
|
2722
|
-
|
|
2723
2750
|
function VizPanelRenderer({ model }) {
|
|
2724
2751
|
var _a;
|
|
2725
2752
|
const theme = ui.useTheme2();
|
|
@@ -2739,10 +2766,9 @@ function VizPanelRenderer({ model }) {
|
|
|
2739
2766
|
const plugin = model.getPlugin();
|
|
2740
2767
|
const { data: data$1 } = sceneGraph.getData(model).useState();
|
|
2741
2768
|
const parentLayout = sceneGraph.getLayout(model);
|
|
2742
|
-
const isDraggable = ((_a =
|
|
2743
|
-
const
|
|
2744
|
-
|
|
2745
|
-
});
|
|
2769
|
+
const isDraggable = parentLayout.isDraggable() && ((_a = placement == null ? void 0 : placement.isDraggable) != null ? _a : true);
|
|
2770
|
+
const dragClass = isDraggable && parentLayout.getDragClass ? parentLayout.getDragClass() : "";
|
|
2771
|
+
const dragClassCancel = isDraggable && parentLayout.getDragClassCancel ? parentLayout.getDragClassCancel() : "";
|
|
2746
2772
|
const titleInterpolated = model.interpolate(title, void 0, "text");
|
|
2747
2773
|
const timeZone = sceneGraph.getTimeRange(model).state.timeZone;
|
|
2748
2774
|
const dataWithOverrides = data.useFieldOverrides(plugin, fieldConfig, data$1, timeZone, theme, model.interpolate);
|
|
@@ -2759,7 +2785,7 @@ function VizPanelRenderer({ model }) {
|
|
|
2759
2785
|
if ($data instanceof SceneQueryRunner) {
|
|
2760
2786
|
$data.setContainerWidth(width);
|
|
2761
2787
|
}
|
|
2762
|
-
const titleItems =
|
|
2788
|
+
const titleItems = [];
|
|
2763
2789
|
if (model.state.$timeRange) {
|
|
2764
2790
|
titleItems.push(/* @__PURE__ */ React__default["default"].createElement(model.state.$timeRange.Component, {
|
|
2765
2791
|
model: model.state.$timeRange
|
|
@@ -2777,7 +2803,9 @@ function VizPanelRenderer({ model }) {
|
|
|
2777
2803
|
height,
|
|
2778
2804
|
displayMode,
|
|
2779
2805
|
hoverHeader,
|
|
2780
|
-
titleItems
|
|
2806
|
+
titleItems,
|
|
2807
|
+
dragClass,
|
|
2808
|
+
dragClassCancel
|
|
2781
2809
|
}, (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, {
|
|
2782
2810
|
dependencies: [plugin, data$1]
|
|
2783
2811
|
}, /* @__PURE__ */ React__default["default"].createElement(data.PluginContextProvider, {
|
|
@@ -3230,6 +3258,9 @@ class SceneFlexLayout extends SceneObjectBase {
|
|
|
3230
3258
|
direction: this.state.direction === "row" ? "column" : "row"
|
|
3231
3259
|
});
|
|
3232
3260
|
}
|
|
3261
|
+
isDraggable() {
|
|
3262
|
+
return false;
|
|
3263
|
+
}
|
|
3233
3264
|
}
|
|
3234
3265
|
SceneFlexLayout.Component = FlexLayoutRenderer;
|
|
3235
3266
|
SceneFlexLayout.Editor = FlexLayoutEditor;
|
|
@@ -3319,6 +3350,19 @@ const GRID_CELL_HEIGHT = 30;
|
|
|
3319
3350
|
const GRID_CELL_VMARGIN = 8;
|
|
3320
3351
|
const GRID_COLUMN_COUNT = 24;
|
|
3321
3352
|
|
|
3353
|
+
function SceneDragHandle({ className, dragClass }) {
|
|
3354
|
+
return /* @__PURE__ */ React__default["default"].createElement("div", {
|
|
3355
|
+
className: `${className} ${dragClass}`,
|
|
3356
|
+
style: {
|
|
3357
|
+
width: "20px",
|
|
3358
|
+
height: "20px",
|
|
3359
|
+
cursor: "move"
|
|
3360
|
+
}
|
|
3361
|
+
}, /* @__PURE__ */ React__default["default"].createElement(ui.Icon, {
|
|
3362
|
+
name: "draggabledots"
|
|
3363
|
+
}));
|
|
3364
|
+
}
|
|
3365
|
+
|
|
3322
3366
|
var __defProp$2 = Object.defineProperty;
|
|
3323
3367
|
var __defProps$1 = Object.defineProperties;
|
|
3324
3368
|
var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
|
|
@@ -3357,13 +3401,16 @@ class SceneGridRow extends SceneObjectBase {
|
|
|
3357
3401
|
if (!this.state.isCollapsible) {
|
|
3358
3402
|
return;
|
|
3359
3403
|
}
|
|
3360
|
-
|
|
3361
|
-
if (!layout || !(layout instanceof SceneGridLayout)) {
|
|
3362
|
-
throw new Error("SceneGridRow must be a child of SceneGridLayout");
|
|
3363
|
-
}
|
|
3364
|
-
layout.toggleRow(this);
|
|
3404
|
+
this.getGridLayout().toggleRow(this);
|
|
3365
3405
|
};
|
|
3366
3406
|
}
|
|
3407
|
+
getGridLayout() {
|
|
3408
|
+
const layout = this.parent;
|
|
3409
|
+
if (!layout || !(layout instanceof SceneGridLayout)) {
|
|
3410
|
+
throw new Error("SceneGridRow must be a child of SceneGridLayout");
|
|
3411
|
+
}
|
|
3412
|
+
return layout;
|
|
3413
|
+
}
|
|
3367
3414
|
getUrlState(state) {
|
|
3368
3415
|
return { rowc: state.isCollapsed ? "1" : "0" };
|
|
3369
3416
|
}
|
|
@@ -3378,9 +3425,8 @@ SceneGridRow.Component = SceneGridRowRenderer;
|
|
|
3378
3425
|
function SceneGridRowRenderer({ model }) {
|
|
3379
3426
|
const styles = ui.useStyles2(getSceneGridRowStyles);
|
|
3380
3427
|
const { isCollapsible, isCollapsed, title, placement } = model.useState();
|
|
3381
|
-
const layout = sceneGraph.getLayout(model);
|
|
3382
3428
|
const dragHandle = /* @__PURE__ */ React__default["default"].createElement(SceneDragHandle, {
|
|
3383
|
-
|
|
3429
|
+
dragClass: model.getGridLayout().getDragClass()
|
|
3384
3430
|
});
|
|
3385
3431
|
return /* @__PURE__ */ React__default["default"].createElement("div", {
|
|
3386
3432
|
className: styles.row
|
|
@@ -3456,9 +3502,8 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
|
3456
3502
|
class SceneGridLayout extends SceneObjectBase {
|
|
3457
3503
|
constructor(state) {
|
|
3458
3504
|
super(__spreadProps(__spreadValues$1({}, state), {
|
|
3459
|
-
|
|
3460
|
-
|
|
3461
|
-
}, state.placement),
|
|
3505
|
+
isDraggable: true,
|
|
3506
|
+
placement: state.placement,
|
|
3462
3507
|
children: sortChildrenByPosition(state.children)
|
|
3463
3508
|
}));
|
|
3464
3509
|
this._skipOnLayoutChange = false;
|
|
@@ -3518,6 +3563,16 @@ class SceneGridLayout extends SceneObjectBase {
|
|
|
3518
3563
|
this._skipOnLayoutChange = true;
|
|
3519
3564
|
};
|
|
3520
3565
|
}
|
|
3566
|
+
isDraggable() {
|
|
3567
|
+
var _a;
|
|
3568
|
+
return (_a = this.state.isDraggable) != null ? _a : false;
|
|
3569
|
+
}
|
|
3570
|
+
getDragClass() {
|
|
3571
|
+
return `grid-drag-handle-${this.state.key}`;
|
|
3572
|
+
}
|
|
3573
|
+
getDragClassCancel() {
|
|
3574
|
+
return `grid-drag-cancel`;
|
|
3575
|
+
}
|
|
3521
3576
|
toggleRow(row) {
|
|
3522
3577
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
3523
3578
|
const isCollapsed = row.state.isCollapsed;
|
|
@@ -3676,6 +3731,7 @@ function SceneGridLayoutRenderer({ model }) {
|
|
|
3676
3731
|
cols: GRID_COLUMN_COUNT,
|
|
3677
3732
|
rowHeight: GRID_CELL_HEIGHT,
|
|
3678
3733
|
draggableHandle: `.grid-drag-handle-${model.state.key}`,
|
|
3734
|
+
draggableCancel: ".grid-drag-cancel",
|
|
3679
3735
|
layout,
|
|
3680
3736
|
onDragStop: model.onDragStop,
|
|
3681
3737
|
onResizeStop: model.onResizeStop,
|