@grafana/scenes 4.32.0 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/esm/components/EmbeddedScene.js +0 -5
- package/dist/esm/components/EmbeddedScene.js.map +1 -1
- package/dist/esm/components/SceneApp/SceneAppPage.js +0 -5
- package/dist/esm/components/SceneApp/SceneAppPage.js.map +1 -1
- package/dist/esm/components/SceneApp/SceneAppPageView.js +3 -1
- package/dist/esm/components/SceneApp/SceneAppPageView.js.map +1 -1
- package/dist/esm/core/sceneGraph/sceneGraph.js +1 -1
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/services/UniqueUrlKeyMapper.js +24 -16
- package/dist/esm/services/UniqueUrlKeyMapper.js.map +1 -1
- package/dist/esm/services/UrlSyncContextProvider.js +12 -0
- package/dist/esm/services/UrlSyncContextProvider.js.map +1 -0
- package/dist/esm/services/UrlSyncManager.js +83 -48
- package/dist/esm/services/UrlSyncManager.js.map +1 -1
- package/dist/esm/services/useUrlSync.js +27 -0
- package/dist/esm/services/useUrlSync.js.map +1 -0
- package/dist/esm/services/utils.js +10 -4
- package/dist/esm/services/utils.js.map +1 -1
- package/dist/index.d.ts +18 -17
- package/dist/index.js +836 -766
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -188,32 +188,32 @@ class UserActionEvent extends data.BusEventWithPayload {
|
|
|
188
188
|
}
|
|
189
189
|
UserActionEvent.type = "scene-object-user-action";
|
|
190
190
|
|
|
191
|
-
var __accessCheck$
|
|
191
|
+
var __accessCheck$2 = (obj, member, msg) => {
|
|
192
192
|
if (!member.has(obj))
|
|
193
193
|
throw TypeError("Cannot " + msg);
|
|
194
194
|
};
|
|
195
|
-
var __privateGet$
|
|
196
|
-
__accessCheck$
|
|
195
|
+
var __privateGet$2 = (obj, member, getter) => {
|
|
196
|
+
__accessCheck$2(obj, member, "read from private field");
|
|
197
197
|
return getter ? getter.call(obj) : member.get(obj);
|
|
198
198
|
};
|
|
199
|
-
var __privateAdd$
|
|
199
|
+
var __privateAdd$2 = (obj, member, value) => {
|
|
200
200
|
if (member.has(obj))
|
|
201
201
|
throw TypeError("Cannot add the same private member more than once");
|
|
202
202
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
203
203
|
};
|
|
204
|
-
var __privateSet = (obj, member, value, setter) => {
|
|
205
|
-
__accessCheck$
|
|
204
|
+
var __privateSet$1 = (obj, member, value, setter) => {
|
|
205
|
+
__accessCheck$2(obj, member, "write to private field");
|
|
206
206
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
207
207
|
return value;
|
|
208
208
|
};
|
|
209
209
|
var _ref;
|
|
210
210
|
class SceneObjectRef {
|
|
211
211
|
constructor(ref) {
|
|
212
|
-
__privateAdd$
|
|
213
|
-
__privateSet(this, _ref, ref);
|
|
212
|
+
__privateAdd$2(this, _ref, void 0);
|
|
213
|
+
__privateSet$1(this, _ref, ref);
|
|
214
214
|
}
|
|
215
215
|
resolve() {
|
|
216
|
-
return __privateGet$
|
|
216
|
+
return __privateGet$2(this, _ref);
|
|
217
217
|
}
|
|
218
218
|
}
|
|
219
219
|
_ref = new WeakMap();
|
|
@@ -586,103 +586,22 @@ function registerRuntimeDataSource({ dataSource }) {
|
|
|
586
586
|
runtimeDataSources.set(dataSource.uid, dataSource);
|
|
587
587
|
}
|
|
588
588
|
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
throw new Error("Cannot find any scene object that uses the key '" + key + "'");
|
|
597
|
-
}
|
|
598
|
-
const address = objectsWithKey.findIndex((o) => o.sceneObject === obj);
|
|
599
|
-
if (address > 0) {
|
|
600
|
-
return `${key}-${address + 1}`;
|
|
601
|
-
}
|
|
602
|
-
return key;
|
|
603
|
-
}
|
|
604
|
-
rebuildIndex(root) {
|
|
605
|
-
this.index.clear();
|
|
606
|
-
this.buildIndex(root, 0);
|
|
607
|
-
}
|
|
608
|
-
buildIndex(sceneObject, depth) {
|
|
609
|
-
if (sceneObject.urlSync) {
|
|
610
|
-
for (const key of sceneObject.urlSync.getKeys()) {
|
|
611
|
-
const hit = this.index.get(key);
|
|
612
|
-
if (hit) {
|
|
613
|
-
hit.push({ sceneObject, depth });
|
|
614
|
-
hit.sort((a, b) => a.depth - b.depth);
|
|
615
|
-
} else {
|
|
616
|
-
this.index.set(key, [{ sceneObject, depth }]);
|
|
617
|
-
}
|
|
618
|
-
}
|
|
619
|
-
}
|
|
620
|
-
sceneObject.forEachChild((child) => this.buildIndex(child, depth + 1));
|
|
621
|
-
}
|
|
622
|
-
}
|
|
623
|
-
|
|
624
|
-
function getUrlState(root) {
|
|
625
|
-
const urlKeyMapper = new UniqueUrlKeyMapper();
|
|
626
|
-
urlKeyMapper.rebuildIndex(root);
|
|
627
|
-
const result = {};
|
|
628
|
-
const visitNode = (obj) => {
|
|
629
|
-
if (obj.urlSync) {
|
|
630
|
-
const newUrlState = obj.urlSync.getUrlState();
|
|
631
|
-
for (const [key, value] of Object.entries(newUrlState)) {
|
|
632
|
-
if (value != null) {
|
|
633
|
-
const uniqueKey = urlKeyMapper.getUniqueKey(key, obj);
|
|
634
|
-
result[uniqueKey] = value;
|
|
635
|
-
}
|
|
636
|
-
}
|
|
637
|
-
}
|
|
638
|
-
obj.forEachChild(visitNode);
|
|
639
|
-
};
|
|
640
|
-
visitNode(root);
|
|
641
|
-
return result;
|
|
642
|
-
}
|
|
643
|
-
function syncStateFromSearchParams(root, urlParams) {
|
|
644
|
-
const urlKeyMapper = new UniqueUrlKeyMapper();
|
|
645
|
-
urlKeyMapper.rebuildIndex(root);
|
|
646
|
-
syncStateFromUrl(root, urlParams, urlKeyMapper);
|
|
647
|
-
}
|
|
648
|
-
function syncStateFromUrl(sceneObject, urlParams, urlKeyMapper) {
|
|
649
|
-
if (sceneObject.urlSync) {
|
|
650
|
-
const urlState = {};
|
|
651
|
-
const currentState = sceneObject.urlSync.getUrlState();
|
|
652
|
-
for (const key of sceneObject.urlSync.getKeys()) {
|
|
653
|
-
const uniqueKey = urlKeyMapper.getUniqueKey(key, sceneObject);
|
|
654
|
-
const newValue = urlParams.getAll(uniqueKey);
|
|
655
|
-
const currentValue = currentState[key];
|
|
656
|
-
if (isUrlValueEqual(newValue, currentValue)) {
|
|
657
|
-
continue;
|
|
658
|
-
}
|
|
659
|
-
if (newValue.length > 0) {
|
|
660
|
-
if (Array.isArray(currentValue)) {
|
|
661
|
-
urlState[key] = newValue;
|
|
662
|
-
} else {
|
|
663
|
-
urlState[key] = newValue[0];
|
|
664
|
-
}
|
|
665
|
-
} else {
|
|
666
|
-
urlState[key] = null;
|
|
667
|
-
}
|
|
668
|
-
}
|
|
669
|
-
if (Object.keys(urlState).length > 0) {
|
|
670
|
-
sceneObject.urlSync.updateFromUrl(urlState);
|
|
589
|
+
function lookupVariable(name, sceneObject) {
|
|
590
|
+
const variables = sceneObject.state.$variables;
|
|
591
|
+
if (!variables) {
|
|
592
|
+
if (sceneObject.parent) {
|
|
593
|
+
return lookupVariable(name, sceneObject.parent);
|
|
594
|
+
} else {
|
|
595
|
+
return null;
|
|
671
596
|
}
|
|
672
597
|
}
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
if (
|
|
677
|
-
return
|
|
678
|
-
}
|
|
679
|
-
if (!Array.isArray(newUrlValue) && (currentUrlValue == null ? void 0 : currentUrlValue.length) === 1) {
|
|
680
|
-
return newUrlValue === currentUrlValue[0];
|
|
681
|
-
}
|
|
682
|
-
if ((newUrlValue == null ? void 0 : newUrlValue.length) === 0 && currentUrlValue === null) {
|
|
683
|
-
return true;
|
|
598
|
+
const found = variables.getByName(name);
|
|
599
|
+
if (found) {
|
|
600
|
+
return found;
|
|
601
|
+
} else if (sceneObject.parent) {
|
|
602
|
+
return lookupVariable(name, sceneObject.parent);
|
|
684
603
|
}
|
|
685
|
-
return
|
|
604
|
+
return null;
|
|
686
605
|
}
|
|
687
606
|
|
|
688
607
|
var __defProp$F = Object.defineProperty;
|
|
@@ -1314,736 +1233,718 @@ function sqlStringFormatter(value) {
|
|
|
1314
1233
|
})}'`;
|
|
1315
1234
|
}
|
|
1316
1235
|
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
if (sceneObject.parent) {
|
|
1321
|
-
return lookupVariable(name, sceneObject.parent);
|
|
1322
|
-
} else {
|
|
1323
|
-
return null;
|
|
1324
|
-
}
|
|
1236
|
+
class SkipFormattingValue {
|
|
1237
|
+
constructor(_value) {
|
|
1238
|
+
this._value = _value;
|
|
1325
1239
|
}
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
return found;
|
|
1329
|
-
} else if (sceneObject.parent) {
|
|
1330
|
-
return lookupVariable(name, sceneObject.parent);
|
|
1240
|
+
formatter() {
|
|
1241
|
+
return this._value;
|
|
1331
1242
|
}
|
|
1332
|
-
return null;
|
|
1333
1243
|
}
|
|
1334
1244
|
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
VARIABLE_REGEX.lastIndex = 0;
|
|
1340
|
-
return target.replace(VARIABLE_REGEX, (match, var1, var2, fmt2, var3, fieldPath, fmt3) => {
|
|
1341
|
-
const variableName = var1 || var2 || var3;
|
|
1342
|
-
const fmt = fmt2 || fmt3 || format;
|
|
1343
|
-
const variable = lookupFormatVariable(variableName, match, scopedVars, sceneObject);
|
|
1344
|
-
if (!variable) {
|
|
1345
|
-
if (interpolations) {
|
|
1346
|
-
interpolations.push({ match, variableName, fieldPath, format: fmt, value: match, found: false });
|
|
1347
|
-
}
|
|
1348
|
-
return match;
|
|
1349
|
-
}
|
|
1350
|
-
const value = formatValue(sceneObject, variable, variable.getValue(fieldPath), fmt);
|
|
1351
|
-
if (interpolations) {
|
|
1352
|
-
interpolations.push({ match, variableName, fieldPath, format: fmt, value, found: value !== match });
|
|
1353
|
-
}
|
|
1354
|
-
return value;
|
|
1355
|
-
});
|
|
1356
|
-
}
|
|
1357
|
-
function lookupFormatVariable(name, match, scopedVars, sceneObject) {
|
|
1358
|
-
if (scopedVars && scopedVars.hasOwnProperty(name)) {
|
|
1359
|
-
const scopedVar = scopedVars[name];
|
|
1360
|
-
if (scopedVar) {
|
|
1361
|
-
return getSceneVariableForScopedVar(name, scopedVar);
|
|
1362
|
-
}
|
|
1245
|
+
class UrlTimeRangeMacro {
|
|
1246
|
+
constructor(name, sceneObject) {
|
|
1247
|
+
this.state = { name, type: "url_variable" };
|
|
1248
|
+
this._sceneObject = sceneObject;
|
|
1363
1249
|
}
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1250
|
+
getValue() {
|
|
1251
|
+
var _a;
|
|
1252
|
+
const timeRange = getTimeRange(this._sceneObject);
|
|
1253
|
+
const urlState = (_a = timeRange.urlSync) == null ? void 0 : _a.getUrlState();
|
|
1254
|
+
return new SkipFormattingValue(data.urlUtil.toUrlParams(urlState));
|
|
1367
1255
|
}
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
return new Macro(name, sceneObject, match, scopedVars);
|
|
1256
|
+
getValueText() {
|
|
1257
|
+
return "";
|
|
1371
1258
|
}
|
|
1372
|
-
return null;
|
|
1373
1259
|
}
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1260
|
+
class TimeFromAndToMacro {
|
|
1261
|
+
constructor(name, sceneObject) {
|
|
1262
|
+
this.state = { name, type: "time_macro" };
|
|
1263
|
+
this._sceneObject = sceneObject;
|
|
1377
1264
|
}
|
|
1378
|
-
|
|
1379
|
-
|
|
1265
|
+
getValue() {
|
|
1266
|
+
const timeRange = getTimeRange(this._sceneObject);
|
|
1267
|
+
if (this.state.name === "__from") {
|
|
1268
|
+
return timeRange.state.value.from.valueOf();
|
|
1269
|
+
} else {
|
|
1270
|
+
return timeRange.state.value.to.valueOf();
|
|
1271
|
+
}
|
|
1380
1272
|
}
|
|
1381
|
-
|
|
1382
|
-
|
|
1273
|
+
getValueText() {
|
|
1274
|
+
const timeRange = getTimeRange(this._sceneObject);
|
|
1275
|
+
if (this.state.name === "__from") {
|
|
1276
|
+
return data.dateTimeFormat(timeRange.state.value.from, { timeZone: timeRange.getTimeZone() });
|
|
1277
|
+
} else {
|
|
1278
|
+
return data.dateTimeFormat(timeRange.state.value.to, { timeZone: timeRange.getTimeZone() });
|
|
1279
|
+
}
|
|
1383
1280
|
}
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
includeAll: variable.state.includeAll
|
|
1390
|
-
});
|
|
1281
|
+
}
|
|
1282
|
+
class TimezoneMacro {
|
|
1283
|
+
constructor(name, sceneObject) {
|
|
1284
|
+
this.state = { name, type: "time_macro" };
|
|
1285
|
+
this._sceneObject = sceneObject;
|
|
1391
1286
|
}
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
if (args.length > 1) {
|
|
1398
|
-
formatNameOrFn = args[0];
|
|
1399
|
-
args = args.slice(1);
|
|
1400
|
-
} else {
|
|
1401
|
-
args = [];
|
|
1287
|
+
getValue() {
|
|
1288
|
+
const timeRange = getTimeRange(this._sceneObject);
|
|
1289
|
+
const timeZone = timeRange.getTimeZone();
|
|
1290
|
+
if (timeZone === "browser") {
|
|
1291
|
+
return Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
1402
1292
|
}
|
|
1293
|
+
return timeZone;
|
|
1403
1294
|
}
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
console.error(`Variable format ${formatNameOrFn} not found. Using glob format as fallback.`);
|
|
1407
|
-
formatter = formatRegistry.get(schema.VariableFormatID.Glob);
|
|
1295
|
+
getValueText() {
|
|
1296
|
+
return this.getValue();
|
|
1408
1297
|
}
|
|
1409
|
-
return formatter.formatter(value, args, variable);
|
|
1410
|
-
}
|
|
1411
|
-
|
|
1412
|
-
function isSceneObject(obj) {
|
|
1413
|
-
return obj.useState !== void 0;
|
|
1414
|
-
}
|
|
1415
|
-
function isDataRequestEnricher(obj) {
|
|
1416
|
-
return "enrichDataRequest" in obj;
|
|
1417
|
-
}
|
|
1418
|
-
function isFiltersRequestEnricher(obj) {
|
|
1419
|
-
return "enrichFiltersRequest" in obj;
|
|
1420
1298
|
}
|
|
1421
|
-
|
|
1422
|
-
|
|
1299
|
+
class IntervalMacro {
|
|
1300
|
+
constructor(name, sceneObject, match) {
|
|
1301
|
+
this.state = { name, type: "time_macro", match };
|
|
1302
|
+
this._sceneObject = sceneObject;
|
|
1303
|
+
}
|
|
1304
|
+
getValue() {
|
|
1305
|
+
var _a;
|
|
1306
|
+
const data = getData(this._sceneObject);
|
|
1307
|
+
if (data) {
|
|
1308
|
+
const request = (_a = data.state.data) == null ? void 0 : _a.request;
|
|
1309
|
+
if (!request) {
|
|
1310
|
+
return this.state.match;
|
|
1311
|
+
}
|
|
1312
|
+
if (this.state.name === "__interval_ms") {
|
|
1313
|
+
return request.intervalMs;
|
|
1314
|
+
}
|
|
1315
|
+
return request.interval;
|
|
1316
|
+
}
|
|
1317
|
+
return this.state.match;
|
|
1318
|
+
}
|
|
1423
1319
|
}
|
|
1424
1320
|
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
var __privateGet = (obj, member, getter) => {
|
|
1430
|
-
__accessCheck(obj, member, "read from private field");
|
|
1431
|
-
return getter ? getter.call(obj) : member.get(obj);
|
|
1432
|
-
};
|
|
1433
|
-
var __privateAdd = (obj, member, value) => {
|
|
1434
|
-
if (member.has(obj))
|
|
1435
|
-
throw TypeError("Cannot add the same private member more than once");
|
|
1436
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
1437
|
-
};
|
|
1438
|
-
var _running;
|
|
1439
|
-
function isQueryController(s) {
|
|
1440
|
-
return "isQueryController" in s;
|
|
1441
|
-
}
|
|
1442
|
-
class SceneQueryController extends SceneObjectBase {
|
|
1443
|
-
constructor() {
|
|
1444
|
-
super({ isRunning: false });
|
|
1445
|
-
this.isQueryController = true;
|
|
1446
|
-
__privateAdd(this, _running, /* @__PURE__ */ new Set());
|
|
1447
|
-
this.addActivationHandler(() => {
|
|
1448
|
-
return () => __privateGet(this, _running).clear();
|
|
1449
|
-
});
|
|
1450
|
-
}
|
|
1451
|
-
queryStarted(entry) {
|
|
1452
|
-
__privateGet(this, _running).add(entry);
|
|
1453
|
-
this.changeRunningQueryCount(1);
|
|
1454
|
-
if (!this.state.isRunning) {
|
|
1455
|
-
this.setState({ isRunning: true });
|
|
1456
|
-
}
|
|
1321
|
+
class AllVariablesMacro {
|
|
1322
|
+
constructor(name, sceneObject) {
|
|
1323
|
+
this.state = { name, type: "url_variable" };
|
|
1324
|
+
this._sceneObject = sceneObject;
|
|
1457
1325
|
}
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1326
|
+
getValue() {
|
|
1327
|
+
const allVars = collectAllVariables(this._sceneObject);
|
|
1328
|
+
const format = formatRegistry.get(schema.VariableFormatID.QueryParam);
|
|
1329
|
+
const params = [];
|
|
1330
|
+
for (const name of Object.keys(allVars)) {
|
|
1331
|
+
const variable = allVars[name];
|
|
1332
|
+
const value = variable.getValue();
|
|
1333
|
+
if (!value) {
|
|
1334
|
+
continue;
|
|
1335
|
+
}
|
|
1336
|
+
if (isCustomVariableValue(value)) {
|
|
1337
|
+
params.push(value.formatter(schema.VariableFormatID.QueryParam));
|
|
1338
|
+
} else {
|
|
1339
|
+
params.push(format.formatter(value, [], variable));
|
|
1340
|
+
}
|
|
1466
1341
|
}
|
|
1342
|
+
return new SkipFormattingValue(params.join("&"));
|
|
1467
1343
|
}
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
window.__grafanaRunningQueryCount = ((_a = window.__grafanaRunningQueryCount) != null ? _a : 0) + dir;
|
|
1344
|
+
getValueText() {
|
|
1345
|
+
return "";
|
|
1471
1346
|
}
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1347
|
+
}
|
|
1348
|
+
function collectAllVariables(sceneObject, record = {}) {
|
|
1349
|
+
if (sceneObject.state.$variables) {
|
|
1350
|
+
for (const variable of sceneObject.state.$variables.state.variables) {
|
|
1351
|
+
if (variable.state.skipUrlSync) {
|
|
1352
|
+
continue;
|
|
1353
|
+
}
|
|
1354
|
+
if (!record[variable.state.name]) {
|
|
1355
|
+
record[variable.state.name] = variable;
|
|
1356
|
+
}
|
|
1476
1357
|
}
|
|
1477
1358
|
}
|
|
1359
|
+
if (sceneObject.parent) {
|
|
1360
|
+
collectAllVariables(sceneObject.parent, record);
|
|
1361
|
+
}
|
|
1362
|
+
return record;
|
|
1478
1363
|
}
|
|
1479
|
-
_running = new WeakMap();
|
|
1480
1364
|
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1365
|
+
var __defProp$D = Object.defineProperty;
|
|
1366
|
+
var __defProps$r = Object.defineProperties;
|
|
1367
|
+
var __getOwnPropDescs$r = Object.getOwnPropertyDescriptors;
|
|
1368
|
+
var __getOwnPropSymbols$D = Object.getOwnPropertySymbols;
|
|
1369
|
+
var __hasOwnProp$D = Object.prototype.hasOwnProperty;
|
|
1370
|
+
var __propIsEnum$D = Object.prototype.propertyIsEnumerable;
|
|
1371
|
+
var __defNormalProp$D = (obj, key, value) => key in obj ? __defProp$D(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1372
|
+
var __spreadValues$D = (a, b) => {
|
|
1373
|
+
for (var prop in b || (b = {}))
|
|
1374
|
+
if (__hasOwnProp$D.call(b, prop))
|
|
1375
|
+
__defNormalProp$D(a, prop, b[prop]);
|
|
1376
|
+
if (__getOwnPropSymbols$D)
|
|
1377
|
+
for (var prop of __getOwnPropSymbols$D(b)) {
|
|
1378
|
+
if (__propIsEnum$D.call(b, prop))
|
|
1379
|
+
__defNormalProp$D(a, prop, b[prop]);
|
|
1380
|
+
}
|
|
1381
|
+
return a;
|
|
1382
|
+
};
|
|
1383
|
+
var __spreadProps$r = (a, b) => __defProps$r(a, __getOwnPropDescs$r(b));
|
|
1384
|
+
function getTemplateProxyForField(field, frame, frames) {
|
|
1385
|
+
return new Proxy(
|
|
1386
|
+
{},
|
|
1387
|
+
{
|
|
1388
|
+
get: (obj, key) => {
|
|
1389
|
+
if (key === "name") {
|
|
1390
|
+
return field.name;
|
|
1391
|
+
}
|
|
1392
|
+
if (key === "displayName") {
|
|
1393
|
+
return data.getFieldDisplayName(field, frame, frames);
|
|
1394
|
+
}
|
|
1395
|
+
if (key === "labels" || key === "formattedLabels") {
|
|
1396
|
+
if (!field.labels) {
|
|
1397
|
+
return "";
|
|
1398
|
+
}
|
|
1399
|
+
return __spreadProps$r(__spreadValues$D({}, field.labels), {
|
|
1400
|
+
__values: Object.values(field.labels).sort().join(", "),
|
|
1401
|
+
toString: () => {
|
|
1402
|
+
return data.formatLabels(field.labels, "", true);
|
|
1403
|
+
}
|
|
1404
|
+
});
|
|
1405
|
+
}
|
|
1406
|
+
return void 0;
|
|
1407
|
+
}
|
|
1408
|
+
}
|
|
1409
|
+
);
|
|
1491
1410
|
}
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1411
|
+
|
|
1412
|
+
class ValueMacro {
|
|
1413
|
+
constructor(name, sceneObject, _match, _scopedVars) {
|
|
1414
|
+
this._match = _match;
|
|
1415
|
+
this._scopedVars = _scopedVars;
|
|
1416
|
+
this.state = { name, type: "__value" };
|
|
1496
1417
|
}
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1418
|
+
getValue(fieldPath) {
|
|
1419
|
+
var _a, _b;
|
|
1420
|
+
const dataContext = (_a = this._scopedVars) == null ? void 0 : _a.__dataContext;
|
|
1421
|
+
if (!dataContext) {
|
|
1422
|
+
return this._match;
|
|
1423
|
+
}
|
|
1424
|
+
const { frame, rowIndex, field, calculatedValue } = dataContext.value;
|
|
1425
|
+
if (calculatedValue) {
|
|
1426
|
+
switch (fieldPath) {
|
|
1427
|
+
case "numeric":
|
|
1428
|
+
return calculatedValue.numeric;
|
|
1429
|
+
case "raw":
|
|
1430
|
+
return calculatedValue.numeric;
|
|
1431
|
+
case "time":
|
|
1432
|
+
return "";
|
|
1433
|
+
case "text":
|
|
1434
|
+
default:
|
|
1435
|
+
return data.formattedValueToString(calculatedValue);
|
|
1436
|
+
}
|
|
1437
|
+
}
|
|
1438
|
+
if (rowIndex == null) {
|
|
1439
|
+
return this._match;
|
|
1440
|
+
}
|
|
1441
|
+
if (fieldPath === "time") {
|
|
1442
|
+
const timeField = frame.fields.find((f) => f.type === data.FieldType.time);
|
|
1443
|
+
return timeField ? timeField.values.get(rowIndex) : void 0;
|
|
1444
|
+
}
|
|
1445
|
+
if (!field) {
|
|
1446
|
+
return this._match;
|
|
1447
|
+
}
|
|
1448
|
+
const value = field.values.get(rowIndex);
|
|
1449
|
+
if (fieldPath === "raw") {
|
|
1450
|
+
return value;
|
|
1451
|
+
}
|
|
1452
|
+
const displayProcessor = (_b = field.display) != null ? _b : fallbackDisplayProcessor;
|
|
1453
|
+
const result = displayProcessor(value);
|
|
1454
|
+
switch (fieldPath) {
|
|
1455
|
+
case "numeric":
|
|
1456
|
+
return result.numeric;
|
|
1457
|
+
case "text":
|
|
1458
|
+
default:
|
|
1459
|
+
return data.formattedValueToString(result);
|
|
1460
|
+
}
|
|
1461
|
+
}
|
|
1462
|
+
getValueText() {
|
|
1501
1463
|
return "";
|
|
1502
1464
|
}
|
|
1503
|
-
return sceneInterpolator(sceneObject, value, scopedVars, format, interpolations);
|
|
1504
1465
|
}
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1466
|
+
const fallbackDisplayProcessor = data.getDisplayProcessor();
|
|
1467
|
+
class DataMacro {
|
|
1468
|
+
constructor(name, sceneObject, _match, _scopedVars) {
|
|
1469
|
+
this._match = _match;
|
|
1470
|
+
this._scopedVars = _scopedVars;
|
|
1471
|
+
this.state = { name, type: "__data" };
|
|
1508
1472
|
}
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1473
|
+
getValue(fieldPath) {
|
|
1474
|
+
var _a, _b;
|
|
1475
|
+
const dataContext = (_a = this._scopedVars) == null ? void 0 : _a.__dataContext;
|
|
1476
|
+
if (!dataContext || !fieldPath) {
|
|
1477
|
+
return this._match;
|
|
1513
1478
|
}
|
|
1514
|
-
const
|
|
1515
|
-
if (
|
|
1516
|
-
return
|
|
1479
|
+
const { frame, rowIndex } = dataContext.value;
|
|
1480
|
+
if (rowIndex === void 0 || fieldPath === void 0) {
|
|
1481
|
+
return this._match;
|
|
1517
1482
|
}
|
|
1483
|
+
const obj = {
|
|
1484
|
+
name: frame.name,
|
|
1485
|
+
refId: frame.refId,
|
|
1486
|
+
fields: data.getFieldDisplayValuesProxy({ frame, rowIndex })
|
|
1487
|
+
};
|
|
1488
|
+
return (_b = getFieldAccessor(fieldPath)(obj)) != null ? _b : "";
|
|
1489
|
+
}
|
|
1490
|
+
getValueText() {
|
|
1491
|
+
return "";
|
|
1518
1492
|
}
|
|
1519
|
-
return false;
|
|
1520
1493
|
}
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1494
|
+
class SeriesMacro {
|
|
1495
|
+
constructor(name, sceneObject, _match, _scopedVars) {
|
|
1496
|
+
this._match = _match;
|
|
1497
|
+
this._scopedVars = _scopedVars;
|
|
1498
|
+
this.state = { name, type: "__series" };
|
|
1524
1499
|
}
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1500
|
+
getValue(fieldPath) {
|
|
1501
|
+
var _a;
|
|
1502
|
+
const dataContext = (_a = this._scopedVars) == null ? void 0 : _a.__dataContext;
|
|
1503
|
+
if (!dataContext || !fieldPath) {
|
|
1504
|
+
return this._match;
|
|
1529
1505
|
}
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
found = maybe;
|
|
1506
|
+
if (fieldPath !== "name") {
|
|
1507
|
+
return this._match;
|
|
1533
1508
|
}
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
return found;
|
|
1537
|
-
}
|
|
1538
|
-
if (shouldSearchUp && scene.parent) {
|
|
1539
|
-
return findObjectInternal(scene.parent, check, scene, true);
|
|
1509
|
+
const { frame, frameIndex } = dataContext.value;
|
|
1510
|
+
return data.getFrameDisplayName(frame, frameIndex);
|
|
1540
1511
|
}
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
function findByKey(sceneObject, key) {
|
|
1544
|
-
const found = findObject(sceneObject, (sceneToCheck) => {
|
|
1545
|
-
return sceneToCheck.state.key === key;
|
|
1546
|
-
});
|
|
1547
|
-
if (!found) {
|
|
1548
|
-
throw new Error("Unable to find scene with key " + key);
|
|
1512
|
+
getValueText() {
|
|
1513
|
+
return "";
|
|
1549
1514
|
}
|
|
1550
|
-
return found;
|
|
1551
1515
|
}
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
throw new Error("Unable to find scene with key " + key);
|
|
1558
|
-
}
|
|
1559
|
-
if (!(found instanceof targetType)) {
|
|
1560
|
-
throw new Error(`Found scene object with key ${key} does not match type ${targetType.name}`);
|
|
1516
|
+
class FieldMacro {
|
|
1517
|
+
constructor(name, sceneObject, _match, _scopedVars) {
|
|
1518
|
+
this._match = _match;
|
|
1519
|
+
this._scopedVars = _scopedVars;
|
|
1520
|
+
this.state = { name, type: "__field" };
|
|
1561
1521
|
}
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
function findAllObjects(scene, check) {
|
|
1568
|
-
const found = [];
|
|
1569
|
-
scene.forEachChild((child) => {
|
|
1570
|
-
if (check(child)) {
|
|
1571
|
-
found.push(child);
|
|
1572
|
-
}
|
|
1573
|
-
found.push(...findAllObjects(child, check));
|
|
1574
|
-
});
|
|
1575
|
-
return found;
|
|
1576
|
-
}
|
|
1577
|
-
function getDataLayers(sceneObject, localOnly = false) {
|
|
1578
|
-
let currentLevel = sceneObject;
|
|
1579
|
-
let collected = [];
|
|
1580
|
-
while (currentLevel) {
|
|
1581
|
-
const dataProvider = currentLevel.state.$data;
|
|
1582
|
-
if (!dataProvider) {
|
|
1583
|
-
currentLevel = currentLevel.parent;
|
|
1584
|
-
continue;
|
|
1585
|
-
}
|
|
1586
|
-
if (isDataLayer(dataProvider)) {
|
|
1587
|
-
collected = collected.concat(dataProvider);
|
|
1588
|
-
} else {
|
|
1589
|
-
if (dataProvider.state.$data && isDataLayer(dataProvider.state.$data)) {
|
|
1590
|
-
collected = collected.concat(dataProvider.state.$data);
|
|
1591
|
-
}
|
|
1522
|
+
getValue(fieldPath) {
|
|
1523
|
+
var _a, _b;
|
|
1524
|
+
const dataContext = (_a = this._scopedVars) == null ? void 0 : _a.__dataContext;
|
|
1525
|
+
if (!dataContext || !fieldPath) {
|
|
1526
|
+
return this._match;
|
|
1592
1527
|
}
|
|
1593
|
-
if (
|
|
1594
|
-
|
|
1528
|
+
if (fieldPath === void 0 || fieldPath === "") {
|
|
1529
|
+
return this._match;
|
|
1595
1530
|
}
|
|
1596
|
-
|
|
1531
|
+
const { frame, field, data } = dataContext.value;
|
|
1532
|
+
const obj = getTemplateProxyForField(field, frame, data);
|
|
1533
|
+
return (_b = getFieldAccessor(fieldPath)(obj)) != null ? _b : "";
|
|
1534
|
+
}
|
|
1535
|
+
getValueText() {
|
|
1536
|
+
return "";
|
|
1597
1537
|
}
|
|
1598
|
-
return collected;
|
|
1599
1538
|
}
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1539
|
+
|
|
1540
|
+
class UrlMacro {
|
|
1541
|
+
constructor(name, _) {
|
|
1542
|
+
this.state = { name, type: "url_macro" };
|
|
1543
|
+
}
|
|
1544
|
+
getValue(fieldPath) {
|
|
1545
|
+
var _a;
|
|
1546
|
+
const location = runtime.locationService.getLocation();
|
|
1547
|
+
const subUrl = (_a = runtime.config.appSubUrl) != null ? _a : "";
|
|
1548
|
+
switch (fieldPath != null ? fieldPath : "") {
|
|
1549
|
+
case "params":
|
|
1550
|
+
return new UrlStateFormatter(location.search);
|
|
1551
|
+
case "path":
|
|
1552
|
+
return subUrl + location.pathname;
|
|
1553
|
+
case "":
|
|
1554
|
+
default:
|
|
1555
|
+
return subUrl + location.pathname + location.search;
|
|
1605
1556
|
}
|
|
1606
|
-
parent = parent.parent;
|
|
1607
1557
|
}
|
|
1608
|
-
|
|
1609
|
-
|
|
1558
|
+
getValueText() {
|
|
1559
|
+
return "";
|
|
1610
1560
|
}
|
|
1611
|
-
return parent;
|
|
1612
1561
|
}
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1562
|
+
class UrlStateFormatter {
|
|
1563
|
+
constructor(_urlQueryParams) {
|
|
1564
|
+
this._urlQueryParams = _urlQueryParams;
|
|
1565
|
+
}
|
|
1566
|
+
formatter(options) {
|
|
1567
|
+
if (!options) {
|
|
1568
|
+
return this._urlQueryParams;
|
|
1569
|
+
}
|
|
1570
|
+
const params = options.split(":");
|
|
1571
|
+
if (params[0] === "exclude" && params.length > 1) {
|
|
1572
|
+
const allParams = new URLSearchParams(this._urlQueryParams);
|
|
1573
|
+
for (const param of params[1].split(",")) {
|
|
1574
|
+
allParams.delete(param);
|
|
1621
1575
|
}
|
|
1576
|
+
return `?${allParams}`;
|
|
1622
1577
|
}
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
return this.
|
|
1578
|
+
if (params[0] === "include" && params.length > 1) {
|
|
1579
|
+
const allParams = new URLSearchParams(this._urlQueryParams);
|
|
1580
|
+
const includeOnly = params[1].split(",");
|
|
1581
|
+
for (const param of allParams.keys()) {
|
|
1582
|
+
if (!includeOnly.includes(param)) {
|
|
1583
|
+
allParams.delete(param);
|
|
1584
|
+
}
|
|
1585
|
+
}
|
|
1586
|
+
return `?${allParams}`;
|
|
1587
|
+
}
|
|
1588
|
+
return this._urlQueryParams;
|
|
1634
1589
|
}
|
|
1635
1590
|
}
|
|
1636
1591
|
|
|
1637
|
-
class
|
|
1638
|
-
constructor(name,
|
|
1639
|
-
this.state = { name, type: "
|
|
1640
|
-
this._sceneObject = sceneObject;
|
|
1592
|
+
class UserMacro {
|
|
1593
|
+
constructor(name, _) {
|
|
1594
|
+
this.state = { name, type: "user_macro" };
|
|
1641
1595
|
}
|
|
1642
|
-
getValue() {
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1596
|
+
getValue(fieldPath) {
|
|
1597
|
+
const user = runtime.config.bootData.user;
|
|
1598
|
+
switch (fieldPath) {
|
|
1599
|
+
case "login":
|
|
1600
|
+
return user.login;
|
|
1601
|
+
case "email":
|
|
1602
|
+
return user.email;
|
|
1603
|
+
case "id":
|
|
1604
|
+
default:
|
|
1605
|
+
return String(user.id);
|
|
1606
|
+
}
|
|
1647
1607
|
}
|
|
1648
1608
|
getValueText() {
|
|
1649
1609
|
return "";
|
|
1650
1610
|
}
|
|
1651
1611
|
}
|
|
1652
|
-
class
|
|
1653
|
-
constructor(name,
|
|
1654
|
-
this.state = { name, type: "
|
|
1655
|
-
this._sceneObject = sceneObject;
|
|
1612
|
+
class OrgMacro {
|
|
1613
|
+
constructor(name, _) {
|
|
1614
|
+
this.state = { name, type: "org_macro" };
|
|
1656
1615
|
}
|
|
1657
|
-
getValue() {
|
|
1658
|
-
const
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1616
|
+
getValue(fieldPath) {
|
|
1617
|
+
const user = runtime.config.bootData.user;
|
|
1618
|
+
switch (fieldPath) {
|
|
1619
|
+
case "name":
|
|
1620
|
+
return user.orgName;
|
|
1621
|
+
case "id":
|
|
1622
|
+
default:
|
|
1623
|
+
return String(user.orgId);
|
|
1663
1624
|
}
|
|
1664
1625
|
}
|
|
1665
1626
|
getValueText() {
|
|
1666
|
-
|
|
1667
|
-
if (this.state.name === "__from") {
|
|
1668
|
-
return data.dateTimeFormat(timeRange.state.value.from, { timeZone: timeRange.getTimeZone() });
|
|
1669
|
-
} else {
|
|
1670
|
-
return data.dateTimeFormat(timeRange.state.value.to, { timeZone: timeRange.getTimeZone() });
|
|
1671
|
-
}
|
|
1627
|
+
return "";
|
|
1672
1628
|
}
|
|
1673
1629
|
}
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1630
|
+
|
|
1631
|
+
const macrosIndex = /* @__PURE__ */ new Map([
|
|
1632
|
+
[data.DataLinkBuiltInVars.includeVars, AllVariablesMacro],
|
|
1633
|
+
[data.DataLinkBuiltInVars.keepTime, UrlTimeRangeMacro],
|
|
1634
|
+
["__value", ValueMacro],
|
|
1635
|
+
["__data", DataMacro],
|
|
1636
|
+
["__series", SeriesMacro],
|
|
1637
|
+
["__field", FieldMacro],
|
|
1638
|
+
["__url", UrlMacro],
|
|
1639
|
+
["__from", TimeFromAndToMacro],
|
|
1640
|
+
["__to", TimeFromAndToMacro],
|
|
1641
|
+
["__timezone", TimezoneMacro],
|
|
1642
|
+
["__user", UserMacro],
|
|
1643
|
+
["__org", OrgMacro],
|
|
1644
|
+
["__interval", IntervalMacro],
|
|
1645
|
+
["__interval_ms", IntervalMacro]
|
|
1646
|
+
]);
|
|
1647
|
+
function registerVariableMacro(name, macro) {
|
|
1648
|
+
if (macrosIndex.get(name)) {
|
|
1649
|
+
throw new Error(`Macro already registered ${name}`);
|
|
1689
1650
|
}
|
|
1651
|
+
macrosIndex.set(name, macro);
|
|
1652
|
+
return () => {
|
|
1653
|
+
macrosIndex.delete(name);
|
|
1654
|
+
};
|
|
1690
1655
|
}
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1656
|
+
|
|
1657
|
+
function sceneInterpolator(sceneObject, target, scopedVars, format, interpolations) {
|
|
1658
|
+
if (!target) {
|
|
1659
|
+
return target != null ? target : "";
|
|
1695
1660
|
}
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
const
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
if (this.state.name === "__interval_ms") {
|
|
1705
|
-
return request.intervalMs;
|
|
1661
|
+
VARIABLE_REGEX.lastIndex = 0;
|
|
1662
|
+
return target.replace(VARIABLE_REGEX, (match, var1, var2, fmt2, var3, fieldPath, fmt3) => {
|
|
1663
|
+
const variableName = var1 || var2 || var3;
|
|
1664
|
+
const fmt = fmt2 || fmt3 || format;
|
|
1665
|
+
const variable = lookupFormatVariable(variableName, match, scopedVars, sceneObject);
|
|
1666
|
+
if (!variable) {
|
|
1667
|
+
if (interpolations) {
|
|
1668
|
+
interpolations.push({ match, variableName, fieldPath, format: fmt, value: match, found: false });
|
|
1706
1669
|
}
|
|
1707
|
-
return
|
|
1670
|
+
return match;
|
|
1708
1671
|
}
|
|
1709
|
-
|
|
1710
|
-
|
|
1672
|
+
const value = formatValue(sceneObject, variable, variable.getValue(fieldPath), fmt);
|
|
1673
|
+
if (interpolations) {
|
|
1674
|
+
interpolations.push({ match, variableName, fieldPath, format: fmt, value, found: value !== match });
|
|
1675
|
+
}
|
|
1676
|
+
return value;
|
|
1677
|
+
});
|
|
1711
1678
|
}
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
}
|
|
1718
|
-
getValue() {
|
|
1719
|
-
const allVars = collectAllVariables(this._sceneObject);
|
|
1720
|
-
const format = formatRegistry.get(schema.VariableFormatID.QueryParam);
|
|
1721
|
-
const params = [];
|
|
1722
|
-
for (const name of Object.keys(allVars)) {
|
|
1723
|
-
const variable = allVars[name];
|
|
1724
|
-
const value = variable.getValue();
|
|
1725
|
-
if (!value) {
|
|
1726
|
-
continue;
|
|
1727
|
-
}
|
|
1728
|
-
if (isCustomVariableValue(value)) {
|
|
1729
|
-
params.push(value.formatter(schema.VariableFormatID.QueryParam));
|
|
1730
|
-
} else {
|
|
1731
|
-
params.push(format.formatter(value, [], variable));
|
|
1732
|
-
}
|
|
1679
|
+
function lookupFormatVariable(name, match, scopedVars, sceneObject) {
|
|
1680
|
+
if (scopedVars && scopedVars.hasOwnProperty(name)) {
|
|
1681
|
+
const scopedVar = scopedVars[name];
|
|
1682
|
+
if (scopedVar) {
|
|
1683
|
+
return getSceneVariableForScopedVar(name, scopedVar);
|
|
1733
1684
|
}
|
|
1734
|
-
return new SkipFormattingValue(params.join("&"));
|
|
1735
1685
|
}
|
|
1736
|
-
|
|
1737
|
-
|
|
1686
|
+
const variable = lookupVariable(name, sceneObject);
|
|
1687
|
+
if (variable) {
|
|
1688
|
+
return variable;
|
|
1738
1689
|
}
|
|
1690
|
+
const Macro = macrosIndex.get(name);
|
|
1691
|
+
if (Macro) {
|
|
1692
|
+
return new Macro(name, sceneObject, match, scopedVars);
|
|
1693
|
+
}
|
|
1694
|
+
return null;
|
|
1739
1695
|
}
|
|
1740
|
-
function
|
|
1741
|
-
if (
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1696
|
+
function formatValue(context, variable, value, formatNameOrFn) {
|
|
1697
|
+
if (value === null || value === void 0) {
|
|
1698
|
+
return "";
|
|
1699
|
+
}
|
|
1700
|
+
if (isCustomVariableValue(value)) {
|
|
1701
|
+
return sceneInterpolator(context, value.formatter(formatNameOrFn));
|
|
1702
|
+
}
|
|
1703
|
+
if (!Array.isArray(value) && typeof value === "object") {
|
|
1704
|
+
value = `${value}`;
|
|
1705
|
+
}
|
|
1706
|
+
if (typeof formatNameOrFn === "function") {
|
|
1707
|
+
return formatNameOrFn(value, {
|
|
1708
|
+
name: variable.state.name,
|
|
1709
|
+
type: variable.state.type,
|
|
1710
|
+
multi: variable.state.isMulti,
|
|
1711
|
+
includeAll: variable.state.includeAll
|
|
1712
|
+
});
|
|
1713
|
+
}
|
|
1714
|
+
let args = [];
|
|
1715
|
+
if (!formatNameOrFn) {
|
|
1716
|
+
formatNameOrFn = schema.VariableFormatID.Glob;
|
|
1717
|
+
} else {
|
|
1718
|
+
args = formatNameOrFn.split(":");
|
|
1719
|
+
if (args.length > 1) {
|
|
1720
|
+
formatNameOrFn = args[0];
|
|
1721
|
+
args = args.slice(1);
|
|
1722
|
+
} else {
|
|
1723
|
+
args = [];
|
|
1749
1724
|
}
|
|
1750
1725
|
}
|
|
1751
|
-
|
|
1752
|
-
|
|
1726
|
+
let formatter = formatRegistry.getIfExists(formatNameOrFn);
|
|
1727
|
+
if (!formatter) {
|
|
1728
|
+
console.error(`Variable format ${formatNameOrFn} not found. Using glob format as fallback.`);
|
|
1729
|
+
formatter = formatRegistry.get(schema.VariableFormatID.Glob);
|
|
1753
1730
|
}
|
|
1754
|
-
return
|
|
1731
|
+
return formatter.formatter(value, args, variable);
|
|
1755
1732
|
}
|
|
1756
1733
|
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
if (__getOwnPropSymbols$D)
|
|
1769
|
-
for (var prop of __getOwnPropSymbols$D(b)) {
|
|
1770
|
-
if (__propIsEnum$D.call(b, prop))
|
|
1771
|
-
__defNormalProp$D(a, prop, b[prop]);
|
|
1772
|
-
}
|
|
1773
|
-
return a;
|
|
1774
|
-
};
|
|
1775
|
-
var __spreadProps$r = (a, b) => __defProps$r(a, __getOwnPropDescs$r(b));
|
|
1776
|
-
function getTemplateProxyForField(field, frame, frames) {
|
|
1777
|
-
return new Proxy(
|
|
1778
|
-
{},
|
|
1779
|
-
{
|
|
1780
|
-
get: (obj, key) => {
|
|
1781
|
-
if (key === "name") {
|
|
1782
|
-
return field.name;
|
|
1783
|
-
}
|
|
1784
|
-
if (key === "displayName") {
|
|
1785
|
-
return data.getFieldDisplayName(field, frame, frames);
|
|
1786
|
-
}
|
|
1787
|
-
if (key === "labels" || key === "formattedLabels") {
|
|
1788
|
-
if (!field.labels) {
|
|
1789
|
-
return "";
|
|
1790
|
-
}
|
|
1791
|
-
return __spreadProps$r(__spreadValues$D({}, field.labels), {
|
|
1792
|
-
__values: Object.values(field.labels).sort().join(", "),
|
|
1793
|
-
toString: () => {
|
|
1794
|
-
return data.formatLabels(field.labels, "", true);
|
|
1795
|
-
}
|
|
1796
|
-
});
|
|
1797
|
-
}
|
|
1798
|
-
return void 0;
|
|
1799
|
-
}
|
|
1800
|
-
}
|
|
1801
|
-
);
|
|
1734
|
+
function isSceneObject(obj) {
|
|
1735
|
+
return obj.useState !== void 0;
|
|
1736
|
+
}
|
|
1737
|
+
function isDataRequestEnricher(obj) {
|
|
1738
|
+
return "enrichDataRequest" in obj;
|
|
1739
|
+
}
|
|
1740
|
+
function isFiltersRequestEnricher(obj) {
|
|
1741
|
+
return "enrichFiltersRequest" in obj;
|
|
1742
|
+
}
|
|
1743
|
+
function isDataLayer(obj) {
|
|
1744
|
+
return "isDataLayer" in obj;
|
|
1802
1745
|
}
|
|
1803
1746
|
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1747
|
+
var __accessCheck$1 = (obj, member, msg) => {
|
|
1748
|
+
if (!member.has(obj))
|
|
1749
|
+
throw TypeError("Cannot " + msg);
|
|
1750
|
+
};
|
|
1751
|
+
var __privateGet$1 = (obj, member, getter) => {
|
|
1752
|
+
__accessCheck$1(obj, member, "read from private field");
|
|
1753
|
+
return getter ? getter.call(obj) : member.get(obj);
|
|
1754
|
+
};
|
|
1755
|
+
var __privateAdd$1 = (obj, member, value) => {
|
|
1756
|
+
if (member.has(obj))
|
|
1757
|
+
throw TypeError("Cannot add the same private member more than once");
|
|
1758
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
1759
|
+
};
|
|
1760
|
+
var _running;
|
|
1761
|
+
function isQueryController(s) {
|
|
1762
|
+
return "isQueryController" in s;
|
|
1763
|
+
}
|
|
1764
|
+
class SceneQueryController extends SceneObjectBase {
|
|
1765
|
+
constructor() {
|
|
1766
|
+
super({ isRunning: false });
|
|
1767
|
+
this.isQueryController = true;
|
|
1768
|
+
__privateAdd$1(this, _running, /* @__PURE__ */ new Set());
|
|
1769
|
+
this.addActivationHandler(() => {
|
|
1770
|
+
return () => __privateGet$1(this, _running).clear();
|
|
1771
|
+
});
|
|
1809
1772
|
}
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
if (!
|
|
1814
|
-
|
|
1815
|
-
}
|
|
1816
|
-
const { frame, rowIndex, field, calculatedValue } = dataContext.value;
|
|
1817
|
-
if (calculatedValue) {
|
|
1818
|
-
switch (fieldPath) {
|
|
1819
|
-
case "numeric":
|
|
1820
|
-
return calculatedValue.numeric;
|
|
1821
|
-
case "raw":
|
|
1822
|
-
return calculatedValue.numeric;
|
|
1823
|
-
case "time":
|
|
1824
|
-
return "";
|
|
1825
|
-
case "text":
|
|
1826
|
-
default:
|
|
1827
|
-
return data.formattedValueToString(calculatedValue);
|
|
1828
|
-
}
|
|
1829
|
-
}
|
|
1830
|
-
if (rowIndex == null) {
|
|
1831
|
-
return this._match;
|
|
1832
|
-
}
|
|
1833
|
-
if (fieldPath === "time") {
|
|
1834
|
-
const timeField = frame.fields.find((f) => f.type === data.FieldType.time);
|
|
1835
|
-
return timeField ? timeField.values.get(rowIndex) : void 0;
|
|
1836
|
-
}
|
|
1837
|
-
if (!field) {
|
|
1838
|
-
return this._match;
|
|
1773
|
+
queryStarted(entry) {
|
|
1774
|
+
__privateGet$1(this, _running).add(entry);
|
|
1775
|
+
this.changeRunningQueryCount(1);
|
|
1776
|
+
if (!this.state.isRunning) {
|
|
1777
|
+
this.setState({ isRunning: true });
|
|
1839
1778
|
}
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1779
|
+
}
|
|
1780
|
+
queryCompleted(entry) {
|
|
1781
|
+
if (!__privateGet$1(this, _running).has(entry)) {
|
|
1782
|
+
return;
|
|
1843
1783
|
}
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
return result.numeric;
|
|
1849
|
-
case "text":
|
|
1850
|
-
default:
|
|
1851
|
-
return data.formattedValueToString(result);
|
|
1784
|
+
__privateGet$1(this, _running).delete(entry);
|
|
1785
|
+
this.changeRunningQueryCount(-1);
|
|
1786
|
+
if (__privateGet$1(this, _running).size === 0) {
|
|
1787
|
+
this.setState({ isRunning: false });
|
|
1852
1788
|
}
|
|
1853
1789
|
}
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
}
|
|
1858
|
-
const fallbackDisplayProcessor = data.getDisplayProcessor();
|
|
1859
|
-
class DataMacro {
|
|
1860
|
-
constructor(name, sceneObject, _match, _scopedVars) {
|
|
1861
|
-
this._match = _match;
|
|
1862
|
-
this._scopedVars = _scopedVars;
|
|
1863
|
-
this.state = { name, type: "__data" };
|
|
1790
|
+
changeRunningQueryCount(dir) {
|
|
1791
|
+
var _a;
|
|
1792
|
+
window.__grafanaRunningQueryCount = ((_a = window.__grafanaRunningQueryCount) != null ? _a : 0) + dir;
|
|
1864
1793
|
}
|
|
1865
|
-
|
|
1866
|
-
var _a
|
|
1867
|
-
const
|
|
1868
|
-
|
|
1869
|
-
return this._match;
|
|
1870
|
-
}
|
|
1871
|
-
const { frame, rowIndex } = dataContext.value;
|
|
1872
|
-
if (rowIndex === void 0 || fieldPath === void 0) {
|
|
1873
|
-
return this._match;
|
|
1794
|
+
cancelAll() {
|
|
1795
|
+
var _a;
|
|
1796
|
+
for (const entry of __privateGet$1(this, _running).values()) {
|
|
1797
|
+
(_a = entry.cancel) == null ? void 0 : _a.call(entry);
|
|
1874
1798
|
}
|
|
1875
|
-
const obj = {
|
|
1876
|
-
name: frame.name,
|
|
1877
|
-
refId: frame.refId,
|
|
1878
|
-
fields: data.getFieldDisplayValuesProxy({ frame, rowIndex })
|
|
1879
|
-
};
|
|
1880
|
-
return (_b = getFieldAccessor(fieldPath)(obj)) != null ? _b : "";
|
|
1881
1799
|
}
|
|
1882
|
-
|
|
1800
|
+
}
|
|
1801
|
+
_running = new WeakMap();
|
|
1802
|
+
|
|
1803
|
+
function getVariables(sceneObject) {
|
|
1804
|
+
var _a;
|
|
1805
|
+
return (_a = getClosest(sceneObject, (s) => s.state.$variables)) != null ? _a : EmptyVariableSet;
|
|
1806
|
+
}
|
|
1807
|
+
function getData(sceneObject) {
|
|
1808
|
+
var _a;
|
|
1809
|
+
return (_a = getClosest(sceneObject, (s) => s.state.$data)) != null ? _a : EmptyDataNode;
|
|
1810
|
+
}
|
|
1811
|
+
function isSceneLayout(s) {
|
|
1812
|
+
return "isDraggable" in s;
|
|
1813
|
+
}
|
|
1814
|
+
function getLayout(scene) {
|
|
1815
|
+
const parent = getClosest(scene, (s) => isSceneLayout(s) ? s : void 0);
|
|
1816
|
+
if (parent) {
|
|
1817
|
+
return parent;
|
|
1818
|
+
}
|
|
1819
|
+
return null;
|
|
1820
|
+
}
|
|
1821
|
+
function interpolate(sceneObject, value, scopedVars, format, interpolations) {
|
|
1822
|
+
if (value === "" || value == null) {
|
|
1883
1823
|
return "";
|
|
1884
1824
|
}
|
|
1825
|
+
return sceneInterpolator(sceneObject, value, scopedVars, format, interpolations);
|
|
1885
1826
|
}
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
this._scopedVars = _scopedVars;
|
|
1890
|
-
this.state = { name, type: "__series" };
|
|
1827
|
+
function hasVariableDependencyInLoadingState(sceneObject) {
|
|
1828
|
+
if (!sceneObject.variableDependency) {
|
|
1829
|
+
return false;
|
|
1891
1830
|
}
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
return this._match;
|
|
1831
|
+
for (const name of sceneObject.variableDependency.getNames()) {
|
|
1832
|
+
const variable = lookupVariable(name, sceneObject);
|
|
1833
|
+
if (!variable) {
|
|
1834
|
+
continue;
|
|
1897
1835
|
}
|
|
1898
|
-
|
|
1899
|
-
|
|
1836
|
+
const set = variable.parent;
|
|
1837
|
+
if (set.isVariableLoadingOrWaitingToUpdate(variable)) {
|
|
1838
|
+
return true;
|
|
1900
1839
|
}
|
|
1901
|
-
const { frame, frameIndex } = dataContext.value;
|
|
1902
|
-
return data.getFrameDisplayName(frame, frameIndex);
|
|
1903
|
-
}
|
|
1904
|
-
getValueText() {
|
|
1905
|
-
return "";
|
|
1906
1840
|
}
|
|
1841
|
+
return false;
|
|
1907
1842
|
}
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
this._scopedVars = _scopedVars;
|
|
1912
|
-
this.state = { name, type: "__field" };
|
|
1843
|
+
function findObjectInternal(scene, check, alreadySearchedChild, shouldSearchUp) {
|
|
1844
|
+
if (check(scene)) {
|
|
1845
|
+
return scene;
|
|
1913
1846
|
}
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
return this._match;
|
|
1847
|
+
let found = null;
|
|
1848
|
+
scene.forEachChild((child) => {
|
|
1849
|
+
if (child === alreadySearchedChild) {
|
|
1850
|
+
return;
|
|
1919
1851
|
}
|
|
1920
|
-
|
|
1921
|
-
|
|
1852
|
+
let maybe = findObjectInternal(child, check);
|
|
1853
|
+
if (maybe) {
|
|
1854
|
+
found = maybe;
|
|
1922
1855
|
}
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
return
|
|
1856
|
+
});
|
|
1857
|
+
if (found) {
|
|
1858
|
+
return found;
|
|
1926
1859
|
}
|
|
1927
|
-
|
|
1928
|
-
return
|
|
1860
|
+
if (shouldSearchUp && scene.parent) {
|
|
1861
|
+
return findObjectInternal(scene.parent, check, scene, true);
|
|
1929
1862
|
}
|
|
1863
|
+
return null;
|
|
1930
1864
|
}
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1865
|
+
function findByKey(sceneObject, key) {
|
|
1866
|
+
const found = findObject(sceneObject, (sceneToCheck) => {
|
|
1867
|
+
return sceneToCheck.state.key === key;
|
|
1868
|
+
});
|
|
1869
|
+
if (!found) {
|
|
1870
|
+
throw new Error("Unable to find scene with key " + key);
|
|
1935
1871
|
}
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
return subUrl + location.pathname;
|
|
1945
|
-
case "":
|
|
1946
|
-
default:
|
|
1947
|
-
return subUrl + location.pathname + location.search;
|
|
1948
|
-
}
|
|
1872
|
+
return found;
|
|
1873
|
+
}
|
|
1874
|
+
function findByKeyAndType(sceneObject, key, targetType) {
|
|
1875
|
+
const found = findObject(sceneObject, (sceneToCheck) => {
|
|
1876
|
+
return sceneToCheck.state.key === key;
|
|
1877
|
+
});
|
|
1878
|
+
if (!found) {
|
|
1879
|
+
throw new Error("Unable to find scene with key " + key);
|
|
1949
1880
|
}
|
|
1950
|
-
|
|
1951
|
-
|
|
1881
|
+
if (!(found instanceof targetType)) {
|
|
1882
|
+
throw new Error(`Found scene object with key ${key} does not match type ${targetType.name}`);
|
|
1952
1883
|
}
|
|
1884
|
+
return found;
|
|
1953
1885
|
}
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1886
|
+
function findObject(scene, check) {
|
|
1887
|
+
return findObjectInternal(scene, check, void 0, true);
|
|
1888
|
+
}
|
|
1889
|
+
function findAllObjects(scene, check) {
|
|
1890
|
+
const found = [];
|
|
1891
|
+
scene.forEachChild((child) => {
|
|
1892
|
+
if (check(child)) {
|
|
1893
|
+
found.push(child);
|
|
1894
|
+
}
|
|
1895
|
+
found.push(...findAllObjects(child, check));
|
|
1896
|
+
});
|
|
1897
|
+
return found;
|
|
1898
|
+
}
|
|
1899
|
+
function getDataLayers(sceneObject, localOnly = false) {
|
|
1900
|
+
let currentLevel = sceneObject;
|
|
1901
|
+
let collected = [];
|
|
1902
|
+
while (currentLevel) {
|
|
1903
|
+
const dataProvider = currentLevel.state.$data;
|
|
1904
|
+
if (!dataProvider) {
|
|
1905
|
+
currentLevel = currentLevel.parent;
|
|
1906
|
+
continue;
|
|
1961
1907
|
}
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1908
|
+
if (isDataLayer(dataProvider)) {
|
|
1909
|
+
collected = collected.concat(dataProvider);
|
|
1910
|
+
} else {
|
|
1911
|
+
if (dataProvider.state.$data && isDataLayer(dataProvider.state.$data)) {
|
|
1912
|
+
collected = collected.concat(dataProvider.state.$data);
|
|
1967
1913
|
}
|
|
1968
|
-
return `?${allParams}`;
|
|
1969
1914
|
}
|
|
1970
|
-
if (
|
|
1971
|
-
|
|
1972
|
-
const includeOnly = params[1].split(",");
|
|
1973
|
-
for (const param of allParams.keys()) {
|
|
1974
|
-
if (!includeOnly.includes(param)) {
|
|
1975
|
-
allParams.delete(param);
|
|
1976
|
-
}
|
|
1977
|
-
}
|
|
1978
|
-
return `?${allParams}`;
|
|
1915
|
+
if (localOnly && collected.length > 0) {
|
|
1916
|
+
break;
|
|
1979
1917
|
}
|
|
1980
|
-
|
|
1918
|
+
currentLevel = currentLevel.parent;
|
|
1981
1919
|
}
|
|
1920
|
+
return collected;
|
|
1982
1921
|
}
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
getValue(fieldPath) {
|
|
1989
|
-
const user = runtime.config.bootData.user;
|
|
1990
|
-
switch (fieldPath) {
|
|
1991
|
-
case "login":
|
|
1992
|
-
return user.login;
|
|
1993
|
-
case "email":
|
|
1994
|
-
return user.email;
|
|
1995
|
-
case "id":
|
|
1996
|
-
default:
|
|
1997
|
-
return String(user.id);
|
|
1922
|
+
function getAncestor(sceneObject, ancestorType) {
|
|
1923
|
+
let parent = sceneObject;
|
|
1924
|
+
while (parent) {
|
|
1925
|
+
if (parent instanceof ancestorType) {
|
|
1926
|
+
return parent;
|
|
1998
1927
|
}
|
|
1928
|
+
parent = parent.parent;
|
|
1999
1929
|
}
|
|
2000
|
-
|
|
2001
|
-
|
|
1930
|
+
if (!parent) {
|
|
1931
|
+
throw new Error("Unable to find parent of type " + ancestorType.name);
|
|
2002
1932
|
}
|
|
1933
|
+
return parent;
|
|
2003
1934
|
}
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
case "id":
|
|
2014
|
-
default:
|
|
2015
|
-
return String(user.orgId);
|
|
1935
|
+
function getQueryController(sceneObject) {
|
|
1936
|
+
let parent = sceneObject;
|
|
1937
|
+
while (parent) {
|
|
1938
|
+
if (parent.state.$behaviors) {
|
|
1939
|
+
for (const behavior of parent.state.$behaviors) {
|
|
1940
|
+
if (isQueryController(behavior)) {
|
|
1941
|
+
return behavior;
|
|
1942
|
+
}
|
|
1943
|
+
}
|
|
2016
1944
|
}
|
|
1945
|
+
parent = parent.parent;
|
|
2017
1946
|
}
|
|
2018
|
-
|
|
2019
|
-
return "";
|
|
2020
|
-
}
|
|
2021
|
-
}
|
|
2022
|
-
|
|
2023
|
-
const macrosIndex = /* @__PURE__ */ new Map([
|
|
2024
|
-
[data.DataLinkBuiltInVars.includeVars, AllVariablesMacro],
|
|
2025
|
-
[data.DataLinkBuiltInVars.keepTime, UrlTimeRangeMacro],
|
|
2026
|
-
["__value", ValueMacro],
|
|
2027
|
-
["__data", DataMacro],
|
|
2028
|
-
["__series", SeriesMacro],
|
|
2029
|
-
["__field", FieldMacro],
|
|
2030
|
-
["__url", UrlMacro],
|
|
2031
|
-
["__from", TimeFromAndToMacro],
|
|
2032
|
-
["__to", TimeFromAndToMacro],
|
|
2033
|
-
["__timezone", TimezoneMacro],
|
|
2034
|
-
["__user", UserMacro],
|
|
2035
|
-
["__org", OrgMacro],
|
|
2036
|
-
["__interval", IntervalMacro],
|
|
2037
|
-
["__interval_ms", IntervalMacro]
|
|
2038
|
-
]);
|
|
2039
|
-
function registerVariableMacro(name, macro) {
|
|
2040
|
-
if (macrosIndex.get(name)) {
|
|
2041
|
-
throw new Error(`Macro already registered ${name}`);
|
|
2042
|
-
}
|
|
2043
|
-
macrosIndex.set(name, macro);
|
|
2044
|
-
return () => {
|
|
2045
|
-
macrosIndex.delete(name);
|
|
2046
|
-
};
|
|
1947
|
+
return void 0;
|
|
2047
1948
|
}
|
|
2048
1949
|
|
|
2049
1950
|
const sceneGraph = {
|
|
@@ -2063,6 +1964,117 @@ const sceneGraph = {
|
|
|
2063
1964
|
getQueryController
|
|
2064
1965
|
};
|
|
2065
1966
|
|
|
1967
|
+
class UniqueUrlKeyMapper {
|
|
1968
|
+
constructor() {
|
|
1969
|
+
this.index = /* @__PURE__ */ new Map();
|
|
1970
|
+
}
|
|
1971
|
+
getUniqueKey(key, obj) {
|
|
1972
|
+
const objectsWithKey = this.index.get(key);
|
|
1973
|
+
if (!objectsWithKey) {
|
|
1974
|
+
this.index.set(key, [obj]);
|
|
1975
|
+
return key;
|
|
1976
|
+
}
|
|
1977
|
+
let address = objectsWithKey.findIndex((o) => o === obj);
|
|
1978
|
+
if (address === -1) {
|
|
1979
|
+
filterOutOrphanedObjects(objectsWithKey);
|
|
1980
|
+
objectsWithKey.push(obj);
|
|
1981
|
+
address = objectsWithKey.length - 1;
|
|
1982
|
+
}
|
|
1983
|
+
if (address > 0) {
|
|
1984
|
+
return `${key}-${address + 1}`;
|
|
1985
|
+
}
|
|
1986
|
+
return key;
|
|
1987
|
+
}
|
|
1988
|
+
clear() {
|
|
1989
|
+
this.index.clear();
|
|
1990
|
+
}
|
|
1991
|
+
}
|
|
1992
|
+
function filterOutOrphanedObjects(sceneObjects) {
|
|
1993
|
+
for (const obj of sceneObjects) {
|
|
1994
|
+
if (isOrphanOrInActive(obj)) {
|
|
1995
|
+
const index = sceneObjects.indexOf(obj);
|
|
1996
|
+
sceneObjects.splice(index, 1);
|
|
1997
|
+
}
|
|
1998
|
+
}
|
|
1999
|
+
}
|
|
2000
|
+
function isOrphanOrInActive(obj) {
|
|
2001
|
+
const root = obj.getRoot();
|
|
2002
|
+
if (!sceneGraph.findObject(root, (child) => child === obj)) {
|
|
2003
|
+
return true;
|
|
2004
|
+
}
|
|
2005
|
+
return false;
|
|
2006
|
+
}
|
|
2007
|
+
|
|
2008
|
+
function getUrlState(root) {
|
|
2009
|
+
const urlKeyMapper = new UniqueUrlKeyMapper();
|
|
2010
|
+
const result = {};
|
|
2011
|
+
const visitNode = (obj) => {
|
|
2012
|
+
if (obj.urlSync) {
|
|
2013
|
+
const newUrlState = obj.urlSync.getUrlState();
|
|
2014
|
+
for (const [key, value] of Object.entries(newUrlState)) {
|
|
2015
|
+
if (value != null) {
|
|
2016
|
+
const uniqueKey = urlKeyMapper.getUniqueKey(key, obj);
|
|
2017
|
+
result[uniqueKey] = value;
|
|
2018
|
+
}
|
|
2019
|
+
}
|
|
2020
|
+
}
|
|
2021
|
+
obj.forEachChild(visitNode);
|
|
2022
|
+
};
|
|
2023
|
+
visitNode(root);
|
|
2024
|
+
return result;
|
|
2025
|
+
}
|
|
2026
|
+
function syncStateFromSearchParams(root, urlParams) {
|
|
2027
|
+
const urlKeyMapper = new UniqueUrlKeyMapper();
|
|
2028
|
+
syncStateFromUrl(root, urlParams, urlKeyMapper);
|
|
2029
|
+
}
|
|
2030
|
+
function syncStateFromUrl(root, urlParams, urlKeyMapper) {
|
|
2031
|
+
if (!root.parent) {
|
|
2032
|
+
syncUrlStateToObject(root, urlParams, urlKeyMapper);
|
|
2033
|
+
}
|
|
2034
|
+
root.forEachChild((child) => {
|
|
2035
|
+
syncUrlStateToObject(child, urlParams, urlKeyMapper);
|
|
2036
|
+
});
|
|
2037
|
+
root.forEachChild((child) => syncStateFromUrl(child, urlParams, urlKeyMapper));
|
|
2038
|
+
}
|
|
2039
|
+
function syncUrlStateToObject(sceneObject, urlParams, urlKeyMapper) {
|
|
2040
|
+
if (sceneObject.urlSync) {
|
|
2041
|
+
const urlState = {};
|
|
2042
|
+
const currentState = sceneObject.urlSync.getUrlState();
|
|
2043
|
+
for (const key of sceneObject.urlSync.getKeys()) {
|
|
2044
|
+
const uniqueKey = urlKeyMapper.getUniqueKey(key, sceneObject);
|
|
2045
|
+
const newValue = urlParams.getAll(uniqueKey);
|
|
2046
|
+
const currentValue = currentState[key];
|
|
2047
|
+
if (isUrlValueEqual(newValue, currentValue)) {
|
|
2048
|
+
continue;
|
|
2049
|
+
}
|
|
2050
|
+
if (newValue.length > 0) {
|
|
2051
|
+
if (Array.isArray(currentValue)) {
|
|
2052
|
+
urlState[key] = newValue;
|
|
2053
|
+
} else {
|
|
2054
|
+
urlState[key] = newValue[0];
|
|
2055
|
+
}
|
|
2056
|
+
} else {
|
|
2057
|
+
urlState[key] = null;
|
|
2058
|
+
}
|
|
2059
|
+
}
|
|
2060
|
+
if (Object.keys(urlState).length > 0) {
|
|
2061
|
+
sceneObject.urlSync.updateFromUrl(urlState);
|
|
2062
|
+
}
|
|
2063
|
+
}
|
|
2064
|
+
}
|
|
2065
|
+
function isUrlValueEqual(currentUrlValue, newUrlValue) {
|
|
2066
|
+
if (currentUrlValue.length === 0 && newUrlValue == null) {
|
|
2067
|
+
return true;
|
|
2068
|
+
}
|
|
2069
|
+
if (!Array.isArray(newUrlValue) && (currentUrlValue == null ? void 0 : currentUrlValue.length) === 1) {
|
|
2070
|
+
return newUrlValue === currentUrlValue[0];
|
|
2071
|
+
}
|
|
2072
|
+
if ((newUrlValue == null ? void 0 : newUrlValue.length) === 0 && currentUrlValue === null) {
|
|
2073
|
+
return true;
|
|
2074
|
+
}
|
|
2075
|
+
return lodash.isEqual(currentUrlValue, newUrlValue);
|
|
2076
|
+
}
|
|
2077
|
+
|
|
2066
2078
|
async function getDataSource(datasource, scopedVars) {
|
|
2067
2079
|
if (datasource == null ? void 0 : datasource.uid) {
|
|
2068
2080
|
const runtimeDataSource = runtimeDataSources.get(datasource.uid);
|
|
@@ -7776,90 +7788,125 @@ IntervalVariable.Component = ({ model }) => {
|
|
|
7776
7788
|
});
|
|
7777
7789
|
};
|
|
7778
7790
|
|
|
7791
|
+
var __accessCheck = (obj, member, msg) => {
|
|
7792
|
+
if (!member.has(obj))
|
|
7793
|
+
throw TypeError("Cannot " + msg);
|
|
7794
|
+
};
|
|
7795
|
+
var __privateGet = (obj, member, getter) => {
|
|
7796
|
+
__accessCheck(obj, member, "read from private field");
|
|
7797
|
+
return getter ? getter.call(obj) : member.get(obj);
|
|
7798
|
+
};
|
|
7799
|
+
var __privateAdd = (obj, member, value) => {
|
|
7800
|
+
if (member.has(obj))
|
|
7801
|
+
throw TypeError("Cannot add the same private member more than once");
|
|
7802
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
7803
|
+
};
|
|
7804
|
+
var __privateSet = (obj, member, value, setter) => {
|
|
7805
|
+
__accessCheck(obj, member, "write to private field");
|
|
7806
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
7807
|
+
return value;
|
|
7808
|
+
};
|
|
7809
|
+
var _urlKeyMapper, _sceneRoot, _stateSub, _lastLocation, _paramsCache, _onStateChanged, _cache, _location;
|
|
7779
7810
|
class UrlSyncManager {
|
|
7780
7811
|
constructor() {
|
|
7781
|
-
this
|
|
7782
|
-
this
|
|
7783
|
-
this
|
|
7784
|
-
this
|
|
7785
|
-
this
|
|
7786
|
-
|
|
7787
|
-
this._ignoreNextLocationUpdate = false;
|
|
7788
|
-
return;
|
|
7789
|
-
}
|
|
7790
|
-
if (this._lastPath !== location.pathname) {
|
|
7791
|
-
return;
|
|
7792
|
-
}
|
|
7793
|
-
const urlParams = new URLSearchParams(location.search);
|
|
7794
|
-
this._urlKeyMapper.rebuildIndex(this._sceneRoot);
|
|
7795
|
-
syncStateFromUrl(this._sceneRoot, urlParams, this._urlKeyMapper);
|
|
7796
|
-
this._lastPath = location.pathname;
|
|
7797
|
-
};
|
|
7798
|
-
this._onStateChanged = ({ payload }) => {
|
|
7812
|
+
__privateAdd(this, _urlKeyMapper, new UniqueUrlKeyMapper());
|
|
7813
|
+
__privateAdd(this, _sceneRoot, void 0);
|
|
7814
|
+
__privateAdd(this, _stateSub, null);
|
|
7815
|
+
__privateAdd(this, _lastLocation, void 0);
|
|
7816
|
+
__privateAdd(this, _paramsCache, new UrlParamsCache());
|
|
7817
|
+
__privateAdd(this, _onStateChanged, ({ payload }) => {
|
|
7799
7818
|
const changedObject = payload.changedObject;
|
|
7800
7819
|
if (changedObject.urlSync) {
|
|
7801
7820
|
const newUrlState = changedObject.urlSync.getUrlState();
|
|
7802
7821
|
const searchParams = runtime.locationService.getSearch();
|
|
7803
7822
|
const mappedUpdated = {};
|
|
7804
|
-
this._urlKeyMapper.rebuildIndex(this._sceneRoot);
|
|
7805
7823
|
for (const [key, newUrlValue] of Object.entries(newUrlState)) {
|
|
7806
|
-
const uniqueKey = this
|
|
7824
|
+
const uniqueKey = __privateGet(this, _urlKeyMapper).getUniqueKey(key, changedObject);
|
|
7807
7825
|
const currentUrlValue = searchParams.getAll(uniqueKey);
|
|
7808
7826
|
if (!isUrlValueEqual(currentUrlValue, newUrlValue)) {
|
|
7809
7827
|
mappedUpdated[uniqueKey] = newUrlValue;
|
|
7810
7828
|
}
|
|
7811
7829
|
}
|
|
7812
7830
|
if (Object.keys(mappedUpdated).length > 0) {
|
|
7813
|
-
|
|
7831
|
+
writeSceneLog("UrlSyncManager", "onStateChange updating URL");
|
|
7814
7832
|
runtime.locationService.partial(mappedUpdated, true);
|
|
7833
|
+
__privateSet(this, _lastLocation, runtime.locationService.getLocation());
|
|
7815
7834
|
}
|
|
7816
7835
|
}
|
|
7817
|
-
};
|
|
7836
|
+
});
|
|
7818
7837
|
}
|
|
7819
7838
|
initSync(root) {
|
|
7820
|
-
|
|
7821
|
-
|
|
7822
|
-
|
|
7823
|
-
|
|
7824
|
-
if (this._stateSub) {
|
|
7825
|
-
writeSceneLog("UrlSyncManager", "Unregister previous scene state subscription", this._sceneRoot.state.key);
|
|
7826
|
-
this._stateSub.unsubscribe();
|
|
7839
|
+
var _a;
|
|
7840
|
+
if (__privateGet(this, _stateSub)) {
|
|
7841
|
+
writeSceneLog("UrlSyncManager", "Unregister previous scene state subscription", (_a = __privateGet(this, _sceneRoot)) == null ? void 0 : _a.state.key);
|
|
7842
|
+
__privateGet(this, _stateSub).unsubscribe();
|
|
7827
7843
|
}
|
|
7828
|
-
|
|
7829
|
-
this
|
|
7830
|
-
this
|
|
7831
|
-
this.
|
|
7844
|
+
writeSceneLog("UrlSyncManager", "init", root.state.key);
|
|
7845
|
+
__privateSet(this, _sceneRoot, root);
|
|
7846
|
+
__privateSet(this, _stateSub, root.subscribeToEvent(SceneObjectStateChangedEvent, __privateGet(this, _onStateChanged)));
|
|
7847
|
+
__privateGet(this, _urlKeyMapper).clear();
|
|
7848
|
+
__privateSet(this, _lastLocation, runtime.locationService.getLocation());
|
|
7849
|
+
this.handleNewObject(__privateGet(this, _sceneRoot));
|
|
7832
7850
|
}
|
|
7833
7851
|
cleanUp(root) {
|
|
7834
|
-
if (this
|
|
7852
|
+
if (__privateGet(this, _sceneRoot) !== root) {
|
|
7835
7853
|
return;
|
|
7836
7854
|
}
|
|
7837
7855
|
writeSceneLog("UrlSyncManager", "Clean up");
|
|
7838
|
-
if (this
|
|
7839
|
-
this.
|
|
7840
|
-
|
|
7841
|
-
this._locationSub = null;
|
|
7842
|
-
}
|
|
7843
|
-
if (this._stateSub) {
|
|
7844
|
-
this._stateSub.unsubscribe();
|
|
7845
|
-
this._stateSub = null;
|
|
7856
|
+
if (__privateGet(this, _stateSub)) {
|
|
7857
|
+
__privateGet(this, _stateSub).unsubscribe();
|
|
7858
|
+
__privateSet(this, _stateSub, null);
|
|
7846
7859
|
writeSceneLog(
|
|
7847
7860
|
"UrlSyncManager",
|
|
7848
7861
|
"Root deactived, unsub to state",
|
|
7849
7862
|
"same key",
|
|
7850
|
-
this
|
|
7863
|
+
__privateGet(this, _sceneRoot).state.key === root.state.key
|
|
7851
7864
|
);
|
|
7852
7865
|
}
|
|
7866
|
+
__privateSet(this, _sceneRoot, void 0);
|
|
7867
|
+
__privateSet(this, _lastLocation, void 0);
|
|
7868
|
+
}
|
|
7869
|
+
handleNewLocation(location) {
|
|
7870
|
+
if (!__privateGet(this, _sceneRoot) || __privateGet(this, _lastLocation) === location) {
|
|
7871
|
+
return;
|
|
7872
|
+
}
|
|
7873
|
+
writeSceneLog("UrlSyncManager", "handleNewLocation");
|
|
7874
|
+
__privateSet(this, _lastLocation, location);
|
|
7875
|
+
syncStateFromUrl(__privateGet(this, _sceneRoot), __privateGet(this, _paramsCache).getParams(), __privateGet(this, _urlKeyMapper));
|
|
7853
7876
|
}
|
|
7854
|
-
|
|
7855
|
-
|
|
7856
|
-
|
|
7857
|
-
|
|
7877
|
+
handleNewObject(sceneObj) {
|
|
7878
|
+
if (!__privateGet(this, _sceneRoot)) {
|
|
7879
|
+
return;
|
|
7880
|
+
}
|
|
7881
|
+
syncStateFromUrl(sceneObj, __privateGet(this, _paramsCache).getParams(), __privateGet(this, _urlKeyMapper));
|
|
7858
7882
|
}
|
|
7859
7883
|
getUrlState(root) {
|
|
7860
7884
|
return getUrlState(root);
|
|
7861
7885
|
}
|
|
7862
7886
|
}
|
|
7887
|
+
_urlKeyMapper = new WeakMap();
|
|
7888
|
+
_sceneRoot = new WeakMap();
|
|
7889
|
+
_stateSub = new WeakMap();
|
|
7890
|
+
_lastLocation = new WeakMap();
|
|
7891
|
+
_paramsCache = new WeakMap();
|
|
7892
|
+
_onStateChanged = new WeakMap();
|
|
7893
|
+
class UrlParamsCache {
|
|
7894
|
+
constructor() {
|
|
7895
|
+
__privateAdd(this, _cache, void 0);
|
|
7896
|
+
__privateAdd(this, _location, void 0);
|
|
7897
|
+
}
|
|
7898
|
+
getParams() {
|
|
7899
|
+
const location = runtime.locationService.getLocation();
|
|
7900
|
+
if (__privateGet(this, _location) === location) {
|
|
7901
|
+
return __privateGet(this, _cache);
|
|
7902
|
+
}
|
|
7903
|
+
__privateSet(this, _location, location);
|
|
7904
|
+
__privateSet(this, _cache, new URLSearchParams(location.search));
|
|
7905
|
+
return __privateGet(this, _cache);
|
|
7906
|
+
}
|
|
7907
|
+
}
|
|
7908
|
+
_cache = new WeakMap();
|
|
7909
|
+
_location = new WeakMap();
|
|
7863
7910
|
let urlSyncManager;
|
|
7864
7911
|
function getUrlSyncManager() {
|
|
7865
7912
|
if (!urlSyncManager) {
|
|
@@ -7868,6 +7915,34 @@ function getUrlSyncManager() {
|
|
|
7868
7915
|
return urlSyncManager;
|
|
7869
7916
|
}
|
|
7870
7917
|
|
|
7918
|
+
function useUrlSync(sceneRoot) {
|
|
7919
|
+
const urlSyncManager = getUrlSyncManager();
|
|
7920
|
+
const location = reactRouterDom.useLocation();
|
|
7921
|
+
const [isInitialized, setIsInitialized] = React.useState(false);
|
|
7922
|
+
React.useEffect(() => {
|
|
7923
|
+
urlSyncManager.initSync(sceneRoot);
|
|
7924
|
+
setIsInitialized(true);
|
|
7925
|
+
return () => urlSyncManager.cleanUp(sceneRoot);
|
|
7926
|
+
}, [sceneRoot, urlSyncManager]);
|
|
7927
|
+
React.useEffect(() => {
|
|
7928
|
+
const latestLocation = runtime.locationService.getLocation();
|
|
7929
|
+
const locationToHandle = latestLocation !== location ? latestLocation : location;
|
|
7930
|
+
if (latestLocation !== location) {
|
|
7931
|
+
console.log("latestLocation different from location");
|
|
7932
|
+
}
|
|
7933
|
+
urlSyncManager.handleNewLocation(locationToHandle);
|
|
7934
|
+
}, [sceneRoot, urlSyncManager, location]);
|
|
7935
|
+
return isInitialized;
|
|
7936
|
+
}
|
|
7937
|
+
|
|
7938
|
+
function UrlSyncContextProvider({ children, scene }) {
|
|
7939
|
+
const isInitialized = useUrlSync(scene);
|
|
7940
|
+
if (!isInitialized) {
|
|
7941
|
+
return null;
|
|
7942
|
+
}
|
|
7943
|
+
return children;
|
|
7944
|
+
}
|
|
7945
|
+
|
|
7871
7946
|
function setWindowGrafanaSceneContext(activeScene) {
|
|
7872
7947
|
const prevScene = window.__grafanaSceneContext;
|
|
7873
7948
|
writeSceneLog("setWindowGrafanaScene", "set window.__grafanaSceneContext", activeScene);
|
|
@@ -7887,13 +7962,9 @@ class EmbeddedScene extends SceneObjectBase {
|
|
|
7887
7962
|
const unsetGlobalScene = setWindowGrafanaSceneContext(this);
|
|
7888
7963
|
return () => {
|
|
7889
7964
|
unsetGlobalScene();
|
|
7890
|
-
getUrlSyncManager().cleanUp(this);
|
|
7891
7965
|
};
|
|
7892
7966
|
});
|
|
7893
7967
|
}
|
|
7894
|
-
initUrlSync() {
|
|
7895
|
-
getUrlSyncManager().initSync(this);
|
|
7896
|
-
}
|
|
7897
7968
|
}
|
|
7898
7969
|
EmbeddedScene.Component = EmbeddedSceneRenderer;
|
|
7899
7970
|
function EmbeddedSceneRenderer({ model }) {
|
|
@@ -10366,7 +10437,8 @@ function SceneAppPageView({ page, routeProps }) {
|
|
|
10366
10437
|
React.useEffect(() => {
|
|
10367
10438
|
return () => containerPage.setState({ initializedScene: void 0 });
|
|
10368
10439
|
}, [containerPage]);
|
|
10369
|
-
|
|
10440
|
+
const urlSyncInitialized = useUrlSync(containerPage);
|
|
10441
|
+
if (!isInitialized && !urlSyncInitialized) {
|
|
10370
10442
|
return null;
|
|
10371
10443
|
}
|
|
10372
10444
|
const pageNav = {
|
|
@@ -10439,13 +10511,9 @@ class SceneAppPage extends SceneObjectBase {
|
|
|
10439
10511
|
super(state);
|
|
10440
10512
|
this._sceneCache = /* @__PURE__ */ new Map();
|
|
10441
10513
|
this._drilldownCache = /* @__PURE__ */ new Map();
|
|
10442
|
-
this.addActivationHandler(() => {
|
|
10443
|
-
return () => getUrlSyncManager().cleanUp(this);
|
|
10444
|
-
});
|
|
10445
10514
|
}
|
|
10446
10515
|
initializeScene(scene) {
|
|
10447
10516
|
this.setState({ initializedScene: scene });
|
|
10448
|
-
getUrlSyncManager().initSync(this);
|
|
10449
10517
|
}
|
|
10450
10518
|
getScene(routeMatch) {
|
|
10451
10519
|
let scene = this._sceneCache.get(routeMatch.url);
|
|
@@ -11440,6 +11508,7 @@ exports.SceneVariableValueChangedEvent = SceneVariableValueChangedEvent;
|
|
|
11440
11508
|
exports.SplitLayout = SplitLayout;
|
|
11441
11509
|
exports.TestVariable = TestVariable;
|
|
11442
11510
|
exports.TextBoxVariable = TextBoxVariable;
|
|
11511
|
+
exports.UrlSyncContextProvider = UrlSyncContextProvider;
|
|
11443
11512
|
exports.UrlSyncManager = UrlSyncManager;
|
|
11444
11513
|
exports.UserActionEvent = UserActionEvent;
|
|
11445
11514
|
exports.VariableDependencyConfig = VariableDependencyConfig;
|
|
@@ -11467,4 +11536,5 @@ exports.sceneGraph = sceneGraph;
|
|
|
11467
11536
|
exports.sceneUtils = sceneUtils;
|
|
11468
11537
|
exports.useSceneApp = useSceneApp;
|
|
11469
11538
|
exports.useSceneObjectState = useSceneObjectState;
|
|
11539
|
+
exports.useUrlSync = useUrlSync;
|
|
11470
11540
|
//# sourceMappingURL=index.js.map
|