@grafana/scenes 4.16.0 → 4.17.1

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
@@ -145,7 +145,7 @@ var __spreadValues$I = (a, b) => {
145
145
  return a;
146
146
  };
147
147
  var __spreadProps$r = (a, b) => __defProps$r(a, __getOwnPropDescs$r(b));
148
- var __objRest$3 = (source, exclude) => {
148
+ var __objRest$4 = (source, exclude) => {
149
149
  var target = {};
150
150
  for (var prop in source)
151
151
  if (__hasOwnProp$I.call(source, prop) && exclude.indexOf(prop) < 0)
@@ -158,7 +158,7 @@ var __objRest$3 = (source, exclude) => {
158
158
  return target;
159
159
  };
160
160
  function SceneComponentWrapperWithoutMemo(_a) {
161
- var _b = _a, { model } = _b, otherProps = __objRest$3(_b, ["model"]);
161
+ var _b = _a, { model } = _b, otherProps = __objRest$4(_b, ["model"]);
162
162
  var _a2;
163
163
  const Component = (_a2 = model.constructor["Component"]) != null ? _a2 : EmptyRenderer;
164
164
  const [_, setValue] = React.useState(0);
@@ -2874,9 +2874,161 @@ var __spreadValues$z = (a, b) => {
2874
2874
  return a;
2875
2875
  };
2876
2876
  var __spreadProps$n = (a, b) => __defProps$n(a, __getOwnPropDescs$n(b));
2877
+ var __objRest$3 = (source, exclude) => {
2878
+ var target = {};
2879
+ for (var prop in source)
2880
+ if (__hasOwnProp$z.call(source, prop) && exclude.indexOf(prop) < 0)
2881
+ target[prop] = source[prop];
2882
+ if (source != null && __getOwnPropSymbols$z)
2883
+ for (var prop of __getOwnPropSymbols$z(source)) {
2884
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$z.call(source, prop))
2885
+ target[prop] = source[prop];
2886
+ }
2887
+ return target;
2888
+ };
2889
+ function VariableValueSelect({ model }) {
2890
+ const { value, key } = model.useState();
2891
+ const onInputChange = model.onSearchChange ? (value2, meta) => {
2892
+ if (meta.action === "input-change") {
2893
+ model.onSearchChange(value2);
2894
+ }
2895
+ } : void 0;
2896
+ return /* @__PURE__ */ React__default["default"].createElement(ui.Select, {
2897
+ id: key,
2898
+ placeholder: "Select value",
2899
+ width: "auto",
2900
+ value,
2901
+ allowCustomValue: true,
2902
+ virtualized: true,
2903
+ tabSelectsValue: false,
2904
+ onInputChange,
2905
+ options: model.getOptionsForSelect(),
2906
+ "data-testid": e2eSelectors.selectors.pages.Dashboard.SubMenu.submenuItemValueDropDownValueLinkTexts(`${value}`),
2907
+ onChange: (newValue) => {
2908
+ model.changeValueTo(newValue.value, newValue.label);
2909
+ }
2910
+ });
2911
+ }
2912
+ function VariableValueSelectMulti({ model }) {
2913
+ const { value, key, maxVisibleValues, noValueOnClear } = model.useState();
2914
+ const arrayValue = React.useMemo(() => lodash.isArray(value) ? value : [value], [value]);
2915
+ const options = model.getOptionsForSelect();
2916
+ const [uncommittedValue, setUncommittedValue] = React.useState(arrayValue);
2917
+ const [inputValue, setInputValue] = React.useState("");
2918
+ React.useEffect(() => {
2919
+ setUncommittedValue(arrayValue);
2920
+ }, [arrayValue]);
2921
+ const onInputChange = (value2, { action }) => {
2922
+ if (action === "input-change") {
2923
+ setInputValue(value2);
2924
+ if (model.onSearchChange) {
2925
+ model.onSearchChange(value2);
2926
+ }
2927
+ return value2;
2928
+ }
2929
+ if (action === "input-blur") {
2930
+ setInputValue("");
2931
+ return "";
2932
+ }
2933
+ return inputValue;
2934
+ };
2935
+ const placeholder = options.length > 0 ? "Select value" : "";
2936
+ return /* @__PURE__ */ React__default["default"].createElement(ui.MultiSelect, {
2937
+ id: key,
2938
+ placeholder,
2939
+ width: "auto",
2940
+ inputValue,
2941
+ value: uncommittedValue,
2942
+ noMultiValueWrap: true,
2943
+ maxVisibleValues: maxVisibleValues != null ? maxVisibleValues : 5,
2944
+ tabSelectsValue: false,
2945
+ virtualized: true,
2946
+ allowCustomValue: true,
2947
+ options: model.getOptionsForSelect(),
2948
+ closeMenuOnSelect: false,
2949
+ components: { Option: OptionWithCheckbox },
2950
+ isClearable: true,
2951
+ hideSelectedOptions: false,
2952
+ onInputChange,
2953
+ onBlur: () => {
2954
+ model.changeValueTo(uncommittedValue);
2955
+ },
2956
+ "data-testid": e2eSelectors.selectors.pages.Dashboard.SubMenu.submenuItemValueDropDownValueLinkTexts(`${uncommittedValue}`),
2957
+ onChange: (newValue, action) => {
2958
+ if (action.action === "clear" && noValueOnClear) {
2959
+ model.changeValueTo([]);
2960
+ }
2961
+ setUncommittedValue(newValue.map((x) => x.value));
2962
+ }
2963
+ });
2964
+ }
2965
+ const OptionWithCheckbox = ({
2966
+ children,
2967
+ data,
2968
+ innerProps,
2969
+ innerRef,
2970
+ isFocused,
2971
+ isSelected,
2972
+ renderOptionLabel
2973
+ }) => {
2974
+ const _a = innerProps, rest = __objRest$3(_a, ["onMouseMove", "onMouseOver"]);
2975
+ const theme = ui.useTheme2();
2976
+ const selectStyles = ui.getSelectStyles(theme);
2977
+ const optionStyles = ui.useStyles2(getOptionStyles);
2978
+ return /* @__PURE__ */ React__default["default"].createElement("div", __spreadProps$n(__spreadValues$z({
2979
+ ref: innerRef,
2980
+ className: css.cx(selectStyles.option, isFocused && selectStyles.optionFocused)
2981
+ }, rest), {
2982
+ "aria-label": "Select option",
2983
+ title: data.title
2984
+ }), /* @__PURE__ */ React__default["default"].createElement("div", {
2985
+ className: optionStyles.checkbox
2986
+ }, /* @__PURE__ */ React__default["default"].createElement(ui.Checkbox, {
2987
+ value: isSelected
2988
+ })), /* @__PURE__ */ React__default["default"].createElement("div", {
2989
+ className: selectStyles.optionBody
2990
+ }, /* @__PURE__ */ React__default["default"].createElement("span", null, children)));
2991
+ };
2992
+ OptionWithCheckbox.displayName = "SelectMenuOptions";
2993
+ const getOptionStyles = (theme) => ({
2994
+ checkbox: css.css({
2995
+ marginRight: theme.spacing(2)
2996
+ })
2997
+ });
2998
+ function renderSelectForVariable(model) {
2999
+ if (model.state.isMulti) {
3000
+ return /* @__PURE__ */ React__default["default"].createElement(VariableValueSelectMulti, {
3001
+ model
3002
+ });
3003
+ } else {
3004
+ return /* @__PURE__ */ React__default["default"].createElement(VariableValueSelect, {
3005
+ model
3006
+ });
3007
+ }
3008
+ }
3009
+
3010
+ var __defProp$y = Object.defineProperty;
3011
+ var __defProps$m = Object.defineProperties;
3012
+ var __getOwnPropDescs$m = Object.getOwnPropertyDescriptors;
3013
+ var __getOwnPropSymbols$y = Object.getOwnPropertySymbols;
3014
+ var __hasOwnProp$y = Object.prototype.hasOwnProperty;
3015
+ var __propIsEnum$y = Object.prototype.propertyIsEnumerable;
3016
+ var __defNormalProp$y = (obj, key, value) => key in obj ? __defProp$y(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3017
+ var __spreadValues$y = (a, b) => {
3018
+ for (var prop in b || (b = {}))
3019
+ if (__hasOwnProp$y.call(b, prop))
3020
+ __defNormalProp$y(a, prop, b[prop]);
3021
+ if (__getOwnPropSymbols$y)
3022
+ for (var prop of __getOwnPropSymbols$y(b)) {
3023
+ if (__propIsEnum$y.call(b, prop))
3024
+ __defNormalProp$y(a, prop, b[prop]);
3025
+ }
3026
+ return a;
3027
+ };
3028
+ var __spreadProps$m = (a, b) => __defProps$m(a, __getOwnPropDescs$m(b));
2877
3029
  class GroupByVariable extends MultiValueVariable {
2878
3030
  constructor(initialState) {
2879
- super(__spreadProps$n(__spreadValues$z({
3031
+ super(__spreadProps$m(__spreadValues$y({
2880
3032
  isMulti: true,
2881
3033
  name: "",
2882
3034
  value: [],
@@ -2980,21 +3132,32 @@ function GroupByVariableRenderer({ model }) {
2980
3132
  const arrayValue = React.useMemo(() => lodash.isArray(value) ? value : [value], [value]);
2981
3133
  const [isFetchingOptions, setIsFetchingOptions] = React.useState(false);
2982
3134
  const [isOptionsOpen, setIsOptionsOpen] = React.useState(false);
3135
+ const [inputValue, setInputValue] = React.useState("");
2983
3136
  const [uncommittedValue, setUncommittedValue] = React.useState(arrayValue);
2984
3137
  React.useEffect(() => {
2985
3138
  setUncommittedValue(arrayValue);
2986
3139
  }, [arrayValue]);
2987
- const onInputChange = model.onSearchChange ? (value2, meta) => {
2988
- if (meta.action === "input-change") {
2989
- model.onSearchChange(value2);
3140
+ const onInputChange = (value2, { action }) => {
3141
+ if (action === "input-change") {
3142
+ setInputValue(value2);
3143
+ if (model.onSearchChange) {
3144
+ model.onSearchChange(value2);
3145
+ }
3146
+ return value2;
2990
3147
  }
2991
- } : void 0;
3148
+ if (action === "input-blur") {
3149
+ setInputValue("");
3150
+ return "";
3151
+ }
3152
+ return inputValue;
3153
+ };
2992
3154
  const placeholder = "Select value";
2993
3155
  return /* @__PURE__ */ React__default["default"].createElement(ui.MultiSelect, {
2994
3156
  "data-testid": `GroupBySelect-${key}`,
2995
3157
  id: key,
2996
3158
  placeholder,
2997
3159
  width: "auto",
3160
+ inputValue,
2998
3161
  value: uncommittedValue,
2999
3162
  noMultiValueWrap: true,
3000
3163
  maxVisibleValues: maxVisibleValues != null ? maxVisibleValues : 5,
@@ -3005,7 +3168,9 @@ function GroupByVariableRenderer({ model }) {
3005
3168
  closeMenuOnSelect: false,
3006
3169
  isOpen: isOptionsOpen,
3007
3170
  isClearable: true,
3171
+ hideSelectedOptions: false,
3008
3172
  isLoading: isFetchingOptions,
3173
+ components: { Option: OptionWithCheckbox },
3009
3174
  onInputChange,
3010
3175
  onBlur: () => {
3011
3176
  model.changeValueTo(uncommittedValue);
@@ -3141,25 +3306,6 @@ const getStyles$8 = (theme) => ({
3141
3306
  })
3142
3307
  });
3143
3308
 
3144
- var __defProp$y = Object.defineProperty;
3145
- var __defProps$m = Object.defineProperties;
3146
- var __getOwnPropDescs$m = Object.getOwnPropertyDescriptors;
3147
- var __getOwnPropSymbols$y = Object.getOwnPropertySymbols;
3148
- var __hasOwnProp$y = Object.prototype.hasOwnProperty;
3149
- var __propIsEnum$y = Object.prototype.propertyIsEnumerable;
3150
- var __defNormalProp$y = (obj, key, value) => key in obj ? __defProp$y(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3151
- var __spreadValues$y = (a, b) => {
3152
- for (var prop in b || (b = {}))
3153
- if (__hasOwnProp$y.call(b, prop))
3154
- __defNormalProp$y(a, prop, b[prop]);
3155
- if (__getOwnPropSymbols$y)
3156
- for (var prop of __getOwnPropSymbols$y(b)) {
3157
- if (__propIsEnum$y.call(b, prop))
3158
- __defNormalProp$y(a, prop, b[prop]);
3159
- }
3160
- return a;
3161
- };
3162
- var __spreadProps$m = (a, b) => __defProps$m(a, __getOwnPropDescs$m(b));
3163
3309
  function keyLabelToOption(key, label) {
3164
3310
  return key !== "" ? {
3165
3311
  value: key,
@@ -3169,7 +3315,12 @@ function keyLabelToOption(key, label) {
3169
3315
  function AdHocFilterRenderer({ filter, model }) {
3170
3316
  var _a, _b;
3171
3317
  const styles = ui.useStyles2(getStyles$7);
3172
- const [state, setState] = React.useState({});
3318
+ const [keys, setKeys] = React.useState([]);
3319
+ const [values, setValues] = React.useState([]);
3320
+ const [isKeysLoading, setIsKeysLoading] = React.useState(false);
3321
+ const [isValuesLoading, setIsValuesLoading] = React.useState(false);
3322
+ const [isKeysOpen, setIsKeysOpen] = React.useState(false);
3323
+ const [isValuesOpen, setIsValuesOpen] = React.useState(false);
3173
3324
  const keyValue = keyLabelToOption(filter.key, filter.keyLabel);
3174
3325
  const valueValue = keyLabelToOption(filter.value, filter.valueLabel);
3175
3326
  const valueSelect = /* @__PURE__ */ React__default["default"].createElement(ui.Select, {
@@ -3177,44 +3328,48 @@ function AdHocFilterRenderer({ filter, model }) {
3177
3328
  allowCreateWhileLoading: true,
3178
3329
  formatCreateLabel: (inputValue) => `Use custom value: ${inputValue}`,
3179
3330
  disabled: model.state.readOnly,
3180
- className: state.isKeysOpen ? styles.widthWhenOpen : void 0,
3331
+ className: isKeysOpen ? styles.widthWhenOpen : void 0,
3181
3332
  width: "auto",
3182
3333
  value: valueValue,
3183
3334
  placeholder: "Select value",
3184
- options: state.values,
3335
+ options: values,
3185
3336
  onChange: (v) => model._updateFilter(filter, "value", v),
3186
- isOpen: state.isValuesOpen,
3187
- isLoading: state.isValuesLoading,
3337
+ isOpen: isValuesOpen && !isValuesLoading,
3338
+ isLoading: isValuesLoading,
3188
3339
  autoFocus: filter.key !== "" && filter.value === "",
3189
3340
  openMenuOnFocus: true,
3190
3341
  onOpenMenu: async () => {
3191
- setState(__spreadProps$m(__spreadValues$y({}, state), { isValuesLoading: true, isValuesOpen: true }));
3192
- const values = await model._getValuesFor(filter);
3193
- setState(__spreadProps$m(__spreadValues$y({}, state), { isValuesLoading: false, values }));
3342
+ setIsValuesLoading(true);
3343
+ setIsValuesOpen(true);
3344
+ const values2 = await model._getValuesFor(filter);
3345
+ setIsValuesLoading(false);
3346
+ setValues(values2);
3194
3347
  },
3195
3348
  onCloseMenu: () => {
3196
- setState(__spreadProps$m(__spreadValues$y({}, state), { isValuesOpen: false }));
3349
+ setIsValuesOpen(false);
3197
3350
  }
3198
3351
  });
3199
3352
  const keySelect = /* @__PURE__ */ React__default["default"].createElement(ui.Select, {
3200
- key: `${state.isValuesLoading ? "loading" : "loaded"}`,
3353
+ key: `${isValuesLoading ? "loading" : "loaded"}`,
3201
3354
  disabled: model.state.readOnly,
3202
- className: state.isKeysOpen ? styles.widthWhenOpen : void 0,
3355
+ className: isKeysOpen ? styles.widthWhenOpen : void 0,
3203
3356
  width: "auto",
3204
3357
  value: keyValue,
3205
3358
  placeholder: "Select label",
3206
- options: state.keys,
3359
+ options: keys,
3207
3360
  onChange: (v) => model._updateFilter(filter, "key", v),
3208
3361
  autoFocus: filter.key === "",
3209
- isOpen: state.isKeysOpen,
3210
- isLoading: state.isKeysLoading,
3362
+ isOpen: isKeysOpen && !isKeysLoading,
3363
+ isLoading: isKeysLoading,
3211
3364
  onOpenMenu: async () => {
3212
- setState(__spreadProps$m(__spreadValues$y({}, state), { isKeysLoading: true }));
3213
- const keys = await model._getKeys(filter.key);
3214
- setState(__spreadProps$m(__spreadValues$y({}, state), { isKeysLoading: false, isKeysOpen: true, keys }));
3365
+ setIsKeysOpen(true);
3366
+ setIsKeysLoading(true);
3367
+ const keys2 = await model._getKeys(filter.key);
3368
+ setIsKeysLoading(false);
3369
+ setKeys(keys2);
3215
3370
  },
3216
3371
  onCloseMenu: () => {
3217
- setState(__spreadProps$m(__spreadValues$y({}, state), { isKeysOpen: false }));
3372
+ setIsKeysOpen(false);
3218
3373
  },
3219
3374
  onBlur: () => {
3220
3375
  if (filter.key === "") {
@@ -6371,81 +6526,6 @@ class ConstantVariable extends SceneObjectBase {
6371
6526
  }
6372
6527
  }
6373
6528
 
6374
- function VariableValueSelect({ model }) {
6375
- const { value, key } = model.useState();
6376
- const onInputChange = model.onSearchChange ? (value2, meta) => {
6377
- if (meta.action === "input-change") {
6378
- model.onSearchChange(value2);
6379
- }
6380
- } : void 0;
6381
- return /* @__PURE__ */ React__default["default"].createElement(ui.Select, {
6382
- id: key,
6383
- placeholder: "Select value",
6384
- width: "auto",
6385
- value,
6386
- allowCustomValue: true,
6387
- virtualized: true,
6388
- tabSelectsValue: false,
6389
- onInputChange,
6390
- options: model.getOptionsForSelect(),
6391
- "data-testid": e2eSelectors.selectors.pages.Dashboard.SubMenu.submenuItemValueDropDownValueLinkTexts(`${value}`),
6392
- onChange: (newValue) => {
6393
- model.changeValueTo(newValue.value, newValue.label);
6394
- }
6395
- });
6396
- }
6397
- function VariableValueSelectMulti({ model }) {
6398
- const { value, key, maxVisibleValues, noValueOnClear } = model.useState();
6399
- const arrayValue = React.useMemo(() => lodash.isArray(value) ? value : [value], [value]);
6400
- const options = model.getOptionsForSelect();
6401
- const [uncommittedValue, setUncommittedValue] = React.useState(arrayValue);
6402
- React.useEffect(() => {
6403
- setUncommittedValue(arrayValue);
6404
- }, [arrayValue]);
6405
- const onInputChange = model.onSearchChange ? (value2, meta) => {
6406
- if (meta.action === "input-change") {
6407
- model.onSearchChange(value2);
6408
- }
6409
- } : void 0;
6410
- const placeholder = options.length > 0 ? "Select value" : "";
6411
- return /* @__PURE__ */ React__default["default"].createElement(ui.MultiSelect, {
6412
- id: key,
6413
- placeholder,
6414
- width: "auto",
6415
- value: uncommittedValue,
6416
- noMultiValueWrap: true,
6417
- maxVisibleValues: maxVisibleValues != null ? maxVisibleValues : 5,
6418
- tabSelectsValue: false,
6419
- virtualized: true,
6420
- allowCustomValue: true,
6421
- options: model.getOptionsForSelect(),
6422
- closeMenuOnSelect: false,
6423
- isClearable: true,
6424
- onInputChange,
6425
- onBlur: () => {
6426
- model.changeValueTo(uncommittedValue);
6427
- },
6428
- "data-testid": e2eSelectors.selectors.pages.Dashboard.SubMenu.submenuItemValueDropDownValueLinkTexts(`${uncommittedValue}`),
6429
- onChange: (newValue, action) => {
6430
- if (action.action === "clear" && noValueOnClear) {
6431
- model.changeValueTo([]);
6432
- }
6433
- setUncommittedValue(newValue.map((x) => x.value));
6434
- }
6435
- });
6436
- }
6437
- function renderSelectForVariable(model) {
6438
- if (model.state.isMulti) {
6439
- return /* @__PURE__ */ React__default["default"].createElement(VariableValueSelectMulti, {
6440
- model
6441
- });
6442
- } else {
6443
- return /* @__PURE__ */ React__default["default"].createElement(VariableValueSelect, {
6444
- model
6445
- });
6446
- }
6447
- }
6448
-
6449
6529
  var __defProp$i = Object.defineProperty;
6450
6530
  var __getOwnPropSymbols$i = Object.getOwnPropertySymbols;
6451
6531
  var __hasOwnProp$i = Object.prototype.hasOwnProperty;