@grafana/scenes 6.30.1 → 6.31.0--canary.1192.17130344208.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/querying/SceneQueryRunner.js +1 -1
- package/dist/esm/querying/SceneQueryRunner.js.map +1 -1
- package/dist/esm/variables/groupby/GroupByValueContainer.js +38 -0
- package/dist/esm/variables/groupby/GroupByValueContainer.js.map +1 -0
- package/dist/esm/variables/groupby/GroupByVariable.js +43 -2
- package/dist/esm/variables/groupby/GroupByVariable.js.map +1 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +75 -3
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -3383,6 +3383,39 @@ const getStyles$h = (theme) => ({
|
|
|
3383
3383
|
})
|
|
3384
3384
|
});
|
|
3385
3385
|
|
|
3386
|
+
const isValidReactElementWithData = (child) => {
|
|
3387
|
+
var _a, _b;
|
|
3388
|
+
return React__default.default.isValidElement(child) && Boolean((_b = (_a = child.props) == null ? void 0 : _a.data) == null ? void 0 : _b.value);
|
|
3389
|
+
};
|
|
3390
|
+
const findKeyApplicability = (keysApplicability, value) => {
|
|
3391
|
+
return keysApplicability == null ? void 0 : keysApplicability.find((applicability) => applicability.key === value);
|
|
3392
|
+
};
|
|
3393
|
+
const renderChildWithApplicability = (child, applicability) => {
|
|
3394
|
+
if (!applicability) {
|
|
3395
|
+
return child;
|
|
3396
|
+
}
|
|
3397
|
+
if (!applicability.applicable) {
|
|
3398
|
+
return /* @__PURE__ */ React__default.default.createElement("s", { key: applicability.key }, child);
|
|
3399
|
+
}
|
|
3400
|
+
return child;
|
|
3401
|
+
};
|
|
3402
|
+
const GroupByValueContainer = ({
|
|
3403
|
+
keysApplicability,
|
|
3404
|
+
children
|
|
3405
|
+
}) => {
|
|
3406
|
+
const theme = ui.useTheme2();
|
|
3407
|
+
const styles = ui.getSelectStyles(theme);
|
|
3408
|
+
const renderChild = (child) => {
|
|
3409
|
+
if (!isValidReactElementWithData(child)) {
|
|
3410
|
+
return child;
|
|
3411
|
+
}
|
|
3412
|
+
const value = child.props.data.value;
|
|
3413
|
+
const applicability = findKeyApplicability(keysApplicability, value);
|
|
3414
|
+
return renderChildWithApplicability(child, applicability);
|
|
3415
|
+
};
|
|
3416
|
+
return /* @__PURE__ */ React__default.default.createElement("div", { className: styles.multiValueContainer }, React__default.default.Children.map(children, renderChild));
|
|
3417
|
+
};
|
|
3418
|
+
|
|
3386
3419
|
class GroupByVariable extends MultiValueVariable {
|
|
3387
3420
|
constructor(initialState) {
|
|
3388
3421
|
super({
|
|
@@ -3402,6 +3435,7 @@ class GroupByVariable extends MultiValueVariable {
|
|
|
3402
3435
|
this.isLazy = true;
|
|
3403
3436
|
this._urlSync = new GroupByVariableUrlSyncHandler(this);
|
|
3404
3437
|
this._activationHandler = () => {
|
|
3438
|
+
this._verifyApplicability();
|
|
3405
3439
|
if (this.state.defaultValue) {
|
|
3406
3440
|
if (this.checkIfRestorable(this.state.value)) {
|
|
3407
3441
|
this.setState({ restorable: true });
|
|
@@ -3519,6 +3553,40 @@ class GroupByVariable extends MultiValueVariable {
|
|
|
3519
3553
|
})
|
|
3520
3554
|
);
|
|
3521
3555
|
}
|
|
3556
|
+
getApplicableKeys() {
|
|
3557
|
+
const { value, keysApplicability } = this.state;
|
|
3558
|
+
const valueArray = lodash.isArray(value) ? value : value ? [value] : [];
|
|
3559
|
+
if (!keysApplicability || keysApplicability.length === 0) {
|
|
3560
|
+
return valueArray;
|
|
3561
|
+
}
|
|
3562
|
+
const applicableValues = valueArray.filter((val) => {
|
|
3563
|
+
const applicability = keysApplicability.find((item) => item.key === val);
|
|
3564
|
+
return !applicability || applicability.applicable !== false;
|
|
3565
|
+
});
|
|
3566
|
+
return applicableValues;
|
|
3567
|
+
}
|
|
3568
|
+
async _verifyApplicability() {
|
|
3569
|
+
const ds = await getDataSource(this.state.datasource, {
|
|
3570
|
+
__sceneObject: wrapInSafeSerializableSceneObject(this)
|
|
3571
|
+
});
|
|
3572
|
+
if (!ds.getFiltersApplicability) {
|
|
3573
|
+
return;
|
|
3574
|
+
}
|
|
3575
|
+
const queries = getQueriesForVariables(this);
|
|
3576
|
+
const timeRange = sceneGraph.getTimeRange(this).state.value;
|
|
3577
|
+
const value = this.state.value;
|
|
3578
|
+
const response = await ds.getFiltersApplicability({
|
|
3579
|
+
groupByKeys: Array.isArray(value) ? value.map((v) => String(v)) : value ? [String(value)] : [],
|
|
3580
|
+
queries,
|
|
3581
|
+
timeRange,
|
|
3582
|
+
scopes: sceneGraph.getScopes(this),
|
|
3583
|
+
...getEnrichedFiltersRequest(this)
|
|
3584
|
+
});
|
|
3585
|
+
if (!lodash.isEqual(response, this.state.keysApplicability)) {
|
|
3586
|
+
this.setState({ keysApplicability: response });
|
|
3587
|
+
this.publishEvent(new SceneVariableValueChangedEvent(this), true);
|
|
3588
|
+
}
|
|
3589
|
+
}
|
|
3522
3590
|
// This method is related to the defaultValue property. We check if the current value
|
|
3523
3591
|
// is different from the default value. If it is, the groupBy will show a button
|
|
3524
3592
|
// allowing the user to restore the default values.
|
|
@@ -3557,7 +3625,8 @@ function GroupByVariableRenderer({ model }) {
|
|
|
3557
3625
|
options,
|
|
3558
3626
|
includeAll,
|
|
3559
3627
|
allowCustomValue = true,
|
|
3560
|
-
defaultValue
|
|
3628
|
+
defaultValue,
|
|
3629
|
+
keysApplicability
|
|
3561
3630
|
} = model.useState();
|
|
3562
3631
|
const values = React.useMemo(() => {
|
|
3563
3632
|
const arrayValue = lodash.isArray(value) ? value : [value];
|
|
@@ -3629,7 +3698,8 @@ function GroupByVariableRenderer({ model }) {
|
|
|
3629
3698
|
Option: OptionWithCheckbox,
|
|
3630
3699
|
...hasDefaultValue ? {
|
|
3631
3700
|
IndicatorsContainer: () => /* @__PURE__ */ React__default.default.createElement(DefaultGroupByCustomIndicatorContainer, { model })
|
|
3632
|
-
} : {}
|
|
3701
|
+
} : {},
|
|
3702
|
+
MultiValueContainer: ({ innerProps, children }) => /* @__PURE__ */ React__default.default.createElement(GroupByValueContainer, { innerProps, keysApplicability }, children)
|
|
3633
3703
|
},
|
|
3634
3704
|
onInputChange,
|
|
3635
3705
|
onBlur: () => {
|
|
@@ -3646,6 +3716,8 @@ function GroupByVariableRenderer({ model }) {
|
|
|
3646
3716
|
onChange: (newValue, action) => {
|
|
3647
3717
|
if (action.action === "clear" && noValueOnClear) {
|
|
3648
3718
|
model.changeValueTo([], void 0, true);
|
|
3719
|
+
} else {
|
|
3720
|
+
model._verifyApplicability();
|
|
3649
3721
|
}
|
|
3650
3722
|
setUncommittedValue(newValue);
|
|
3651
3723
|
},
|
|
@@ -6685,7 +6757,7 @@ class SceneQueryRunner extends SceneObjectBase {
|
|
|
6685
6757
|
].filter((f) => isFilterComplete(f) && isFilterApplicable(f));
|
|
6686
6758
|
}
|
|
6687
6759
|
if (this._groupByVar) {
|
|
6688
|
-
request.groupByKeys = this._groupByVar.
|
|
6760
|
+
request.groupByKeys = this._groupByVar.getApplicableKeys();
|
|
6689
6761
|
}
|
|
6690
6762
|
request.targets = request.targets.map((query) => {
|
|
6691
6763
|
var _a2;
|