@grafana/scenes 6.43.0--canary.1296.19132771015.0 → 6.43.0--canary.1297.19135213685.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 (23) hide show
  1. package/dist/esm/components/VizPanel/VizPanel.js.map +1 -1
  2. package/dist/esm/components/VizPanel/VizPanelRenderer.js +2 -17
  3. package/dist/esm/components/VizPanel/VizPanelRenderer.js.map +1 -1
  4. package/dist/esm/variables/adhoc/AdHocFiltersCombobox/AdHocFiltersComboboxRenderer.js +2 -9
  5. package/dist/esm/variables/adhoc/AdHocFiltersCombobox/AdHocFiltersComboboxRenderer.js.map +1 -1
  6. package/dist/esm/variables/adhoc/AdHocFiltersVariable.js +23 -35
  7. package/dist/esm/variables/adhoc/AdHocFiltersVariable.js.map +1 -1
  8. package/dist/esm/variables/adhoc/AdHocFiltersVariableUrlSyncHandler.js +1 -1
  9. package/dist/esm/variables/adhoc/AdHocFiltersVariableUrlSyncHandler.js.map +1 -1
  10. package/dist/esm/variables/adhoc/controller/AdHocFiltersVariableController.js +1 -8
  11. package/dist/esm/variables/adhoc/controller/AdHocFiltersVariableController.js.map +1 -1
  12. package/dist/esm/variables/groupby/GroupByVariable.js +6 -32
  13. package/dist/esm/variables/groupby/GroupByVariable.js.map +1 -1
  14. package/dist/esm/variables/interpolation/formatRegistry.js +6 -3
  15. package/dist/esm/variables/interpolation/formatRegistry.js.map +1 -1
  16. package/dist/esm/variables/interpolation/sceneInterpolator.js +3 -3
  17. package/dist/esm/variables/interpolation/sceneInterpolator.js.map +1 -1
  18. package/dist/esm/variables/variants/SwitchVariable.js +1 -0
  19. package/dist/esm/variables/variants/SwitchVariable.js.map +1 -1
  20. package/dist/index.d.ts +3 -44
  21. package/dist/index.js +40 -103
  22. package/dist/index.js.map +1 -1
  23. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -1514,7 +1514,10 @@ const formatRegistry = new data.Registry(() => {
1514
1514
  id: "join",
1515
1515
  // join not yet available in depended @grafana/schema version
1516
1516
  name: "Join",
1517
- description: "Join values with a comma",
1517
+ description: i18n.t(
1518
+ "grafana-scenes.variables.format-registry.formats.description.join-values-with-a-comma",
1519
+ "Join values with a comma"
1520
+ ),
1518
1521
  formatter: (value, args) => {
1519
1522
  var _a;
1520
1523
  if (lodash.isArray(value)) {
@@ -1587,8 +1590,8 @@ const formatRegistry = new data.Registry(() => {
1587
1590
  id: schema.VariableFormatID.QueryParam,
1588
1591
  name: "Query parameter",
1589
1592
  description: "Format variables as URL parameters. Example in multi-variable scenario A + B + C => var-foo=A&var-foo=B&var-foo=C.",
1590
- formatter: (value, _args, variable) => {
1591
- if (variable.urlSync) {
1593
+ formatter: (value, _args, variable, fieldPath) => {
1594
+ if (variable.urlSync && !fieldPath) {
1592
1595
  const urlParam = variable.urlSync.getUrlState();
1593
1596
  return data.urlUtil.toUrlParams(urlParam);
1594
1597
  }
@@ -2442,7 +2445,7 @@ function sceneInterpolator(sceneObject, target, scopedVars, format, interpolatio
2442
2445
  }
2443
2446
  return match;
2444
2447
  }
2445
- const value = formatValue(sceneObject, variable, variable.getValue(fieldPath), fmt);
2448
+ const value = formatValue(sceneObject, variable, variable.getValue(fieldPath), fmt, fieldPath);
2446
2449
  if (interpolations) {
2447
2450
  interpolations.push({ match, variableName, fieldPath, format: fmt, value, found: value !== match });
2448
2451
  }
@@ -2466,7 +2469,7 @@ function lookupFormatVariable(name, match, scopedVars, sceneObject) {
2466
2469
  }
2467
2470
  return null;
2468
2471
  }
2469
- function formatValue(context, variable, value, formatNameOrFn) {
2472
+ function formatValue(context, variable, value, formatNameOrFn, fieldPath) {
2470
2473
  if (value === null || value === void 0) {
2471
2474
  return "";
2472
2475
  }
@@ -2501,7 +2504,7 @@ function formatValue(context, variable, value, formatNameOrFn) {
2501
2504
  console.error(`Variable format ${formatNameOrFn} not found. Using glob format as fallback.`);
2502
2505
  formatter = formatRegistry.get(schema.VariableFormatID.Glob);
2503
2506
  }
2504
- return formatter.formatter(value, args, variable);
2507
+ return formatter.formatter(value, args, variable, fieldPath);
2505
2508
  }
2506
2509
 
2507
2510
  function isSceneObject(obj) {
@@ -3585,29 +3588,23 @@ class GroupByVariable extends MultiValueVariable {
3585
3588
  });
3586
3589
  return applicableValues;
3587
3590
  }
3588
- async getGroupByApplicabilityForQueries(value, queries) {
3591
+ async _verifyApplicability() {
3589
3592
  const ds = await getDataSource(this.state.datasource, {
3590
3593
  __sceneObject: wrapInSafeSerializableSceneObject(this)
3591
3594
  });
3592
3595
  if (!ds.getDrilldownsApplicability) {
3593
3596
  return;
3594
3597
  }
3598
+ const queries = getQueriesForVariables(this);
3595
3599
  const timeRange = sceneGraph.getTimeRange(this).state.value;
3596
- return await ds.getDrilldownsApplicability({
3600
+ const value = this.state.value;
3601
+ const response = await ds.getDrilldownsApplicability({
3597
3602
  groupByKeys: Array.isArray(value) ? value.map((v) => String(v)) : value ? [String(value)] : [],
3598
3603
  queries,
3599
3604
  timeRange,
3600
3605
  scopes: sceneGraph.getScopes(this),
3601
3606
  ...getEnrichedFiltersRequest(this)
3602
3607
  });
3603
- }
3604
- async _verifyApplicability() {
3605
- const queries = getQueriesForVariables(this);
3606
- const value = this.state.value;
3607
- const response = await this.getGroupByApplicabilityForQueries(value, queries);
3608
- if (!response) {
3609
- return;
3610
- }
3611
3608
  if (!lodash.isEqual(response, this.state.keysApplicability)) {
3612
3609
  this.setState({ keysApplicability: response != null ? response : void 0 });
3613
3610
  this.publishEvent(new SceneVariableValueChangedEvent(this), true);
@@ -3638,15 +3635,6 @@ class GroupByVariable extends MultiValueVariable {
3638
3635
  getDefaultMultiState(options) {
3639
3636
  return { value: [], text: [] };
3640
3637
  }
3641
- /**
3642
- * Focus the group by input to start selecting dimensions.
3643
- */
3644
- focusInput() {
3645
- if (this.state.readOnly) {
3646
- return;
3647
- }
3648
- this.setState({ _shouldFocus: true });
3649
- }
3650
3638
  }
3651
3639
  GroupByVariable.Component = GroupByVariableRenderer;
3652
3640
  function GroupByVariableRenderer({ model }) {
@@ -3661,8 +3649,7 @@ function GroupByVariableRenderer({ model }) {
3661
3649
  includeAll,
3662
3650
  allowCustomValue = true,
3663
3651
  defaultValue,
3664
- keysApplicability,
3665
- _shouldFocus
3652
+ keysApplicability
3666
3653
  } = model.useState();
3667
3654
  const values = React.useMemo(() => {
3668
3655
  const arrayValue = lodash.isArray(value) ? value : [value];
@@ -3681,14 +3668,6 @@ function GroupByVariableRenderer({ model }) {
3681
3668
  const [uncommittedValue, setUncommittedValue] = React.useState(values);
3682
3669
  const optionSearcher = React.useMemo(() => getOptionSearcher(options, includeAll), [options, includeAll]);
3683
3670
  const hasDefaultValue = defaultValue !== void 0;
3684
- const selectRef = React.useRef(null);
3685
- React.useEffect(() => {
3686
- var _a, _b;
3687
- if (_shouldFocus) {
3688
- (_b = (_a = selectRef.current) == null ? void 0 : _a.focus) == null ? void 0 : _b.call(_a);
3689
- model.setState({ _shouldFocus: false });
3690
- }
3691
- }, [_shouldFocus, model]);
3692
3671
  React.useEffect(() => {
3693
3672
  setUncommittedValue(values);
3694
3673
  }, [values]);
@@ -3713,7 +3692,6 @@ function GroupByVariableRenderer({ model }) {
3713
3692
  return isMulti ? /* @__PURE__ */ React__default.default.createElement(
3714
3693
  ui.MultiSelect,
3715
3694
  {
3716
- selectRef,
3717
3695
  "aria-label": i18n.t(
3718
3696
  "grafana-scenes.variables.group-by-variable-renderer.aria-label-group-by-selector",
3719
3697
  "Group by selector"
@@ -3781,7 +3759,6 @@ function GroupByVariableRenderer({ model }) {
3781
3759
  ) : /* @__PURE__ */ React__default.default.createElement(
3782
3760
  ui.Select,
3783
3761
  {
3784
- selectRef,
3785
3762
  "aria-label": i18n.t(
3786
3763
  "grafana-scenes.variables.group-by-variable-renderer.aria-label-group-by-selector",
3787
3764
  "Group by selector"
@@ -3975,7 +3952,6 @@ function VizPanelRenderer({ model }) {
3975
3952
  hoverHeaderOffset,
3976
3953
  menu,
3977
3954
  headerActions,
3978
- subHeader,
3979
3955
  titleItems,
3980
3956
  seriesLimit,
3981
3957
  seriesLimitShowAll,
@@ -4040,20 +4016,6 @@ function VizPanelRenderer({ model }) {
4040
4016
  if (dataObject && dataObject.setContainerWidth) {
4041
4017
  dataObject.setContainerWidth(Math.round(width));
4042
4018
  }
4043
- let subHeaderElement = [];
4044
- if (subHeader) {
4045
- if (Array.isArray(subHeader)) {
4046
- subHeaderElement = subHeaderElement.concat(
4047
- subHeader.map((subHeaderItem) => {
4048
- return /* @__PURE__ */ React__default.default.createElement(subHeaderItem.Component, { model: subHeaderItem, key: `${subHeaderItem.state.key}` });
4049
- })
4050
- );
4051
- } else if (isSceneObject(subHeader)) {
4052
- subHeaderElement.push(/* @__PURE__ */ React__default.default.createElement(subHeader.Component, { model: subHeader }));
4053
- } else {
4054
- subHeaderElement.push(subHeader);
4055
- }
4056
- }
4057
4019
  let titleItemsElement = [];
4058
4020
  if (titleItems) {
4059
4021
  if (Array.isArray(titleItems)) {
@@ -4127,7 +4089,8 @@ function VizPanelRenderer({ model }) {
4127
4089
  const isReadyToRender = dataObject.isDataReadyToDisplay ? dataObject.isDataReadyToDisplay() : true;
4128
4090
  const context = model.getPanelContext();
4129
4091
  const panelId = model.getLegacyPanelId();
4130
- return /* @__PURE__ */ React__default.default.createElement("div", { className: relativeWrapper }, /* @__PURE__ */ React__default.default.createElement("div", { ref, className: absoluteWrapper, "data-viz-panel-key": model.state.key }, width > 0 && height > 0 && /* @__PURE__ */ React__default.default.createElement(
4092
+ return /* @__PURE__ */ React__default.default.createElement("div", { className: relativeWrapper }, /* @__PURE__ */ React__default.default.createElement("div", { ref, className: absoluteWrapper, "data-viz-panel-key": model.state.key }, width > 0 && height > 0 && // @ts-expect-error showMenuAlways remove when updating to @grafana/ui@12 fixed in https://github.com/grafana/grafana/pull/103553
4093
+ /* @__PURE__ */ React__default.default.createElement(
4131
4094
  ui.PanelChrome,
4132
4095
  {
4133
4096
  title: titleInterpolated,
@@ -4149,7 +4112,6 @@ function VizPanelRenderer({ model }) {
4149
4112
  onFocus: setPanelAttention,
4150
4113
  onMouseEnter: setPanelAttention,
4151
4114
  onMouseMove: debouncedMouseMove,
4152
- subHeaderContent: subHeaderElement.length ? subHeaderElement : void 0,
4153
4115
  onDragStart: (e) => {
4154
4116
  var _a2;
4155
4117
  (_a2 = dragHooks.onDragStart) == null ? void 0 : _a2.call(dragHooks, e, model);
@@ -7634,16 +7596,9 @@ const AdHocFiltersAlwaysWipCombobox = React.forwardRef(function AdHocFiltersAlwa
7634
7596
  });
7635
7597
 
7636
7598
  const AdHocFiltersComboboxRenderer = React.memo(function AdHocFiltersComboboxRenderer2({ controller }) {
7637
- const { originFilters, filters, readOnly, _shouldFocus } = controller.useState();
7599
+ const { originFilters, filters, readOnly } = controller.useState();
7638
7600
  const styles = ui.useStyles2(getStyles$9);
7639
7601
  const focusOnWipInputRef = React.useRef();
7640
- React.useEffect(() => {
7641
- var _a, _b;
7642
- if (_shouldFocus) {
7643
- (_a = focusOnWipInputRef.current) == null ? void 0 : _a.call(focusOnWipInputRef);
7644
- (_b = controller.resetFocusFlag) == null ? void 0 : _b.call(controller);
7645
- }
7646
- }, [_shouldFocus, controller]);
7647
7602
  return /* @__PURE__ */ React__default.default.createElement(
7648
7603
  "div",
7649
7604
  {
@@ -7810,8 +7765,7 @@ class AdHocFiltersVariableController {
7810
7765
  allowCustomValue: state.allowCustomValue,
7811
7766
  supportsMultiValueOperators: state.supportsMultiValueOperators,
7812
7767
  onAddCustomValue: state.onAddCustomValue,
7813
- wip: state._wip,
7814
- _shouldFocus: state._shouldFocus
7768
+ wip: state._wip
7815
7769
  };
7816
7770
  }
7817
7771
  async getKeys(currentKey) {
@@ -7844,12 +7798,6 @@ class AdHocFiltersVariableController {
7844
7798
  restoreOriginalFilter(filter) {
7845
7799
  this.model.restoreOriginalFilter(filter);
7846
7800
  }
7847
- focusInput() {
7848
- this.model.focusInput();
7849
- }
7850
- resetFocusFlag() {
7851
- this.model._resetFocusFlag();
7852
- }
7853
7801
  startProfile(name) {
7854
7802
  const queryController = getQueryController(this.model);
7855
7803
  queryController == null ? void 0 : queryController.startProfile(name);
@@ -7864,6 +7812,7 @@ class AdHocFiltersVariableController {
7864
7812
  }
7865
7813
  }
7866
7814
 
7815
+ const ORIGIN_FILTERS_KEY = "originFilters";
7867
7816
  const OPERATORS = [
7868
7817
  {
7869
7818
  value: "=",
@@ -8064,7 +8013,18 @@ class AdHocFiltersVariable extends SceneObjectBase {
8064
8013
  this._updateFilter(filter, original);
8065
8014
  }
8066
8015
  }
8067
- getValue() {
8016
+ getValue(fieldPath) {
8017
+ if (fieldPath === ORIGIN_FILTERS_KEY) {
8018
+ const originFilters = this.state.originFilters;
8019
+ if (!originFilters || (originFilters == null ? void 0 : originFilters.length) === 0) {
8020
+ return [];
8021
+ }
8022
+ return [
8023
+ ...originFilters.map(
8024
+ (filter) => toArray(filter).map(escapeOriginFilterUrlDelimiters).join("|").concat(`#${filter.origin}`)
8025
+ )
8026
+ ];
8027
+ }
8068
8028
  return this.state.filterExpression;
8069
8029
  }
8070
8030
  _updateFilter(filter, update) {
@@ -8173,28 +8133,25 @@ class AdHocFiltersVariable extends SceneObjectBase {
8173
8133
  });
8174
8134
  }
8175
8135
  }
8176
- async getFiltersApplicabilityForQueries(filters, queries) {
8136
+ async _verifyApplicability() {
8137
+ var _a, _b, _c;
8138
+ const filters = [...this.state.filters, ...(_a = this.state.originFilters) != null ? _a : []];
8177
8139
  const ds = await this._dataSourceSrv.get(this.state.datasource, this._scopedVars);
8178
8140
  if (!ds || !ds.getDrilldownsApplicability) {
8179
8141
  return;
8180
8142
  }
8143
+ if (!filters) {
8144
+ return;
8145
+ }
8181
8146
  const timeRange = sceneGraph.getTimeRange(this).state.value;
8182
- return await ds.getDrilldownsApplicability({
8147
+ const queries = this.state.useQueriesAsFilterForOptions ? getQueriesForVariables(this) : void 0;
8148
+ const response = await ds.getDrilldownsApplicability({
8183
8149
  filters,
8184
8150
  queries,
8185
8151
  timeRange,
8186
8152
  scopes: sceneGraph.getScopes(this),
8187
8153
  ...getEnrichedFiltersRequest(this)
8188
8154
  });
8189
- }
8190
- async _verifyApplicability() {
8191
- var _a, _b, _c;
8192
- const filters = [...this.state.filters, ...(_a = this.state.originFilters) != null ? _a : []];
8193
- const queries = this.state.useQueriesAsFilterForOptions ? getQueriesForVariables(this) : void 0;
8194
- const response = await this.getFiltersApplicabilityForQueries(filters, queries != null ? queries : []);
8195
- if (!response) {
8196
- return;
8197
- }
8198
8155
  const responseMap = /* @__PURE__ */ new Map();
8199
8156
  response.forEach((filter) => {
8200
8157
  responseMap.set(`${filter.key}${filter.origin ? `-${filter.origin}` : ""}`, filter);
@@ -8317,27 +8274,6 @@ class AdHocFiltersVariable extends SceneObjectBase {
8317
8274
  _wip: { key: "", value: "", operator: "=", condition: "" }
8318
8275
  });
8319
8276
  }
8320
- /**
8321
- * Focus the filter input to start adding a new filter.
8322
- * Works with both standard and combobox layouts.
8323
- */
8324
- focusInput() {
8325
- if (this.state.readOnly) {
8326
- return;
8327
- }
8328
- if (this.state.layout === "combobox") {
8329
- this.setState({ _shouldFocus: true });
8330
- }
8331
- }
8332
- /**
8333
- * Reset the focus flag after focusing has completed
8334
- * @internal
8335
- */
8336
- _resetFocusFlag() {
8337
- if (this.state._shouldFocus) {
8338
- this.setState({ _shouldFocus: false });
8339
- }
8340
- }
8341
8277
  _getOperators() {
8342
8278
  const { supportsMultiValueOperators, allowCustomValue = true } = this.state;
8343
8279
  return OPERATORS.filter(({ isMulti, isRegex }) => {
@@ -11964,6 +11900,7 @@ function SwitchVariableRenderer({ model }) {
11964
11900
  return /* @__PURE__ */ React__default.default.createElement("div", { className: styles.container }, /* @__PURE__ */ React__default.default.createElement(
11965
11901
  ui.Switch,
11966
11902
  {
11903
+ id: `var-${state.key}`,
11967
11904
  value: state.value === state.enabledValue,
11968
11905
  onChange: (event) => {
11969
11906
  model.setValue(event.currentTarget.checked ? state.enabledValue : state.disabledValue);