@grafana/scenes 5.4.0--canary.813.9776503756.0 → 5.4.0

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.js CHANGED
@@ -2854,7 +2854,7 @@ var __objRest$3 = (source, exclude) => {
2854
2854
  return target;
2855
2855
  };
2856
2856
  const filterNoOp$2 = () => true;
2857
- function toSelectableValue$1(value, label) {
2857
+ function toSelectableValue$2(value, label) {
2858
2858
  return {
2859
2859
  value,
2860
2860
  label: label != null ? label : String(value)
@@ -2864,7 +2864,7 @@ function VariableValueSelect({ model }) {
2864
2864
  const { value, text, key, options, includeAll, isReadOnly } = model.useState();
2865
2865
  const [inputValue, setInputValue] = React.useState("");
2866
2866
  const [hasCustomValue, setHasCustomValue] = React.useState(false);
2867
- const selectValue = toSelectableValue$1(value, String(text));
2867
+ const selectValue = toSelectableValue$2(value, String(text));
2868
2868
  const optionSearcher = React.useMemo(() => getOptionSearcher(options, includeAll), [options, includeAll]);
2869
2869
  const onInputChange = (value2, { action }) => {
2870
2870
  if (action === "input-change") {
@@ -3178,7 +3178,8 @@ class GroupByVariable extends MultiValueVariable {
3178
3178
  return rxjs.of(
3179
3179
  this.state.defaultOptions.map((o) => ({
3180
3180
  label: o.text,
3181
- value: String(o.value)
3181
+ value: String(o.value),
3182
+ group: o.group
3182
3183
  }))
3183
3184
  );
3184
3185
  }
@@ -3201,7 +3202,8 @@ class GroupByVariable extends MultiValueVariable {
3201
3202
  const a = data.map((i) => {
3202
3203
  return {
3203
3204
  label: i.text,
3204
- value: i.value ? String(i.value) : i.text
3205
+ value: i.value ? String(i.value) : i.text,
3206
+ group: i.group
3205
3207
  };
3206
3208
  });
3207
3209
  return rxjs.of(a);
@@ -3250,7 +3252,10 @@ function GroupByVariableRenderer({ model }) {
3250
3252
  }
3251
3253
  return inputValue;
3252
3254
  };
3253
- const filteredOptions = optionSearcher(inputValue);
3255
+ const filteredOptions = React.useMemo(
3256
+ () => handleOptionGroups(optionSearcher(inputValue).map(toSelectableValue$1)),
3257
+ [optionSearcher, inputValue]
3258
+ );
3254
3259
  return /* @__PURE__ */ React__default["default"].createElement(ui.MultiSelect, {
3255
3260
  "data-testid": `GroupBySelect-${key}`,
3256
3261
  id: key,
@@ -3295,6 +3300,17 @@ function GroupByVariableRenderer({ model }) {
3295
3300
  });
3296
3301
  }
3297
3302
  const filterNoOp$1 = () => true;
3303
+ function toSelectableValue$1(input) {
3304
+ const { label, value, group } = input;
3305
+ const result = {
3306
+ label,
3307
+ value
3308
+ };
3309
+ if (group) {
3310
+ result.group = group;
3311
+ }
3312
+ return result;
3313
+ }
3298
3314
 
3299
3315
  function LoadingIndicator(props) {
3300
3316
  return /* @__PURE__ */ React__default["default"].createElement(ui.Tooltip, {
@@ -3311,7 +3327,7 @@ function LoadingIndicator(props) {
3311
3327
  }
3312
3328
 
3313
3329
  function ControlsLabel(props) {
3314
- const styles = ui.useStyles2(getStyles$9);
3330
+ const styles = ui.useStyles2(getStyles$a);
3315
3331
  const theme = ui.useTheme2();
3316
3332
  const isVertical = props.layout === "vertical";
3317
3333
  const loadingIndicator = Boolean(props.isLoading) ? /* @__PURE__ */ React__default["default"].createElement("div", {
@@ -3374,7 +3390,7 @@ function ControlsLabel(props) {
3374
3390
  }
3375
3391
  return labelElement;
3376
3392
  }
3377
- const getStyles$9 = (theme) => ({
3393
+ const getStyles$a = (theme) => ({
3378
3394
  horizontalLabel: css.css({
3379
3395
  background: theme.isDark ? theme.colors.background.primary : theme.colors.background.secondary,
3380
3396
  display: `flex`,
@@ -3409,13 +3425,42 @@ const getStyles$9 = (theme) => ({
3409
3425
  })
3410
3426
  });
3411
3427
 
3412
- function selectableValueToVariableValueOption(value) {
3413
- var _a;
3414
- return {
3415
- label: (_a = value.label) != null ? _a : String(value.value),
3416
- value: value.value
3428
+ function getAdhocOptionSearcher(options) {
3429
+ const ufuzzy = new uFuzzy__default["default"]();
3430
+ const haystack = [];
3431
+ const limit = 1e4;
3432
+ return (search) => {
3433
+ var _a;
3434
+ if (search === "") {
3435
+ if (options.length > limit) {
3436
+ return options.slice(0, limit);
3437
+ } else {
3438
+ return options;
3439
+ }
3440
+ }
3441
+ if (haystack.length === 0) {
3442
+ for (let i = 0; i < options.length; i++) {
3443
+ haystack.push((_a = options[i].label) != null ? _a : String(options[i].value));
3444
+ }
3445
+ }
3446
+ const idxs = ufuzzy.filter(haystack, search);
3447
+ const filteredOptions = [];
3448
+ if (idxs) {
3449
+ for (let i = 0; i < idxs.length; i++) {
3450
+ filteredOptions.push(options[idxs[i]]);
3451
+ if (filteredOptions.length > limit) {
3452
+ return filteredOptions;
3453
+ }
3454
+ }
3455
+ return filteredOptions;
3456
+ }
3457
+ if (options.length > limit) {
3458
+ return options.slice(0, limit);
3459
+ }
3460
+ return options;
3417
3461
  };
3418
3462
  }
3463
+
3419
3464
  function keyLabelToOption(key, label) {
3420
3465
  return key !== "" ? {
3421
3466
  value: key,
@@ -3425,7 +3470,7 @@ function keyLabelToOption(key, label) {
3425
3470
  const filterNoOp = () => true;
3426
3471
  function AdHocFilterRenderer({ filter, model }) {
3427
3472
  var _a, _b;
3428
- const styles = ui.useStyles2(getStyles$8);
3473
+ const styles = ui.useStyles2(getStyles$9);
3429
3474
  const [keys, setKeys] = React.useState([]);
3430
3475
  const [values, setValues] = React.useState([]);
3431
3476
  const [isKeysLoading, setIsKeysLoading] = React.useState(false);
@@ -3437,7 +3482,7 @@ function AdHocFilterRenderer({ filter, model }) {
3437
3482
  const keyValue = keyLabelToOption(filter.key, filter.keyLabel);
3438
3483
  const valueValue = keyLabelToOption(filter.value, filter.valueLabel);
3439
3484
  const optionSearcher = React.useMemo(
3440
- () => getOptionSearcher(values.map(selectableValueToVariableValueOption), void 0),
3485
+ () => getAdhocOptionSearcher(values),
3441
3486
  [values]
3442
3487
  );
3443
3488
  const onValueInputChange = (value, { action }) => {
@@ -3446,7 +3491,10 @@ function AdHocFilterRenderer({ filter, model }) {
3446
3491
  }
3447
3492
  return value;
3448
3493
  };
3449
- const filteredValueOptions = optionSearcher(valueInputValue);
3494
+ const filteredValueOptions = React.useMemo(
3495
+ () => handleOptionGroups(optionSearcher(valueInputValue)),
3496
+ [optionSearcher, valueInputValue]
3497
+ );
3450
3498
  const valueSelect = /* @__PURE__ */ React__default["default"].createElement(ui.Select, {
3451
3499
  virtualized: true,
3452
3500
  allowCustomValue: true,
@@ -3495,7 +3543,7 @@ function AdHocFilterRenderer({ filter, model }) {
3495
3543
  width: "auto",
3496
3544
  value: keyValue,
3497
3545
  placeholder: "Select label",
3498
- options: keys,
3546
+ options: handleOptionGroups(keys),
3499
3547
  onChange: (v) => model._updateFilter(filter, "key", v),
3500
3548
  autoFocus: filter.key === "",
3501
3549
  isOpen: isKeysOpen && !isKeysLoading,
@@ -3566,7 +3614,7 @@ function AdHocFilterRenderer({ filter, model }) {
3566
3614
  onClick: () => model._removeFilter(filter)
3567
3615
  }));
3568
3616
  }
3569
- const getStyles$8 = (theme) => ({
3617
+ const getStyles$9 = (theme) => ({
3570
3618
  field: css.css({
3571
3619
  marginBottom: 0
3572
3620
  }),
@@ -3823,7 +3871,7 @@ class AdHocFiltersVariable extends SceneObjectBase {
3823
3871
  var _a, _b, _c;
3824
3872
  const override = await ((_b = (_a = this.state).getTagValuesProvider) == null ? void 0 : _b.call(_a, this, filter));
3825
3873
  if (override && override.replace) {
3826
- return handleOptionGroups(dataFromResponse(override.values));
3874
+ return dataFromResponse(override.values).map(toSelectableValue);
3827
3875
  }
3828
3876
  const ds = await this._dataSourceSrv.get(this.state.datasource, this._scopedVars);
3829
3877
  if (!ds || !ds.getTagValues) {
@@ -3845,7 +3893,7 @@ class AdHocFiltersVariable extends SceneObjectBase {
3845
3893
  if (override) {
3846
3894
  values = values.concat(dataFromResponse(override.values));
3847
3895
  }
3848
- return handleOptionGroups(values);
3896
+ return values.map(toSelectableValue);
3849
3897
  }
3850
3898
  _addWip() {
3851
3899
  this.setState({
@@ -3865,7 +3913,7 @@ function renderExpression(builder, filters) {
3865
3913
  }
3866
3914
  function AdHocFiltersVariableRenderer({ model }) {
3867
3915
  const { filters, readOnly, addFilterButtonText } = model.useState();
3868
- const styles = ui.useStyles2(getStyles$7);
3916
+ const styles = ui.useStyles2(getStyles$8);
3869
3917
  return /* @__PURE__ */ React__default["default"].createElement("div", {
3870
3918
  className: styles.wrapper
3871
3919
  }, filters.map((filter, index) => /* @__PURE__ */ React__default["default"].createElement(React__default["default"].Fragment, {
@@ -3879,7 +3927,7 @@ function AdHocFiltersVariableRenderer({ model }) {
3879
3927
  addFilterButtonText
3880
3928
  }));
3881
3929
  }
3882
- const getStyles$7 = (theme) => ({
3930
+ const getStyles$8 = (theme) => ({
3883
3931
  wrapper: css.css({
3884
3932
  display: "flex",
3885
3933
  flexWrap: "wrap",
@@ -3892,34 +3940,20 @@ const getStyles$7 = (theme) => ({
3892
3940
  paddingRight: theme.spacing(0.5)
3893
3941
  })
3894
3942
  });
3895
- function toSelectableValue({ text, value }) {
3896
- return {
3943
+ function toSelectableValue(input) {
3944
+ const { text, value } = input;
3945
+ const result = {
3897
3946
  label: text,
3898
3947
  value: String(value != null ? value : text)
3899
3948
  };
3949
+ if ("group" in input) {
3950
+ result.group = input.group;
3951
+ }
3952
+ return result;
3900
3953
  }
3901
3954
  function isFilterComplete(filter) {
3902
3955
  return filter.key !== "" && filter.operator !== "" && filter.value !== "";
3903
3956
  }
3904
- function handleOptionGroups(values) {
3905
- const result = [];
3906
- const groupedResults = /* @__PURE__ */ new Map();
3907
- for (const value of values) {
3908
- const groupLabel = value.group;
3909
- if (groupLabel) {
3910
- let group = groupedResults.get(groupLabel);
3911
- if (!group) {
3912
- group = [];
3913
- groupedResults.set(groupLabel, group);
3914
- result.push({ label: groupLabel, options: group });
3915
- }
3916
- group.push(toSelectableValue(value));
3917
- } else {
3918
- result.push(toSelectableValue(value));
3919
- }
3920
- }
3921
- return result;
3922
- }
3923
3957
 
3924
3958
  class DataLayersMerger {
3925
3959
  constructor() {
@@ -4509,6 +4543,25 @@ function dataFromResponse(response) {
4509
4543
  function responseHasError(response) {
4510
4544
  return !Array.isArray(response) && Boolean(response.error);
4511
4545
  }
4546
+ function handleOptionGroups(values) {
4547
+ const result = [];
4548
+ const groupedResults = /* @__PURE__ */ new Map();
4549
+ for (const value of values) {
4550
+ const groupLabel = value.group;
4551
+ if (groupLabel) {
4552
+ let group = groupedResults.get(groupLabel);
4553
+ if (!group) {
4554
+ group = [];
4555
+ groupedResults.set(groupLabel, group);
4556
+ result.push({ label: groupLabel, options: group });
4557
+ }
4558
+ group.push(value);
4559
+ } else {
4560
+ result.push(value);
4561
+ }
4562
+ }
4563
+ return result;
4564
+ }
4512
4565
 
4513
4566
  function isAdHocVariable(variable) {
4514
4567
  return variable.state.type === "adhoc";
@@ -4763,6 +4816,7 @@ function VizPanelRenderer({ model }) {
4763
4816
  menu: panelMenu,
4764
4817
  onCancelQuery: model.onCancelQuery,
4765
4818
  onFocus: setPanelAttention,
4819
+ onMouseEnter: setPanelAttention,
4766
4820
  onMouseMove: debouncedMouseMove
4767
4821
  }, (innerWidth, innerHeight) => /* @__PURE__ */ React__default["default"].createElement(React__default["default"].Fragment, null, /* @__PURE__ */ React__default["default"].createElement(ui.ErrorBoundaryAlert, {
4768
4822
  dependencies: [plugin, data$1]
@@ -7995,7 +8049,7 @@ class EmbeddedScene extends SceneObjectBase {
7995
8049
  EmbeddedScene.Component = EmbeddedSceneRenderer;
7996
8050
  function EmbeddedSceneRenderer({ model }) {
7997
8051
  const { body, controls } = model.useState();
7998
- const styles = ui.useStyles2(getStyles$6);
8052
+ const styles = ui.useStyles2(getStyles$7);
7999
8053
  return /* @__PURE__ */ React__default["default"].createElement("div", {
8000
8054
  className: styles.container
8001
8055
  }, controls && /* @__PURE__ */ React__default["default"].createElement("div", {
@@ -8009,7 +8063,7 @@ function EmbeddedSceneRenderer({ model }) {
8009
8063
  model: body
8010
8064
  })));
8011
8065
  }
8012
- const getStyles$6 = (theme) => {
8066
+ const getStyles$7 = (theme) => {
8013
8067
  return {
8014
8068
  container: css.css({
8015
8069
  flexGrow: 1,
@@ -8148,8 +8202,9 @@ function useUniqueId() {
8148
8202
  }
8149
8203
  const LazyLoader = React__default["default"].forwardRef(
8150
8204
  (_a, ref) => {
8151
- var _b = _a, { children, onLoad, onChange } = _b, rest = __objRest$1(_b, ["children", "onLoad", "onChange"]);
8205
+ var _b = _a, { children, onLoad, onChange, className } = _b, rest = __objRest$1(_b, ["children", "onLoad", "onChange", "className"]);
8152
8206
  const id = useUniqueId();
8207
+ const { hideEmpty } = ui.useStyles2(getStyles$6);
8153
8208
  const [loaded, setLoaded] = React.useState(false);
8154
8209
  const [isInView, setIsInView] = React.useState(false);
8155
8210
  const innerRef = React.useRef(null);
@@ -8175,12 +8230,23 @@ const LazyLoader = React__default["default"].forwardRef(
8175
8230
  }
8176
8231
  };
8177
8232
  });
8233
+ const classes = `${loaded ? hideEmpty : ""} ${className}`;
8178
8234
  return /* @__PURE__ */ React__default["default"].createElement("div", __spreadValues$b({
8179
8235
  id,
8180
- ref: innerRef
8236
+ ref: innerRef,
8237
+ className: classes
8181
8238
  }, rest), loaded && (typeof children === "function" ? children({ isInView }) : children));
8182
8239
  }
8183
8240
  );
8241
+ function getStyles$6() {
8242
+ return {
8243
+ hideEmpty: css.css({
8244
+ "&:empty": {
8245
+ display: "none"
8246
+ }
8247
+ })
8248
+ };
8249
+ }
8184
8250
  LazyLoader.displayName = "LazyLoader";
8185
8251
  LazyLoader.callbacks = {};
8186
8252
  LazyLoader.addCallback = (id, c) => LazyLoader.callbacks[id] = c;
@@ -8689,6 +8755,9 @@ class SceneGridRow extends SceneObjectBase {
8689
8755
  height: 1,
8690
8756
  width: GRID_COLUMN_COUNT
8691
8757
  }));
8758
+ this._variableDependency = new VariableDependencyConfig(this, {
8759
+ statePaths: ["title"]
8760
+ });
8692
8761
  this.onCollapseToggle = () => {
8693
8762
  if (!this.state.isCollapsible) {
8694
8763
  return;
@@ -9158,15 +9227,15 @@ class SceneRefreshPicker extends SceneObjectBase {
9158
9227
  }
9159
9228
  getUrlState() {
9160
9229
  return {
9161
- refresh: this.state.refresh !== "" ? this.state.refresh : void 0
9230
+ refresh: this.state.refresh
9162
9231
  };
9163
9232
  }
9164
9233
  updateFromUrl(values) {
9165
9234
  const refresh = values.refresh;
9166
- if (typeof refresh === "string") {
9167
- this.setState({ refresh });
9168
- } else if (refresh == null) {
9169
- this.setState({ refresh: "" });
9235
+ if (refresh && typeof refresh === "string") {
9236
+ this.setState({
9237
+ refresh
9238
+ });
9170
9239
  }
9171
9240
  }
9172
9241
  }
@@ -11477,7 +11546,6 @@ const sceneUtils = {
11477
11546
  syncStateFromSearchParams,
11478
11547
  getUrlState,
11479
11548
  renderPrometheusLabelFilters,
11480
- safeStringifyValue,
11481
11549
  isAdHocVariable,
11482
11550
  isConstantVariable,
11483
11551
  isCustomVariable,