@grafana/scenes 6.7.0 → 6.8.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
@@ -2749,8 +2749,8 @@ function toSelectableValue$2(value, label) {
2749
2749
  label: label != null ? label : String(value)
2750
2750
  };
2751
2751
  }
2752
- function VariableValueSelect({ model }) {
2753
- const { value, text, key, options, includeAll, isReadOnly, allowCustomValue = true } = model.useState();
2752
+ function VariableValueSelect({ model, state }) {
2753
+ const { value, text, key, options, includeAll, isReadOnly, allowCustomValue = true } = state;
2754
2754
  const [inputValue, setInputValue] = React.useState("");
2755
2755
  const [hasCustomValue, setHasCustomValue] = React.useState(false);
2756
2756
  const selectValue = toSelectableValue$2(value, String(text));
@@ -2804,7 +2804,10 @@ function VariableValueSelect({ model }) {
2804
2804
  }
2805
2805
  );
2806
2806
  }
2807
- function VariableValueSelectMulti({ model }) {
2807
+ function VariableValueSelectMulti({
2808
+ model,
2809
+ state
2810
+ }) {
2808
2811
  const {
2809
2812
  value,
2810
2813
  options,
@@ -2814,7 +2817,7 @@ function VariableValueSelectMulti({ model }) {
2814
2817
  includeAll,
2815
2818
  isReadOnly,
2816
2819
  allowCustomValue = true
2817
- } = model.useState();
2820
+ } = state;
2818
2821
  const arrayValue = React.useMemo(() => lodash.isArray(value) ? value : [value], [value]);
2819
2822
  const [uncommittedValue, setUncommittedValue] = React.useState(arrayValue);
2820
2823
  const [inputValue, setInputValue] = React.useState("");
@@ -2922,11 +2925,12 @@ const getOptionStyles = (theme) => ({
2922
2925
  marginRight: theme.spacing(2)
2923
2926
  })
2924
2927
  });
2925
- function renderSelectForVariable(model) {
2926
- if (model.state.isMulti) {
2927
- return /* @__PURE__ */ React__default.default.createElement(VariableValueSelectMulti, { model });
2928
+ function MultiOrSingleValueSelect({ model }) {
2929
+ const state = model.useState();
2930
+ if (state.isMulti) {
2931
+ return /* @__PURE__ */ React__default.default.createElement(VariableValueSelectMulti, { model, state });
2928
2932
  } else {
2929
- return /* @__PURE__ */ React__default.default.createElement(VariableValueSelect, { model });
2933
+ return /* @__PURE__ */ React__default.default.createElement(VariableValueSelect, { model, state });
2930
2934
  }
2931
2935
  }
2932
2936
 
@@ -6325,8 +6329,26 @@ class ConstantVariable extends SceneObjectBase {
6325
6329
  ...initialState,
6326
6330
  skipUrlSync: true
6327
6331
  });
6332
+ this._variableDependency = new VariableDependencyConfig(this, {
6333
+ statePaths: ["value"]
6334
+ });
6335
+ this._prevValue = "";
6336
+ }
6337
+ /**
6338
+ * This function is called on when SceneVariableSet is activated or when a dependency changes.
6339
+ */
6340
+ validateAndUpdate() {
6341
+ const newValue = this.getValue();
6342
+ if (this._prevValue !== newValue) {
6343
+ this._prevValue = newValue;
6344
+ this.publishEvent(new SceneVariableValueChangedEvent(this), true);
6345
+ }
6346
+ return rxjs.of({});
6328
6347
  }
6329
6348
  getValue() {
6349
+ if (typeof this.state.value === "string") {
6350
+ return sceneGraph.interpolate(this, this.state.value);
6351
+ }
6330
6352
  return this.state.value;
6331
6353
  }
6332
6354
  }
@@ -6948,7 +6970,7 @@ class QueryVariable extends MultiValueVariable {
6948
6970
  }
6949
6971
  }
6950
6972
  QueryVariable.Component = ({ model }) => {
6951
- return renderSelectForVariable(model);
6973
+ return /* @__PURE__ */ React__default.default.createElement(MultiOrSingleValueSelect, { model });
6952
6974
  };
6953
6975
  function containsSearchFilter(query) {
6954
6976
  const str = safeStringifyValue(query);
@@ -9682,7 +9704,7 @@ class CustomVariable extends MultiValueVariable {
9682
9704
  }
9683
9705
  }
9684
9706
  CustomVariable.Component = ({ model }) => {
9685
- return renderSelectForVariable(model);
9707
+ return /* @__PURE__ */ React__default.default.createElement(MultiOrSingleValueSelect, { model });
9686
9708
  };
9687
9709
 
9688
9710
  class DataSourceVariable extends MultiValueVariable {
@@ -9730,7 +9752,7 @@ class DataSourceVariable extends MultiValueVariable {
9730
9752
  }
9731
9753
  }
9732
9754
  DataSourceVariable.Component = ({ model }) => {
9733
- return renderSelectForVariable(model);
9755
+ return /* @__PURE__ */ React__default.default.createElement(MultiOrSingleValueSelect, { model });
9734
9756
  };
9735
9757
  function isValid(source, regex) {
9736
9758
  if (!regex) {
@@ -9887,7 +9909,7 @@ class TestVariable extends MultiValueVariable {
9887
9909
  }
9888
9910
  }
9889
9911
  TestVariable.Component = ({ model }) => {
9890
- return renderSelectForVariable(model);
9912
+ return /* @__PURE__ */ React__default.default.createElement(MultiOrSingleValueSelect, { model });
9891
9913
  };
9892
9914
 
9893
9915
  function VariableValueInput({ model }) {
@@ -13867,6 +13889,7 @@ exports.GroupByVariable = GroupByVariable;
13867
13889
  exports.IntervalVariable = IntervalVariable;
13868
13890
  exports.LazyLoader = LazyLoader;
13869
13891
  exports.LocalValueVariable = LocalValueVariable;
13892
+ exports.MultiOrSingleValueSelect = MultiOrSingleValueSelect;
13870
13893
  exports.MultiValueVariable = MultiValueVariable;
13871
13894
  exports.NestedScene = NestedScene;
13872
13895
  exports.NewSceneObjectAddedEvent = NewSceneObjectAddedEvent;
@@ -13940,7 +13963,6 @@ exports.isFiltersRequestEnricher = isFiltersRequestEnricher;
13940
13963
  exports.isSceneObject = isSceneObject;
13941
13964
  exports.registerQueryWithController = registerQueryWithController;
13942
13965
  exports.registerRuntimeDataSource = registerRuntimeDataSource;
13943
- exports.renderSelectForVariable = renderSelectForVariable;
13944
13966
  exports.sceneGraph = sceneGraph;
13945
13967
  exports.sceneUtils = sceneUtils;
13946
13968
  exports.useSceneApp = useSceneApp;