@grafana/scenes 6.27.0 → 6.27.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +31 -0
- package/dist/esm/variables/interpolation/formatRegistry.js +30 -0
- package/dist/esm/variables/interpolation/formatRegistry.js.map +1 -1
- package/dist/esm/variables/variants/MultiValueVariable.js +10 -3
- package/dist/esm/variables/variants/MultiValueVariable.js.map +1 -1
- package/dist/esm/variables/variants/TextBoxVariable.js +10 -1
- package/dist/esm/variables/variants/TextBoxVariable.js.map +1 -1
- package/dist/esm/variables/variants/query/QueryVariable.js +14 -2
- package/dist/esm/variables/variants/query/QueryVariable.js.map +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +63 -5
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
@@ -1504,6 +1504,20 @@ const formatRegistry = new data.Registry(() => {
|
|
1504
1504
|
description: "SQL string quoting and commas for use in IN statements and other scenarios",
|
1505
1505
|
formatter: sqlStringFormatter
|
1506
1506
|
},
|
1507
|
+
{
|
1508
|
+
id: "join",
|
1509
|
+
// join not yet available in depended @grafana/schema version
|
1510
|
+
name: "Join",
|
1511
|
+
description: "Join values with a comma",
|
1512
|
+
formatter: (value, args) => {
|
1513
|
+
var _a;
|
1514
|
+
if (lodash.isArray(value)) {
|
1515
|
+
const separator = (_a = args[0]) != null ? _a : ",";
|
1516
|
+
return value.join(separator);
|
1517
|
+
}
|
1518
|
+
return String(value);
|
1519
|
+
}
|
1520
|
+
},
|
1507
1521
|
{
|
1508
1522
|
id: schema.VariableFormatID.Date,
|
1509
1523
|
name: "Date",
|
@@ -1578,6 +1592,19 @@ const formatRegistry = new data.Registry(() => {
|
|
1578
1592
|
return formatQueryParameter(variable.state.name, value);
|
1579
1593
|
}
|
1580
1594
|
},
|
1595
|
+
{
|
1596
|
+
id: "customqueryparam",
|
1597
|
+
name: "Custom query parameter",
|
1598
|
+
description: "Format variables as URL parameters with custom name and value prefix. Example in multi-variable scenario A + B + C => p-foo=x-A&p-foo=x-B&p-foo=x-C.",
|
1599
|
+
formatter: (value, args, variable) => {
|
1600
|
+
const name = encodeURIComponentStrict(args[0] || variable.state.name);
|
1601
|
+
const valuePrefix = encodeURIComponentStrict(args[1] || "");
|
1602
|
+
if (Array.isArray(value)) {
|
1603
|
+
return value.map((v) => customFormatQueryParameter(name, v, valuePrefix)).join("&");
|
1604
|
+
}
|
1605
|
+
return customFormatQueryParameter(name, value, valuePrefix);
|
1606
|
+
}
|
1607
|
+
},
|
1581
1608
|
{
|
1582
1609
|
id: schema.VariableFormatID.UriEncode,
|
1583
1610
|
name: "Percent encode as URI",
|
@@ -1614,6 +1641,9 @@ const replaceSpecialCharactersToASCII = (value) => value.replace(/[!'()*]/g, (c)
|
|
1614
1641
|
function formatQueryParameter(name, value) {
|
1615
1642
|
return `var-${name}=${encodeURIComponentStrict(value)}`;
|
1616
1643
|
}
|
1644
|
+
function customFormatQueryParameter(name, value, valuePrefix = "") {
|
1645
|
+
return `${name}=${valuePrefix}${encodeURIComponentStrict(value)}`;
|
1646
|
+
}
|
1617
1647
|
const SQL_ESCAPE_MAP = {
|
1618
1648
|
"'": "''",
|
1619
1649
|
'"': '\\"'
|
@@ -1835,14 +1865,21 @@ class MultiValueVariable extends SceneObjectBase {
|
|
1835
1865
|
}
|
1836
1866
|
this.skipNextValidation = false;
|
1837
1867
|
}
|
1838
|
-
getValue() {
|
1868
|
+
getValue(fieldPath) {
|
1869
|
+
let value = this.state.value;
|
1839
1870
|
if (this.hasAllValue()) {
|
1840
1871
|
if (this.state.allValue) {
|
1841
1872
|
return new CustomAllValue(this.state.allValue, this);
|
1842
1873
|
}
|
1843
|
-
|
1874
|
+
value = this.state.options.map((x) => x.value);
|
1844
1875
|
}
|
1845
|
-
|
1876
|
+
if (fieldPath != null && Array.isArray(value)) {
|
1877
|
+
const index = parseInt(fieldPath, 10);
|
1878
|
+
if (!isNaN(index) && index >= 0 && index < value.length) {
|
1879
|
+
return value[index];
|
1880
|
+
}
|
1881
|
+
}
|
1882
|
+
return value;
|
1846
1883
|
}
|
1847
1884
|
getValueText() {
|
1848
1885
|
if (this.hasAllValue()) {
|
@@ -7354,7 +7391,19 @@ class QueryVariable extends MultiValueVariable {
|
|
7354
7391
|
if (this.state.regex) {
|
7355
7392
|
regex = sceneGraph.interpolate(this, this.state.regex, void 0, "regex");
|
7356
7393
|
}
|
7357
|
-
|
7394
|
+
let options = metricNamesToVariableValues(regex, this.state.sort, values);
|
7395
|
+
if (this.state.staticOptions) {
|
7396
|
+
const customOptions = this.state.staticOptions;
|
7397
|
+
options = options.filter((option) => !customOptions.find((custom) => custom.value === option.value));
|
7398
|
+
if (this.state.staticOptionsOrder === "after") {
|
7399
|
+
options.push(...customOptions);
|
7400
|
+
} else if (this.state.staticOptionsOrder === "sorted") {
|
7401
|
+
options = sortVariableValues(options.concat(customOptions), this.state.sort);
|
7402
|
+
} else {
|
7403
|
+
options.unshift(...customOptions);
|
7404
|
+
}
|
7405
|
+
}
|
7406
|
+
return rxjs.of(options);
|
7358
7407
|
}),
|
7359
7408
|
rxjs.catchError((error) => {
|
7360
7409
|
if (error.cancelled) {
|
@@ -10424,7 +10473,7 @@ class TextBoxVariable extends SceneObjectBase {
|
|
10424
10473
|
name: "",
|
10425
10474
|
...initialState
|
10426
10475
|
});
|
10427
|
-
this._urlSync = new SceneObjectUrlSyncConfig(this, { keys: () =>
|
10476
|
+
this._urlSync = new SceneObjectUrlSyncConfig(this, { keys: () => this.getKeys() });
|
10428
10477
|
}
|
10429
10478
|
getValue() {
|
10430
10479
|
return this.state.value;
|
@@ -10438,7 +10487,16 @@ class TextBoxVariable extends SceneObjectBase {
|
|
10438
10487
|
getKey() {
|
10439
10488
|
return `var-${this.state.name}`;
|
10440
10489
|
}
|
10490
|
+
getKeys() {
|
10491
|
+
if (this.state.skipUrlSync) {
|
10492
|
+
return [];
|
10493
|
+
}
|
10494
|
+
return [this.getKey()];
|
10495
|
+
}
|
10441
10496
|
getUrlState() {
|
10497
|
+
if (this.state.skipUrlSync) {
|
10498
|
+
return {};
|
10499
|
+
}
|
10442
10500
|
return { [this.getKey()]: this.state.value };
|
10443
10501
|
}
|
10444
10502
|
updateFromUrl(values) {
|