@grafana/scenes 6.11.1 → 6.12.0--canary.1122.15063334499.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/README.md +10 -0
- package/dist/esm/variables/groupby/DefaultGroupByCustomIndicatorContainer.js +102 -0
- package/dist/esm/variables/groupby/DefaultGroupByCustomIndicatorContainer.js.map +1 -0
- package/dist/esm/variables/groupby/GroupByVariable.js +38 -5
- package/dist/esm/variables/groupby/GroupByVariable.js.map +1 -1
- package/dist/esm/variables/groupby/GroupByVariableUrlSyncHandler.js +31 -7
- package/dist/esm/variables/groupby/GroupByVariableUrlSyncHandler.js.map +1 -1
- package/dist/index.d.ts +7 -0
- package/dist/index.js +160 -10
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
@@ -2964,18 +2964,34 @@ class GroupByVariableUrlSyncHandler {
|
|
2964
2964
|
return [this.getKey()];
|
2965
2965
|
}
|
2966
2966
|
getUrlState() {
|
2967
|
+
var _a;
|
2967
2968
|
if (this._sceneObject.state.skipUrlSync) {
|
2968
2969
|
return {};
|
2969
2970
|
}
|
2970
|
-
return {
|
2971
|
+
return {
|
2972
|
+
[this.getKey()]: toUrlValues(
|
2973
|
+
this._sceneObject.state.value,
|
2974
|
+
this._sceneObject.state.text,
|
2975
|
+
(_a = this._sceneObject.state.defaultValues) == null ? void 0 : _a.value
|
2976
|
+
)
|
2977
|
+
};
|
2971
2978
|
}
|
2972
2979
|
updateFromUrl(values) {
|
2980
|
+
var _a, _b;
|
2973
2981
|
let urlValue = values[this.getKey()];
|
2974
2982
|
if (urlValue != null) {
|
2975
2983
|
if (!this._sceneObject.isActive) {
|
2976
2984
|
this._sceneObject.skipNextValidation = true;
|
2977
2985
|
}
|
2978
|
-
const { values: values2, texts } = fromUrlValues(urlValue);
|
2986
|
+
const { values: values2, texts, defaults } = fromUrlValues(urlValue);
|
2987
|
+
if (lodash.isEqual(values2, defaults) && this._sceneObject.state.defaultValues) {
|
2988
|
+
this._sceneObject.changeValueTo(
|
2989
|
+
(_a = this._sceneObject.state.defaultValues) == null ? void 0 : _a.value,
|
2990
|
+
(_b = this._sceneObject.state.defaultValues) == null ? void 0 : _b.text,
|
2991
|
+
false
|
2992
|
+
);
|
2993
|
+
return;
|
2994
|
+
}
|
2979
2995
|
this._sceneObject.changeValueTo(values2, texts);
|
2980
2996
|
}
|
2981
2997
|
}
|
@@ -2988,9 +3004,10 @@ class GroupByVariableUrlSyncHandler {
|
|
2988
3004
|
return this._nextChangeShouldAddHistoryStep;
|
2989
3005
|
}
|
2990
3006
|
}
|
2991
|
-
function toUrlValues(values, texts) {
|
3007
|
+
function toUrlValues(values, texts, defaultValues) {
|
2992
3008
|
values = Array.isArray(values) ? values : [values];
|
2993
3009
|
texts = Array.isArray(texts) ? texts : [texts];
|
3010
|
+
const defaults = defaultValues ? Array.isArray(defaultValues) ? defaultValues : [defaultValues] : [];
|
2994
3011
|
return values.map((value, idx) => {
|
2995
3012
|
if (value === void 0 || value === null) {
|
2996
3013
|
return "";
|
@@ -2998,21 +3015,27 @@ function toUrlValues(values, texts) {
|
|
2998
3015
|
value = String(value);
|
2999
3016
|
let text = texts[idx];
|
3000
3017
|
text = text === void 0 || text === null ? value : String(text);
|
3001
|
-
return toUrlCommaDelimitedString(value, text);
|
3018
|
+
return toUrlCommaDelimitedString(value, text) + (defaults.includes(value) ? escapeUrlPipeDelimiters("|default") : "");
|
3002
3019
|
});
|
3003
3020
|
}
|
3004
3021
|
function fromUrlValues(urlValues) {
|
3005
3022
|
urlValues = Array.isArray(urlValues) ? urlValues : [urlValues];
|
3006
3023
|
return urlValues.reduce(
|
3007
3024
|
(acc, urlValue) => {
|
3008
|
-
const
|
3025
|
+
const pipeEscapedVal = /__gfp__/g[Symbol.replace](urlValue, "|");
|
3026
|
+
const [commaValues, isDefault] = (pipeEscapedVal != null ? pipeEscapedVal : "").split("|");
|
3027
|
+
const [value, label] = (commaValues != null ? commaValues : "").split(",");
|
3009
3028
|
acc.values.push(unescapeUrlDelimiters(value));
|
3010
3029
|
acc.texts.push(unescapeUrlDelimiters(label != null ? label : value));
|
3030
|
+
if (isDefault) {
|
3031
|
+
acc.defaults.push(value);
|
3032
|
+
}
|
3011
3033
|
return acc;
|
3012
3034
|
},
|
3013
3035
|
{
|
3014
3036
|
values: [],
|
3015
|
-
texts: []
|
3037
|
+
texts: [],
|
3038
|
+
defaults: []
|
3016
3039
|
}
|
3017
3040
|
);
|
3018
3041
|
}
|
@@ -3076,6 +3099,101 @@ function wrapInSafeSerializableSceneObject(sceneObject) {
|
|
3076
3099
|
return { value: sceneObject, text: "__sceneObject" };
|
3077
3100
|
}
|
3078
3101
|
|
3102
|
+
function DefaultGroupByCustomIndicatorContainer(props) {
|
3103
|
+
const { model } = props;
|
3104
|
+
const theme = ui.useTheme2();
|
3105
|
+
const styles = getStyles$h(theme);
|
3106
|
+
const inputStyles = ui.getInputStyles({ theme, invalid: false });
|
3107
|
+
const value = React.useMemo(
|
3108
|
+
() => lodash.isArray(model.state.value) ? model.state.value : model.state.value ? [model.state.value] : [],
|
3109
|
+
[model.state.value]
|
3110
|
+
);
|
3111
|
+
const isRestorable = React.useMemo(() => {
|
3112
|
+
return model.checkIfRestorable(value);
|
3113
|
+
}, [value, model]);
|
3114
|
+
let buttons = [];
|
3115
|
+
if (value && value.length) {
|
3116
|
+
buttons.push(
|
3117
|
+
/* @__PURE__ */ React__default.default.createElement(
|
3118
|
+
ui.IconButton,
|
3119
|
+
{
|
3120
|
+
"aria-label": "clear",
|
3121
|
+
key: "clear",
|
3122
|
+
name: "times",
|
3123
|
+
size: "md",
|
3124
|
+
className: styles.clearIcon,
|
3125
|
+
onClick: (e) => {
|
3126
|
+
model.changeValueTo([], void 0, true);
|
3127
|
+
}
|
3128
|
+
}
|
3129
|
+
)
|
3130
|
+
);
|
3131
|
+
}
|
3132
|
+
if (isRestorable) {
|
3133
|
+
buttons.push(
|
3134
|
+
/* @__PURE__ */ React__default.default.createElement(
|
3135
|
+
ui.IconButton,
|
3136
|
+
{
|
3137
|
+
onClick: (e) => {
|
3138
|
+
props.model.restoreDefaultValues();
|
3139
|
+
},
|
3140
|
+
onKeyDownCapture: (e) => {
|
3141
|
+
if (e.key === "Enter") {
|
3142
|
+
props.model.restoreDefaultValues();
|
3143
|
+
}
|
3144
|
+
},
|
3145
|
+
key: "restore",
|
3146
|
+
name: "history",
|
3147
|
+
size: "md",
|
3148
|
+
className: styles.clearIcon,
|
3149
|
+
tooltip: "Restore groupby set by this dashboard."
|
3150
|
+
}
|
3151
|
+
)
|
3152
|
+
);
|
3153
|
+
}
|
3154
|
+
if (!isRestorable) {
|
3155
|
+
buttons.push(
|
3156
|
+
/* @__PURE__ */ React__default.default.createElement(
|
3157
|
+
ui.Tooltip,
|
3158
|
+
{
|
3159
|
+
key: "tooltip",
|
3160
|
+
content: "Applied by default in this dashboard. If edited, it carries over to other dashboards.",
|
3161
|
+
placement: "bottom"
|
3162
|
+
},
|
3163
|
+
/* @__PURE__ */ React__default.default.createElement(ui.Icon, { name: "info-circle", size: "md" })
|
3164
|
+
)
|
3165
|
+
);
|
3166
|
+
}
|
3167
|
+
return /* @__PURE__ */ React__default.default.createElement(
|
3168
|
+
"div",
|
3169
|
+
{
|
3170
|
+
onMouseDown: (e) => {
|
3171
|
+
e.preventDefault();
|
3172
|
+
e.stopPropagation();
|
3173
|
+
},
|
3174
|
+
className: css.cx(
|
3175
|
+
inputStyles.suffix,
|
3176
|
+
css.css({
|
3177
|
+
position: "relative"
|
3178
|
+
})
|
3179
|
+
)
|
3180
|
+
},
|
3181
|
+
buttons
|
3182
|
+
);
|
3183
|
+
}
|
3184
|
+
const getStyles$h = (theme) => ({
|
3185
|
+
clearIcon: css.css({
|
3186
|
+
color: theme.colors.action.disabledText,
|
3187
|
+
cursor: "pointer",
|
3188
|
+
"&:hover:before": {
|
3189
|
+
backgroundColor: "transparent"
|
3190
|
+
},
|
3191
|
+
"&:hover": {
|
3192
|
+
color: theme.colors.text.primary
|
3193
|
+
}
|
3194
|
+
})
|
3195
|
+
});
|
3196
|
+
|
3079
3197
|
class GroupByVariable extends MultiValueVariable {
|
3080
3198
|
constructor(initialState) {
|
3081
3199
|
super({
|
@@ -3094,6 +3212,15 @@ class GroupByVariable extends MultiValueVariable {
|
|
3094
3212
|
});
|
3095
3213
|
this.isLazy = true;
|
3096
3214
|
this._urlSync = new GroupByVariableUrlSyncHandler(this);
|
3215
|
+
this._activationHandler = () => {
|
3216
|
+
if (this.state.defaultValues && (lodash.isArray(this.state.value) && !this.state.value.length || !this.state.value)) {
|
3217
|
+
this.setState({
|
3218
|
+
value: this.state.defaultValues.value,
|
3219
|
+
text: this.state.defaultValues.text
|
3220
|
+
});
|
3221
|
+
return;
|
3222
|
+
}
|
3223
|
+
};
|
3097
3224
|
/**
|
3098
3225
|
* Get possible keys given current filters. Do not call from plugins directly
|
3099
3226
|
*/
|
@@ -3138,6 +3265,7 @@ class GroupByVariable extends MultiValueVariable {
|
|
3138
3265
|
return () => allActiveGroupByVariables.delete(this);
|
3139
3266
|
});
|
3140
3267
|
}
|
3268
|
+
this.addActivationHandler(this._activationHandler);
|
3141
3269
|
}
|
3142
3270
|
validateAndUpdate() {
|
3143
3271
|
return this.getValueOptions({}).pipe(
|
@@ -3196,6 +3324,21 @@ class GroupByVariable extends MultiValueVariable {
|
|
3196
3324
|
})
|
3197
3325
|
);
|
3198
3326
|
}
|
3327
|
+
checkIfRestorable(values) {
|
3328
|
+
var _a, _b, _c, _d;
|
3329
|
+
const originalValues = lodash.isArray((_a = this.state.defaultValues) == null ? void 0 : _a.value) ? (_b = this.state.defaultValues) == null ? void 0 : _b.value : ((_c = this.state.defaultValues) == null ? void 0 : _c.value) ? [(_d = this.state.defaultValues) == null ? void 0 : _d.value] : [];
|
3330
|
+
const vals = lodash.isArray(values) ? values : [values];
|
3331
|
+
if (vals.length !== originalValues.length) {
|
3332
|
+
return true;
|
3333
|
+
}
|
3334
|
+
return !lodash.isEqual(vals, originalValues);
|
3335
|
+
}
|
3336
|
+
restoreDefaultValues() {
|
3337
|
+
if (!this.state.defaultValues) {
|
3338
|
+
return;
|
3339
|
+
}
|
3340
|
+
this.changeValueTo(this.state.defaultValues.value, this.state.defaultValues.text, true);
|
3341
|
+
}
|
3199
3342
|
/**
|
3200
3343
|
* Allows clearing the value of the variable to an empty value. Overrides default behavior of a MultiValueVariable
|
3201
3344
|
*/
|
@@ -3214,7 +3357,8 @@ function GroupByVariableRenderer({ model }) {
|
|
3214
3357
|
noValueOnClear,
|
3215
3358
|
options,
|
3216
3359
|
includeAll,
|
3217
|
-
allowCustomValue = true
|
3360
|
+
allowCustomValue = true,
|
3361
|
+
defaultValues
|
3218
3362
|
} = model.useState();
|
3219
3363
|
const values = React.useMemo(() => {
|
3220
3364
|
const arrayValue = lodash.isArray(value) ? value : [value];
|
@@ -3232,6 +3376,7 @@ function GroupByVariableRenderer({ model }) {
|
|
3232
3376
|
const [inputValue, setInputValue] = React.useState("");
|
3233
3377
|
const [uncommittedValue, setUncommittedValue] = React.useState(values);
|
3234
3378
|
const optionSearcher = React.useMemo(() => getOptionSearcher(options, includeAll), [options, includeAll]);
|
3379
|
+
const hasDefaultValues = defaultValues !== void 0;
|
3235
3380
|
React.useEffect(() => {
|
3236
3381
|
setUncommittedValue(values);
|
3237
3382
|
}, [values]);
|
@@ -3259,7 +3404,7 @@ function GroupByVariableRenderer({ model }) {
|
|
3259
3404
|
"aria-label": "Group by selector",
|
3260
3405
|
"data-testid": `GroupBySelect-${key}`,
|
3261
3406
|
id: key,
|
3262
|
-
placeholder: "
|
3407
|
+
placeholder: "Group by label",
|
3263
3408
|
width: "auto",
|
3264
3409
|
allowCustomValue,
|
3265
3410
|
inputValue,
|
@@ -3275,7 +3420,12 @@ function GroupByVariableRenderer({ model }) {
|
|
3275
3420
|
isClearable: true,
|
3276
3421
|
hideSelectedOptions: false,
|
3277
3422
|
isLoading: isFetchingOptions,
|
3278
|
-
components: {
|
3423
|
+
components: {
|
3424
|
+
Option: OptionWithCheckbox,
|
3425
|
+
...hasDefaultValues ? {
|
3426
|
+
IndicatorsContainer: () => /* @__PURE__ */ React__default.default.createElement(DefaultGroupByCustomIndicatorContainer, { model })
|
3427
|
+
} : {}
|
3428
|
+
},
|
3279
3429
|
onInputChange,
|
3280
3430
|
onBlur: () => {
|
3281
3431
|
model.changeValueTo(
|
@@ -3306,7 +3456,7 @@ function GroupByVariableRenderer({ model }) {
|
|
3306
3456
|
"aria-label": "Group by selector",
|
3307
3457
|
"data-testid": `GroupBySelect-${key}`,
|
3308
3458
|
id: key,
|
3309
|
-
placeholder: "
|
3459
|
+
placeholder: "Group by label",
|
3310
3460
|
width: "auto",
|
3311
3461
|
inputValue,
|
3312
3462
|
value: uncommittedValue && uncommittedValue.length > 0 ? uncommittedValue : null,
|