@grafana/scenes 4.11.1--canary.699.8720696583.0 → 4.11.1--canary.690.8722374680.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/variables/adhoc/AdHocFilterRenderer.js +12 -20
- package/dist/esm/variables/adhoc/AdHocFilterRenderer.js.map +1 -1
- package/dist/esm/variables/adhoc/AdHocFiltersVariable.js +8 -5
- package/dist/esm/variables/adhoc/AdHocFiltersVariable.js.map +1 -1
- package/dist/esm/variables/adhoc/AdHocFiltersVariableUrlSyncHandler.js +36 -12
- package/dist/esm/variables/adhoc/AdHocFiltersVariableUrlSyncHandler.js.map +1 -1
- package/dist/esm/variables/variants/LocalValueVariable.js +0 -12
- package/dist/esm/variables/variants/LocalValueVariable.js.map +1 -1
- package/dist/index.d.ts +12 -9
- package/dist/index.js +55 -46
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -3168,24 +3168,18 @@ var __spreadValues$y = (a, b) => {
|
|
|
3168
3168
|
return a;
|
|
3169
3169
|
};
|
|
3170
3170
|
var __spreadProps$m = (a, b) => __defProps$m(a, __getOwnPropDescs$m(b));
|
|
3171
|
+
function keyLabelToOption(key, label) {
|
|
3172
|
+
return key !== "" ? {
|
|
3173
|
+
value: key,
|
|
3174
|
+
label: label || key
|
|
3175
|
+
} : null;
|
|
3176
|
+
}
|
|
3171
3177
|
function AdHocFilterRenderer({ filter, model }) {
|
|
3172
3178
|
var _a, _b;
|
|
3173
3179
|
const styles = ui.useStyles2(getStyles$7);
|
|
3174
3180
|
const [state, setState] = React.useState({});
|
|
3175
|
-
const keyValue =
|
|
3176
|
-
|
|
3177
|
-
if (model.state.defaultKeys) {
|
|
3178
|
-
const matchingDefaultKey = model.state.defaultKeys.find((option) => option.value === filter.key);
|
|
3179
|
-
if (matchingDefaultKey) {
|
|
3180
|
-
return toSelectableValue(matchingDefaultKey);
|
|
3181
|
-
}
|
|
3182
|
-
} else {
|
|
3183
|
-
return data.toOption(filter.key);
|
|
3184
|
-
}
|
|
3185
|
-
}
|
|
3186
|
-
return null;
|
|
3187
|
-
}, [filter.key, model.state.defaultKeys]);
|
|
3188
|
-
const valueValue = filter.value !== "" ? data.toOption(filter.value) : null;
|
|
3181
|
+
const keyValue = keyLabelToOption(filter.key, filter.keyLabel);
|
|
3182
|
+
const valueValue = keyLabelToOption(filter.value, filter.valueLabel);
|
|
3189
3183
|
const valueSelect = /* @__PURE__ */ React__default["default"].createElement(ui.Select, {
|
|
3190
3184
|
allowCustomValue: true,
|
|
3191
3185
|
formatCreateLabel: (inputValue) => `Use custom value: ${inputValue}`,
|
|
@@ -3195,7 +3189,7 @@ function AdHocFilterRenderer({ filter, model }) {
|
|
|
3195
3189
|
value: valueValue,
|
|
3196
3190
|
placeholder: "Select value",
|
|
3197
3191
|
options: state.values,
|
|
3198
|
-
onChange: (v) => model._updateFilter(filter, "value", v
|
|
3192
|
+
onChange: (v) => model._updateFilter(filter, "value", v),
|
|
3199
3193
|
isOpen: state.isValuesOpen,
|
|
3200
3194
|
isLoading: state.isValuesLoading,
|
|
3201
3195
|
autoFocus: filter.key !== "" && filter.value === "",
|
|
@@ -3217,7 +3211,7 @@ function AdHocFilterRenderer({ filter, model }) {
|
|
|
3217
3211
|
value: keyValue,
|
|
3218
3212
|
placeholder: "Select label",
|
|
3219
3213
|
options: state.keys,
|
|
3220
|
-
onChange: (v) => model._updateFilter(filter, "key", v
|
|
3214
|
+
onChange: (v) => model._updateFilter(filter, "key", v),
|
|
3221
3215
|
autoFocus: filter.key === "",
|
|
3222
3216
|
isOpen: state.isKeysOpen,
|
|
3223
3217
|
isLoading: state.isKeysLoading,
|
|
@@ -3264,7 +3258,7 @@ function AdHocFilterRenderer({ filter, model }) {
|
|
|
3264
3258
|
disabled: model.state.readOnly,
|
|
3265
3259
|
options: model._getOperators(),
|
|
3266
3260
|
width: "auto",
|
|
3267
|
-
onChange: (v) => model._updateFilter(filter, "operator", v
|
|
3261
|
+
onChange: (v) => model._updateFilter(filter, "operator", v)
|
|
3268
3262
|
}), valueSelect, /* @__PURE__ */ React__default["default"].createElement(ui.Button, {
|
|
3269
3263
|
variant: "secondary",
|
|
3270
3264
|
"aria-label": "Remove filter",
|
|
@@ -3351,7 +3345,7 @@ class AdHocFiltersVariableUrlSyncHandler {
|
|
|
3351
3345
|
if (filters.length === 0) {
|
|
3352
3346
|
return { [this.getKey()]: [""] };
|
|
3353
3347
|
}
|
|
3354
|
-
const value = filters.map((filter) => toArray(filter).map(
|
|
3348
|
+
const value = filters.map((filter) => toArray(filter).map(escapePipeDelimiters).join("|"));
|
|
3355
3349
|
return { [this.getKey()]: value };
|
|
3356
3350
|
}
|
|
3357
3351
|
updateFromUrl(values) {
|
|
@@ -3371,30 +3365,54 @@ function deserializeUrlToFilters(value) {
|
|
|
3371
3365
|
const filter = toFilter(value);
|
|
3372
3366
|
return filter === null ? [] : [filter];
|
|
3373
3367
|
}
|
|
3374
|
-
function
|
|
3368
|
+
function escapePipeDelimiters(value) {
|
|
3375
3369
|
if (value === null || value === void 0) {
|
|
3376
3370
|
return "";
|
|
3377
3371
|
}
|
|
3378
|
-
return /\|/g[Symbol.replace](value, "__gfp__");
|
|
3372
|
+
return value = /\|/g[Symbol.replace](value, "__gfp__");
|
|
3379
3373
|
}
|
|
3380
|
-
function
|
|
3374
|
+
function escapeCommaDelimiters(value) {
|
|
3381
3375
|
if (value === null || value === void 0) {
|
|
3382
3376
|
return "";
|
|
3383
3377
|
}
|
|
3384
|
-
return
|
|
3378
|
+
return /,/g[Symbol.replace](value, "__gfc__");
|
|
3379
|
+
}
|
|
3380
|
+
function unescapeDelimiters(value) {
|
|
3381
|
+
if (value === null || value === void 0) {
|
|
3382
|
+
return "";
|
|
3383
|
+
}
|
|
3384
|
+
value = /__gfp__/g[Symbol.replace](value, "|");
|
|
3385
|
+
value = /__gfc__/g[Symbol.replace](value, ",");
|
|
3386
|
+
return value;
|
|
3385
3387
|
}
|
|
3386
3388
|
function toArray(filter) {
|
|
3387
|
-
return [
|
|
3389
|
+
return [
|
|
3390
|
+
toCommaDelimitedString(filter.key, filter.keyLabel),
|
|
3391
|
+
filter.operator,
|
|
3392
|
+
toCommaDelimitedString(filter.value, filter.valueLabel)
|
|
3393
|
+
];
|
|
3394
|
+
}
|
|
3395
|
+
function toCommaDelimitedString(key, label) {
|
|
3396
|
+
if (!label || key === label) {
|
|
3397
|
+
return escapeCommaDelimiters(key);
|
|
3398
|
+
}
|
|
3399
|
+
return [key, label].map(escapeCommaDelimiters).map(escapeCommaDelimiters).join(",");
|
|
3388
3400
|
}
|
|
3389
|
-
function toFilter(
|
|
3390
|
-
if (typeof
|
|
3401
|
+
function toFilter(urlValue) {
|
|
3402
|
+
if (typeof urlValue !== "string" || urlValue.length === 0) {
|
|
3391
3403
|
return null;
|
|
3392
3404
|
}
|
|
3393
|
-
const
|
|
3405
|
+
const [key, keyLabel, operator, _operatorLabel, value, valueLabel] = urlValue.split("|").reduce((acc, v) => {
|
|
3406
|
+
const [key2, label] = v.split(",");
|
|
3407
|
+
acc.push(key2, label != null ? label : key2);
|
|
3408
|
+
return acc;
|
|
3409
|
+
}, []).map(unescapeDelimiters);
|
|
3394
3410
|
return {
|
|
3395
|
-
key
|
|
3396
|
-
|
|
3397
|
-
|
|
3411
|
+
key,
|
|
3412
|
+
keyLabel,
|
|
3413
|
+
operator,
|
|
3414
|
+
value,
|
|
3415
|
+
valueLabel,
|
|
3398
3416
|
condition: ""
|
|
3399
3417
|
};
|
|
3400
3418
|
}
|
|
@@ -3453,22 +3471,23 @@ class AdHocFiltersVariable extends SceneObjectBase {
|
|
|
3453
3471
|
getValue() {
|
|
3454
3472
|
return this.state.filterExpression;
|
|
3455
3473
|
}
|
|
3456
|
-
_updateFilter(filter, prop, value) {
|
|
3474
|
+
_updateFilter(filter, prop, { value, label }) {
|
|
3457
3475
|
if (value == null) {
|
|
3458
3476
|
return;
|
|
3459
3477
|
}
|
|
3460
3478
|
const { filters, _wip } = this.state;
|
|
3479
|
+
const propLabelKey = `${prop}Label`;
|
|
3461
3480
|
if (filter === _wip) {
|
|
3462
3481
|
if (prop === "value") {
|
|
3463
|
-
this.setState({ filters: [...filters, __spreadProps$l(__spreadValues$x({}, _wip), { [prop]: value })], _wip: void 0 });
|
|
3482
|
+
this.setState({ filters: [...filters, __spreadProps$l(__spreadValues$x({}, _wip), { [prop]: value, [propLabelKey]: label })], _wip: void 0 });
|
|
3464
3483
|
} else {
|
|
3465
|
-
this.setState({ _wip: __spreadProps$l(__spreadValues$x({}, filter), { [prop]: value }) });
|
|
3484
|
+
this.setState({ _wip: __spreadProps$l(__spreadValues$x({}, filter), { [prop]: value, [propLabelKey]: label }) });
|
|
3466
3485
|
}
|
|
3467
3486
|
return;
|
|
3468
3487
|
}
|
|
3469
3488
|
const updatedFilters = this.state.filters.map((f) => {
|
|
3470
3489
|
if (f === filter) {
|
|
3471
|
-
return __spreadProps$l(__spreadValues$x({}, f), { [prop]: value });
|
|
3490
|
+
return __spreadProps$l(__spreadValues$x({}, f), { [prop]: value, [propLabelKey]: label });
|
|
3472
3491
|
}
|
|
3473
3492
|
return f;
|
|
3474
3493
|
});
|
|
@@ -3527,7 +3546,9 @@ class AdHocFiltersVariable extends SceneObjectBase {
|
|
|
3527
3546
|
return values.map(toSelectableValue);
|
|
3528
3547
|
}
|
|
3529
3548
|
_addWip() {
|
|
3530
|
-
this.setState({
|
|
3549
|
+
this.setState({
|
|
3550
|
+
_wip: { key: "", keyLabel: "", value: "", valueLabel: "", operator: "=", condition: "" }
|
|
3551
|
+
});
|
|
3531
3552
|
}
|
|
3532
3553
|
_getOperators() {
|
|
3533
3554
|
return ["=", "!=", "<", ">", "=~", "!~"].map((value) => ({
|
|
@@ -7200,18 +7221,6 @@ class LocalValueVariable extends SceneObjectBase {
|
|
|
7200
7221
|
}
|
|
7201
7222
|
return false;
|
|
7202
7223
|
}
|
|
7203
|
-
getAncestorVariable() {
|
|
7204
|
-
var _a, _b;
|
|
7205
|
-
const ancestorScope = (_b = (_a = this.parent) == null ? void 0 : _a.parent) == null ? void 0 : _b.parent;
|
|
7206
|
-
if (!ancestorScope) {
|
|
7207
|
-
throw new Error("LocalValueVariable requires a parent SceneVariableSet that has an ancestor SceneVariableSet");
|
|
7208
|
-
}
|
|
7209
|
-
const parentVar = sceneGraph.lookupVariable(this.state.name, ancestorScope);
|
|
7210
|
-
if (!parentVar) {
|
|
7211
|
-
return null;
|
|
7212
|
-
}
|
|
7213
|
-
return parentVar;
|
|
7214
|
-
}
|
|
7215
7224
|
}
|
|
7216
7225
|
|
|
7217
7226
|
var __defProp$b = Object.defineProperty;
|