@grafana/scenes 4.13.0--canary.705.8801395113.0 → 4.13.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.
Files changed (27) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/dist/esm/components/VizPanel/VizPanelMenu.js +24 -24
  3. package/dist/esm/components/VizPanel/VizPanelMenu.js.map +1 -1
  4. package/dist/esm/components/layout/grid/SceneGridRow.js +3 -1
  5. package/dist/esm/components/layout/grid/SceneGridRow.js.map +1 -1
  6. package/dist/esm/core/sceneGraph/sceneGraph.js +2 -2
  7. package/dist/esm/core/sceneGraph/sceneGraph.js.map +1 -1
  8. package/dist/esm/querying/SceneQueryRunner.js +18 -5
  9. package/dist/esm/querying/SceneQueryRunner.js.map +1 -1
  10. package/dist/esm/variables/adhoc/AdHocFiltersVariableUrlSyncHandler.js +30 -6
  11. package/dist/esm/variables/adhoc/AdHocFiltersVariableUrlSyncHandler.js.map +1 -1
  12. package/dist/esm/variables/components/VariableValueSelect.js +3 -0
  13. package/dist/esm/variables/components/VariableValueSelect.js.map +1 -1
  14. package/dist/esm/variables/components/VariableValueSelectors.js +5 -2
  15. package/dist/esm/variables/components/VariableValueSelectors.js.map +1 -1
  16. package/dist/esm/variables/groupby/GroupByVariable.js +10 -24
  17. package/dist/esm/variables/groupby/GroupByVariable.js.map +1 -1
  18. package/dist/esm/variables/interpolation/sceneInterpolator.js +9 -2
  19. package/dist/esm/variables/interpolation/sceneInterpolator.js.map +1 -1
  20. package/dist/esm/variables/utils.js +1 -27
  21. package/dist/esm/variables/utils.js.map +1 -1
  22. package/dist/index.d.ts +11 -4
  23. package/dist/index.js +99 -141
  24. package/dist/index.js.map +1 -1
  25. package/package.json +2 -2
  26. package/dist/esm/variables/groupby/GroupByVariableUrlSyncHandler.js +0 -58
  27. package/dist/esm/variables/groupby/GroupByVariableUrlSyncHandler.js.map +0 -1
package/dist/index.js CHANGED
@@ -1304,7 +1304,7 @@ function lookupVariable(name, sceneObject) {
1304
1304
  return null;
1305
1305
  }
1306
1306
 
1307
- function sceneInterpolator(sceneObject, target, scopedVars, format) {
1307
+ function sceneInterpolator(sceneObject, target, scopedVars, format, interpolations) {
1308
1308
  if (!target) {
1309
1309
  return target != null ? target : "";
1310
1310
  }
@@ -1314,9 +1314,16 @@ function sceneInterpolator(sceneObject, target, scopedVars, format) {
1314
1314
  const fmt = fmt2 || fmt3 || format;
1315
1315
  const variable = lookupFormatVariable(variableName, match, scopedVars, sceneObject);
1316
1316
  if (!variable) {
1317
+ if (interpolations) {
1318
+ interpolations.push({ match, variableName, fieldPath, format: fmt, value: match, found: false });
1319
+ }
1317
1320
  return match;
1318
1321
  }
1319
- return formatValue(variable, variable.getValue(fieldPath), fmt);
1322
+ const value = formatValue(variable, variable.getValue(fieldPath), fmt);
1323
+ if (interpolations) {
1324
+ interpolations.push({ match, variableName, fieldPath, format: fmt, value, found: value !== match });
1325
+ }
1326
+ return value;
1320
1327
  });
1321
1328
  }
1322
1329
  function lookupFormatVariable(name, match, scopedVars, sceneObject) {
@@ -1455,11 +1462,11 @@ function getLayout(scene) {
1455
1462
  }
1456
1463
  return null;
1457
1464
  }
1458
- function interpolate(sceneObject, value, scopedVars, format) {
1465
+ function interpolate(sceneObject, value, scopedVars, format, interpolations) {
1459
1466
  if (value === "" || value == null) {
1460
1467
  return "";
1461
1468
  }
1462
- return sceneInterpolator(sceneObject, value, scopedVars, format);
1469
+ return sceneInterpolator(sceneObject, value, scopedVars, format, interpolations);
1463
1470
  }
1464
1471
  function hasVariableDependencyInLoadingState(sceneObject) {
1465
1472
  if (!sceneObject.variableDependency) {
@@ -2840,59 +2847,6 @@ class CustomAllValue {
2840
2847
  }
2841
2848
  }
2842
2849
 
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
-
2896
2850
  var __defProp$z = Object.defineProperty;
2897
2851
  var __defProps$n = Object.defineProperties;
2898
2852
  var __getOwnPropDescs$n = Object.getOwnPropertyDescriptors;
@@ -2929,7 +2883,6 @@ class GroupByVariable extends MultiValueVariable {
2929
2883
  noValueOnClear: true
2930
2884
  }));
2931
2885
  this.isLazy = true;
2932
- this._urlSync = new GroupByVariableUrlSyncHandler(this);
2933
2886
  this._getKeys = async (ds) => {
2934
2887
  var _a, _b, _c;
2935
2888
  const override = await ((_b = (_a = this.state).getTagKeysProvider) == null ? void 0 : _b.call(_a, this, null));
@@ -2979,11 +2932,9 @@ class GroupByVariable extends MultiValueVariable {
2979
2932
  this.setState(stateUpdate);
2980
2933
  }
2981
2934
  getValueOptions(args) {
2982
- var _a;
2983
- const urlOptions = (_a = this.state.urlOptions) != null ? _a : [];
2984
2935
  if (this.state.defaultOptions) {
2985
2936
  return rxjs.of(
2986
- lodash.unionBy(this.state.defaultOptions, urlOptions, "value").map((o) => ({
2937
+ this.state.defaultOptions.map((o) => ({
2987
2938
  label: o.text,
2988
2939
  value: String(o.value)
2989
2940
  }))
@@ -2999,7 +2950,7 @@ class GroupByVariable extends MultiValueVariable {
2999
2950
  return rxjs.from(this._getKeys(ds)).pipe(
3000
2951
  rxjs.take(1),
3001
2952
  rxjs.mergeMap((data) => {
3002
- const a = lodash.unionBy(data, urlOptions, "value").map((i) => {
2953
+ const a = data.map((i) => {
3003
2954
  return {
3004
2955
  label: i.text,
3005
2956
  value: i.value ? String(i.value) : i.text
@@ -3017,24 +2968,14 @@ class GroupByVariable extends MultiValueVariable {
3017
2968
  }
3018
2969
  GroupByVariable.Component = GroupByVariableRenderer;
3019
2970
  function GroupByVariableRenderer({ model }) {
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]);
2971
+ const { value, key, maxVisibleValues, noValueOnClear } = model.useState();
2972
+ const arrayValue = React.useMemo(() => lodash.isArray(value) ? value : [value], [value]);
3032
2973
  const [isFetchingOptions, setIsFetchingOptions] = React.useState(false);
3033
2974
  const [isOptionsOpen, setIsOptionsOpen] = React.useState(false);
3034
- const [uncommittedValue, setUncommittedValue] = React.useState(values);
2975
+ const [uncommittedValue, setUncommittedValue] = React.useState(arrayValue);
3035
2976
  React.useEffect(() => {
3036
- setUncommittedValue(values);
3037
- }, [values]);
2977
+ setUncommittedValue(arrayValue);
2978
+ }, [arrayValue]);
3038
2979
  const onInputChange = model.onSearchChange ? (value2, meta) => {
3039
2980
  if (meta.action === "input-change") {
3040
2981
  model.onSearchChange(value2);
@@ -3059,13 +3000,13 @@ function GroupByVariableRenderer({ model }) {
3059
3000
  isLoading: isFetchingOptions,
3060
3001
  onInputChange,
3061
3002
  onBlur: () => {
3062
- model.changeValueTo(uncommittedValue.map((x) => x.value));
3003
+ model.changeValueTo(uncommittedValue);
3063
3004
  },
3064
3005
  onChange: (newValue, action) => {
3065
3006
  if (action.action === "clear" && noValueOnClear) {
3066
3007
  model.changeValueTo([]);
3067
3008
  }
3068
- setUncommittedValue(newValue);
3009
+ setUncommittedValue(newValue.map((x) => x.value));
3069
3010
  },
3070
3011
  onOpenMenu: async () => {
3071
3012
  setIsFetchingOptions(true);
@@ -3388,7 +3329,7 @@ class AdHocFiltersVariableUrlSyncHandler {
3388
3329
  if (filters.length === 0) {
3389
3330
  return { [this.getKey()]: [""] };
3390
3331
  }
3391
- const value = filters.map((filter) => toArray(filter).map(escapeUrlPipeDelimiters).join("|"));
3332
+ const value = filters.map((filter) => toArray(filter).map(escapePipeDelimiters).join("|"));
3392
3333
  return { [this.getKey()]: value };
3393
3334
  }
3394
3335
  updateFromUrl(values) {
@@ -3408,13 +3349,39 @@ function deserializeUrlToFilters(value) {
3408
3349
  const filter = toFilter(value);
3409
3350
  return filter === null ? [] : [filter];
3410
3351
  }
3352
+ function escapePipeDelimiters(value) {
3353
+ if (value === null || value === void 0) {
3354
+ return "";
3355
+ }
3356
+ return value = /\|/g[Symbol.replace](value, "__gfp__");
3357
+ }
3358
+ function escapeCommaDelimiters(value) {
3359
+ if (value === null || value === void 0) {
3360
+ return "";
3361
+ }
3362
+ return /,/g[Symbol.replace](value, "__gfc__");
3363
+ }
3364
+ function unescapeDelimiters(value) {
3365
+ if (value === null || value === void 0) {
3366
+ return "";
3367
+ }
3368
+ value = /__gfp__/g[Symbol.replace](value, "|");
3369
+ value = /__gfc__/g[Symbol.replace](value, ",");
3370
+ return value;
3371
+ }
3411
3372
  function toArray(filter) {
3412
3373
  return [
3413
- toUrlCommaDelimitedString(filter.key, filter.keyLabel),
3374
+ toCommaDelimitedString(filter.key, filter.keyLabel),
3414
3375
  filter.operator,
3415
- toUrlCommaDelimitedString(filter.value, filter.valueLabel)
3376
+ toCommaDelimitedString(filter.value, filter.valueLabel)
3416
3377
  ];
3417
3378
  }
3379
+ function toCommaDelimitedString(key, label) {
3380
+ if (!label || key === label) {
3381
+ return escapeCommaDelimiters(key);
3382
+ }
3383
+ return [key, label].map(escapeCommaDelimiters).join(",");
3384
+ }
3418
3385
  function toFilter(urlValue) {
3419
3386
  if (typeof urlValue !== "string" || urlValue.length === 0) {
3420
3387
  return null;
@@ -3423,7 +3390,7 @@ function toFilter(urlValue) {
3423
3390
  const [key2, label] = v.split(",");
3424
3391
  acc.push(key2, label != null ? label : key2);
3425
3392
  return acc;
3426
- }, []).map(unescapeUrlDelimiters);
3393
+ }, []).map(unescapeDelimiters);
3427
3394
  return {
3428
3395
  key,
3429
3396
  keyLabel,
@@ -3757,11 +3724,7 @@ class SceneQueryRunner extends SceneObjectBase {
3757
3724
  })
3758
3725
  );
3759
3726
  }
3760
- this._subs.add(
3761
- timeRange.subscribeToState(() => {
3762
- this.runWithTimeRange(timeRange);
3763
- })
3764
- );
3727
+ this.subscribeToTimeRangeChanges(timeRange);
3765
3728
  if (this.shouldRunQueriesOnActivate()) {
3766
3729
  this.runQueries();
3767
3730
  }
@@ -3865,6 +3828,7 @@ class SceneQueryRunner extends SceneObjectBase {
3865
3828
  return true;
3866
3829
  }
3867
3830
  _onDeactivate() {
3831
+ var _a;
3868
3832
  if (this._querySub) {
3869
3833
  this._querySub.unsubscribe();
3870
3834
  this._querySub = void 0;
@@ -3873,6 +3837,9 @@ class SceneQueryRunner extends SceneObjectBase {
3873
3837
  this._dataLayersSub.unsubscribe();
3874
3838
  this._dataLayersSub = void 0;
3875
3839
  }
3840
+ (_a = this._timeSub) == null ? void 0 : _a.unsubscribe();
3841
+ this._timeSub = void 0;
3842
+ this._timeSubRange = void 0;
3876
3843
  this._adhocFiltersVar = void 0;
3877
3844
  this._groupByVar = void 0;
3878
3845
  this._variableValueRecorder.recordCurrentDependencyValuesForSceneObject(this);
@@ -3896,8 +3863,21 @@ class SceneQueryRunner extends SceneObjectBase {
3896
3863
  isDataReadyToDisplay() {
3897
3864
  return Boolean(this.state._hasFetchedData);
3898
3865
  }
3866
+ subscribeToTimeRangeChanges(timeRange) {
3867
+ if (this._timeSubRange === timeRange) {
3868
+ return;
3869
+ }
3870
+ if (this._timeSub) {
3871
+ this._timeSub.unsubscribe();
3872
+ }
3873
+ this._timeSubRange = timeRange;
3874
+ this._timeSub = timeRange.subscribeToState(() => {
3875
+ this.runWithTimeRange(timeRange);
3876
+ });
3877
+ }
3899
3878
  runQueries() {
3900
3879
  const timeRange = sceneGraph.getTimeRange(this);
3880
+ this.subscribeToTimeRangeChanges(timeRange);
3901
3881
  this.runWithTimeRange(timeRange);
3902
3882
  }
3903
3883
  getMaxDataPoints() {
@@ -4120,32 +4100,6 @@ function filterOutInactiveRunnerDuplicates(runners) {
4120
4100
  return activeItems;
4121
4101
  });
4122
4102
  }
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
- }
4149
4103
 
4150
4104
  function isAdHocVariable(variable) {
4151
4105
  return variable.state.type === "adhoc";
@@ -6078,7 +6032,8 @@ function VariableValueSelectWrapper({ variable, layout, showAlways }) {
6078
6032
  }
6079
6033
  if (layout === "vertical") {
6080
6034
  return /* @__PURE__ */ React__default["default"].createElement("div", {
6081
- className: verticalContainer
6035
+ className: verticalContainer,
6036
+ "data-testid": e2eSelectors.selectors.pages.Dashboard.SubMenu.submenuItem
6082
6037
  }, /* @__PURE__ */ React__default["default"].createElement(VariableLabel, {
6083
6038
  variable,
6084
6039
  layout
@@ -6087,7 +6042,8 @@ function VariableValueSelectWrapper({ variable, layout, showAlways }) {
6087
6042
  }));
6088
6043
  }
6089
6044
  return /* @__PURE__ */ React__default["default"].createElement("div", {
6090
- className: containerStyle
6045
+ className: containerStyle,
6046
+ "data-testid": e2eSelectors.selectors.pages.Dashboard.SubMenu.submenuItem
6091
6047
  }, /* @__PURE__ */ React__default["default"].createElement(VariableLabel, {
6092
6048
  variable
6093
6049
  }), /* @__PURE__ */ React__default["default"].createElement(variable.Component, {
@@ -6422,6 +6378,7 @@ function VariableValueSelect({ model }) {
6422
6378
  tabSelectsValue: false,
6423
6379
  onInputChange,
6424
6380
  options: model.getOptionsForSelect(),
6381
+ "data-testid": e2eSelectors.selectors.pages.Dashboard.SubMenu.submenuItemValueDropDownValueLinkTexts(`${value}`),
6425
6382
  onChange: (newValue) => {
6426
6383
  model.changeValueTo(newValue.value, newValue.label);
6427
6384
  }
@@ -6458,6 +6415,7 @@ function VariableValueSelectMulti({ model }) {
6458
6415
  onBlur: () => {
6459
6416
  model.changeValueTo(uncommittedValue);
6460
6417
  },
6418
+ "data-testid": e2eSelectors.selectors.pages.Dashboard.SubMenu.submenuItemValueDropDownValueLinkTexts(`${uncommittedValue}`),
6461
6419
  onChange: (newValue, action) => {
6462
6420
  if (action.action === "clear" && noValueOnClear) {
6463
6421
  model.changeValueTo([]);
@@ -7655,31 +7613,30 @@ function VizPanelMenuRenderer({ model }) {
7655
7613
  }
7656
7614
  }, []);
7657
7615
  const renderItems = (items2) => {
7658
- return items2.map(
7659
- (item) => {
7660
- switch (item.type) {
7661
- case "divider":
7662
- return /* @__PURE__ */ React__default["default"].createElement(ui.Menu.Divider, {
7663
- key: item.text
7664
- });
7665
- case "group":
7666
- return /* @__PURE__ */ React__default["default"].createElement(ui.Menu.Group, {
7667
- key: item.text,
7668
- label: item.text
7669
- }, item.subMenu ? renderItems(item.subMenu) : void 0);
7670
- default:
7671
- return /* @__PURE__ */ React__default["default"].createElement(ui.Menu.Item, {
7672
- key: item.text,
7673
- label: item.text,
7674
- icon: item.iconClassName,
7675
- childItems: item.subMenu ? renderItems(item.subMenu) : void 0,
7676
- url: item.href,
7677
- onClick: item.onClick,
7678
- shortcut: item.shortcut
7679
- });
7680
- }
7616
+ return items2.map((item) => {
7617
+ switch (item.type) {
7618
+ case "divider":
7619
+ return /* @__PURE__ */ React__default["default"].createElement(ui.Menu.Divider, {
7620
+ key: item.text
7621
+ });
7622
+ case "group":
7623
+ return /* @__PURE__ */ React__default["default"].createElement(ui.Menu.Group, {
7624
+ key: item.text,
7625
+ label: item.text
7626
+ }, item.subMenu ? renderItems(item.subMenu) : void 0);
7627
+ default:
7628
+ return /* @__PURE__ */ React__default["default"].createElement(ui.Menu.Item, {
7629
+ key: item.text,
7630
+ label: item.text,
7631
+ icon: item.iconClassName,
7632
+ childItems: item.subMenu ? renderItems(item.subMenu) : void 0,
7633
+ url: item.href,
7634
+ onClick: item.onClick,
7635
+ shortcut: item.shortcut,
7636
+ testId: e2eSelectors.selectors.components.Panels.Panel.menuItems(item.text)
7637
+ });
7681
7638
  }
7682
- );
7639
+ });
7683
7640
  };
7684
7641
  return /* @__PURE__ */ React__default["default"].createElement(ui.Menu, {
7685
7642
  ref
@@ -8303,7 +8260,8 @@ function SceneGridRowRenderer({ model }) {
8303
8260
  }, /* @__PURE__ */ React__default["default"].createElement("button", {
8304
8261
  onClick: model.onCollapseToggle,
8305
8262
  className: styles.rowTitleButton,
8306
- "aria-label": isCollapsed ? "Expand row" : "Collapse row"
8263
+ "aria-label": isCollapsed ? "Expand row" : "Collapse row",
8264
+ "data-testid": e2eSelectors.selectors.components.DashboardRow.title(sceneGraph.interpolate(model, title, void 0, "text"))
8307
8265
  }, isCollapsible && /* @__PURE__ */ React__default["default"].createElement(ui.Icon, {
8308
8266
  name: isCollapsed ? "angle-right" : "angle-down"
8309
8267
  }), /* @__PURE__ */ React__default["default"].createElement("span", {