@grafana/scenes 4.25.0--canary.753.9269482662.0 → 4.25.0--canary.758.9288152473.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +13 -0
- package/dist/esm/core/sceneGraph/index.js +1 -3
- package/dist/esm/core/sceneGraph/index.js.map +1 -1
- package/dist/esm/core/sceneGraph/sceneGraph.js +1 -22
- package/dist/esm/core/sceneGraph/sceneGraph.js.map +1 -1
- package/dist/esm/variables/adhoc/AdHocFiltersVariable.js +23 -2
- package/dist/esm/variables/adhoc/AdHocFiltersVariable.js.map +1 -1
- package/dist/esm/variables/variants/MultiValueVariable.js +34 -17
- package/dist/esm/variables/variants/MultiValueVariable.js.map +1 -1
- package/dist/index.d.ts +1 -17
- package/dist/index.js +57 -42
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
@@ -1532,27 +1532,6 @@ function findObjectInternal(scene, check, alreadySearchedChild, shouldSearchUp)
|
|
1532
1532
|
}
|
1533
1533
|
return null;
|
1534
1534
|
}
|
1535
|
-
function findByKey(sceneObject, key) {
|
1536
|
-
const found = findObject(sceneObject, (sceneToCheck) => {
|
1537
|
-
return sceneToCheck.state.key === key;
|
1538
|
-
});
|
1539
|
-
if (!found) {
|
1540
|
-
throw new Error("Unable to find scene with key " + key);
|
1541
|
-
}
|
1542
|
-
return found;
|
1543
|
-
}
|
1544
|
-
function findByKeyAndType(sceneObject, key, targetType) {
|
1545
|
-
const found = findObject(sceneObject, (sceneToCheck) => {
|
1546
|
-
return sceneToCheck.state.key === key;
|
1547
|
-
});
|
1548
|
-
if (!found) {
|
1549
|
-
throw new Error("Unable to find scene with key " + key);
|
1550
|
-
}
|
1551
|
-
if (!(found instanceof targetType)) {
|
1552
|
-
throw new Error(`Found scene object with key ${key} does not match type ${targetType.name}`);
|
1553
|
-
}
|
1554
|
-
return found;
|
1555
|
-
}
|
1556
1535
|
function findObject(scene, check) {
|
1557
1536
|
return findObjectInternal(scene, check, void 0, true);
|
1558
1537
|
}
|
@@ -2043,8 +2022,6 @@ const sceneGraph = {
|
|
2043
2022
|
interpolate,
|
2044
2023
|
lookupVariable,
|
2045
2024
|
hasVariableDependencyInLoadingState,
|
2046
|
-
findByKey,
|
2047
|
-
findByKeyAndType,
|
2048
2025
|
findObject,
|
2049
2026
|
findAllObjects,
|
2050
2027
|
getAncestor,
|
@@ -2682,6 +2659,14 @@ class MultiValueVariable extends SceneObjectBase {
|
|
2682
2659
|
}
|
2683
2660
|
updateValueGivenNewOptions(options) {
|
2684
2661
|
const { value: currentValue, text: currentText } = this.state;
|
2662
|
+
const stateUpdate = this.getStateUpdateGivenNewOptions(options, currentValue, currentText);
|
2663
|
+
this.interceptStateUpdateAfterValidation(stateUpdate);
|
2664
|
+
this.setStateHelper(stateUpdate);
|
2665
|
+
if (stateUpdate.value !== currentValue || stateUpdate.text !== currentText || this.hasAllValue()) {
|
2666
|
+
this.publishEvent(new SceneVariableValueChangedEvent(this), true);
|
2667
|
+
}
|
2668
|
+
}
|
2669
|
+
getStateUpdateGivenNewOptions(options, currentValue, currentText) {
|
2685
2670
|
const stateUpdate = {
|
2686
2671
|
options,
|
2687
2672
|
loading: false,
|
@@ -2699,7 +2684,20 @@ class MultiValueVariable extends SceneObjectBase {
|
|
2699
2684
|
stateUpdate.value = "";
|
2700
2685
|
stateUpdate.text = "";
|
2701
2686
|
}
|
2702
|
-
|
2687
|
+
return stateUpdate;
|
2688
|
+
}
|
2689
|
+
if (this.hasAllValue()) {
|
2690
|
+
if (!this.state.includeAll) {
|
2691
|
+
stateUpdate.value = options[0].value;
|
2692
|
+
stateUpdate.text = options[0].label;
|
2693
|
+
if (this.state.isMulti) {
|
2694
|
+
stateUpdate.value = [stateUpdate.value];
|
2695
|
+
stateUpdate.text = [stateUpdate.text];
|
2696
|
+
}
|
2697
|
+
}
|
2698
|
+
return stateUpdate;
|
2699
|
+
}
|
2700
|
+
if (this.state.isMulti) {
|
2703
2701
|
const currentValues = Array.isArray(currentValue) ? currentValue : [currentValue];
|
2704
2702
|
const validValues = currentValues.filter((v) => options.find((o) => o.value === v));
|
2705
2703
|
const validTexts = validValues.map((v) => options.find((o) => o.value === v).label);
|
@@ -2715,26 +2713,22 @@ class MultiValueVariable extends SceneObjectBase {
|
|
2715
2713
|
stateUpdate.text = validTexts;
|
2716
2714
|
}
|
2717
2715
|
}
|
2716
|
+
return stateUpdate;
|
2717
|
+
}
|
2718
|
+
let matchingOption = findOptionMatchingCurrent(currentValue, currentText, options);
|
2719
|
+
if (matchingOption) {
|
2720
|
+
stateUpdate.text = matchingOption.label;
|
2721
|
+
stateUpdate.value = matchingOption.value;
|
2718
2722
|
} else {
|
2719
|
-
|
2720
|
-
|
2721
|
-
stateUpdate.text =
|
2722
|
-
stateUpdate.value = matchingOption.value;
|
2723
|
+
if (this.state.defaultToAll) {
|
2724
|
+
stateUpdate.value = ALL_VARIABLE_VALUE;
|
2725
|
+
stateUpdate.text = ALL_VARIABLE_TEXT;
|
2723
2726
|
} else {
|
2724
|
-
|
2725
|
-
|
2726
|
-
stateUpdate.text = ALL_VARIABLE_TEXT;
|
2727
|
-
} else {
|
2728
|
-
stateUpdate.value = options[0].value;
|
2729
|
-
stateUpdate.text = options[0].label;
|
2730
|
-
}
|
2727
|
+
stateUpdate.value = options[0].value;
|
2728
|
+
stateUpdate.text = options[0].label;
|
2731
2729
|
}
|
2732
2730
|
}
|
2733
|
-
|
2734
|
-
this.setStateHelper(stateUpdate);
|
2735
|
-
if (stateUpdate.value !== currentValue || stateUpdate.text !== currentText || this.hasAllValue()) {
|
2736
|
-
this.publishEvent(new SceneVariableValueChangedEvent(this), true);
|
2737
|
-
}
|
2731
|
+
return stateUpdate;
|
2738
2732
|
}
|
2739
2733
|
interceptStateUpdateAfterValidation(stateUpdate) {
|
2740
2734
|
const isAllValueFix = stateUpdate.value === ALL_VARIABLE_VALUE && this.state.text === ALL_VARIABLE_TEXT;
|
@@ -3800,7 +3794,7 @@ class AdHocFiltersVariable extends SceneObjectBase {
|
|
3800
3794
|
var _a, _b, _c;
|
3801
3795
|
const override = await ((_b = (_a = this.state).getTagValuesProvider) == null ? void 0 : _b.call(_a, this, filter));
|
3802
3796
|
if (override && override.replace) {
|
3803
|
-
return override.values
|
3797
|
+
return handleOptionGroups(override.values);
|
3804
3798
|
}
|
3805
3799
|
const ds = await this._dataSourceSrv.get(this.state.datasource, this._scopedVars);
|
3806
3800
|
if (!ds || !ds.getTagValues) {
|
@@ -3813,7 +3807,7 @@ class AdHocFiltersVariable extends SceneObjectBase {
|
|
3813
3807
|
if (override) {
|
3814
3808
|
values = values.concat(override.values);
|
3815
3809
|
}
|
3816
|
-
return values
|
3810
|
+
return handleOptionGroups(values);
|
3817
3811
|
}
|
3818
3812
|
_addWip() {
|
3819
3813
|
this.setState({
|
@@ -3869,6 +3863,27 @@ function toSelectableValue({ text, value }) {
|
|
3869
3863
|
function isFilterComplete(filter) {
|
3870
3864
|
return filter.key !== "" && filter.operator !== "" && filter.value !== "";
|
3871
3865
|
}
|
3866
|
+
function handleOptionGroups(values) {
|
3867
|
+
const result = [];
|
3868
|
+
const groupedResults = /* @__PURE__ */ new Map();
|
3869
|
+
for (const value of values) {
|
3870
|
+
const groupLabel = value.group;
|
3871
|
+
if (groupLabel) {
|
3872
|
+
let group = groupedResults.get(groupLabel);
|
3873
|
+
if (!group) {
|
3874
|
+
group = [];
|
3875
|
+
groupedResults.set(groupLabel, group);
|
3876
|
+
}
|
3877
|
+
group.push(toSelectableValue(value));
|
3878
|
+
} else {
|
3879
|
+
result.push(toSelectableValue(value));
|
3880
|
+
}
|
3881
|
+
}
|
3882
|
+
for (const [group, values2] of groupedResults) {
|
3883
|
+
result.unshift({ label: group, options: values2 });
|
3884
|
+
}
|
3885
|
+
return result;
|
3886
|
+
}
|
3872
3887
|
|
3873
3888
|
class DataLayersMerger {
|
3874
3889
|
constructor() {
|