@grafana/scenes 4.26.3--canary.765.9397990341.0 → 4.26.3--canary.765.9398400471.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/esm/core/sceneGraph/sceneGraph.js +1 -1
- package/dist/esm/services/UniqueUrlKeyMapper.js +15 -11
- package/dist/esm/services/UniqueUrlKeyMapper.js.map +1 -1
- package/dist/esm/services/UrlSyncManager.js +4 -8
- package/dist/esm/services/UrlSyncManager.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +646 -648
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
@@ -586,113 +586,22 @@ function registerRuntimeDataSource({ dataSource }) {
|
|
586
586
|
runtimeDataSources.set(dataSource.uid, dataSource);
|
587
587
|
}
|
588
588
|
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
this.index.set(key, [obj]);
|
597
|
-
return key;
|
598
|
-
}
|
599
|
-
let address = objectsWithKey.findIndex((o) => o === obj);
|
600
|
-
if (address === -1) {
|
601
|
-
objectsWithKey = filterOutDeadObjects(objectsWithKey);
|
602
|
-
objectsWithKey.push(obj);
|
603
|
-
address = objectsWithKey.length - 1;
|
604
|
-
}
|
605
|
-
if (address > 0) {
|
606
|
-
return `${key}-${address + 1}`;
|
607
|
-
}
|
608
|
-
return key;
|
609
|
-
}
|
610
|
-
clear() {
|
611
|
-
this.index.clear();
|
612
|
-
}
|
613
|
-
}
|
614
|
-
function filterOutDeadObjects(sceneObjects) {
|
615
|
-
const filtered = [];
|
616
|
-
for (const obj of sceneObjects) {
|
617
|
-
if (obj.parent) {
|
618
|
-
obj.parent.forEachChild((child) => {
|
619
|
-
if (child === obj) {
|
620
|
-
filtered.push(child);
|
621
|
-
}
|
622
|
-
});
|
623
|
-
}
|
624
|
-
}
|
625
|
-
return filtered;
|
626
|
-
}
|
627
|
-
|
628
|
-
function getUrlState(root) {
|
629
|
-
const urlKeyMapper = new UniqueUrlKeyMapper();
|
630
|
-
const result = {};
|
631
|
-
const visitNode = (obj) => {
|
632
|
-
if (obj.urlSync) {
|
633
|
-
const newUrlState = obj.urlSync.getUrlState();
|
634
|
-
for (const [key, value] of Object.entries(newUrlState)) {
|
635
|
-
if (value != null) {
|
636
|
-
const uniqueKey = urlKeyMapper.getUniqueKey(key, obj);
|
637
|
-
result[uniqueKey] = value;
|
638
|
-
}
|
639
|
-
}
|
640
|
-
}
|
641
|
-
obj.forEachChild(visitNode);
|
642
|
-
};
|
643
|
-
visitNode(root);
|
644
|
-
return result;
|
645
|
-
}
|
646
|
-
function syncStateFromSearchParams(root, urlParams) {
|
647
|
-
const urlKeyMapper = new UniqueUrlKeyMapper();
|
648
|
-
syncStateFromUrl(root, urlParams, urlKeyMapper);
|
649
|
-
}
|
650
|
-
function syncStateFromUrl(root, urlParams, urlKeyMapper) {
|
651
|
-
if (!root.parent) {
|
652
|
-
syncUrlStateToObject(root, urlParams, urlKeyMapper);
|
653
|
-
}
|
654
|
-
root.forEachChild((child) => {
|
655
|
-
syncUrlStateToObject(child, urlParams, urlKeyMapper);
|
656
|
-
});
|
657
|
-
root.forEachChild((child) => syncStateFromUrl(child, urlParams, urlKeyMapper));
|
658
|
-
}
|
659
|
-
function syncUrlStateToObject(sceneObject, urlParams, urlKeyMapper) {
|
660
|
-
if (sceneObject.urlSync) {
|
661
|
-
const urlState = {};
|
662
|
-
const currentState = sceneObject.urlSync.getUrlState();
|
663
|
-
for (const key of sceneObject.urlSync.getKeys()) {
|
664
|
-
const uniqueKey = urlKeyMapper.getUniqueKey(key, sceneObject);
|
665
|
-
const newValue = urlParams.getAll(uniqueKey);
|
666
|
-
const currentValue = currentState[key];
|
667
|
-
if (isUrlValueEqual(newValue, currentValue)) {
|
668
|
-
continue;
|
669
|
-
}
|
670
|
-
if (newValue.length > 0) {
|
671
|
-
if (Array.isArray(currentValue)) {
|
672
|
-
urlState[key] = newValue;
|
673
|
-
} else {
|
674
|
-
urlState[key] = newValue[0];
|
675
|
-
}
|
676
|
-
} else {
|
677
|
-
urlState[key] = null;
|
678
|
-
}
|
679
|
-
}
|
680
|
-
if (Object.keys(urlState).length > 0) {
|
681
|
-
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;
|
682
596
|
}
|
683
597
|
}
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
if (!Array.isArray(newUrlValue) && (currentUrlValue == null ? void 0 : currentUrlValue.length) === 1) {
|
690
|
-
return newUrlValue === currentUrlValue[0];
|
691
|
-
}
|
692
|
-
if ((newUrlValue == null ? void 0 : newUrlValue.length) === 0 && currentUrlValue === null) {
|
693
|
-
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);
|
694
603
|
}
|
695
|
-
return
|
604
|
+
return null;
|
696
605
|
}
|
697
606
|
|
698
607
|
var __defProp$F = Object.defineProperty;
|
@@ -1324,393 +1233,88 @@ function sqlStringFormatter(value) {
|
|
1324
1233
|
})}'`;
|
1325
1234
|
}
|
1326
1235
|
|
1327
|
-
|
1328
|
-
|
1329
|
-
|
1330
|
-
if (sceneObject.parent) {
|
1331
|
-
return lookupVariable(name, sceneObject.parent);
|
1332
|
-
} else {
|
1333
|
-
return null;
|
1334
|
-
}
|
1236
|
+
class SkipFormattingValue {
|
1237
|
+
constructor(_value) {
|
1238
|
+
this._value = _value;
|
1335
1239
|
}
|
1336
|
-
|
1337
|
-
|
1338
|
-
return found;
|
1339
|
-
} else if (sceneObject.parent) {
|
1340
|
-
return lookupVariable(name, sceneObject.parent);
|
1240
|
+
formatter() {
|
1241
|
+
return this._value;
|
1341
1242
|
}
|
1342
|
-
return null;
|
1343
1243
|
}
|
1344
1244
|
|
1345
|
-
|
1346
|
-
|
1347
|
-
|
1245
|
+
class UrlTimeRangeMacro {
|
1246
|
+
constructor(name, sceneObject) {
|
1247
|
+
this.state = { name, type: "url_variable" };
|
1248
|
+
this._sceneObject = sceneObject;
|
1249
|
+
}
|
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));
|
1255
|
+
}
|
1256
|
+
getValueText() {
|
1257
|
+
return "";
|
1348
1258
|
}
|
1349
|
-
VARIABLE_REGEX.lastIndex = 0;
|
1350
|
-
return target.replace(VARIABLE_REGEX, (match, var1, var2, fmt2, var3, fieldPath, fmt3) => {
|
1351
|
-
const variableName = var1 || var2 || var3;
|
1352
|
-
const fmt = fmt2 || fmt3 || format;
|
1353
|
-
const variable = lookupFormatVariable(variableName, match, scopedVars, sceneObject);
|
1354
|
-
if (!variable) {
|
1355
|
-
if (interpolations) {
|
1356
|
-
interpolations.push({ match, variableName, fieldPath, format: fmt, value: match, found: false });
|
1357
|
-
}
|
1358
|
-
return match;
|
1359
|
-
}
|
1360
|
-
const value = formatValue(sceneObject, variable, variable.getValue(fieldPath), fmt);
|
1361
|
-
if (interpolations) {
|
1362
|
-
interpolations.push({ match, variableName, fieldPath, format: fmt, value, found: value !== match });
|
1363
|
-
}
|
1364
|
-
return value;
|
1365
|
-
});
|
1366
1259
|
}
|
1367
|
-
|
1368
|
-
|
1369
|
-
|
1370
|
-
|
1260
|
+
class TimeFromAndToMacro {
|
1261
|
+
constructor(name, sceneObject) {
|
1262
|
+
this.state = { name, type: "time_macro" };
|
1263
|
+
this._sceneObject = sceneObject;
|
1371
1264
|
}
|
1372
|
-
|
1373
|
-
|
1374
|
-
|
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
|
+
}
|
1375
1272
|
}
|
1376
|
-
|
1377
|
-
|
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
|
+
}
|
1378
1280
|
}
|
1379
|
-
return null;
|
1380
1281
|
}
|
1381
|
-
|
1382
|
-
|
1383
|
-
|
1282
|
+
class TimezoneMacro {
|
1283
|
+
constructor(name, sceneObject) {
|
1284
|
+
this.state = { name, type: "time_macro" };
|
1285
|
+
this._sceneObject = sceneObject;
|
1384
1286
|
}
|
1385
|
-
|
1386
|
-
|
1287
|
+
getValue() {
|
1288
|
+
const timeRange = getTimeRange(this._sceneObject);
|
1289
|
+
const timeZone = timeRange.getTimeZone();
|
1290
|
+
if (timeZone === "browser") {
|
1291
|
+
return Intl.DateTimeFormat().resolvedOptions().timeZone;
|
1292
|
+
}
|
1293
|
+
return timeZone;
|
1387
1294
|
}
|
1388
|
-
|
1389
|
-
|
1295
|
+
getValueText() {
|
1296
|
+
return this.getValue();
|
1390
1297
|
}
|
1391
|
-
|
1392
|
-
|
1393
|
-
|
1394
|
-
|
1395
|
-
|
1396
|
-
includeAll: variable.state.includeAll
|
1397
|
-
});
|
1298
|
+
}
|
1299
|
+
class IntervalMacro {
|
1300
|
+
constructor(name, sceneObject, match) {
|
1301
|
+
this.state = { name, type: "time_macro", match };
|
1302
|
+
this._sceneObject = sceneObject;
|
1398
1303
|
}
|
1399
|
-
|
1400
|
-
|
1401
|
-
|
1402
|
-
|
1403
|
-
|
1404
|
-
|
1405
|
-
|
1406
|
-
|
1407
|
-
|
1408
|
-
|
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;
|
1409
1316
|
}
|
1410
|
-
|
1411
|
-
let formatter = formatRegistry.getIfExists(formatNameOrFn);
|
1412
|
-
if (!formatter) {
|
1413
|
-
console.error(`Variable format ${formatNameOrFn} not found. Using glob format as fallback.`);
|
1414
|
-
formatter = formatRegistry.get(schema.VariableFormatID.Glob);
|
1415
|
-
}
|
1416
|
-
return formatter.formatter(value, args, variable);
|
1417
|
-
}
|
1418
|
-
|
1419
|
-
function isSceneObject(obj) {
|
1420
|
-
return obj.useState !== void 0;
|
1421
|
-
}
|
1422
|
-
function isDataRequestEnricher(obj) {
|
1423
|
-
return "enrichDataRequest" in obj;
|
1424
|
-
}
|
1425
|
-
function isDataLayer(obj) {
|
1426
|
-
return "isDataLayer" in obj;
|
1427
|
-
}
|
1428
|
-
|
1429
|
-
var __accessCheck = (obj, member, msg) => {
|
1430
|
-
if (!member.has(obj))
|
1431
|
-
throw TypeError("Cannot " + msg);
|
1432
|
-
};
|
1433
|
-
var __privateGet = (obj, member, getter) => {
|
1434
|
-
__accessCheck(obj, member, "read from private field");
|
1435
|
-
return getter ? getter.call(obj) : member.get(obj);
|
1436
|
-
};
|
1437
|
-
var __privateAdd = (obj, member, value) => {
|
1438
|
-
if (member.has(obj))
|
1439
|
-
throw TypeError("Cannot add the same private member more than once");
|
1440
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
1441
|
-
};
|
1442
|
-
var _running;
|
1443
|
-
function isQueryController(s) {
|
1444
|
-
return "isQueryController" in s;
|
1445
|
-
}
|
1446
|
-
class SceneQueryController extends SceneObjectBase {
|
1447
|
-
constructor() {
|
1448
|
-
super({ isRunning: false });
|
1449
|
-
this.isQueryController = true;
|
1450
|
-
__privateAdd(this, _running, /* @__PURE__ */ new Set());
|
1451
|
-
this.addActivationHandler(() => {
|
1452
|
-
return () => __privateGet(this, _running).clear();
|
1453
|
-
});
|
1454
|
-
}
|
1455
|
-
queryStarted(entry) {
|
1456
|
-
__privateGet(this, _running).add(entry);
|
1457
|
-
this.changeRunningQueryCount(1);
|
1458
|
-
if (!this.state.isRunning) {
|
1459
|
-
this.setState({ isRunning: true });
|
1460
|
-
}
|
1461
|
-
}
|
1462
|
-
queryCompleted(entry) {
|
1463
|
-
if (!__privateGet(this, _running).has(entry)) {
|
1464
|
-
return;
|
1465
|
-
}
|
1466
|
-
__privateGet(this, _running).delete(entry);
|
1467
|
-
this.changeRunningQueryCount(-1);
|
1468
|
-
if (__privateGet(this, _running).size === 0) {
|
1469
|
-
this.setState({ isRunning: false });
|
1470
|
-
}
|
1471
|
-
}
|
1472
|
-
changeRunningQueryCount(dir) {
|
1473
|
-
var _a;
|
1474
|
-
window.__grafanaRunningQueryCount = ((_a = window.__grafanaRunningQueryCount) != null ? _a : 0) + dir;
|
1475
|
-
}
|
1476
|
-
cancelAll() {
|
1477
|
-
var _a;
|
1478
|
-
for (const entry of __privateGet(this, _running).values()) {
|
1479
|
-
(_a = entry.cancel) == null ? void 0 : _a.call(entry);
|
1480
|
-
}
|
1481
|
-
}
|
1482
|
-
}
|
1483
|
-
_running = new WeakMap();
|
1484
|
-
|
1485
|
-
function getVariables(sceneObject) {
|
1486
|
-
var _a;
|
1487
|
-
return (_a = getClosest(sceneObject, (s) => s.state.$variables)) != null ? _a : EmptyVariableSet;
|
1488
|
-
}
|
1489
|
-
function getData(sceneObject) {
|
1490
|
-
var _a;
|
1491
|
-
return (_a = getClosest(sceneObject, (s) => s.state.$data)) != null ? _a : EmptyDataNode;
|
1492
|
-
}
|
1493
|
-
function isSceneLayout(s) {
|
1494
|
-
return "isDraggable" in s;
|
1495
|
-
}
|
1496
|
-
function getLayout(scene) {
|
1497
|
-
const parent = getClosest(scene, (s) => isSceneLayout(s) ? s : void 0);
|
1498
|
-
if (parent) {
|
1499
|
-
return parent;
|
1500
|
-
}
|
1501
|
-
return null;
|
1502
|
-
}
|
1503
|
-
function interpolate(sceneObject, value, scopedVars, format, interpolations) {
|
1504
|
-
if (value === "" || value == null) {
|
1505
|
-
return "";
|
1506
|
-
}
|
1507
|
-
return sceneInterpolator(sceneObject, value, scopedVars, format, interpolations);
|
1508
|
-
}
|
1509
|
-
function hasVariableDependencyInLoadingState(sceneObject) {
|
1510
|
-
if (!sceneObject.variableDependency) {
|
1511
|
-
return false;
|
1512
|
-
}
|
1513
|
-
for (const name of sceneObject.variableDependency.getNames()) {
|
1514
|
-
const variable = lookupVariable(name, sceneObject);
|
1515
|
-
if (!variable) {
|
1516
|
-
continue;
|
1517
|
-
}
|
1518
|
-
const set = variable.parent;
|
1519
|
-
if (set.isVariableLoadingOrWaitingToUpdate(variable)) {
|
1520
|
-
return true;
|
1521
|
-
}
|
1522
|
-
}
|
1523
|
-
return false;
|
1524
|
-
}
|
1525
|
-
function findObjectInternal(scene, check, alreadySearchedChild, shouldSearchUp) {
|
1526
|
-
if (check(scene)) {
|
1527
|
-
return scene;
|
1528
|
-
}
|
1529
|
-
let found = null;
|
1530
|
-
scene.forEachChild((child) => {
|
1531
|
-
if (child === alreadySearchedChild) {
|
1532
|
-
return;
|
1533
|
-
}
|
1534
|
-
let maybe = findObjectInternal(child, check);
|
1535
|
-
if (maybe) {
|
1536
|
-
found = maybe;
|
1537
|
-
}
|
1538
|
-
});
|
1539
|
-
if (found) {
|
1540
|
-
return found;
|
1541
|
-
}
|
1542
|
-
if (shouldSearchUp && scene.parent) {
|
1543
|
-
return findObjectInternal(scene.parent, check, scene, true);
|
1544
|
-
}
|
1545
|
-
return null;
|
1546
|
-
}
|
1547
|
-
function findByKey(sceneObject, key) {
|
1548
|
-
const found = findObject(sceneObject, (sceneToCheck) => {
|
1549
|
-
return sceneToCheck.state.key === key;
|
1550
|
-
});
|
1551
|
-
if (!found) {
|
1552
|
-
throw new Error("Unable to find scene with key " + key);
|
1553
|
-
}
|
1554
|
-
return found;
|
1555
|
-
}
|
1556
|
-
function findByKeyAndType(sceneObject, key, targetType) {
|
1557
|
-
const found = findObject(sceneObject, (sceneToCheck) => {
|
1558
|
-
return sceneToCheck.state.key === key;
|
1559
|
-
});
|
1560
|
-
if (!found) {
|
1561
|
-
throw new Error("Unable to find scene with key " + key);
|
1562
|
-
}
|
1563
|
-
if (!(found instanceof targetType)) {
|
1564
|
-
throw new Error(`Found scene object with key ${key} does not match type ${targetType.name}`);
|
1565
|
-
}
|
1566
|
-
return found;
|
1567
|
-
}
|
1568
|
-
function findObject(scene, check) {
|
1569
|
-
return findObjectInternal(scene, check, void 0, true);
|
1570
|
-
}
|
1571
|
-
function findAllObjects(scene, check) {
|
1572
|
-
const found = [];
|
1573
|
-
scene.forEachChild((child) => {
|
1574
|
-
if (check(child)) {
|
1575
|
-
found.push(child);
|
1576
|
-
}
|
1577
|
-
found.push(...findAllObjects(child, check));
|
1578
|
-
});
|
1579
|
-
return found;
|
1580
|
-
}
|
1581
|
-
function getDataLayers(sceneObject, localOnly = false) {
|
1582
|
-
let currentLevel = sceneObject;
|
1583
|
-
let collected = [];
|
1584
|
-
while (currentLevel) {
|
1585
|
-
const dataProvider = currentLevel.state.$data;
|
1586
|
-
if (!dataProvider) {
|
1587
|
-
currentLevel = currentLevel.parent;
|
1588
|
-
continue;
|
1589
|
-
}
|
1590
|
-
if (isDataLayer(dataProvider)) {
|
1591
|
-
collected = collected.concat(dataProvider);
|
1592
|
-
} else {
|
1593
|
-
if (dataProvider.state.$data && isDataLayer(dataProvider.state.$data)) {
|
1594
|
-
collected = collected.concat(dataProvider.state.$data);
|
1595
|
-
}
|
1596
|
-
}
|
1597
|
-
if (localOnly && collected.length > 0) {
|
1598
|
-
break;
|
1599
|
-
}
|
1600
|
-
currentLevel = currentLevel.parent;
|
1601
|
-
}
|
1602
|
-
return collected;
|
1603
|
-
}
|
1604
|
-
function getAncestor(sceneObject, ancestorType) {
|
1605
|
-
let parent = sceneObject;
|
1606
|
-
while (parent) {
|
1607
|
-
if (parent instanceof ancestorType) {
|
1608
|
-
return parent;
|
1609
|
-
}
|
1610
|
-
parent = parent.parent;
|
1611
|
-
}
|
1612
|
-
if (!parent) {
|
1613
|
-
throw new Error("Unable to find parent of type " + ancestorType.name);
|
1614
|
-
}
|
1615
|
-
return parent;
|
1616
|
-
}
|
1617
|
-
function getQueryController(sceneObject) {
|
1618
|
-
let parent = sceneObject;
|
1619
|
-
while (parent) {
|
1620
|
-
if (parent.state.$behaviors) {
|
1621
|
-
for (const behavior of parent.state.$behaviors) {
|
1622
|
-
if (isQueryController(behavior)) {
|
1623
|
-
return behavior;
|
1624
|
-
}
|
1625
|
-
}
|
1626
|
-
}
|
1627
|
-
parent = parent.parent;
|
1628
|
-
}
|
1629
|
-
return void 0;
|
1630
|
-
}
|
1631
|
-
|
1632
|
-
class SkipFormattingValue {
|
1633
|
-
constructor(_value) {
|
1634
|
-
this._value = _value;
|
1635
|
-
}
|
1636
|
-
formatter() {
|
1637
|
-
return this._value;
|
1638
|
-
}
|
1639
|
-
}
|
1640
|
-
|
1641
|
-
class UrlTimeRangeMacro {
|
1642
|
-
constructor(name, sceneObject) {
|
1643
|
-
this.state = { name, type: "url_variable" };
|
1644
|
-
this._sceneObject = sceneObject;
|
1645
|
-
}
|
1646
|
-
getValue() {
|
1647
|
-
var _a;
|
1648
|
-
const timeRange = getTimeRange(this._sceneObject);
|
1649
|
-
const urlState = (_a = timeRange.urlSync) == null ? void 0 : _a.getUrlState();
|
1650
|
-
return new SkipFormattingValue(data.urlUtil.toUrlParams(urlState));
|
1651
|
-
}
|
1652
|
-
getValueText() {
|
1653
|
-
return "";
|
1654
|
-
}
|
1655
|
-
}
|
1656
|
-
class TimeFromAndToMacro {
|
1657
|
-
constructor(name, sceneObject) {
|
1658
|
-
this.state = { name, type: "time_macro" };
|
1659
|
-
this._sceneObject = sceneObject;
|
1660
|
-
}
|
1661
|
-
getValue() {
|
1662
|
-
const timeRange = getTimeRange(this._sceneObject);
|
1663
|
-
if (this.state.name === "__from") {
|
1664
|
-
return timeRange.state.value.from.valueOf();
|
1665
|
-
} else {
|
1666
|
-
return timeRange.state.value.to.valueOf();
|
1667
|
-
}
|
1668
|
-
}
|
1669
|
-
getValueText() {
|
1670
|
-
const timeRange = getTimeRange(this._sceneObject);
|
1671
|
-
if (this.state.name === "__from") {
|
1672
|
-
return data.dateTimeFormat(timeRange.state.value.from, { timeZone: timeRange.getTimeZone() });
|
1673
|
-
} else {
|
1674
|
-
return data.dateTimeFormat(timeRange.state.value.to, { timeZone: timeRange.getTimeZone() });
|
1675
|
-
}
|
1676
|
-
}
|
1677
|
-
}
|
1678
|
-
class TimezoneMacro {
|
1679
|
-
constructor(name, sceneObject) {
|
1680
|
-
this.state = { name, type: "time_macro" };
|
1681
|
-
this._sceneObject = sceneObject;
|
1682
|
-
}
|
1683
|
-
getValue() {
|
1684
|
-
const timeRange = getTimeRange(this._sceneObject);
|
1685
|
-
const timeZone = timeRange.getTimeZone();
|
1686
|
-
if (timeZone === "browser") {
|
1687
|
-
return Intl.DateTimeFormat().resolvedOptions().timeZone;
|
1688
|
-
}
|
1689
|
-
return timeZone;
|
1690
|
-
}
|
1691
|
-
getValueText() {
|
1692
|
-
return this.getValue();
|
1693
|
-
}
|
1694
|
-
}
|
1695
|
-
class IntervalMacro {
|
1696
|
-
constructor(name, sceneObject, match) {
|
1697
|
-
this.state = { name, type: "time_macro", match };
|
1698
|
-
this._sceneObject = sceneObject;
|
1699
|
-
}
|
1700
|
-
getValue() {
|
1701
|
-
var _a;
|
1702
|
-
const data = getData(this._sceneObject);
|
1703
|
-
if (data) {
|
1704
|
-
const request = (_a = data.state.data) == null ? void 0 : _a.request;
|
1705
|
-
if (!request) {
|
1706
|
-
return this.state.match;
|
1707
|
-
}
|
1708
|
-
if (this.state.name === "__interval_ms") {
|
1709
|
-
return request.intervalMs;
|
1710
|
-
}
|
1711
|
-
return request.interval;
|
1712
|
-
}
|
1713
|
-
return this.state.match;
|
1317
|
+
return this.state.match;
|
1714
1318
|
}
|
1715
1319
|
}
|
1716
1320
|
|
@@ -1845,209 +1449,496 @@ class ValueMacro {
|
|
1845
1449
|
if (fieldPath === "raw") {
|
1846
1450
|
return value;
|
1847
1451
|
}
|
1848
|
-
const displayProcessor = (_b = field.display) != null ? _b : fallbackDisplayProcessor;
|
1849
|
-
const result = displayProcessor(value);
|
1850
|
-
switch (fieldPath) {
|
1851
|
-
case "numeric":
|
1852
|
-
return result.numeric;
|
1853
|
-
case "text":
|
1854
|
-
default:
|
1855
|
-
return data.formattedValueToString(result);
|
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() {
|
1463
|
+
return "";
|
1464
|
+
}
|
1465
|
+
}
|
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" };
|
1472
|
+
}
|
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;
|
1478
|
+
}
|
1479
|
+
const { frame, rowIndex } = dataContext.value;
|
1480
|
+
if (rowIndex === void 0 || fieldPath === void 0) {
|
1481
|
+
return this._match;
|
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 "";
|
1492
|
+
}
|
1493
|
+
}
|
1494
|
+
class SeriesMacro {
|
1495
|
+
constructor(name, sceneObject, _match, _scopedVars) {
|
1496
|
+
this._match = _match;
|
1497
|
+
this._scopedVars = _scopedVars;
|
1498
|
+
this.state = { name, type: "__series" };
|
1499
|
+
}
|
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;
|
1505
|
+
}
|
1506
|
+
if (fieldPath !== "name") {
|
1507
|
+
return this._match;
|
1508
|
+
}
|
1509
|
+
const { frame, frameIndex } = dataContext.value;
|
1510
|
+
return data.getFrameDisplayName(frame, frameIndex);
|
1511
|
+
}
|
1512
|
+
getValueText() {
|
1513
|
+
return "";
|
1514
|
+
}
|
1515
|
+
}
|
1516
|
+
class FieldMacro {
|
1517
|
+
constructor(name, sceneObject, _match, _scopedVars) {
|
1518
|
+
this._match = _match;
|
1519
|
+
this._scopedVars = _scopedVars;
|
1520
|
+
this.state = { name, type: "__field" };
|
1521
|
+
}
|
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;
|
1527
|
+
}
|
1528
|
+
if (fieldPath === void 0 || fieldPath === "") {
|
1529
|
+
return this._match;
|
1530
|
+
}
|
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 "";
|
1537
|
+
}
|
1538
|
+
}
|
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;
|
1556
|
+
}
|
1557
|
+
}
|
1558
|
+
getValueText() {
|
1559
|
+
return "";
|
1560
|
+
}
|
1561
|
+
}
|
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);
|
1575
|
+
}
|
1576
|
+
return `?${allParams}`;
|
1577
|
+
}
|
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;
|
1589
|
+
}
|
1590
|
+
}
|
1591
|
+
|
1592
|
+
class UserMacro {
|
1593
|
+
constructor(name, _) {
|
1594
|
+
this.state = { name, type: "user_macro" };
|
1595
|
+
}
|
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
|
+
}
|
1607
|
+
}
|
1608
|
+
getValueText() {
|
1609
|
+
return "";
|
1610
|
+
}
|
1611
|
+
}
|
1612
|
+
class OrgMacro {
|
1613
|
+
constructor(name, _) {
|
1614
|
+
this.state = { name, type: "org_macro" };
|
1615
|
+
}
|
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);
|
1624
|
+
}
|
1625
|
+
}
|
1626
|
+
getValueText() {
|
1627
|
+
return "";
|
1628
|
+
}
|
1629
|
+
}
|
1630
|
+
|
1631
|
+
const macrosIndex = {
|
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[name]) {
|
1649
|
+
throw new Error(`Macro already registered ${name}`);
|
1650
|
+
}
|
1651
|
+
macrosIndex[name] = macro;
|
1652
|
+
return () => {
|
1653
|
+
delete macrosIndex[name];
|
1654
|
+
};
|
1655
|
+
}
|
1656
|
+
|
1657
|
+
function sceneInterpolator(sceneObject, target, scopedVars, format, interpolations) {
|
1658
|
+
if (!target) {
|
1659
|
+
return target != null ? target : "";
|
1660
|
+
}
|
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 });
|
1669
|
+
}
|
1670
|
+
return match;
|
1671
|
+
}
|
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 });
|
1856
1675
|
}
|
1676
|
+
return value;
|
1677
|
+
});
|
1678
|
+
}
|
1679
|
+
function lookupFormatVariable(name, match, scopedVars, sceneObject) {
|
1680
|
+
const scopedVar = scopedVars == null ? void 0 : scopedVars[name];
|
1681
|
+
if (scopedVar) {
|
1682
|
+
return getSceneVariableForScopedVar(name, scopedVar);
|
1857
1683
|
}
|
1858
|
-
|
1859
|
-
|
1684
|
+
const variable = lookupVariable(name, sceneObject);
|
1685
|
+
if (variable) {
|
1686
|
+
return variable;
|
1687
|
+
}
|
1688
|
+
if (macrosIndex[name]) {
|
1689
|
+
return new macrosIndex[name](name, sceneObject, match, scopedVars);
|
1860
1690
|
}
|
1691
|
+
return null;
|
1861
1692
|
}
|
1862
|
-
|
1863
|
-
|
1864
|
-
|
1865
|
-
this._match = _match;
|
1866
|
-
this._scopedVars = _scopedVars;
|
1867
|
-
this.state = { name, type: "__data" };
|
1693
|
+
function formatValue(context, variable, value, formatNameOrFn) {
|
1694
|
+
if (value === null || value === void 0) {
|
1695
|
+
return "";
|
1868
1696
|
}
|
1869
|
-
|
1870
|
-
|
1871
|
-
|
1872
|
-
|
1873
|
-
|
1874
|
-
|
1875
|
-
|
1876
|
-
|
1877
|
-
|
1697
|
+
if (isCustomVariableValue(value)) {
|
1698
|
+
return sceneInterpolator(context, value.formatter(formatNameOrFn));
|
1699
|
+
}
|
1700
|
+
if (!Array.isArray(value) && typeof value === "object") {
|
1701
|
+
value = `${value}`;
|
1702
|
+
}
|
1703
|
+
if (typeof formatNameOrFn === "function") {
|
1704
|
+
return formatNameOrFn(value, {
|
1705
|
+
name: variable.state.name,
|
1706
|
+
type: variable.state.type,
|
1707
|
+
multi: variable.state.isMulti,
|
1708
|
+
includeAll: variable.state.includeAll
|
1709
|
+
});
|
1710
|
+
}
|
1711
|
+
let args = [];
|
1712
|
+
if (!formatNameOrFn) {
|
1713
|
+
formatNameOrFn = schema.VariableFormatID.Glob;
|
1714
|
+
} else {
|
1715
|
+
args = formatNameOrFn.split(":");
|
1716
|
+
if (args.length > 1) {
|
1717
|
+
formatNameOrFn = args[0];
|
1718
|
+
args = args.slice(1);
|
1719
|
+
} else {
|
1720
|
+
args = [];
|
1878
1721
|
}
|
1879
|
-
const obj = {
|
1880
|
-
name: frame.name,
|
1881
|
-
refId: frame.refId,
|
1882
|
-
fields: data.getFieldDisplayValuesProxy({ frame, rowIndex })
|
1883
|
-
};
|
1884
|
-
return (_b = getFieldAccessor(fieldPath)(obj)) != null ? _b : "";
|
1885
1722
|
}
|
1886
|
-
|
1887
|
-
|
1723
|
+
let formatter = formatRegistry.getIfExists(formatNameOrFn);
|
1724
|
+
if (!formatter) {
|
1725
|
+
console.error(`Variable format ${formatNameOrFn} not found. Using glob format as fallback.`);
|
1726
|
+
formatter = formatRegistry.get(schema.VariableFormatID.Glob);
|
1888
1727
|
}
|
1728
|
+
return formatter.formatter(value, args, variable);
|
1889
1729
|
}
|
1890
|
-
|
1891
|
-
|
1892
|
-
|
1893
|
-
|
1894
|
-
|
1730
|
+
|
1731
|
+
function isSceneObject(obj) {
|
1732
|
+
return obj.useState !== void 0;
|
1733
|
+
}
|
1734
|
+
function isDataRequestEnricher(obj) {
|
1735
|
+
return "enrichDataRequest" in obj;
|
1736
|
+
}
|
1737
|
+
function isDataLayer(obj) {
|
1738
|
+
return "isDataLayer" in obj;
|
1739
|
+
}
|
1740
|
+
|
1741
|
+
var __accessCheck = (obj, member, msg) => {
|
1742
|
+
if (!member.has(obj))
|
1743
|
+
throw TypeError("Cannot " + msg);
|
1744
|
+
};
|
1745
|
+
var __privateGet = (obj, member, getter) => {
|
1746
|
+
__accessCheck(obj, member, "read from private field");
|
1747
|
+
return getter ? getter.call(obj) : member.get(obj);
|
1748
|
+
};
|
1749
|
+
var __privateAdd = (obj, member, value) => {
|
1750
|
+
if (member.has(obj))
|
1751
|
+
throw TypeError("Cannot add the same private member more than once");
|
1752
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
1753
|
+
};
|
1754
|
+
var _running;
|
1755
|
+
function isQueryController(s) {
|
1756
|
+
return "isQueryController" in s;
|
1757
|
+
}
|
1758
|
+
class SceneQueryController extends SceneObjectBase {
|
1759
|
+
constructor() {
|
1760
|
+
super({ isRunning: false });
|
1761
|
+
this.isQueryController = true;
|
1762
|
+
__privateAdd(this, _running, /* @__PURE__ */ new Set());
|
1763
|
+
this.addActivationHandler(() => {
|
1764
|
+
return () => __privateGet(this, _running).clear();
|
1765
|
+
});
|
1895
1766
|
}
|
1896
|
-
|
1897
|
-
|
1898
|
-
|
1899
|
-
if (!
|
1900
|
-
|
1767
|
+
queryStarted(entry) {
|
1768
|
+
__privateGet(this, _running).add(entry);
|
1769
|
+
this.changeRunningQueryCount(1);
|
1770
|
+
if (!this.state.isRunning) {
|
1771
|
+
this.setState({ isRunning: true });
|
1901
1772
|
}
|
1902
|
-
|
1903
|
-
|
1773
|
+
}
|
1774
|
+
queryCompleted(entry) {
|
1775
|
+
if (!__privateGet(this, _running).has(entry)) {
|
1776
|
+
return;
|
1777
|
+
}
|
1778
|
+
__privateGet(this, _running).delete(entry);
|
1779
|
+
this.changeRunningQueryCount(-1);
|
1780
|
+
if (__privateGet(this, _running).size === 0) {
|
1781
|
+
this.setState({ isRunning: false });
|
1904
1782
|
}
|
1905
|
-
const { frame, frameIndex } = dataContext.value;
|
1906
|
-
return data.getFrameDisplayName(frame, frameIndex);
|
1907
1783
|
}
|
1908
|
-
|
1784
|
+
changeRunningQueryCount(dir) {
|
1785
|
+
var _a;
|
1786
|
+
window.__grafanaRunningQueryCount = ((_a = window.__grafanaRunningQueryCount) != null ? _a : 0) + dir;
|
1787
|
+
}
|
1788
|
+
cancelAll() {
|
1789
|
+
var _a;
|
1790
|
+
for (const entry of __privateGet(this, _running).values()) {
|
1791
|
+
(_a = entry.cancel) == null ? void 0 : _a.call(entry);
|
1792
|
+
}
|
1793
|
+
}
|
1794
|
+
}
|
1795
|
+
_running = new WeakMap();
|
1796
|
+
|
1797
|
+
function getVariables(sceneObject) {
|
1798
|
+
var _a;
|
1799
|
+
return (_a = getClosest(sceneObject, (s) => s.state.$variables)) != null ? _a : EmptyVariableSet;
|
1800
|
+
}
|
1801
|
+
function getData(sceneObject) {
|
1802
|
+
var _a;
|
1803
|
+
return (_a = getClosest(sceneObject, (s) => s.state.$data)) != null ? _a : EmptyDataNode;
|
1804
|
+
}
|
1805
|
+
function isSceneLayout(s) {
|
1806
|
+
return "isDraggable" in s;
|
1807
|
+
}
|
1808
|
+
function getLayout(scene) {
|
1809
|
+
const parent = getClosest(scene, (s) => isSceneLayout(s) ? s : void 0);
|
1810
|
+
if (parent) {
|
1811
|
+
return parent;
|
1812
|
+
}
|
1813
|
+
return null;
|
1814
|
+
}
|
1815
|
+
function interpolate(sceneObject, value, scopedVars, format, interpolations) {
|
1816
|
+
if (value === "" || value == null) {
|
1909
1817
|
return "";
|
1910
1818
|
}
|
1819
|
+
return sceneInterpolator(sceneObject, value, scopedVars, format, interpolations);
|
1911
1820
|
}
|
1912
|
-
|
1913
|
-
|
1914
|
-
|
1915
|
-
this._scopedVars = _scopedVars;
|
1916
|
-
this.state = { name, type: "__field" };
|
1821
|
+
function hasVariableDependencyInLoadingState(sceneObject) {
|
1822
|
+
if (!sceneObject.variableDependency) {
|
1823
|
+
return false;
|
1917
1824
|
}
|
1918
|
-
|
1919
|
-
|
1920
|
-
|
1921
|
-
|
1922
|
-
return this._match;
|
1825
|
+
for (const name of sceneObject.variableDependency.getNames()) {
|
1826
|
+
const variable = lookupVariable(name, sceneObject);
|
1827
|
+
if (!variable) {
|
1828
|
+
continue;
|
1923
1829
|
}
|
1924
|
-
|
1925
|
-
|
1830
|
+
const set = variable.parent;
|
1831
|
+
if (set.isVariableLoadingOrWaitingToUpdate(variable)) {
|
1832
|
+
return true;
|
1926
1833
|
}
|
1927
|
-
const { frame, field, data } = dataContext.value;
|
1928
|
-
const obj = getTemplateProxyForField(field, frame, data);
|
1929
|
-
return (_b = getFieldAccessor(fieldPath)(obj)) != null ? _b : "";
|
1930
|
-
}
|
1931
|
-
getValueText() {
|
1932
|
-
return "";
|
1933
1834
|
}
|
1835
|
+
return false;
|
1934
1836
|
}
|
1935
|
-
|
1936
|
-
|
1937
|
-
|
1938
|
-
this.state = { name, type: "url_macro" };
|
1837
|
+
function findObjectInternal(scene, check, alreadySearchedChild, shouldSearchUp) {
|
1838
|
+
if (check(scene)) {
|
1839
|
+
return scene;
|
1939
1840
|
}
|
1940
|
-
|
1941
|
-
|
1942
|
-
|
1943
|
-
|
1944
|
-
|
1945
|
-
|
1946
|
-
|
1947
|
-
|
1948
|
-
return subUrl + location.pathname;
|
1949
|
-
case "":
|
1950
|
-
default:
|
1951
|
-
return subUrl + location.pathname + location.search;
|
1841
|
+
let found = null;
|
1842
|
+
scene.forEachChild((child) => {
|
1843
|
+
if (child === alreadySearchedChild) {
|
1844
|
+
return;
|
1845
|
+
}
|
1846
|
+
let maybe = findObjectInternal(child, check);
|
1847
|
+
if (maybe) {
|
1848
|
+
found = maybe;
|
1952
1849
|
}
|
1850
|
+
});
|
1851
|
+
if (found) {
|
1852
|
+
return found;
|
1953
1853
|
}
|
1954
|
-
|
1955
|
-
return
|
1854
|
+
if (shouldSearchUp && scene.parent) {
|
1855
|
+
return findObjectInternal(scene.parent, check, scene, true);
|
1856
|
+
}
|
1857
|
+
return null;
|
1858
|
+
}
|
1859
|
+
function findByKey(sceneObject, key) {
|
1860
|
+
const found = findObject(sceneObject, (sceneToCheck) => {
|
1861
|
+
return sceneToCheck.state.key === key;
|
1862
|
+
});
|
1863
|
+
if (!found) {
|
1864
|
+
throw new Error("Unable to find scene with key " + key);
|
1956
1865
|
}
|
1866
|
+
return found;
|
1957
1867
|
}
|
1958
|
-
|
1959
|
-
|
1960
|
-
|
1868
|
+
function findByKeyAndType(sceneObject, key, targetType) {
|
1869
|
+
const found = findObject(sceneObject, (sceneToCheck) => {
|
1870
|
+
return sceneToCheck.state.key === key;
|
1871
|
+
});
|
1872
|
+
if (!found) {
|
1873
|
+
throw new Error("Unable to find scene with key " + key);
|
1961
1874
|
}
|
1962
|
-
|
1963
|
-
|
1964
|
-
|
1875
|
+
if (!(found instanceof targetType)) {
|
1876
|
+
throw new Error(`Found scene object with key ${key} does not match type ${targetType.name}`);
|
1877
|
+
}
|
1878
|
+
return found;
|
1879
|
+
}
|
1880
|
+
function findObject(scene, check) {
|
1881
|
+
return findObjectInternal(scene, check, void 0, true);
|
1882
|
+
}
|
1883
|
+
function findAllObjects(scene, check) {
|
1884
|
+
const found = [];
|
1885
|
+
scene.forEachChild((child) => {
|
1886
|
+
if (check(child)) {
|
1887
|
+
found.push(child);
|
1965
1888
|
}
|
1966
|
-
|
1967
|
-
|
1968
|
-
|
1969
|
-
|
1970
|
-
|
1971
|
-
|
1972
|
-
|
1889
|
+
found.push(...findAllObjects(child, check));
|
1890
|
+
});
|
1891
|
+
return found;
|
1892
|
+
}
|
1893
|
+
function getDataLayers(sceneObject, localOnly = false) {
|
1894
|
+
let currentLevel = sceneObject;
|
1895
|
+
let collected = [];
|
1896
|
+
while (currentLevel) {
|
1897
|
+
const dataProvider = currentLevel.state.$data;
|
1898
|
+
if (!dataProvider) {
|
1899
|
+
currentLevel = currentLevel.parent;
|
1900
|
+
continue;
|
1973
1901
|
}
|
1974
|
-
if (
|
1975
|
-
|
1976
|
-
|
1977
|
-
|
1978
|
-
|
1979
|
-
allParams.delete(param);
|
1980
|
-
}
|
1902
|
+
if (isDataLayer(dataProvider)) {
|
1903
|
+
collected = collected.concat(dataProvider);
|
1904
|
+
} else {
|
1905
|
+
if (dataProvider.state.$data && isDataLayer(dataProvider.state.$data)) {
|
1906
|
+
collected = collected.concat(dataProvider.state.$data);
|
1981
1907
|
}
|
1982
|
-
return `?${allParams}`;
|
1983
1908
|
}
|
1984
|
-
|
1985
|
-
|
1986
|
-
}
|
1987
|
-
|
1988
|
-
class UserMacro {
|
1989
|
-
constructor(name, _) {
|
1990
|
-
this.state = { name, type: "user_macro" };
|
1991
|
-
}
|
1992
|
-
getValue(fieldPath) {
|
1993
|
-
const user = runtime.config.bootData.user;
|
1994
|
-
switch (fieldPath) {
|
1995
|
-
case "login":
|
1996
|
-
return user.login;
|
1997
|
-
case "email":
|
1998
|
-
return user.email;
|
1999
|
-
case "id":
|
2000
|
-
default:
|
2001
|
-
return String(user.id);
|
1909
|
+
if (localOnly && collected.length > 0) {
|
1910
|
+
break;
|
2002
1911
|
}
|
1912
|
+
currentLevel = currentLevel.parent;
|
2003
1913
|
}
|
2004
|
-
|
2005
|
-
return "";
|
2006
|
-
}
|
1914
|
+
return collected;
|
2007
1915
|
}
|
2008
|
-
|
2009
|
-
|
2010
|
-
|
2011
|
-
|
2012
|
-
|
2013
|
-
const user = runtime.config.bootData.user;
|
2014
|
-
switch (fieldPath) {
|
2015
|
-
case "name":
|
2016
|
-
return user.orgName;
|
2017
|
-
case "id":
|
2018
|
-
default:
|
2019
|
-
return String(user.orgId);
|
1916
|
+
function getAncestor(sceneObject, ancestorType) {
|
1917
|
+
let parent = sceneObject;
|
1918
|
+
while (parent) {
|
1919
|
+
if (parent instanceof ancestorType) {
|
1920
|
+
return parent;
|
2020
1921
|
}
|
1922
|
+
parent = parent.parent;
|
2021
1923
|
}
|
2022
|
-
|
2023
|
-
|
1924
|
+
if (!parent) {
|
1925
|
+
throw new Error("Unable to find parent of type " + ancestorType.name);
|
2024
1926
|
}
|
1927
|
+
return parent;
|
2025
1928
|
}
|
2026
|
-
|
2027
|
-
|
2028
|
-
|
2029
|
-
|
2030
|
-
|
2031
|
-
|
2032
|
-
|
2033
|
-
|
2034
|
-
|
2035
|
-
|
2036
|
-
|
2037
|
-
["__timezone"]: TimezoneMacro,
|
2038
|
-
["__user"]: UserMacro,
|
2039
|
-
["__org"]: OrgMacro,
|
2040
|
-
["__interval"]: IntervalMacro,
|
2041
|
-
["__interval_ms"]: IntervalMacro
|
2042
|
-
};
|
2043
|
-
function registerVariableMacro(name, macro) {
|
2044
|
-
if (macrosIndex[name]) {
|
2045
|
-
throw new Error(`Macro already registered ${name}`);
|
1929
|
+
function getQueryController(sceneObject) {
|
1930
|
+
let parent = sceneObject;
|
1931
|
+
while (parent) {
|
1932
|
+
if (parent.state.$behaviors) {
|
1933
|
+
for (const behavior of parent.state.$behaviors) {
|
1934
|
+
if (isQueryController(behavior)) {
|
1935
|
+
return behavior;
|
1936
|
+
}
|
1937
|
+
}
|
1938
|
+
}
|
1939
|
+
parent = parent.parent;
|
2046
1940
|
}
|
2047
|
-
|
2048
|
-
return () => {
|
2049
|
-
delete macrosIndex[name];
|
2050
|
-
};
|
1941
|
+
return void 0;
|
2051
1942
|
}
|
2052
1943
|
|
2053
1944
|
const sceneGraph = {
|
@@ -2067,6 +1958,117 @@ const sceneGraph = {
|
|
2067
1958
|
getQueryController
|
2068
1959
|
};
|
2069
1960
|
|
1961
|
+
class UniqueUrlKeyMapper {
|
1962
|
+
constructor() {
|
1963
|
+
this.index = /* @__PURE__ */ new Map();
|
1964
|
+
}
|
1965
|
+
getUniqueKey(key, obj) {
|
1966
|
+
const objectsWithKey = this.index.get(key);
|
1967
|
+
if (!objectsWithKey) {
|
1968
|
+
this.index.set(key, [obj]);
|
1969
|
+
return key;
|
1970
|
+
}
|
1971
|
+
let address = objectsWithKey.findIndex((o) => o === obj);
|
1972
|
+
if (address === -1) {
|
1973
|
+
filterOutOrphanedObjects(objectsWithKey);
|
1974
|
+
objectsWithKey.push(obj);
|
1975
|
+
address = objectsWithKey.length - 1;
|
1976
|
+
}
|
1977
|
+
if (address > 0) {
|
1978
|
+
return `${key}-${address + 1}`;
|
1979
|
+
}
|
1980
|
+
return key;
|
1981
|
+
}
|
1982
|
+
clear() {
|
1983
|
+
this.index.clear();
|
1984
|
+
}
|
1985
|
+
}
|
1986
|
+
function filterOutOrphanedObjects(sceneObjects) {
|
1987
|
+
for (const obj of sceneObjects) {
|
1988
|
+
if (isOrphanOrInActive(obj)) {
|
1989
|
+
const index = sceneObjects.indexOf(obj);
|
1990
|
+
sceneObjects.splice(index, 1);
|
1991
|
+
}
|
1992
|
+
}
|
1993
|
+
}
|
1994
|
+
function isOrphanOrInActive(obj) {
|
1995
|
+
const root = obj.getRoot();
|
1996
|
+
if (!sceneGraph.findObject(root, (child) => child === obj)) {
|
1997
|
+
return true;
|
1998
|
+
}
|
1999
|
+
return false;
|
2000
|
+
}
|
2001
|
+
|
2002
|
+
function getUrlState(root) {
|
2003
|
+
const urlKeyMapper = new UniqueUrlKeyMapper();
|
2004
|
+
const result = {};
|
2005
|
+
const visitNode = (obj) => {
|
2006
|
+
if (obj.urlSync) {
|
2007
|
+
const newUrlState = obj.urlSync.getUrlState();
|
2008
|
+
for (const [key, value] of Object.entries(newUrlState)) {
|
2009
|
+
if (value != null) {
|
2010
|
+
const uniqueKey = urlKeyMapper.getUniqueKey(key, obj);
|
2011
|
+
result[uniqueKey] = value;
|
2012
|
+
}
|
2013
|
+
}
|
2014
|
+
}
|
2015
|
+
obj.forEachChild(visitNode);
|
2016
|
+
};
|
2017
|
+
visitNode(root);
|
2018
|
+
return result;
|
2019
|
+
}
|
2020
|
+
function syncStateFromSearchParams(root, urlParams) {
|
2021
|
+
const urlKeyMapper = new UniqueUrlKeyMapper();
|
2022
|
+
syncStateFromUrl(root, urlParams, urlKeyMapper);
|
2023
|
+
}
|
2024
|
+
function syncStateFromUrl(root, urlParams, urlKeyMapper) {
|
2025
|
+
if (!root.parent) {
|
2026
|
+
syncUrlStateToObject(root, urlParams, urlKeyMapper);
|
2027
|
+
}
|
2028
|
+
root.forEachChild((child) => {
|
2029
|
+
syncUrlStateToObject(child, urlParams, urlKeyMapper);
|
2030
|
+
});
|
2031
|
+
root.forEachChild((child) => syncStateFromUrl(child, urlParams, urlKeyMapper));
|
2032
|
+
}
|
2033
|
+
function syncUrlStateToObject(sceneObject, urlParams, urlKeyMapper) {
|
2034
|
+
if (sceneObject.urlSync) {
|
2035
|
+
const urlState = {};
|
2036
|
+
const currentState = sceneObject.urlSync.getUrlState();
|
2037
|
+
for (const key of sceneObject.urlSync.getKeys()) {
|
2038
|
+
const uniqueKey = urlKeyMapper.getUniqueKey(key, sceneObject);
|
2039
|
+
const newValue = urlParams.getAll(uniqueKey);
|
2040
|
+
const currentValue = currentState[key];
|
2041
|
+
if (isUrlValueEqual(newValue, currentValue)) {
|
2042
|
+
continue;
|
2043
|
+
}
|
2044
|
+
if (newValue.length > 0) {
|
2045
|
+
if (Array.isArray(currentValue)) {
|
2046
|
+
urlState[key] = newValue;
|
2047
|
+
} else {
|
2048
|
+
urlState[key] = newValue[0];
|
2049
|
+
}
|
2050
|
+
} else {
|
2051
|
+
urlState[key] = null;
|
2052
|
+
}
|
2053
|
+
}
|
2054
|
+
if (Object.keys(urlState).length > 0) {
|
2055
|
+
sceneObject.urlSync.updateFromUrl(urlState);
|
2056
|
+
}
|
2057
|
+
}
|
2058
|
+
}
|
2059
|
+
function isUrlValueEqual(currentUrlValue, newUrlValue) {
|
2060
|
+
if (currentUrlValue.length === 0 && newUrlValue == null) {
|
2061
|
+
return true;
|
2062
|
+
}
|
2063
|
+
if (!Array.isArray(newUrlValue) && (currentUrlValue == null ? void 0 : currentUrlValue.length) === 1) {
|
2064
|
+
return newUrlValue === currentUrlValue[0];
|
2065
|
+
}
|
2066
|
+
if ((newUrlValue == null ? void 0 : newUrlValue.length) === 0 && currentUrlValue === null) {
|
2067
|
+
return true;
|
2068
|
+
}
|
2069
|
+
return lodash.isEqual(currentUrlValue, newUrlValue);
|
2070
|
+
}
|
2071
|
+
|
2070
2072
|
async function getDataSource(datasource, scopedVars) {
|
2071
2073
|
if (datasource == null ? void 0 : datasource.uid) {
|
2072
2074
|
const runtimeDataSource = runtimeDataSources.get(datasource.uid);
|
@@ -7747,6 +7749,7 @@ class UrlSyncManager {
|
|
7747
7749
|
writeSceneLog("UrlSyncManager", "onStateChange updating URL");
|
7748
7750
|
runtime.locationService.partial(mappedUpdated, true);
|
7749
7751
|
this._lastLocation = runtime.locationService.getLocation();
|
7752
|
+
this._urlParams = new URLSearchParams(this._lastLocation.search);
|
7750
7753
|
}
|
7751
7754
|
}
|
7752
7755
|
};
|
@@ -7758,13 +7761,12 @@ class UrlSyncManager {
|
|
7758
7761
|
this._stateSub.unsubscribe();
|
7759
7762
|
}
|
7760
7763
|
writeSceneLog("UrlSyncManager", "init", root.state.key);
|
7761
|
-
const location = runtime.locationService.getLocation();
|
7762
7764
|
this._sceneRoot = root;
|
7763
|
-
this._lastLocation = location;
|
7764
|
-
this._urlParams = new URLSearchParams(location.search);
|
7765
7765
|
this._stateSub = root.subscribeToEvent(SceneObjectStateChangedEvent, this._onStateChanged);
|
7766
7766
|
this._urlKeyMapper.clear();
|
7767
|
-
this.
|
7767
|
+
this._lastLocation = runtime.locationService.getLocation();
|
7768
|
+
this._urlParams = new URLSearchParams(this._lastLocation.search);
|
7769
|
+
this.handleNewObject(this._sceneRoot);
|
7768
7770
|
}
|
7769
7771
|
cleanUp(root) {
|
7770
7772
|
if (this._sceneRoot !== root) {
|
@@ -7784,10 +7786,6 @@ class UrlSyncManager {
|
|
7784
7786
|
this._sceneRoot = void 0;
|
7785
7787
|
this._urlParams = void 0;
|
7786
7788
|
}
|
7787
|
-
syncFrom(sceneObj) {
|
7788
|
-
const urlParams = runtime.locationService.getSearch();
|
7789
|
-
syncStateFromUrl(sceneObj, urlParams, this._urlKeyMapper);
|
7790
|
-
}
|
7791
7789
|
handleNewLocation(location) {
|
7792
7790
|
if (!this._sceneRoot || this._lastLocation === location) {
|
7793
7791
|
return;
|