@grafana/scenes 4.12.1--canary.704.8799450327.0 → 4.13.0--canary.705.8801395113.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/index.js CHANGED
@@ -2840,6 +2840,59 @@ class CustomAllValue {
2840
2840
  }
2841
2841
  }
2842
2842
 
2843
+ class GroupByVariableUrlSyncHandler {
2844
+ constructor(_sceneObject) {
2845
+ this._sceneObject = _sceneObject;
2846
+ }
2847
+ getKey() {
2848
+ return `var-${this._sceneObject.state.name}`;
2849
+ }
2850
+ getKeys() {
2851
+ if (this._sceneObject.state.skipUrlSync) {
2852
+ return [];
2853
+ }
2854
+ return [this.getKey()];
2855
+ }
2856
+ getUrlState() {
2857
+ if (this._sceneObject.state.skipUrlSync) {
2858
+ return {};
2859
+ }
2860
+ let { value: values, text: texts } = this._sceneObject.state;
2861
+ values = Array.isArray(values) ? values : [values];
2862
+ texts = Array.isArray(texts) ? texts : [texts];
2863
+ const urlValue = lodash.zip(values, texts).map(toUrlValues);
2864
+ return { [this.getKey()]: urlValue };
2865
+ }
2866
+ updateFromUrl(values) {
2867
+ let urlValue = values[this.getKey()];
2868
+ if (urlValue != null) {
2869
+ if (!this._sceneObject.isActive) {
2870
+ this._sceneObject.skipNextValidation = true;
2871
+ }
2872
+ urlValue = Array.isArray(urlValue) ? urlValue : [urlValue];
2873
+ const valuesLabelsPairs = urlValue.map((value) => value ? value.split(",") : [value]);
2874
+ let [values2, labels] = lodash.unzip(valuesLabelsPairs);
2875
+ values2 = (values2 != null ? values2 : []).map(unescapeUrlDelimiters);
2876
+ labels = (labels != null ? labels : []).map(unescapeUrlDelimiters);
2877
+ this._sceneObject.setState({
2878
+ urlOptions: values2.map((value, idx) => ({
2879
+ value,
2880
+ text: labels[idx]
2881
+ }))
2882
+ });
2883
+ this._sceneObject.changeValueTo(values2, labels);
2884
+ }
2885
+ }
2886
+ }
2887
+ function toUrlValues([value, label]) {
2888
+ if (value === void 0 || value === null) {
2889
+ return "";
2890
+ }
2891
+ value = String(value);
2892
+ label = label === void 0 || label === null ? value : String(label);
2893
+ return toUrlCommaDelimitedString(value, label);
2894
+ }
2895
+
2843
2896
  var __defProp$z = Object.defineProperty;
2844
2897
  var __defProps$n = Object.defineProperties;
2845
2898
  var __getOwnPropDescs$n = Object.getOwnPropertyDescriptors;
@@ -2876,6 +2929,7 @@ class GroupByVariable extends MultiValueVariable {
2876
2929
  noValueOnClear: true
2877
2930
  }));
2878
2931
  this.isLazy = true;
2932
+ this._urlSync = new GroupByVariableUrlSyncHandler(this);
2879
2933
  this._getKeys = async (ds) => {
2880
2934
  var _a, _b, _c;
2881
2935
  const override = await ((_b = (_a = this.state).getTagKeysProvider) == null ? void 0 : _b.call(_a, this, null));
@@ -2925,9 +2979,11 @@ class GroupByVariable extends MultiValueVariable {
2925
2979
  this.setState(stateUpdate);
2926
2980
  }
2927
2981
  getValueOptions(args) {
2982
+ var _a;
2983
+ const urlOptions = (_a = this.state.urlOptions) != null ? _a : [];
2928
2984
  if (this.state.defaultOptions) {
2929
2985
  return rxjs.of(
2930
- this.state.defaultOptions.map((o) => ({
2986
+ lodash.unionBy(this.state.defaultOptions, urlOptions, "value").map((o) => ({
2931
2987
  label: o.text,
2932
2988
  value: String(o.value)
2933
2989
  }))
@@ -2943,7 +2999,7 @@ class GroupByVariable extends MultiValueVariable {
2943
2999
  return rxjs.from(this._getKeys(ds)).pipe(
2944
3000
  rxjs.take(1),
2945
3001
  rxjs.mergeMap((data) => {
2946
- const a = data.map((i) => {
3002
+ const a = lodash.unionBy(data, urlOptions, "value").map((i) => {
2947
3003
  return {
2948
3004
  label: i.text,
2949
3005
  value: i.value ? String(i.value) : i.text
@@ -2961,14 +3017,24 @@ class GroupByVariable extends MultiValueVariable {
2961
3017
  }
2962
3018
  GroupByVariable.Component = GroupByVariableRenderer;
2963
3019
  function GroupByVariableRenderer({ model }) {
2964
- const { value, key, maxVisibleValues, noValueOnClear } = model.useState();
2965
- const arrayValue = React.useMemo(() => lodash.isArray(value) ? value : [value], [value]);
3020
+ const { value, text, key, maxVisibleValues, noValueOnClear } = model.useState();
3021
+ const values = React.useMemo(() => {
3022
+ const arrayValue = lodash.isArray(value) ? value : [value];
3023
+ const arrayText = lodash.isArray(text) ? text : [text];
3024
+ return arrayValue.map((value2, idx) => {
3025
+ var _a;
3026
+ return {
3027
+ value: value2,
3028
+ label: String((_a = arrayText[idx]) != null ? _a : value2)
3029
+ };
3030
+ });
3031
+ }, [value, text]);
2966
3032
  const [isFetchingOptions, setIsFetchingOptions] = React.useState(false);
2967
3033
  const [isOptionsOpen, setIsOptionsOpen] = React.useState(false);
2968
- const [uncommittedValue, setUncommittedValue] = React.useState(arrayValue);
3034
+ const [uncommittedValue, setUncommittedValue] = React.useState(values);
2969
3035
  React.useEffect(() => {
2970
- setUncommittedValue(arrayValue);
2971
- }, [arrayValue]);
3036
+ setUncommittedValue(values);
3037
+ }, [values]);
2972
3038
  const onInputChange = model.onSearchChange ? (value2, meta) => {
2973
3039
  if (meta.action === "input-change") {
2974
3040
  model.onSearchChange(value2);
@@ -2993,13 +3059,13 @@ function GroupByVariableRenderer({ model }) {
2993
3059
  isLoading: isFetchingOptions,
2994
3060
  onInputChange,
2995
3061
  onBlur: () => {
2996
- model.changeValueTo(uncommittedValue);
3062
+ model.changeValueTo(uncommittedValue.map((x) => x.value));
2997
3063
  },
2998
3064
  onChange: (newValue, action) => {
2999
3065
  if (action.action === "clear" && noValueOnClear) {
3000
3066
  model.changeValueTo([]);
3001
3067
  }
3002
- setUncommittedValue(newValue.map((x) => x.value));
3068
+ setUncommittedValue(newValue);
3003
3069
  },
3004
3070
  onOpenMenu: async () => {
3005
3071
  setIsFetchingOptions(true);
@@ -3322,7 +3388,7 @@ class AdHocFiltersVariableUrlSyncHandler {
3322
3388
  if (filters.length === 0) {
3323
3389
  return { [this.getKey()]: [""] };
3324
3390
  }
3325
- const value = filters.map((filter) => toArray(filter).map(escapePipeDelimiters).join("|"));
3391
+ const value = filters.map((filter) => toArray(filter).map(escapeUrlPipeDelimiters).join("|"));
3326
3392
  return { [this.getKey()]: value };
3327
3393
  }
3328
3394
  updateFromUrl(values) {
@@ -3342,39 +3408,13 @@ function deserializeUrlToFilters(value) {
3342
3408
  const filter = toFilter(value);
3343
3409
  return filter === null ? [] : [filter];
3344
3410
  }
3345
- function escapePipeDelimiters(value) {
3346
- if (value === null || value === void 0) {
3347
- return "";
3348
- }
3349
- return value = /\|/g[Symbol.replace](value, "__gfp__");
3350
- }
3351
- function escapeCommaDelimiters(value) {
3352
- if (value === null || value === void 0) {
3353
- return "";
3354
- }
3355
- return /,/g[Symbol.replace](value, "__gfc__");
3356
- }
3357
- function unescapeDelimiters(value) {
3358
- if (value === null || value === void 0) {
3359
- return "";
3360
- }
3361
- value = /__gfp__/g[Symbol.replace](value, "|");
3362
- value = /__gfc__/g[Symbol.replace](value, ",");
3363
- return value;
3364
- }
3365
3411
  function toArray(filter) {
3366
3412
  return [
3367
- toCommaDelimitedString(filter.key, filter.keyLabel),
3413
+ toUrlCommaDelimitedString(filter.key, filter.keyLabel),
3368
3414
  filter.operator,
3369
- toCommaDelimitedString(filter.value, filter.valueLabel)
3415
+ toUrlCommaDelimitedString(filter.value, filter.valueLabel)
3370
3416
  ];
3371
3417
  }
3372
- function toCommaDelimitedString(key, label) {
3373
- if (!label || key === label) {
3374
- return escapeCommaDelimiters(key);
3375
- }
3376
- return [key, label].map(escapeCommaDelimiters).join(",");
3377
- }
3378
3418
  function toFilter(urlValue) {
3379
3419
  if (typeof urlValue !== "string" || urlValue.length === 0) {
3380
3420
  return null;
@@ -3383,7 +3423,7 @@ function toFilter(urlValue) {
3383
3423
  const [key2, label] = v.split(",");
3384
3424
  acc.push(key2, label != null ? label : key2);
3385
3425
  return acc;
3386
- }, []).map(unescapeDelimiters);
3426
+ }, []).map(unescapeUrlDelimiters);
3387
3427
  return {
3388
3428
  key,
3389
3429
  keyLabel,
@@ -4080,6 +4120,32 @@ function filterOutInactiveRunnerDuplicates(runners) {
4080
4120
  return activeItems;
4081
4121
  });
4082
4122
  }
4123
+ function escapeUrlPipeDelimiters(value) {
4124
+ if (value === null || value === void 0) {
4125
+ return "";
4126
+ }
4127
+ return value = /\|/g[Symbol.replace](value, "__gfp__");
4128
+ }
4129
+ function escapeUrlCommaDelimiters(value) {
4130
+ if (value === null || value === void 0) {
4131
+ return "";
4132
+ }
4133
+ return /,/g[Symbol.replace](value, "__gfc__");
4134
+ }
4135
+ function unescapeUrlDelimiters(value) {
4136
+ if (value === null || value === void 0) {
4137
+ return "";
4138
+ }
4139
+ value = /__gfp__/g[Symbol.replace](value, "|");
4140
+ value = /__gfc__/g[Symbol.replace](value, ",");
4141
+ return value;
4142
+ }
4143
+ function toUrlCommaDelimitedString(key, label) {
4144
+ if (!label || key === label) {
4145
+ return escapeUrlCommaDelimiters(key);
4146
+ }
4147
+ return [key, label].map(escapeUrlCommaDelimiters).join(",");
4148
+ }
4083
4149
 
4084
4150
  function isAdHocVariable(variable) {
4085
4151
  return variable.state.type === "adhoc";