@grafana/scenes 5.16.1--canary.924.11083854672.0 → 5.16.1
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +15 -0
- package/dist/esm/components/layout/grid/SceneGridRow.js +11 -1
- package/dist/esm/components/layout/grid/SceneGridRow.js.map +1 -1
- package/dist/esm/variables/macros/AllVariablesMacro.js +6 -0
- package/dist/esm/variables/macros/AllVariablesMacro.js.map +1 -1
- package/dist/index.js +922 -908
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
@@ -1384,434 +1384,727 @@ class IntervalMacro {
|
|
1384
1384
|
}
|
1385
1385
|
}
|
1386
1386
|
|
1387
|
-
|
1388
|
-
|
1389
|
-
|
1390
|
-
|
1387
|
+
function setBaseClassState(sceneObject, newState) {
|
1388
|
+
sceneObject.setState(newState);
|
1389
|
+
}
|
1390
|
+
function useLocationServiceSafe() {
|
1391
|
+
return runtime.useLocationService ? runtime.useLocationService() : runtime.locationService;
|
1392
|
+
}
|
1393
|
+
|
1394
|
+
class MultiValueVariable extends SceneObjectBase {
|
1395
|
+
constructor() {
|
1396
|
+
super(...arguments);
|
1397
|
+
this._urlSync = new MultiValueUrlSyncHandler(this);
|
1391
1398
|
}
|
1392
|
-
|
1393
|
-
|
1394
|
-
|
1395
|
-
|
1396
|
-
|
1397
|
-
|
1398
|
-
|
1399
|
-
if (!value) {
|
1400
|
-
continue;
|
1401
|
-
}
|
1402
|
-
if (isCustomVariableValue(value)) {
|
1403
|
-
params.push(value.formatter(schema.VariableFormatID.QueryParam));
|
1404
|
-
} else {
|
1405
|
-
params.push(format.formatter(value, [], variable));
|
1406
|
-
}
|
1407
|
-
}
|
1408
|
-
return new SkipFormattingValue(params.join("&"));
|
1399
|
+
validateAndUpdate() {
|
1400
|
+
return this.getValueOptions({}).pipe(
|
1401
|
+
rxjs.map((options) => {
|
1402
|
+
this.updateValueGivenNewOptions(options);
|
1403
|
+
return {};
|
1404
|
+
})
|
1405
|
+
);
|
1409
1406
|
}
|
1410
|
-
|
1411
|
-
|
1407
|
+
onCancel() {
|
1408
|
+
this.setStateHelper({ loading: false });
|
1409
|
+
const sceneVarSet = this.parent;
|
1410
|
+
sceneVarSet == null ? void 0 : sceneVarSet.cancel(this);
|
1412
1411
|
}
|
1413
|
-
|
1414
|
-
|
1415
|
-
|
1416
|
-
|
1417
|
-
|
1418
|
-
|
1419
|
-
|
1420
|
-
if (!record[variable.state.name]) {
|
1421
|
-
record[variable.state.name] = variable;
|
1422
|
-
}
|
1412
|
+
updateValueGivenNewOptions(options) {
|
1413
|
+
const { value: currentValue, text: currentText, options: oldOptions } = this.state;
|
1414
|
+
const stateUpdate = this.getStateUpdateGivenNewOptions(options, currentValue, currentText);
|
1415
|
+
this.interceptStateUpdateAfterValidation(stateUpdate);
|
1416
|
+
this.setStateHelper(stateUpdate);
|
1417
|
+
if (stateUpdate.value !== currentValue || stateUpdate.text !== currentText || this.hasAllValue() && !lodash.isEqual(options, oldOptions)) {
|
1418
|
+
this.publishEvent(new SceneVariableValueChangedEvent(this), true);
|
1423
1419
|
}
|
1424
1420
|
}
|
1425
|
-
|
1426
|
-
|
1427
|
-
|
1428
|
-
|
1429
|
-
|
1430
|
-
|
1431
|
-
|
1432
|
-
|
1433
|
-
|
1434
|
-
|
1435
|
-
|
1436
|
-
|
1437
|
-
|
1438
|
-
|
1439
|
-
|
1440
|
-
|
1441
|
-
|
1442
|
-
|
1443
|
-
|
1444
|
-
if (__propIsEnum$H.call(b, prop))
|
1445
|
-
__defNormalProp$H(a, prop, b[prop]);
|
1421
|
+
getStateUpdateGivenNewOptions(options, currentValue, currentText) {
|
1422
|
+
const stateUpdate = {
|
1423
|
+
options,
|
1424
|
+
loading: false,
|
1425
|
+
value: currentValue,
|
1426
|
+
text: currentText
|
1427
|
+
};
|
1428
|
+
if (options.length === 0) {
|
1429
|
+
if (this.state.defaultToAll || this.state.includeAll) {
|
1430
|
+
stateUpdate.value = ALL_VARIABLE_VALUE;
|
1431
|
+
stateUpdate.text = ALL_VARIABLE_TEXT;
|
1432
|
+
} else if (this.state.isMulti) {
|
1433
|
+
stateUpdate.value = [];
|
1434
|
+
stateUpdate.text = [];
|
1435
|
+
} else {
|
1436
|
+
stateUpdate.value = "";
|
1437
|
+
stateUpdate.text = "";
|
1438
|
+
}
|
1439
|
+
return stateUpdate;
|
1446
1440
|
}
|
1447
|
-
|
1448
|
-
|
1449
|
-
|
1450
|
-
|
1451
|
-
|
1452
|
-
|
1453
|
-
|
1454
|
-
get: (obj, key) => {
|
1455
|
-
if (key === "name") {
|
1456
|
-
return field.name;
|
1441
|
+
if (this.hasAllValue()) {
|
1442
|
+
if (!this.state.includeAll) {
|
1443
|
+
stateUpdate.value = options[0].value;
|
1444
|
+
stateUpdate.text = options[0].label;
|
1445
|
+
if (this.state.isMulti) {
|
1446
|
+
stateUpdate.value = [stateUpdate.value];
|
1447
|
+
stateUpdate.text = [stateUpdate.text];
|
1457
1448
|
}
|
1458
|
-
|
1459
|
-
|
1449
|
+
}
|
1450
|
+
return stateUpdate;
|
1451
|
+
}
|
1452
|
+
if (this.state.isMulti) {
|
1453
|
+
const currentValues = Array.isArray(currentValue) ? currentValue : [currentValue];
|
1454
|
+
const validValues = currentValues.filter((v) => options.find((o) => o.value === v));
|
1455
|
+
const validTexts = validValues.map((v) => options.find((o) => o.value === v).label);
|
1456
|
+
if (validValues.length === 0) {
|
1457
|
+
const defaultState = this.getDefaultMultiState(options);
|
1458
|
+
stateUpdate.value = defaultState.value;
|
1459
|
+
stateUpdate.text = defaultState.text;
|
1460
|
+
} else {
|
1461
|
+
if (!lodash.isEqual(validValues, currentValue)) {
|
1462
|
+
stateUpdate.value = validValues;
|
1460
1463
|
}
|
1461
|
-
if (
|
1462
|
-
|
1463
|
-
return "";
|
1464
|
-
}
|
1465
|
-
return __spreadProps$s(__spreadValues$H({}, field.labels), {
|
1466
|
-
__values: Object.values(field.labels).sort().join(", "),
|
1467
|
-
toString: () => {
|
1468
|
-
return data.formatLabels(field.labels, "", true);
|
1469
|
-
}
|
1470
|
-
});
|
1464
|
+
if (!lodash.isEqual(validTexts, currentText)) {
|
1465
|
+
stateUpdate.text = validTexts;
|
1471
1466
|
}
|
1472
|
-
return void 0;
|
1473
1467
|
}
|
1468
|
+
return stateUpdate;
|
1474
1469
|
}
|
1475
|
-
|
1476
|
-
|
1477
|
-
|
1478
|
-
|
1479
|
-
|
1480
|
-
|
1481
|
-
|
1482
|
-
|
1483
|
-
|
1484
|
-
|
1485
|
-
|
1486
|
-
const dataContext = (_a = this._scopedVars) == null ? void 0 : _a.__dataContext;
|
1487
|
-
if (!dataContext) {
|
1488
|
-
return this._match;
|
1489
|
-
}
|
1490
|
-
const { frame, rowIndex, field, calculatedValue } = dataContext.value;
|
1491
|
-
if (calculatedValue) {
|
1492
|
-
switch (fieldPath) {
|
1493
|
-
case "numeric":
|
1494
|
-
return calculatedValue.numeric;
|
1495
|
-
case "raw":
|
1496
|
-
return calculatedValue.numeric;
|
1497
|
-
case "time":
|
1498
|
-
return "";
|
1499
|
-
case "text":
|
1500
|
-
default:
|
1501
|
-
return data.formattedValueToString(calculatedValue);
|
1470
|
+
let matchingOption = findOptionMatchingCurrent(currentValue, currentText, options);
|
1471
|
+
if (matchingOption) {
|
1472
|
+
stateUpdate.text = matchingOption.label;
|
1473
|
+
stateUpdate.value = matchingOption.value;
|
1474
|
+
} else {
|
1475
|
+
if (this.state.defaultToAll) {
|
1476
|
+
stateUpdate.value = ALL_VARIABLE_VALUE;
|
1477
|
+
stateUpdate.text = ALL_VARIABLE_TEXT;
|
1478
|
+
} else {
|
1479
|
+
stateUpdate.value = options[0].value;
|
1480
|
+
stateUpdate.text = options[0].label;
|
1502
1481
|
}
|
1503
1482
|
}
|
1504
|
-
|
1505
|
-
|
1506
|
-
|
1507
|
-
|
1508
|
-
|
1509
|
-
|
1510
|
-
|
1511
|
-
if (!field) {
|
1512
|
-
return this._match;
|
1513
|
-
}
|
1514
|
-
const value = field.values.get(rowIndex);
|
1515
|
-
if (fieldPath === "raw") {
|
1516
|
-
return value;
|
1483
|
+
return stateUpdate;
|
1484
|
+
}
|
1485
|
+
interceptStateUpdateAfterValidation(stateUpdate) {
|
1486
|
+
const isAllValueFix = stateUpdate.value === ALL_VARIABLE_VALUE && this.state.text === ALL_VARIABLE_TEXT;
|
1487
|
+
if (this.skipNextValidation && stateUpdate.value !== this.state.value && stateUpdate.text !== this.state.text && !isAllValueFix) {
|
1488
|
+
stateUpdate.value = this.state.value;
|
1489
|
+
stateUpdate.text = this.state.text;
|
1517
1490
|
}
|
1518
|
-
|
1519
|
-
|
1520
|
-
|
1521
|
-
|
1522
|
-
|
1523
|
-
|
1524
|
-
|
1525
|
-
|
1491
|
+
this.skipNextValidation = false;
|
1492
|
+
}
|
1493
|
+
getValue() {
|
1494
|
+
if (this.hasAllValue()) {
|
1495
|
+
if (this.state.allValue) {
|
1496
|
+
return new CustomAllValue(this.state.allValue, this);
|
1497
|
+
}
|
1498
|
+
return this.state.options.map((x) => x.value);
|
1526
1499
|
}
|
1500
|
+
return this.state.value;
|
1527
1501
|
}
|
1528
1502
|
getValueText() {
|
1529
|
-
|
1530
|
-
|
1531
|
-
}
|
1532
|
-
const fallbackDisplayProcessor = data.getDisplayProcessor();
|
1533
|
-
class DataMacro {
|
1534
|
-
constructor(name, sceneObject, _match, _scopedVars) {
|
1535
|
-
this._match = _match;
|
1536
|
-
this._scopedVars = _scopedVars;
|
1537
|
-
this.state = { name, type: "__data" };
|
1538
|
-
}
|
1539
|
-
getValue(fieldPath) {
|
1540
|
-
var _a, _b;
|
1541
|
-
const dataContext = (_a = this._scopedVars) == null ? void 0 : _a.__dataContext;
|
1542
|
-
if (!dataContext || !fieldPath) {
|
1543
|
-
return this._match;
|
1503
|
+
if (this.hasAllValue()) {
|
1504
|
+
return ALL_VARIABLE_TEXT;
|
1544
1505
|
}
|
1545
|
-
|
1546
|
-
|
1547
|
-
return this._match;
|
1506
|
+
if (Array.isArray(this.state.text)) {
|
1507
|
+
return this.state.text.join(" + ");
|
1548
1508
|
}
|
1549
|
-
|
1550
|
-
name: frame.name,
|
1551
|
-
refId: frame.refId,
|
1552
|
-
fields: data.getFieldDisplayValuesProxy({ frame, rowIndex })
|
1553
|
-
};
|
1554
|
-
return (_b = getFieldAccessor(fieldPath)(obj)) != null ? _b : "";
|
1555
|
-
}
|
1556
|
-
getValueText() {
|
1557
|
-
return "";
|
1509
|
+
return String(this.state.text);
|
1558
1510
|
}
|
1559
|
-
|
1560
|
-
|
1561
|
-
|
1562
|
-
this._match = _match;
|
1563
|
-
this._scopedVars = _scopedVars;
|
1564
|
-
this.state = { name, type: "__series" };
|
1511
|
+
hasAllValue() {
|
1512
|
+
const value = this.state.value;
|
1513
|
+
return value === ALL_VARIABLE_VALUE || Array.isArray(value) && value[0] === ALL_VARIABLE_VALUE;
|
1565
1514
|
}
|
1566
|
-
|
1567
|
-
|
1568
|
-
|
1569
|
-
if (
|
1570
|
-
return
|
1515
|
+
getDefaultMultiState(options) {
|
1516
|
+
if (this.state.defaultToAll) {
|
1517
|
+
return { value: [ALL_VARIABLE_VALUE], text: [ALL_VARIABLE_TEXT] };
|
1518
|
+
} else if (options.length > 0) {
|
1519
|
+
return { value: [options[0].value], text: [options[0].label] };
|
1520
|
+
} else {
|
1521
|
+
return { value: [], text: [] };
|
1571
1522
|
}
|
1572
|
-
|
1573
|
-
|
1523
|
+
}
|
1524
|
+
changeValueTo(value, text) {
|
1525
|
+
if (value === this.state.value && text === this.state.text) {
|
1526
|
+
return;
|
1574
1527
|
}
|
1575
|
-
|
1576
|
-
|
1528
|
+
if (!text) {
|
1529
|
+
if (Array.isArray(value)) {
|
1530
|
+
text = value.map((v) => this.findLabelTextForValue(v));
|
1531
|
+
} else {
|
1532
|
+
text = this.findLabelTextForValue(value);
|
1533
|
+
}
|
1534
|
+
}
|
1535
|
+
if (Array.isArray(value)) {
|
1536
|
+
if (value.length === 0) {
|
1537
|
+
const state = this.getDefaultMultiState(this.state.options);
|
1538
|
+
value = state.value;
|
1539
|
+
text = state.text;
|
1540
|
+
}
|
1541
|
+
if (value[value.length - 1] === ALL_VARIABLE_VALUE) {
|
1542
|
+
value = [ALL_VARIABLE_VALUE];
|
1543
|
+
text = [ALL_VARIABLE_TEXT];
|
1544
|
+
} else if (value[0] === ALL_VARIABLE_VALUE && value.length > 1) {
|
1545
|
+
value.shift();
|
1546
|
+
if (Array.isArray(text)) {
|
1547
|
+
text.shift();
|
1548
|
+
}
|
1549
|
+
}
|
1550
|
+
}
|
1551
|
+
if (lodash.isEqual(value, this.state.value) && lodash.isEqual(text, this.state.text)) {
|
1552
|
+
return;
|
1553
|
+
}
|
1554
|
+
this.setStateHelper({ value, text, loading: false });
|
1555
|
+
this.publishEvent(new SceneVariableValueChangedEvent(this), true);
|
1577
1556
|
}
|
1578
|
-
|
1579
|
-
|
1557
|
+
findLabelTextForValue(value) {
|
1558
|
+
if (value === ALL_VARIABLE_VALUE) {
|
1559
|
+
return ALL_VARIABLE_TEXT;
|
1560
|
+
}
|
1561
|
+
const option = this.state.options.find((x) => x.value === value);
|
1562
|
+
if (option) {
|
1563
|
+
return option.label;
|
1564
|
+
}
|
1565
|
+
const optionByLabel = this.state.options.find((x) => x.label === value);
|
1566
|
+
if (optionByLabel) {
|
1567
|
+
return optionByLabel.label;
|
1568
|
+
}
|
1569
|
+
return value;
|
1580
1570
|
}
|
1581
|
-
|
1582
|
-
|
1583
|
-
constructor(name, sceneObject, _match, _scopedVars) {
|
1584
|
-
this._match = _match;
|
1585
|
-
this._scopedVars = _scopedVars;
|
1586
|
-
this.state = { name, type: "__field" };
|
1571
|
+
setStateHelper(state) {
|
1572
|
+
setBaseClassState(this, state);
|
1587
1573
|
}
|
1588
|
-
|
1589
|
-
|
1590
|
-
|
1591
|
-
|
1592
|
-
return this._match;
|
1574
|
+
getOptionsForSelect() {
|
1575
|
+
let options = this.state.options;
|
1576
|
+
if (this.state.includeAll) {
|
1577
|
+
options = [{ value: ALL_VARIABLE_VALUE, label: ALL_VARIABLE_TEXT }, ...options];
|
1593
1578
|
}
|
1594
|
-
if (
|
1595
|
-
|
1579
|
+
if (!Array.isArray(this.state.value)) {
|
1580
|
+
const current = options.find((x) => x.value === this.state.value);
|
1581
|
+
if (!current) {
|
1582
|
+
options = [{ value: this.state.value, label: String(this.state.text) }, ...options];
|
1583
|
+
}
|
1596
1584
|
}
|
1597
|
-
|
1598
|
-
const obj = getTemplateProxyForField(field, frame, data);
|
1599
|
-
return (_b = getFieldAccessor(fieldPath)(obj)) != null ? _b : "";
|
1585
|
+
return options;
|
1600
1586
|
}
|
1601
|
-
|
1602
|
-
|
1587
|
+
refreshOptions() {
|
1588
|
+
this.getValueOptions({}).subscribe((options) => {
|
1589
|
+
this.updateValueGivenNewOptions(options);
|
1590
|
+
});
|
1603
1591
|
}
|
1604
1592
|
}
|
1605
|
-
|
1606
|
-
|
1607
|
-
|
1608
|
-
|
1593
|
+
function findOptionMatchingCurrent(currentValue, currentText, options) {
|
1594
|
+
let textMatch;
|
1595
|
+
for (const item of options) {
|
1596
|
+
if (item.value === currentValue) {
|
1597
|
+
return item;
|
1598
|
+
}
|
1599
|
+
if (item.label === currentText) {
|
1600
|
+
textMatch = item;
|
1601
|
+
}
|
1609
1602
|
}
|
1610
|
-
|
1611
|
-
|
1612
|
-
|
1613
|
-
|
1614
|
-
|
1615
|
-
|
1616
|
-
|
1617
|
-
|
1618
|
-
|
1619
|
-
|
1620
|
-
|
1621
|
-
|
1603
|
+
return textMatch;
|
1604
|
+
}
|
1605
|
+
class MultiValueUrlSyncHandler {
|
1606
|
+
constructor(_sceneObject) {
|
1607
|
+
this._sceneObject = _sceneObject;
|
1608
|
+
}
|
1609
|
+
getKey() {
|
1610
|
+
return `var-${this._sceneObject.state.name}`;
|
1611
|
+
}
|
1612
|
+
getKeys() {
|
1613
|
+
if (this._sceneObject.state.skipUrlSync) {
|
1614
|
+
return [];
|
1622
1615
|
}
|
1616
|
+
return [this.getKey()];
|
1623
1617
|
}
|
1624
|
-
|
1625
|
-
|
1618
|
+
getUrlState() {
|
1619
|
+
if (this._sceneObject.state.skipUrlSync) {
|
1620
|
+
return {};
|
1621
|
+
}
|
1622
|
+
let urlValue = null;
|
1623
|
+
let value = this._sceneObject.state.value;
|
1624
|
+
if (Array.isArray(value)) {
|
1625
|
+
urlValue = value.map(String);
|
1626
|
+
} else if (this._sceneObject.state.isMulti) {
|
1627
|
+
urlValue = [String(value)];
|
1628
|
+
} else {
|
1629
|
+
urlValue = String(value);
|
1630
|
+
}
|
1631
|
+
return { [this.getKey()]: urlValue };
|
1632
|
+
}
|
1633
|
+
updateFromUrl(values) {
|
1634
|
+
let urlValue = values[this.getKey()];
|
1635
|
+
if (urlValue != null) {
|
1636
|
+
if (this._sceneObject.state.includeAll) {
|
1637
|
+
urlValue = handleLegacyUrlAllValue(urlValue);
|
1638
|
+
}
|
1639
|
+
if (this._sceneObject.state.allValue && this._sceneObject.state.allValue === urlValue) {
|
1640
|
+
urlValue = ALL_VARIABLE_VALUE;
|
1641
|
+
}
|
1642
|
+
if (!this._sceneObject.isActive) {
|
1643
|
+
this._sceneObject.skipNextValidation = true;
|
1644
|
+
}
|
1645
|
+
this._sceneObject.changeValueTo(urlValue);
|
1646
|
+
}
|
1626
1647
|
}
|
1627
1648
|
}
|
1628
|
-
|
1629
|
-
|
1630
|
-
|
1649
|
+
function handleLegacyUrlAllValue(value) {
|
1650
|
+
if (lodash.isArray(value) && value[0] === ALL_VARIABLE_TEXT) {
|
1651
|
+
return [ALL_VARIABLE_VALUE];
|
1652
|
+
} else if (value === ALL_VARIABLE_TEXT) {
|
1653
|
+
return ALL_VARIABLE_VALUE;
|
1631
1654
|
}
|
1632
|
-
|
1633
|
-
|
1634
|
-
|
1655
|
+
return value;
|
1656
|
+
}
|
1657
|
+
class CustomAllValue {
|
1658
|
+
constructor(_value, _variable) {
|
1659
|
+
this._value = _value;
|
1660
|
+
this._variable = _variable;
|
1661
|
+
}
|
1662
|
+
formatter(formatNameOrFn) {
|
1663
|
+
if (formatNameOrFn === schema.VariableFormatID.Text) {
|
1664
|
+
return ALL_VARIABLE_TEXT;
|
1635
1665
|
}
|
1636
|
-
|
1637
|
-
|
1638
|
-
const allParams = new URLSearchParams(this._urlQueryParams);
|
1639
|
-
for (const param of params[1].split(",")) {
|
1640
|
-
allParams.delete(param);
|
1641
|
-
}
|
1642
|
-
return `?${allParams}`;
|
1666
|
+
if (formatNameOrFn === schema.VariableFormatID.PercentEncode) {
|
1667
|
+
return formatRegistry.get(schema.VariableFormatID.PercentEncode).formatter(this._value, [], this._variable);
|
1643
1668
|
}
|
1644
|
-
if (
|
1645
|
-
|
1646
|
-
const includeOnly = params[1].split(",");
|
1647
|
-
for (const param of allParams.keys()) {
|
1648
|
-
if (!includeOnly.includes(param)) {
|
1649
|
-
allParams.delete(param);
|
1650
|
-
}
|
1651
|
-
}
|
1652
|
-
return `?${allParams}`;
|
1669
|
+
if (formatNameOrFn === schema.VariableFormatID.QueryParam) {
|
1670
|
+
return formatRegistry.get(schema.VariableFormatID.QueryParam).formatter(ALL_VARIABLE_TEXT, [], this._variable);
|
1653
1671
|
}
|
1654
|
-
return this.
|
1672
|
+
return this._value;
|
1655
1673
|
}
|
1656
1674
|
}
|
1657
1675
|
|
1658
|
-
class
|
1659
|
-
constructor(name,
|
1660
|
-
this.state = { name, type: "
|
1676
|
+
class AllVariablesMacro {
|
1677
|
+
constructor(name, sceneObject) {
|
1678
|
+
this.state = { name, type: "url_variable" };
|
1679
|
+
this._sceneObject = sceneObject;
|
1661
1680
|
}
|
1662
|
-
getValue(
|
1663
|
-
const
|
1664
|
-
|
1665
|
-
|
1666
|
-
|
1667
|
-
|
1668
|
-
|
1669
|
-
|
1670
|
-
|
1671
|
-
|
1681
|
+
getValue() {
|
1682
|
+
const allVars = collectAllVariables(this._sceneObject);
|
1683
|
+
const format = formatRegistry.get(schema.VariableFormatID.QueryParam);
|
1684
|
+
const params = [];
|
1685
|
+
for (const name of Object.keys(allVars)) {
|
1686
|
+
const variable = allVars[name];
|
1687
|
+
if (variable instanceof MultiValueVariable && variable.hasAllValue() && !variable.state.allValue) {
|
1688
|
+
params.push(format.formatter(ALL_VARIABLE_VALUE, [], variable));
|
1689
|
+
continue;
|
1690
|
+
}
|
1691
|
+
const value = variable.getValue();
|
1692
|
+
if (!value) {
|
1693
|
+
continue;
|
1694
|
+
}
|
1695
|
+
if (isCustomVariableValue(value)) {
|
1696
|
+
params.push(value.formatter(schema.VariableFormatID.QueryParam));
|
1697
|
+
} else {
|
1698
|
+
params.push(format.formatter(value, [], variable));
|
1699
|
+
}
|
1672
1700
|
}
|
1701
|
+
return new SkipFormattingValue(params.join("&"));
|
1673
1702
|
}
|
1674
1703
|
getValueText() {
|
1675
1704
|
return "";
|
1676
1705
|
}
|
1677
1706
|
}
|
1678
|
-
|
1679
|
-
|
1680
|
-
|
1681
|
-
|
1682
|
-
|
1683
|
-
|
1684
|
-
|
1685
|
-
|
1686
|
-
|
1687
|
-
case "id":
|
1688
|
-
default:
|
1689
|
-
return String(user.orgId);
|
1707
|
+
function collectAllVariables(sceneObject, record = {}) {
|
1708
|
+
if (sceneObject.state.$variables) {
|
1709
|
+
for (const variable of sceneObject.state.$variables.state.variables) {
|
1710
|
+
if (variable.state.skipUrlSync) {
|
1711
|
+
continue;
|
1712
|
+
}
|
1713
|
+
if (!record[variable.state.name]) {
|
1714
|
+
record[variable.state.name] = variable;
|
1715
|
+
}
|
1690
1716
|
}
|
1691
1717
|
}
|
1692
|
-
|
1693
|
-
|
1718
|
+
if (sceneObject.parent) {
|
1719
|
+
collectAllVariables(sceneObject.parent, record);
|
1694
1720
|
}
|
1721
|
+
return record;
|
1695
1722
|
}
|
1696
1723
|
|
1697
|
-
|
1698
|
-
|
1699
|
-
|
1700
|
-
|
1701
|
-
|
1702
|
-
|
1703
|
-
|
1704
|
-
|
1705
|
-
|
1706
|
-
|
1707
|
-
|
1708
|
-
|
1709
|
-
|
1710
|
-
|
1711
|
-
|
1712
|
-
|
1713
|
-
|
1714
|
-
|
1715
|
-
|
1716
|
-
|
1717
|
-
|
1718
|
-
|
1719
|
-
|
1720
|
-
|
1724
|
+
var __defProp$H = Object.defineProperty;
|
1725
|
+
var __defProps$s = Object.defineProperties;
|
1726
|
+
var __getOwnPropDescs$s = Object.getOwnPropertyDescriptors;
|
1727
|
+
var __getOwnPropSymbols$H = Object.getOwnPropertySymbols;
|
1728
|
+
var __hasOwnProp$H = Object.prototype.hasOwnProperty;
|
1729
|
+
var __propIsEnum$H = Object.prototype.propertyIsEnumerable;
|
1730
|
+
var __defNormalProp$H = (obj, key, value) => key in obj ? __defProp$H(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
1731
|
+
var __spreadValues$H = (a, b) => {
|
1732
|
+
for (var prop in b || (b = {}))
|
1733
|
+
if (__hasOwnProp$H.call(b, prop))
|
1734
|
+
__defNormalProp$H(a, prop, b[prop]);
|
1735
|
+
if (__getOwnPropSymbols$H)
|
1736
|
+
for (var prop of __getOwnPropSymbols$H(b)) {
|
1737
|
+
if (__propIsEnum$H.call(b, prop))
|
1738
|
+
__defNormalProp$H(a, prop, b[prop]);
|
1739
|
+
}
|
1740
|
+
return a;
|
1741
|
+
};
|
1742
|
+
var __spreadProps$s = (a, b) => __defProps$s(a, __getOwnPropDescs$s(b));
|
1743
|
+
function getTemplateProxyForField(field, frame, frames) {
|
1744
|
+
return new Proxy(
|
1745
|
+
{},
|
1746
|
+
{
|
1747
|
+
get: (obj, key) => {
|
1748
|
+
if (key === "name") {
|
1749
|
+
return field.name;
|
1750
|
+
}
|
1751
|
+
if (key === "displayName") {
|
1752
|
+
return data.getFieldDisplayName(field, frame, frames);
|
1753
|
+
}
|
1754
|
+
if (key === "labels" || key === "formattedLabels") {
|
1755
|
+
if (!field.labels) {
|
1756
|
+
return "";
|
1757
|
+
}
|
1758
|
+
return __spreadProps$s(__spreadValues$H({}, field.labels), {
|
1759
|
+
__values: Object.values(field.labels).sort().join(", "),
|
1760
|
+
toString: () => {
|
1761
|
+
return data.formatLabels(field.labels, "", true);
|
1762
|
+
}
|
1763
|
+
});
|
1764
|
+
}
|
1765
|
+
return void 0;
|
1766
|
+
}
|
1767
|
+
}
|
1768
|
+
);
|
1721
1769
|
}
|
1722
1770
|
|
1723
|
-
|
1724
|
-
|
1725
|
-
|
1771
|
+
class ValueMacro {
|
1772
|
+
constructor(name, sceneObject, _match, _scopedVars) {
|
1773
|
+
this._match = _match;
|
1774
|
+
this._scopedVars = _scopedVars;
|
1775
|
+
this.state = { name, type: "__value" };
|
1726
1776
|
}
|
1727
|
-
|
1728
|
-
|
1729
|
-
const
|
1730
|
-
|
1731
|
-
|
1732
|
-
|
1733
|
-
|
1734
|
-
|
1777
|
+
getValue(fieldPath) {
|
1778
|
+
var _a, _b;
|
1779
|
+
const dataContext = (_a = this._scopedVars) == null ? void 0 : _a.__dataContext;
|
1780
|
+
if (!dataContext) {
|
1781
|
+
return this._match;
|
1782
|
+
}
|
1783
|
+
const { frame, rowIndex, field, calculatedValue } = dataContext.value;
|
1784
|
+
if (calculatedValue) {
|
1785
|
+
switch (fieldPath) {
|
1786
|
+
case "numeric":
|
1787
|
+
return calculatedValue.numeric;
|
1788
|
+
case "raw":
|
1789
|
+
return calculatedValue.numeric;
|
1790
|
+
case "time":
|
1791
|
+
return "";
|
1792
|
+
case "text":
|
1793
|
+
default:
|
1794
|
+
return data.formattedValueToString(calculatedValue);
|
1735
1795
|
}
|
1736
|
-
return match;
|
1737
1796
|
}
|
1738
|
-
|
1739
|
-
|
1740
|
-
interpolations.push({ match, variableName, fieldPath, format: fmt, value, found: value !== match });
|
1797
|
+
if (rowIndex == null) {
|
1798
|
+
return this._match;
|
1741
1799
|
}
|
1742
|
-
|
1743
|
-
|
1744
|
-
|
1745
|
-
|
1746
|
-
|
1747
|
-
|
1748
|
-
|
1749
|
-
|
1800
|
+
if (fieldPath === "time") {
|
1801
|
+
const timeField = frame.fields.find((f) => f.type === data.FieldType.time);
|
1802
|
+
return timeField ? timeField.values.get(rowIndex) : void 0;
|
1803
|
+
}
|
1804
|
+
if (!field) {
|
1805
|
+
return this._match;
|
1806
|
+
}
|
1807
|
+
const value = field.values.get(rowIndex);
|
1808
|
+
if (fieldPath === "raw") {
|
1809
|
+
return value;
|
1810
|
+
}
|
1811
|
+
const displayProcessor = (_b = field.display) != null ? _b : fallbackDisplayProcessor;
|
1812
|
+
const result = displayProcessor(value);
|
1813
|
+
switch (fieldPath) {
|
1814
|
+
case "numeric":
|
1815
|
+
return result.numeric;
|
1816
|
+
case "text":
|
1817
|
+
default:
|
1818
|
+
return data.formattedValueToString(result);
|
1750
1819
|
}
|
1751
1820
|
}
|
1752
|
-
|
1753
|
-
|
1754
|
-
return variable;
|
1755
|
-
}
|
1756
|
-
const Macro = macrosIndex.get(name);
|
1757
|
-
if (Macro) {
|
1758
|
-
return new Macro(name, sceneObject, match, scopedVars);
|
1821
|
+
getValueText() {
|
1822
|
+
return "";
|
1759
1823
|
}
|
1760
|
-
return null;
|
1761
1824
|
}
|
1762
|
-
|
1763
|
-
|
1764
|
-
|
1825
|
+
const fallbackDisplayProcessor = data.getDisplayProcessor();
|
1826
|
+
class DataMacro {
|
1827
|
+
constructor(name, sceneObject, _match, _scopedVars) {
|
1828
|
+
this._match = _match;
|
1829
|
+
this._scopedVars = _scopedVars;
|
1830
|
+
this.state = { name, type: "__data" };
|
1765
1831
|
}
|
1766
|
-
|
1767
|
-
|
1832
|
+
getValue(fieldPath) {
|
1833
|
+
var _a, _b;
|
1834
|
+
const dataContext = (_a = this._scopedVars) == null ? void 0 : _a.__dataContext;
|
1835
|
+
if (!dataContext || !fieldPath) {
|
1836
|
+
return this._match;
|
1837
|
+
}
|
1838
|
+
const { frame, rowIndex } = dataContext.value;
|
1839
|
+
if (rowIndex === void 0 || fieldPath === void 0) {
|
1840
|
+
return this._match;
|
1841
|
+
}
|
1842
|
+
const obj = {
|
1843
|
+
name: frame.name,
|
1844
|
+
refId: frame.refId,
|
1845
|
+
fields: data.getFieldDisplayValuesProxy({ frame, rowIndex })
|
1846
|
+
};
|
1847
|
+
return (_b = getFieldAccessor(fieldPath)(obj)) != null ? _b : "";
|
1768
1848
|
}
|
1769
|
-
|
1770
|
-
|
1849
|
+
getValueText() {
|
1850
|
+
return "";
|
1771
1851
|
}
|
1772
|
-
|
1773
|
-
|
1774
|
-
|
1775
|
-
|
1776
|
-
|
1777
|
-
|
1778
|
-
});
|
1852
|
+
}
|
1853
|
+
class SeriesMacro {
|
1854
|
+
constructor(name, sceneObject, _match, _scopedVars) {
|
1855
|
+
this._match = _match;
|
1856
|
+
this._scopedVars = _scopedVars;
|
1857
|
+
this.state = { name, type: "__series" };
|
1779
1858
|
}
|
1780
|
-
|
1781
|
-
|
1782
|
-
|
1783
|
-
|
1784
|
-
|
1785
|
-
if (args.length > 1) {
|
1786
|
-
formatNameOrFn = args[0];
|
1787
|
-
args = args.slice(1);
|
1788
|
-
} else {
|
1789
|
-
args = [];
|
1859
|
+
getValue(fieldPath) {
|
1860
|
+
var _a;
|
1861
|
+
const dataContext = (_a = this._scopedVars) == null ? void 0 : _a.__dataContext;
|
1862
|
+
if (!dataContext || !fieldPath) {
|
1863
|
+
return this._match;
|
1790
1864
|
}
|
1865
|
+
if (fieldPath !== "name") {
|
1866
|
+
return this._match;
|
1867
|
+
}
|
1868
|
+
const { frame, frameIndex } = dataContext.value;
|
1869
|
+
return data.getFrameDisplayName(frame, frameIndex);
|
1791
1870
|
}
|
1792
|
-
|
1793
|
-
|
1794
|
-
console.error(`Variable format ${formatNameOrFn} not found. Using glob format as fallback.`);
|
1795
|
-
formatter = formatRegistry.get(schema.VariableFormatID.Glob);
|
1871
|
+
getValueText() {
|
1872
|
+
return "";
|
1796
1873
|
}
|
1797
|
-
return formatter.formatter(value, args, variable);
|
1798
1874
|
}
|
1799
|
-
|
1800
|
-
|
1801
|
-
|
1802
|
-
|
1803
|
-
|
1804
|
-
|
1805
|
-
|
1806
|
-
|
1807
|
-
|
1808
|
-
|
1809
|
-
|
1810
|
-
|
1811
|
-
|
1812
|
-
|
1813
|
-
|
1814
|
-
|
1875
|
+
class FieldMacro {
|
1876
|
+
constructor(name, sceneObject, _match, _scopedVars) {
|
1877
|
+
this._match = _match;
|
1878
|
+
this._scopedVars = _scopedVars;
|
1879
|
+
this.state = { name, type: "__field" };
|
1880
|
+
}
|
1881
|
+
getValue(fieldPath) {
|
1882
|
+
var _a, _b;
|
1883
|
+
const dataContext = (_a = this._scopedVars) == null ? void 0 : _a.__dataContext;
|
1884
|
+
if (!dataContext || !fieldPath) {
|
1885
|
+
return this._match;
|
1886
|
+
}
|
1887
|
+
if (fieldPath === void 0 || fieldPath === "") {
|
1888
|
+
return this._match;
|
1889
|
+
}
|
1890
|
+
const { frame, field, data } = dataContext.value;
|
1891
|
+
const obj = getTemplateProxyForField(field, frame, data);
|
1892
|
+
return (_b = getFieldAccessor(fieldPath)(obj)) != null ? _b : "";
|
1893
|
+
}
|
1894
|
+
getValueText() {
|
1895
|
+
return "";
|
1896
|
+
}
|
1897
|
+
}
|
1898
|
+
|
1899
|
+
class UrlMacro {
|
1900
|
+
constructor(name, _) {
|
1901
|
+
this.state = { name, type: "url_macro" };
|
1902
|
+
}
|
1903
|
+
getValue(fieldPath) {
|
1904
|
+
var _a;
|
1905
|
+
const location = runtime.locationService.getLocation();
|
1906
|
+
const subUrl = (_a = runtime.config.appSubUrl) != null ? _a : "";
|
1907
|
+
switch (fieldPath != null ? fieldPath : "") {
|
1908
|
+
case "params":
|
1909
|
+
return new UrlStateFormatter(location.search);
|
1910
|
+
case "path":
|
1911
|
+
return subUrl + location.pathname;
|
1912
|
+
case "":
|
1913
|
+
default:
|
1914
|
+
return subUrl + location.pathname + location.search;
|
1915
|
+
}
|
1916
|
+
}
|
1917
|
+
getValueText() {
|
1918
|
+
return "";
|
1919
|
+
}
|
1920
|
+
}
|
1921
|
+
class UrlStateFormatter {
|
1922
|
+
constructor(_urlQueryParams) {
|
1923
|
+
this._urlQueryParams = _urlQueryParams;
|
1924
|
+
}
|
1925
|
+
formatter(options) {
|
1926
|
+
if (!options) {
|
1927
|
+
return this._urlQueryParams;
|
1928
|
+
}
|
1929
|
+
const params = options.split(":");
|
1930
|
+
if (params[0] === "exclude" && params.length > 1) {
|
1931
|
+
const allParams = new URLSearchParams(this._urlQueryParams);
|
1932
|
+
for (const param of params[1].split(",")) {
|
1933
|
+
allParams.delete(param);
|
1934
|
+
}
|
1935
|
+
return `?${allParams}`;
|
1936
|
+
}
|
1937
|
+
if (params[0] === "include" && params.length > 1) {
|
1938
|
+
const allParams = new URLSearchParams(this._urlQueryParams);
|
1939
|
+
const includeOnly = params[1].split(",");
|
1940
|
+
for (const param of allParams.keys()) {
|
1941
|
+
if (!includeOnly.includes(param)) {
|
1942
|
+
allParams.delete(param);
|
1943
|
+
}
|
1944
|
+
}
|
1945
|
+
return `?${allParams}`;
|
1946
|
+
}
|
1947
|
+
return this._urlQueryParams;
|
1948
|
+
}
|
1949
|
+
}
|
1950
|
+
|
1951
|
+
class UserMacro {
|
1952
|
+
constructor(name, _) {
|
1953
|
+
this.state = { name, type: "user_macro" };
|
1954
|
+
}
|
1955
|
+
getValue(fieldPath) {
|
1956
|
+
const user = runtime.config.bootData.user;
|
1957
|
+
switch (fieldPath) {
|
1958
|
+
case "login":
|
1959
|
+
return user.login;
|
1960
|
+
case "email":
|
1961
|
+
return user.email;
|
1962
|
+
case "id":
|
1963
|
+
default:
|
1964
|
+
return String(user.id);
|
1965
|
+
}
|
1966
|
+
}
|
1967
|
+
getValueText() {
|
1968
|
+
return "";
|
1969
|
+
}
|
1970
|
+
}
|
1971
|
+
class OrgMacro {
|
1972
|
+
constructor(name, _) {
|
1973
|
+
this.state = { name, type: "org_macro" };
|
1974
|
+
}
|
1975
|
+
getValue(fieldPath) {
|
1976
|
+
const user = runtime.config.bootData.user;
|
1977
|
+
switch (fieldPath) {
|
1978
|
+
case "name":
|
1979
|
+
return user.orgName;
|
1980
|
+
case "id":
|
1981
|
+
default:
|
1982
|
+
return String(user.orgId);
|
1983
|
+
}
|
1984
|
+
}
|
1985
|
+
getValueText() {
|
1986
|
+
return "";
|
1987
|
+
}
|
1988
|
+
}
|
1989
|
+
|
1990
|
+
const macrosIndex = /* @__PURE__ */ new Map([
|
1991
|
+
[data.DataLinkBuiltInVars.includeVars, AllVariablesMacro],
|
1992
|
+
[data.DataLinkBuiltInVars.keepTime, UrlTimeRangeMacro],
|
1993
|
+
["__value", ValueMacro],
|
1994
|
+
["__data", DataMacro],
|
1995
|
+
["__series", SeriesMacro],
|
1996
|
+
["__field", FieldMacro],
|
1997
|
+
["__url", UrlMacro],
|
1998
|
+
["__from", TimeFromAndToMacro],
|
1999
|
+
["__to", TimeFromAndToMacro],
|
2000
|
+
["__timezone", TimezoneMacro],
|
2001
|
+
["__user", UserMacro],
|
2002
|
+
["__org", OrgMacro],
|
2003
|
+
["__interval", IntervalMacro],
|
2004
|
+
["__interval_ms", IntervalMacro]
|
2005
|
+
]);
|
2006
|
+
function registerVariableMacro(name, macro) {
|
2007
|
+
if (macrosIndex.get(name)) {
|
2008
|
+
throw new Error(`Macro already registered ${name}`);
|
2009
|
+
}
|
2010
|
+
macrosIndex.set(name, macro);
|
2011
|
+
return () => {
|
2012
|
+
macrosIndex.delete(name);
|
2013
|
+
};
|
2014
|
+
}
|
2015
|
+
|
2016
|
+
function sceneInterpolator(sceneObject, target, scopedVars, format, interpolations) {
|
2017
|
+
if (!target || typeof target !== "string") {
|
2018
|
+
return target != null ? target : "";
|
2019
|
+
}
|
2020
|
+
VARIABLE_REGEX.lastIndex = 0;
|
2021
|
+
return target.replace(VARIABLE_REGEX, (match, var1, var2, fmt2, var3, fieldPath, fmt3) => {
|
2022
|
+
const variableName = var1 || var2 || var3;
|
2023
|
+
const fmt = fmt2 || fmt3 || format;
|
2024
|
+
const variable = lookupFormatVariable(variableName, match, scopedVars, sceneObject);
|
2025
|
+
if (!variable) {
|
2026
|
+
if (interpolations) {
|
2027
|
+
interpolations.push({ match, variableName, fieldPath, format: fmt, value: match, found: false });
|
2028
|
+
}
|
2029
|
+
return match;
|
2030
|
+
}
|
2031
|
+
const value = formatValue(sceneObject, variable, variable.getValue(fieldPath), fmt);
|
2032
|
+
if (interpolations) {
|
2033
|
+
interpolations.push({ match, variableName, fieldPath, format: fmt, value, found: value !== match });
|
2034
|
+
}
|
2035
|
+
return value;
|
2036
|
+
});
|
2037
|
+
}
|
2038
|
+
function lookupFormatVariable(name, match, scopedVars, sceneObject) {
|
2039
|
+
if (scopedVars && scopedVars.hasOwnProperty(name)) {
|
2040
|
+
const scopedVar = scopedVars[name];
|
2041
|
+
if (scopedVar) {
|
2042
|
+
return getSceneVariableForScopedVar(name, scopedVar);
|
2043
|
+
}
|
2044
|
+
}
|
2045
|
+
const variable = lookupVariable(name, sceneObject);
|
2046
|
+
if (variable) {
|
2047
|
+
return variable;
|
2048
|
+
}
|
2049
|
+
const Macro = macrosIndex.get(name);
|
2050
|
+
if (Macro) {
|
2051
|
+
return new Macro(name, sceneObject, match, scopedVars);
|
2052
|
+
}
|
2053
|
+
return null;
|
2054
|
+
}
|
2055
|
+
function formatValue(context, variable, value, formatNameOrFn) {
|
2056
|
+
if (value === null || value === void 0) {
|
2057
|
+
return "";
|
2058
|
+
}
|
2059
|
+
if (isCustomVariableValue(value)) {
|
2060
|
+
return sceneInterpolator(context, value.formatter(formatNameOrFn));
|
2061
|
+
}
|
2062
|
+
if (!Array.isArray(value) && typeof value === "object") {
|
2063
|
+
value = `${value}`;
|
2064
|
+
}
|
2065
|
+
if (typeof formatNameOrFn === "function") {
|
2066
|
+
return formatNameOrFn(value, {
|
2067
|
+
name: variable.state.name,
|
2068
|
+
type: variable.state.type,
|
2069
|
+
multi: variable.state.isMulti,
|
2070
|
+
includeAll: variable.state.includeAll
|
2071
|
+
});
|
2072
|
+
}
|
2073
|
+
let args = [];
|
2074
|
+
if (!formatNameOrFn) {
|
2075
|
+
formatNameOrFn = schema.VariableFormatID.Glob;
|
2076
|
+
} else {
|
2077
|
+
args = formatNameOrFn.split(":");
|
2078
|
+
if (args.length > 1) {
|
2079
|
+
formatNameOrFn = args[0];
|
2080
|
+
args = args.slice(1);
|
2081
|
+
} else {
|
2082
|
+
args = [];
|
2083
|
+
}
|
2084
|
+
}
|
2085
|
+
let formatter = formatRegistry.getIfExists(formatNameOrFn);
|
2086
|
+
if (!formatter) {
|
2087
|
+
console.error(`Variable format ${formatNameOrFn} not found. Using glob format as fallback.`);
|
2088
|
+
formatter = formatRegistry.get(schema.VariableFormatID.Glob);
|
2089
|
+
}
|
2090
|
+
return formatter.formatter(value, args, variable);
|
2091
|
+
}
|
2092
|
+
|
2093
|
+
function isSceneObject(obj) {
|
2094
|
+
return obj.useState !== void 0;
|
2095
|
+
}
|
2096
|
+
function isDataRequestEnricher(obj) {
|
2097
|
+
return "enrichDataRequest" in obj;
|
2098
|
+
}
|
2099
|
+
function isFiltersRequestEnricher(obj) {
|
2100
|
+
return "enrichFiltersRequest" in obj;
|
2101
|
+
}
|
2102
|
+
function isDataLayer(obj) {
|
2103
|
+
return "isDataLayer" in obj;
|
2104
|
+
}
|
2105
|
+
|
2106
|
+
var __accessCheck$2 = (obj, member, msg) => {
|
2107
|
+
if (!member.has(obj))
|
1815
2108
|
throw TypeError("Cannot " + msg);
|
1816
2109
|
};
|
1817
2110
|
var __privateGet$2 = (obj, member, getter) => {
|
@@ -1871,602 +2164,313 @@ function writeSceneLog(logger, message, ...rest) {
|
|
1871
2164
|
if (typeof window !== "undefined") {
|
1872
2165
|
loggingEnabled = localStorage.getItem("grafana.debug.scenes") === "true";
|
1873
2166
|
}
|
1874
|
-
if (loggingEnabled) {
|
1875
|
-
console.log(`${logger}: `, message, ...rest);
|
1876
|
-
}
|
1877
|
-
}
|
1878
|
-
|
1879
|
-
async function getDataSource(datasource, scopedVars) {
|
1880
|
-
if (datasource == null ? void 0 : datasource.uid) {
|
1881
|
-
const runtimeDataSource = runtimeDataSources.get(datasource.uid);
|
1882
|
-
if (runtimeDataSource) {
|
1883
|
-
return runtimeDataSource;
|
1884
|
-
}
|
1885
|
-
}
|
1886
|
-
if (datasource && datasource.query) {
|
1887
|
-
return datasource;
|
1888
|
-
}
|
1889
|
-
return await runtime.getDataSourceSrv().get(datasource, scopedVars);
|
1890
|
-
}
|
1891
|
-
|
1892
|
-
class VariableValueRecorder {
|
1893
|
-
constructor() {
|
1894
|
-
this._values = /* @__PURE__ */ new Map();
|
1895
|
-
}
|
1896
|
-
recordCurrentDependencyValuesForSceneObject(sceneObject) {
|
1897
|
-
this.clearValues();
|
1898
|
-
if (!sceneObject.variableDependency) {
|
1899
|
-
return;
|
1900
|
-
}
|
1901
|
-
for (const variableName of sceneObject.variableDependency.getNames()) {
|
1902
|
-
const variable = sceneGraph.lookupVariable(variableName, sceneObject);
|
1903
|
-
if (variable) {
|
1904
|
-
this._values.set(variable.state.name, variable.getValue());
|
1905
|
-
}
|
1906
|
-
}
|
1907
|
-
}
|
1908
|
-
cloneAndRecordCurrentValuesForSceneObject(sceneObject) {
|
1909
|
-
const clone = new VariableValueRecorder();
|
1910
|
-
clone.recordCurrentDependencyValuesForSceneObject(sceneObject);
|
1911
|
-
return clone;
|
1912
|
-
}
|
1913
|
-
clearValues() {
|
1914
|
-
this._values.clear();
|
1915
|
-
}
|
1916
|
-
hasValues() {
|
1917
|
-
return !!this._values;
|
1918
|
-
}
|
1919
|
-
recordCurrentValue(variable) {
|
1920
|
-
this._values.set(variable.state.name, variable.getValue());
|
1921
|
-
}
|
1922
|
-
hasRecordedValue(variable) {
|
1923
|
-
return this._values.has(variable.state.name);
|
1924
|
-
}
|
1925
|
-
hasValueChanged(variable) {
|
1926
|
-
if (this._values.has(variable.state.name)) {
|
1927
|
-
const value = this._values.get(variable.state.name);
|
1928
|
-
if (!isVariableValueEqual(value, variable.getValue())) {
|
1929
|
-
return true;
|
1930
|
-
}
|
1931
|
-
}
|
1932
|
-
return false;
|
1933
|
-
}
|
1934
|
-
hasDependenciesChanged(sceneObject) {
|
1935
|
-
if (!this._values) {
|
1936
|
-
return false;
|
1937
|
-
}
|
1938
|
-
if (!sceneObject.variableDependency) {
|
1939
|
-
return false;
|
1940
|
-
}
|
1941
|
-
for (const variableName of sceneObject.variableDependency.getNames()) {
|
1942
|
-
const variable = sceneGraph.lookupVariable(variableName, sceneObject);
|
1943
|
-
if (!variable) {
|
1944
|
-
continue;
|
1945
|
-
}
|
1946
|
-
const name = variable.state.name;
|
1947
|
-
if (variable && this._values.has(name)) {
|
1948
|
-
const value = this._values.get(name);
|
1949
|
-
if (!isVariableValueEqual(value, variable.getValue())) {
|
1950
|
-
return true;
|
1951
|
-
}
|
1952
|
-
}
|
1953
|
-
}
|
1954
|
-
return false;
|
1955
|
-
}
|
1956
|
-
}
|
1957
|
-
|
1958
|
-
function isExtraQueryProvider(obj) {
|
1959
|
-
return typeof obj === "object" && "getExtraQueries" in obj;
|
1960
|
-
}
|
1961
|
-
|
1962
|
-
var __defProp$G = Object.defineProperty;
|
1963
|
-
var __defProps$r = Object.defineProperties;
|
1964
|
-
var __getOwnPropDescs$r = Object.getOwnPropertyDescriptors;
|
1965
|
-
var __getOwnPropSymbols$G = Object.getOwnPropertySymbols;
|
1966
|
-
var __hasOwnProp$G = Object.prototype.hasOwnProperty;
|
1967
|
-
var __propIsEnum$G = Object.prototype.propertyIsEnumerable;
|
1968
|
-
var __defNormalProp$G = (obj, key, value) => key in obj ? __defProp$G(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
1969
|
-
var __spreadValues$G = (a, b) => {
|
1970
|
-
for (var prop in b || (b = {}))
|
1971
|
-
if (__hasOwnProp$G.call(b, prop))
|
1972
|
-
__defNormalProp$G(a, prop, b[prop]);
|
1973
|
-
if (__getOwnPropSymbols$G)
|
1974
|
-
for (var prop of __getOwnPropSymbols$G(b)) {
|
1975
|
-
if (__propIsEnum$G.call(b, prop))
|
1976
|
-
__defNormalProp$G(a, prop, b[prop]);
|
1977
|
-
}
|
1978
|
-
return a;
|
1979
|
-
};
|
1980
|
-
var __spreadProps$r = (a, b) => __defProps$r(a, __getOwnPropDescs$r(b));
|
1981
|
-
const passthroughProcessor = (_, secondary) => rxjs.of(secondary);
|
1982
|
-
const extraQueryProcessingOperator = (processors) => (data) => {
|
1983
|
-
return data.pipe(
|
1984
|
-
rxjs.mergeMap(([primary, ...secondaries]) => {
|
1985
|
-
const processedSecondaries = secondaries.flatMap((s) => {
|
1986
|
-
var _a, _b;
|
1987
|
-
return (_b = (_a = processors.get(s.request.requestId)) == null ? void 0 : _a(primary, s)) != null ? _b : rxjs.of(s);
|
1988
|
-
});
|
1989
|
-
return rxjs.forkJoin([rxjs.of(primary), ...processedSecondaries]);
|
1990
|
-
}),
|
1991
|
-
rxjs.map(([primary, ...processedSecondaries]) => {
|
1992
|
-
var _a;
|
1993
|
-
return __spreadProps$r(__spreadValues$G({}, primary), {
|
1994
|
-
series: [...primary.series, ...processedSecondaries.flatMap((s) => s.series)],
|
1995
|
-
annotations: [...(_a = primary.annotations) != null ? _a : [], ...processedSecondaries.flatMap((s) => {
|
1996
|
-
var _a2;
|
1997
|
-
return (_a2 = s.annotations) != null ? _a2 : [];
|
1998
|
-
})]
|
1999
|
-
});
|
2000
|
-
})
|
2001
|
-
);
|
2002
|
-
};
|
2003
|
-
|
2004
|
-
var __defProp$F = Object.defineProperty;
|
2005
|
-
var __defProps$q = Object.defineProperties;
|
2006
|
-
var __getOwnPropDescs$q = Object.getOwnPropertyDescriptors;
|
2007
|
-
var __getOwnPropSymbols$F = Object.getOwnPropertySymbols;
|
2008
|
-
var __hasOwnProp$F = Object.prototype.hasOwnProperty;
|
2009
|
-
var __propIsEnum$F = Object.prototype.propertyIsEnumerable;
|
2010
|
-
var __defNormalProp$F = (obj, key, value) => key in obj ? __defProp$F(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
2011
|
-
var __spreadValues$F = (a, b) => {
|
2012
|
-
for (var prop in b || (b = {}))
|
2013
|
-
if (__hasOwnProp$F.call(b, prop))
|
2014
|
-
__defNormalProp$F(a, prop, b[prop]);
|
2015
|
-
if (__getOwnPropSymbols$F)
|
2016
|
-
for (var prop of __getOwnPropSymbols$F(b)) {
|
2017
|
-
if (__propIsEnum$F.call(b, prop))
|
2018
|
-
__defNormalProp$F(a, prop, b[prop]);
|
2019
|
-
}
|
2020
|
-
return a;
|
2021
|
-
};
|
2022
|
-
var __spreadProps$q = (a, b) => __defProps$q(a, __getOwnPropDescs$q(b));
|
2023
|
-
function filterAnnotations(data, filters) {
|
2024
|
-
var _a;
|
2025
|
-
if (!Array.isArray(data) || data.length === 0) {
|
2026
|
-
return data;
|
2027
|
-
}
|
2028
|
-
const rows = Array.from({ length: data.length }, () => /* @__PURE__ */ new Set());
|
2029
|
-
let frameIdx = 0;
|
2030
|
-
for (const frame of data) {
|
2031
|
-
for (let index = 0; index < frame.length; index++) {
|
2032
|
-
if (rows[frameIdx].has(index)) {
|
2033
|
-
continue;
|
2034
|
-
}
|
2035
|
-
let matching = true;
|
2036
|
-
const panelIdField = frame.fields.find((f) => f.name === "panelId");
|
2037
|
-
const sourceField = frame.fields.find((f) => f.name === "source");
|
2038
|
-
if (sourceField) {
|
2039
|
-
if (panelIdField && sourceField.values[index].type === "dashboard") {
|
2040
|
-
matching = panelIdField.values[index] === filters.panelId;
|
2041
|
-
}
|
2042
|
-
const sourceFilter = sourceField.values[index].filter;
|
2043
|
-
if (sourceFilter) {
|
2044
|
-
const includes = ((_a = sourceFilter.ids) != null ? _a : []).includes(filters.panelId);
|
2045
|
-
if (sourceFilter.exclude) {
|
2046
|
-
if (includes) {
|
2047
|
-
matching = false;
|
2048
|
-
}
|
2049
|
-
} else if (!includes) {
|
2050
|
-
matching = false;
|
2051
|
-
}
|
2052
|
-
}
|
2053
|
-
}
|
2054
|
-
if (matching) {
|
2055
|
-
rows[frameIdx].add(index);
|
2056
|
-
}
|
2057
|
-
}
|
2058
|
-
frameIdx++;
|
2059
|
-
}
|
2060
|
-
const processed = [];
|
2061
|
-
frameIdx = 0;
|
2062
|
-
for (const frame of data) {
|
2063
|
-
const frameLength = rows[frameIdx].size;
|
2064
|
-
const fields = [];
|
2065
|
-
for (const field of frame.fields) {
|
2066
|
-
const buffer = [];
|
2067
|
-
for (let index = 0; index < frame.length; index++) {
|
2068
|
-
if (rows[frameIdx].has(index)) {
|
2069
|
-
buffer.push(field.values[index]);
|
2070
|
-
continue;
|
2071
|
-
}
|
2072
|
-
}
|
2073
|
-
fields.push(__spreadProps$q(__spreadValues$F({}, field), {
|
2074
|
-
values: buffer
|
2075
|
-
}));
|
2076
|
-
}
|
2077
|
-
processed.push(__spreadProps$q(__spreadValues$F({}, frame), {
|
2078
|
-
fields,
|
2079
|
-
length: frameLength
|
2080
|
-
}));
|
2081
|
-
frameIdx++;
|
2082
|
-
}
|
2083
|
-
return processed;
|
2084
|
-
}
|
2085
|
-
|
2086
|
-
function getEnrichedDataRequest(sourceRunner) {
|
2087
|
-
const root = sourceRunner.getRoot();
|
2088
|
-
if (isDataRequestEnricher(root)) {
|
2089
|
-
return root.enrichDataRequest(sourceRunner);
|
2090
|
-
}
|
2091
|
-
return null;
|
2092
|
-
}
|
2093
|
-
|
2094
|
-
let originalGetAdhocFilters = void 0;
|
2095
|
-
let allActiveFilterSets = /* @__PURE__ */ new Set();
|
2096
|
-
function patchGetAdhocFilters(filterVar) {
|
2097
|
-
filterVar.addActivationHandler(() => {
|
2098
|
-
allActiveFilterSets.add(filterVar);
|
2099
|
-
return () => allActiveFilterSets.delete(filterVar);
|
2100
|
-
});
|
2101
|
-
if (originalGetAdhocFilters) {
|
2102
|
-
return;
|
2103
|
-
}
|
2104
|
-
const templateSrv = runtime.getTemplateSrv();
|
2105
|
-
if (!(templateSrv == null ? void 0 : templateSrv.getAdhocFilters)) {
|
2106
|
-
console.log("Failed to patch getAdhocFilters");
|
2107
|
-
return;
|
2108
|
-
}
|
2109
|
-
originalGetAdhocFilters = templateSrv.getAdhocFilters;
|
2110
|
-
templateSrv.getAdhocFilters = function getAdhocFiltersScenePatch(dsName) {
|
2111
|
-
var _a;
|
2112
|
-
if (allActiveFilterSets.size === 0) {
|
2113
|
-
return originalGetAdhocFilters.call(templateSrv);
|
2114
|
-
}
|
2115
|
-
const ds = runtime.getDataSourceSrv().getInstanceSettings(dsName);
|
2116
|
-
if (!ds) {
|
2117
|
-
return [];
|
2118
|
-
}
|
2119
|
-
for (const filter of allActiveFilterSets.values()) {
|
2120
|
-
if (((_a = filter.state.datasource) == null ? void 0 : _a.uid) === ds.uid) {
|
2121
|
-
return filter.state.filters;
|
2122
|
-
}
|
2123
|
-
}
|
2124
|
-
return [];
|
2125
|
-
}.bind(templateSrv);
|
2126
|
-
}
|
2127
|
-
function findActiveAdHocFilterVariableByUid(dsUid) {
|
2128
|
-
var _a;
|
2129
|
-
for (const filter of allActiveFilterSets.values()) {
|
2130
|
-
if (((_a = filter.state.datasource) == null ? void 0 : _a.uid) === dsUid) {
|
2131
|
-
return filter;
|
2132
|
-
}
|
2133
|
-
}
|
2134
|
-
return void 0;
|
2135
|
-
}
|
2136
|
-
|
2137
|
-
function registerQueryWithController(entry) {
|
2138
|
-
return (queryStream) => {
|
2139
|
-
const queryControler = sceneGraph.getQueryController(entry.origin);
|
2140
|
-
if (!queryControler) {
|
2141
|
-
return queryStream;
|
2142
|
-
}
|
2143
|
-
return new rxjs.Observable((observer) => {
|
2144
|
-
if (!entry.cancel) {
|
2145
|
-
entry.cancel = () => observer.complete();
|
2146
|
-
}
|
2147
|
-
queryControler.queryStarted(entry);
|
2148
|
-
let markedAsCompleted = false;
|
2149
|
-
const sub = queryStream.subscribe({
|
2150
|
-
next: (v) => {
|
2151
|
-
if (!markedAsCompleted && v.state !== schema.LoadingState.Loading) {
|
2152
|
-
markedAsCompleted = true;
|
2153
|
-
queryControler.queryCompleted(entry);
|
2154
|
-
}
|
2155
|
-
observer.next(v);
|
2156
|
-
},
|
2157
|
-
error: (e) => observer.error(e),
|
2158
|
-
complete: () => {
|
2159
|
-
observer.complete();
|
2160
|
-
}
|
2161
|
-
});
|
2162
|
-
return () => {
|
2163
|
-
sub.unsubscribe();
|
2164
|
-
if (!markedAsCompleted) {
|
2165
|
-
queryControler.queryCompleted(entry);
|
2166
|
-
}
|
2167
|
-
};
|
2168
|
-
});
|
2169
|
-
};
|
2170
|
-
}
|
2171
|
-
|
2172
|
-
const allActiveGroupByVariables = /* @__PURE__ */ new Set();
|
2173
|
-
function findActiveGroupByVariablesByUid(dsUid) {
|
2174
|
-
var _a;
|
2175
|
-
for (const groupByVariable of allActiveGroupByVariables.values()) {
|
2176
|
-
if (((_a = groupByVariable.state.datasource) == null ? void 0 : _a.uid) === dsUid) {
|
2177
|
-
return groupByVariable;
|
2178
|
-
}
|
2167
|
+
if (loggingEnabled) {
|
2168
|
+
console.log(`${logger}: `, message, ...rest);
|
2179
2169
|
}
|
2180
|
-
return void 0;
|
2181
2170
|
}
|
2182
2171
|
|
2183
|
-
function
|
2184
|
-
|
2185
|
-
|
2186
|
-
|
2187
|
-
|
2172
|
+
async function getDataSource(datasource, scopedVars) {
|
2173
|
+
if (datasource == null ? void 0 : datasource.uid) {
|
2174
|
+
const runtimeDataSource = runtimeDataSources.get(datasource.uid);
|
2175
|
+
if (runtimeDataSource) {
|
2176
|
+
return runtimeDataSource;
|
2177
|
+
}
|
2178
|
+
}
|
2179
|
+
if (datasource && datasource.query) {
|
2180
|
+
return datasource;
|
2181
|
+
}
|
2182
|
+
return await runtime.getDataSourceSrv().get(datasource, scopedVars);
|
2188
2183
|
}
|
2189
2184
|
|
2190
|
-
class
|
2185
|
+
class VariableValueRecorder {
|
2191
2186
|
constructor() {
|
2192
|
-
|
2193
|
-
this._urlSync = new MultiValueUrlSyncHandler(this);
|
2194
|
-
}
|
2195
|
-
validateAndUpdate() {
|
2196
|
-
return this.getValueOptions({}).pipe(
|
2197
|
-
rxjs.map((options) => {
|
2198
|
-
this.updateValueGivenNewOptions(options);
|
2199
|
-
return {};
|
2200
|
-
})
|
2201
|
-
);
|
2202
|
-
}
|
2203
|
-
onCancel() {
|
2204
|
-
this.setStateHelper({ loading: false });
|
2205
|
-
const sceneVarSet = this.parent;
|
2206
|
-
sceneVarSet == null ? void 0 : sceneVarSet.cancel(this);
|
2207
|
-
}
|
2208
|
-
updateValueGivenNewOptions(options) {
|
2209
|
-
const { value: currentValue, text: currentText, options: oldOptions } = this.state;
|
2210
|
-
const stateUpdate = this.getStateUpdateGivenNewOptions(options, currentValue, currentText);
|
2211
|
-
this.interceptStateUpdateAfterValidation(stateUpdate);
|
2212
|
-
this.setStateHelper(stateUpdate);
|
2213
|
-
if (stateUpdate.value !== currentValue || stateUpdate.text !== currentText || this.hasAllValue() && !lodash.isEqual(options, oldOptions)) {
|
2214
|
-
this.publishEvent(new SceneVariableValueChangedEvent(this), true);
|
2215
|
-
}
|
2187
|
+
this._values = /* @__PURE__ */ new Map();
|
2216
2188
|
}
|
2217
|
-
|
2218
|
-
|
2219
|
-
|
2220
|
-
|
2221
|
-
value: currentValue,
|
2222
|
-
text: currentText
|
2223
|
-
};
|
2224
|
-
if (options.length === 0) {
|
2225
|
-
if (this.state.defaultToAll || this.state.includeAll) {
|
2226
|
-
stateUpdate.value = ALL_VARIABLE_VALUE;
|
2227
|
-
stateUpdate.text = ALL_VARIABLE_TEXT;
|
2228
|
-
} else if (this.state.isMulti) {
|
2229
|
-
stateUpdate.value = [];
|
2230
|
-
stateUpdate.text = [];
|
2231
|
-
} else {
|
2232
|
-
stateUpdate.value = "";
|
2233
|
-
stateUpdate.text = "";
|
2234
|
-
}
|
2235
|
-
return stateUpdate;
|
2236
|
-
}
|
2237
|
-
if (this.hasAllValue()) {
|
2238
|
-
if (!this.state.includeAll) {
|
2239
|
-
stateUpdate.value = options[0].value;
|
2240
|
-
stateUpdate.text = options[0].label;
|
2241
|
-
if (this.state.isMulti) {
|
2242
|
-
stateUpdate.value = [stateUpdate.value];
|
2243
|
-
stateUpdate.text = [stateUpdate.text];
|
2244
|
-
}
|
2245
|
-
}
|
2246
|
-
return stateUpdate;
|
2247
|
-
}
|
2248
|
-
if (this.state.isMulti) {
|
2249
|
-
const currentValues = Array.isArray(currentValue) ? currentValue : [currentValue];
|
2250
|
-
const validValues = currentValues.filter((v) => options.find((o) => o.value === v));
|
2251
|
-
const validTexts = validValues.map((v) => options.find((o) => o.value === v).label);
|
2252
|
-
if (validValues.length === 0) {
|
2253
|
-
const defaultState = this.getDefaultMultiState(options);
|
2254
|
-
stateUpdate.value = defaultState.value;
|
2255
|
-
stateUpdate.text = defaultState.text;
|
2256
|
-
} else {
|
2257
|
-
if (!lodash.isEqual(validValues, currentValue)) {
|
2258
|
-
stateUpdate.value = validValues;
|
2259
|
-
}
|
2260
|
-
if (!lodash.isEqual(validTexts, currentText)) {
|
2261
|
-
stateUpdate.text = validTexts;
|
2262
|
-
}
|
2263
|
-
}
|
2264
|
-
return stateUpdate;
|
2189
|
+
recordCurrentDependencyValuesForSceneObject(sceneObject) {
|
2190
|
+
this.clearValues();
|
2191
|
+
if (!sceneObject.variableDependency) {
|
2192
|
+
return;
|
2265
2193
|
}
|
2266
|
-
|
2267
|
-
|
2268
|
-
|
2269
|
-
|
2270
|
-
} else {
|
2271
|
-
if (this.state.defaultToAll) {
|
2272
|
-
stateUpdate.value = ALL_VARIABLE_VALUE;
|
2273
|
-
stateUpdate.text = ALL_VARIABLE_TEXT;
|
2274
|
-
} else {
|
2275
|
-
stateUpdate.value = options[0].value;
|
2276
|
-
stateUpdate.text = options[0].label;
|
2194
|
+
for (const variableName of sceneObject.variableDependency.getNames()) {
|
2195
|
+
const variable = sceneGraph.lookupVariable(variableName, sceneObject);
|
2196
|
+
if (variable) {
|
2197
|
+
this._values.set(variable.state.name, variable.getValue());
|
2277
2198
|
}
|
2278
2199
|
}
|
2279
|
-
return stateUpdate;
|
2280
2200
|
}
|
2281
|
-
|
2282
|
-
const
|
2283
|
-
|
2284
|
-
|
2285
|
-
stateUpdate.text = this.state.text;
|
2286
|
-
}
|
2287
|
-
this.skipNextValidation = false;
|
2201
|
+
cloneAndRecordCurrentValuesForSceneObject(sceneObject) {
|
2202
|
+
const clone = new VariableValueRecorder();
|
2203
|
+
clone.recordCurrentDependencyValuesForSceneObject(sceneObject);
|
2204
|
+
return clone;
|
2288
2205
|
}
|
2289
|
-
|
2290
|
-
|
2291
|
-
|
2292
|
-
|
2206
|
+
clearValues() {
|
2207
|
+
this._values.clear();
|
2208
|
+
}
|
2209
|
+
hasValues() {
|
2210
|
+
return !!this._values;
|
2211
|
+
}
|
2212
|
+
recordCurrentValue(variable) {
|
2213
|
+
this._values.set(variable.state.name, variable.getValue());
|
2214
|
+
}
|
2215
|
+
hasRecordedValue(variable) {
|
2216
|
+
return this._values.has(variable.state.name);
|
2217
|
+
}
|
2218
|
+
hasValueChanged(variable) {
|
2219
|
+
if (this._values.has(variable.state.name)) {
|
2220
|
+
const value = this._values.get(variable.state.name);
|
2221
|
+
if (!isVariableValueEqual(value, variable.getValue())) {
|
2222
|
+
return true;
|
2293
2223
|
}
|
2294
|
-
return this.state.options.map((x) => x.value);
|
2295
2224
|
}
|
2296
|
-
return
|
2225
|
+
return false;
|
2297
2226
|
}
|
2298
|
-
|
2299
|
-
if (this.
|
2300
|
-
return
|
2227
|
+
hasDependenciesChanged(sceneObject) {
|
2228
|
+
if (!this._values) {
|
2229
|
+
return false;
|
2301
2230
|
}
|
2302
|
-
if (
|
2303
|
-
return
|
2231
|
+
if (!sceneObject.variableDependency) {
|
2232
|
+
return false;
|
2304
2233
|
}
|
2305
|
-
|
2306
|
-
|
2307
|
-
|
2308
|
-
|
2309
|
-
|
2310
|
-
|
2311
|
-
|
2312
|
-
|
2313
|
-
|
2314
|
-
|
2315
|
-
|
2316
|
-
|
2317
|
-
return { value: [], text: [] };
|
2234
|
+
for (const variableName of sceneObject.variableDependency.getNames()) {
|
2235
|
+
const variable = sceneGraph.lookupVariable(variableName, sceneObject);
|
2236
|
+
if (!variable) {
|
2237
|
+
continue;
|
2238
|
+
}
|
2239
|
+
const name = variable.state.name;
|
2240
|
+
if (variable && this._values.has(name)) {
|
2241
|
+
const value = this._values.get(name);
|
2242
|
+
if (!isVariableValueEqual(value, variable.getValue())) {
|
2243
|
+
return true;
|
2244
|
+
}
|
2245
|
+
}
|
2318
2246
|
}
|
2247
|
+
return false;
|
2319
2248
|
}
|
2320
|
-
|
2321
|
-
|
2322
|
-
|
2249
|
+
}
|
2250
|
+
|
2251
|
+
function isExtraQueryProvider(obj) {
|
2252
|
+
return typeof obj === "object" && "getExtraQueries" in obj;
|
2253
|
+
}
|
2254
|
+
|
2255
|
+
var __defProp$G = Object.defineProperty;
|
2256
|
+
var __defProps$r = Object.defineProperties;
|
2257
|
+
var __getOwnPropDescs$r = Object.getOwnPropertyDescriptors;
|
2258
|
+
var __getOwnPropSymbols$G = Object.getOwnPropertySymbols;
|
2259
|
+
var __hasOwnProp$G = Object.prototype.hasOwnProperty;
|
2260
|
+
var __propIsEnum$G = Object.prototype.propertyIsEnumerable;
|
2261
|
+
var __defNormalProp$G = (obj, key, value) => key in obj ? __defProp$G(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
2262
|
+
var __spreadValues$G = (a, b) => {
|
2263
|
+
for (var prop in b || (b = {}))
|
2264
|
+
if (__hasOwnProp$G.call(b, prop))
|
2265
|
+
__defNormalProp$G(a, prop, b[prop]);
|
2266
|
+
if (__getOwnPropSymbols$G)
|
2267
|
+
for (var prop of __getOwnPropSymbols$G(b)) {
|
2268
|
+
if (__propIsEnum$G.call(b, prop))
|
2269
|
+
__defNormalProp$G(a, prop, b[prop]);
|
2323
2270
|
}
|
2324
|
-
|
2325
|
-
|
2326
|
-
|
2327
|
-
|
2328
|
-
|
2329
|
-
|
2271
|
+
return a;
|
2272
|
+
};
|
2273
|
+
var __spreadProps$r = (a, b) => __defProps$r(a, __getOwnPropDescs$r(b));
|
2274
|
+
const passthroughProcessor = (_, secondary) => rxjs.of(secondary);
|
2275
|
+
const extraQueryProcessingOperator = (processors) => (data) => {
|
2276
|
+
return data.pipe(
|
2277
|
+
rxjs.mergeMap(([primary, ...secondaries]) => {
|
2278
|
+
const processedSecondaries = secondaries.flatMap((s) => {
|
2279
|
+
var _a, _b;
|
2280
|
+
return (_b = (_a = processors.get(s.request.requestId)) == null ? void 0 : _a(primary, s)) != null ? _b : rxjs.of(s);
|
2281
|
+
});
|
2282
|
+
return rxjs.forkJoin([rxjs.of(primary), ...processedSecondaries]);
|
2283
|
+
}),
|
2284
|
+
rxjs.map(([primary, ...processedSecondaries]) => {
|
2285
|
+
var _a;
|
2286
|
+
return __spreadProps$r(__spreadValues$G({}, primary), {
|
2287
|
+
series: [...primary.series, ...processedSecondaries.flatMap((s) => s.series)],
|
2288
|
+
annotations: [...(_a = primary.annotations) != null ? _a : [], ...processedSecondaries.flatMap((s) => {
|
2289
|
+
var _a2;
|
2290
|
+
return (_a2 = s.annotations) != null ? _a2 : [];
|
2291
|
+
})]
|
2292
|
+
});
|
2293
|
+
})
|
2294
|
+
);
|
2295
|
+
};
|
2296
|
+
|
2297
|
+
var __defProp$F = Object.defineProperty;
|
2298
|
+
var __defProps$q = Object.defineProperties;
|
2299
|
+
var __getOwnPropDescs$q = Object.getOwnPropertyDescriptors;
|
2300
|
+
var __getOwnPropSymbols$F = Object.getOwnPropertySymbols;
|
2301
|
+
var __hasOwnProp$F = Object.prototype.hasOwnProperty;
|
2302
|
+
var __propIsEnum$F = Object.prototype.propertyIsEnumerable;
|
2303
|
+
var __defNormalProp$F = (obj, key, value) => key in obj ? __defProp$F(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
2304
|
+
var __spreadValues$F = (a, b) => {
|
2305
|
+
for (var prop in b || (b = {}))
|
2306
|
+
if (__hasOwnProp$F.call(b, prop))
|
2307
|
+
__defNormalProp$F(a, prop, b[prop]);
|
2308
|
+
if (__getOwnPropSymbols$F)
|
2309
|
+
for (var prop of __getOwnPropSymbols$F(b)) {
|
2310
|
+
if (__propIsEnum$F.call(b, prop))
|
2311
|
+
__defNormalProp$F(a, prop, b[prop]);
|
2330
2312
|
}
|
2331
|
-
|
2332
|
-
|
2333
|
-
|
2334
|
-
|
2335
|
-
|
2313
|
+
return a;
|
2314
|
+
};
|
2315
|
+
var __spreadProps$q = (a, b) => __defProps$q(a, __getOwnPropDescs$q(b));
|
2316
|
+
function filterAnnotations(data, filters) {
|
2317
|
+
var _a;
|
2318
|
+
if (!Array.isArray(data) || data.length === 0) {
|
2319
|
+
return data;
|
2320
|
+
}
|
2321
|
+
const rows = Array.from({ length: data.length }, () => /* @__PURE__ */ new Set());
|
2322
|
+
let frameIdx = 0;
|
2323
|
+
for (const frame of data) {
|
2324
|
+
for (let index = 0; index < frame.length; index++) {
|
2325
|
+
if (rows[frameIdx].has(index)) {
|
2326
|
+
continue;
|
2336
2327
|
}
|
2337
|
-
|
2338
|
-
|
2339
|
-
|
2340
|
-
|
2341
|
-
|
2342
|
-
|
2343
|
-
|
2328
|
+
let matching = true;
|
2329
|
+
const panelIdField = frame.fields.find((f) => f.name === "panelId");
|
2330
|
+
const sourceField = frame.fields.find((f) => f.name === "source");
|
2331
|
+
if (sourceField) {
|
2332
|
+
if (panelIdField && sourceField.values[index].type === "dashboard") {
|
2333
|
+
matching = panelIdField.values[index] === filters.panelId;
|
2334
|
+
}
|
2335
|
+
const sourceFilter = sourceField.values[index].filter;
|
2336
|
+
if (sourceFilter) {
|
2337
|
+
const includes = ((_a = sourceFilter.ids) != null ? _a : []).includes(filters.panelId);
|
2338
|
+
if (sourceFilter.exclude) {
|
2339
|
+
if (includes) {
|
2340
|
+
matching = false;
|
2341
|
+
}
|
2342
|
+
} else if (!includes) {
|
2343
|
+
matching = false;
|
2344
|
+
}
|
2344
2345
|
}
|
2345
2346
|
}
|
2347
|
+
if (matching) {
|
2348
|
+
rows[frameIdx].add(index);
|
2349
|
+
}
|
2346
2350
|
}
|
2347
|
-
|
2348
|
-
return;
|
2349
|
-
}
|
2350
|
-
this.setStateHelper({ value, text, loading: false });
|
2351
|
-
this.publishEvent(new SceneVariableValueChangedEvent(this), true);
|
2352
|
-
}
|
2353
|
-
findLabelTextForValue(value) {
|
2354
|
-
if (value === ALL_VARIABLE_VALUE) {
|
2355
|
-
return ALL_VARIABLE_TEXT;
|
2356
|
-
}
|
2357
|
-
const option = this.state.options.find((x) => x.value === value);
|
2358
|
-
if (option) {
|
2359
|
-
return option.label;
|
2360
|
-
}
|
2361
|
-
const optionByLabel = this.state.options.find((x) => x.label === value);
|
2362
|
-
if (optionByLabel) {
|
2363
|
-
return optionByLabel.label;
|
2364
|
-
}
|
2365
|
-
return value;
|
2366
|
-
}
|
2367
|
-
setStateHelper(state) {
|
2368
|
-
setBaseClassState(this, state);
|
2351
|
+
frameIdx++;
|
2369
2352
|
}
|
2370
|
-
|
2371
|
-
|
2372
|
-
|
2373
|
-
|
2374
|
-
|
2375
|
-
|
2376
|
-
const
|
2377
|
-
|
2378
|
-
|
2353
|
+
const processed = [];
|
2354
|
+
frameIdx = 0;
|
2355
|
+
for (const frame of data) {
|
2356
|
+
const frameLength = rows[frameIdx].size;
|
2357
|
+
const fields = [];
|
2358
|
+
for (const field of frame.fields) {
|
2359
|
+
const buffer = [];
|
2360
|
+
for (let index = 0; index < frame.length; index++) {
|
2361
|
+
if (rows[frameIdx].has(index)) {
|
2362
|
+
buffer.push(field.values[index]);
|
2363
|
+
continue;
|
2364
|
+
}
|
2379
2365
|
}
|
2366
|
+
fields.push(__spreadProps$q(__spreadValues$F({}, field), {
|
2367
|
+
values: buffer
|
2368
|
+
}));
|
2380
2369
|
}
|
2381
|
-
|
2382
|
-
|
2383
|
-
|
2384
|
-
|
2385
|
-
|
2386
|
-
});
|
2370
|
+
processed.push(__spreadProps$q(__spreadValues$F({}, frame), {
|
2371
|
+
fields,
|
2372
|
+
length: frameLength
|
2373
|
+
}));
|
2374
|
+
frameIdx++;
|
2387
2375
|
}
|
2376
|
+
return processed;
|
2388
2377
|
}
|
2389
|
-
|
2390
|
-
|
2391
|
-
|
2392
|
-
|
2393
|
-
|
2394
|
-
}
|
2395
|
-
if (item.label === currentText) {
|
2396
|
-
textMatch = item;
|
2397
|
-
}
|
2378
|
+
|
2379
|
+
function getEnrichedDataRequest(sourceRunner) {
|
2380
|
+
const root = sourceRunner.getRoot();
|
2381
|
+
if (isDataRequestEnricher(root)) {
|
2382
|
+
return root.enrichDataRequest(sourceRunner);
|
2398
2383
|
}
|
2399
|
-
return
|
2384
|
+
return null;
|
2400
2385
|
}
|
2401
|
-
|
2402
|
-
|
2403
|
-
|
2404
|
-
|
2405
|
-
|
2406
|
-
|
2386
|
+
|
2387
|
+
let originalGetAdhocFilters = void 0;
|
2388
|
+
let allActiveFilterSets = /* @__PURE__ */ new Set();
|
2389
|
+
function patchGetAdhocFilters(filterVar) {
|
2390
|
+
filterVar.addActivationHandler(() => {
|
2391
|
+
allActiveFilterSets.add(filterVar);
|
2392
|
+
return () => allActiveFilterSets.delete(filterVar);
|
2393
|
+
});
|
2394
|
+
if (originalGetAdhocFilters) {
|
2395
|
+
return;
|
2407
2396
|
}
|
2408
|
-
|
2409
|
-
|
2410
|
-
|
2411
|
-
|
2412
|
-
return [this.getKey()];
|
2397
|
+
const templateSrv = runtime.getTemplateSrv();
|
2398
|
+
if (!(templateSrv == null ? void 0 : templateSrv.getAdhocFilters)) {
|
2399
|
+
console.log("Failed to patch getAdhocFilters");
|
2400
|
+
return;
|
2413
2401
|
}
|
2414
|
-
|
2415
|
-
|
2416
|
-
|
2402
|
+
originalGetAdhocFilters = templateSrv.getAdhocFilters;
|
2403
|
+
templateSrv.getAdhocFilters = function getAdhocFiltersScenePatch(dsName) {
|
2404
|
+
var _a;
|
2405
|
+
if (allActiveFilterSets.size === 0) {
|
2406
|
+
return originalGetAdhocFilters.call(templateSrv);
|
2417
2407
|
}
|
2418
|
-
|
2419
|
-
|
2420
|
-
|
2421
|
-
urlValue = value.map(String);
|
2422
|
-
} else if (this._sceneObject.state.isMulti) {
|
2423
|
-
urlValue = [String(value)];
|
2424
|
-
} else {
|
2425
|
-
urlValue = String(value);
|
2408
|
+
const ds = runtime.getDataSourceSrv().getInstanceSettings(dsName);
|
2409
|
+
if (!ds) {
|
2410
|
+
return [];
|
2426
2411
|
}
|
2427
|
-
|
2428
|
-
|
2429
|
-
|
2430
|
-
let urlValue = values[this.getKey()];
|
2431
|
-
if (urlValue != null) {
|
2432
|
-
if (this._sceneObject.state.includeAll) {
|
2433
|
-
urlValue = handleLegacyUrlAllValue(urlValue);
|
2434
|
-
}
|
2435
|
-
if (this._sceneObject.state.allValue && this._sceneObject.state.allValue === urlValue) {
|
2436
|
-
urlValue = ALL_VARIABLE_VALUE;
|
2437
|
-
}
|
2438
|
-
if (!this._sceneObject.isActive) {
|
2439
|
-
this._sceneObject.skipNextValidation = true;
|
2412
|
+
for (const filter of allActiveFilterSets.values()) {
|
2413
|
+
if (((_a = filter.state.datasource) == null ? void 0 : _a.uid) === ds.uid) {
|
2414
|
+
return filter.state.filters;
|
2440
2415
|
}
|
2441
|
-
this._sceneObject.changeValueTo(urlValue);
|
2442
2416
|
}
|
2443
|
-
|
2417
|
+
return [];
|
2418
|
+
}.bind(templateSrv);
|
2444
2419
|
}
|
2445
|
-
function
|
2446
|
-
|
2447
|
-
|
2448
|
-
|
2449
|
-
|
2420
|
+
function findActiveAdHocFilterVariableByUid(dsUid) {
|
2421
|
+
var _a;
|
2422
|
+
for (const filter of allActiveFilterSets.values()) {
|
2423
|
+
if (((_a = filter.state.datasource) == null ? void 0 : _a.uid) === dsUid) {
|
2424
|
+
return filter;
|
2425
|
+
}
|
2450
2426
|
}
|
2451
|
-
return
|
2427
|
+
return void 0;
|
2452
2428
|
}
|
2453
|
-
|
2454
|
-
|
2455
|
-
|
2456
|
-
|
2457
|
-
|
2458
|
-
|
2459
|
-
if (formatNameOrFn === schema.VariableFormatID.Text) {
|
2460
|
-
return ALL_VARIABLE_TEXT;
|
2461
|
-
}
|
2462
|
-
if (formatNameOrFn === schema.VariableFormatID.PercentEncode) {
|
2463
|
-
return formatRegistry.get(schema.VariableFormatID.PercentEncode).formatter(this._value, [], this._variable);
|
2429
|
+
|
2430
|
+
function registerQueryWithController(entry) {
|
2431
|
+
return (queryStream) => {
|
2432
|
+
const queryControler = sceneGraph.getQueryController(entry.origin);
|
2433
|
+
if (!queryControler) {
|
2434
|
+
return queryStream;
|
2464
2435
|
}
|
2465
|
-
|
2466
|
-
|
2436
|
+
return new rxjs.Observable((observer) => {
|
2437
|
+
if (!entry.cancel) {
|
2438
|
+
entry.cancel = () => observer.complete();
|
2439
|
+
}
|
2440
|
+
queryControler.queryStarted(entry);
|
2441
|
+
let markedAsCompleted = false;
|
2442
|
+
const sub = queryStream.subscribe({
|
2443
|
+
next: (v) => {
|
2444
|
+
if (!markedAsCompleted && v.state !== schema.LoadingState.Loading) {
|
2445
|
+
markedAsCompleted = true;
|
2446
|
+
queryControler.queryCompleted(entry);
|
2447
|
+
}
|
2448
|
+
observer.next(v);
|
2449
|
+
},
|
2450
|
+
error: (e) => observer.error(e),
|
2451
|
+
complete: () => {
|
2452
|
+
observer.complete();
|
2453
|
+
}
|
2454
|
+
});
|
2455
|
+
return () => {
|
2456
|
+
sub.unsubscribe();
|
2457
|
+
if (!markedAsCompleted) {
|
2458
|
+
queryControler.queryCompleted(entry);
|
2459
|
+
}
|
2460
|
+
};
|
2461
|
+
});
|
2462
|
+
};
|
2463
|
+
}
|
2464
|
+
|
2465
|
+
const allActiveGroupByVariables = /* @__PURE__ */ new Set();
|
2466
|
+
function findActiveGroupByVariablesByUid(dsUid) {
|
2467
|
+
var _a;
|
2468
|
+
for (const groupByVariable of allActiveGroupByVariables.values()) {
|
2469
|
+
if (((_a = groupByVariable.state.datasource) == null ? void 0 : _a.uid) === dsUid) {
|
2470
|
+
return groupByVariable;
|
2467
2471
|
}
|
2468
|
-
return this._value;
|
2469
2472
|
}
|
2473
|
+
return void 0;
|
2470
2474
|
}
|
2471
2475
|
|
2472
2476
|
function getOptionSearcher(options, includeAll) {
|
@@ -10377,6 +10381,7 @@ const getSceneGridRowStyles = (theme) => {
|
|
10377
10381
|
cursor: "pointer",
|
10378
10382
|
background: "transparent",
|
10379
10383
|
border: "none",
|
10384
|
+
minWidth: 0,
|
10380
10385
|
gap: theme.spacing(1)
|
10381
10386
|
}),
|
10382
10387
|
rowCollapsed: css.css({
|
@@ -10384,7 +10389,13 @@ const getSceneGridRowStyles = (theme) => {
|
|
10384
10389
|
}),
|
10385
10390
|
rowTitle: css.css({
|
10386
10391
|
fontSize: theme.typography.h5.fontSize,
|
10387
|
-
fontWeight: theme.typography.fontWeightMedium
|
10392
|
+
fontWeight: theme.typography.fontWeightMedium,
|
10393
|
+
whiteSpace: "nowrap",
|
10394
|
+
overflow: "hidden",
|
10395
|
+
textOverflow: "ellipsis",
|
10396
|
+
maxWidth: "100%",
|
10397
|
+
flexGrow: 1,
|
10398
|
+
minWidth: 0
|
10388
10399
|
}),
|
10389
10400
|
collapsedInfo: css.css({
|
10390
10401
|
fontSize: theme.typography.bodySmall.fontSize,
|
@@ -10395,6 +10406,7 @@ const getSceneGridRowStyles = (theme) => {
|
|
10395
10406
|
}),
|
10396
10407
|
rowTitleAndActionsGroup: css.css({
|
10397
10408
|
display: "flex",
|
10409
|
+
minWidth: 0,
|
10398
10410
|
"&:hover, &:focus-within": {
|
10399
10411
|
"& > div": {
|
10400
10412
|
opacity: 1
|
@@ -10403,6 +10415,7 @@ const getSceneGridRowStyles = (theme) => {
|
|
10403
10415
|
}),
|
10404
10416
|
rowActions: css.css({
|
10405
10417
|
display: "flex",
|
10418
|
+
whiteSpace: "nowrap",
|
10406
10419
|
opacity: 0,
|
10407
10420
|
transition: "200ms opacity ease-in 200ms",
|
10408
10421
|
"&:hover, &:focus-within": {
|
@@ -10421,6 +10434,7 @@ const getSceneGridRowStyles = (theme) => {
|
|
10421
10434
|
}
|
10422
10435
|
}),
|
10423
10436
|
panelCount: css.css({
|
10437
|
+
whiteSpace: "nowrap",
|
10424
10438
|
paddingLeft: theme.spacing(2),
|
10425
10439
|
color: theme.colors.text.secondary,
|
10426
10440
|
fontStyle: "italic",
|