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