@grafana/scenes 6.39.3--canary.1266.18358172419.0 → 6.39.4--canary.1269.18370250318.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.
package/dist/index.js CHANGED
@@ -3603,7 +3603,7 @@ function wrapInSafeSerializableSceneObject(sceneObject) {
3603
3603
  function DefaultGroupByCustomIndicatorContainer(props) {
3604
3604
  const { model } = props;
3605
3605
  const theme = ui.useTheme2();
3606
- const styles = getStyles$h(theme);
3606
+ const styles = getStyles$i(theme);
3607
3607
  const inputStyles = ui.getInputStyles({ theme, invalid: false });
3608
3608
  const value = lodash.isArray(model.state.value) ? model.state.value : model.state.value ? [model.state.value] : [];
3609
3609
  let buttons = [];
@@ -3685,7 +3685,7 @@ function DefaultGroupByCustomIndicatorContainer(props) {
3685
3685
  buttons
3686
3686
  );
3687
3687
  }
3688
- const getStyles$h = (theme) => ({
3688
+ const getStyles$i = (theme) => ({
3689
3689
  clearIcon: css.css({
3690
3690
  color: theme.colors.action.disabledText,
3691
3691
  cursor: "pointer",
@@ -4206,7 +4206,7 @@ function LoadingIndicator(props) {
4206
4206
  }
4207
4207
 
4208
4208
  function ControlsLabel(props) {
4209
- const styles = ui.useStyles2(getStyles$g);
4209
+ const styles = ui.useStyles2(getStyles$h);
4210
4210
  const theme = ui.useTheme2();
4211
4211
  const isVertical = props.layout === "vertical";
4212
4212
  const loadingIndicator = Boolean(props.isLoading) ? /* @__PURE__ */ React__default.default.createElement(
@@ -4253,7 +4253,7 @@ function ControlsLabel(props) {
4253
4253
  }
4254
4254
  return labelElement;
4255
4255
  }
4256
- const getStyles$g = (theme) => ({
4256
+ const getStyles$h = (theme) => ({
4257
4257
  horizontalLabel: css.css({
4258
4258
  background: theme.isDark ? theme.colors.background.primary : theme.colors.background.secondary,
4259
4259
  display: `flex`,
@@ -4306,7 +4306,7 @@ function keyLabelToOption(key, label) {
4306
4306
  const filterNoOp = () => true;
4307
4307
  function AdHocFilterRenderer({ filter, model }) {
4308
4308
  var _a, _b, _c, _d, _e;
4309
- const styles = ui.useStyles2(getStyles$f);
4309
+ const styles = ui.useStyles2(getStyles$g);
4310
4310
  const [keys, setKeys] = React.useState([]);
4311
4311
  const [values, setValues] = React.useState([]);
4312
4312
  const [isKeysLoading, setIsKeysLoading] = React.useState(false);
@@ -4533,7 +4533,7 @@ function AdHocFilterRenderer({ filter, model }) {
4533
4533
  }
4534
4534
  ));
4535
4535
  }
4536
- const getStyles$f = (theme) => ({
4536
+ const getStyles$g = (theme) => ({
4537
4537
  field: css.css({
4538
4538
  marginBottom: 0
4539
4539
  }),
@@ -4733,7 +4733,7 @@ function isFilter(filter) {
4733
4733
 
4734
4734
  const DropdownItem = React.forwardRef(
4735
4735
  function DropdownItem2({ children, active, addGroupBottomBorder, isMultiValueEdit, checked, ...rest }, ref) {
4736
- const styles = ui.useStyles2(getStyles$e);
4736
+ const styles = ui.useStyles2(getStyles$f);
4737
4737
  const id = React.useId();
4738
4738
  return /* @__PURE__ */ React__default.default.createElement(
4739
4739
  "div",
@@ -4749,7 +4749,7 @@ const DropdownItem = React.forwardRef(
4749
4749
  );
4750
4750
  }
4751
4751
  );
4752
- const getStyles$e = (theme) => ({
4752
+ const getStyles$f = (theme) => ({
4753
4753
  option: css.css({
4754
4754
  label: "grafana-select-option",
4755
4755
  top: 0,
@@ -4819,7 +4819,7 @@ const MultiValueApplyButton = ({
4819
4819
  maxOptionWidth,
4820
4820
  menuHeight
4821
4821
  }) => {
4822
- const styles = ui.useStyles2(getStyles$e);
4822
+ const styles = ui.useStyles2(getStyles$f);
4823
4823
  const floatingElementRect = floatingElement == null ? void 0 : floatingElement.getBoundingClientRect();
4824
4824
  return /* @__PURE__ */ React__default.default.createElement(
4825
4825
  "div",
@@ -5040,7 +5040,7 @@ const MultiValuePill = ({
5040
5040
  handleEditMultiValuePill
5041
5041
  }) => {
5042
5042
  var _a, _b;
5043
- const styles = ui.useStyles2(getStyles$d);
5043
+ const styles = ui.useStyles2(getStyles$e);
5044
5044
  const editMultiValuePill = React.useCallback(
5045
5045
  (e) => {
5046
5046
  e.stopPropagation();
@@ -5104,7 +5104,7 @@ const MultiValuePill = ({
5104
5104
  )
5105
5105
  );
5106
5106
  };
5107
- const getStyles$d = (theme) => ({
5107
+ const getStyles$e = (theme) => ({
5108
5108
  basePill: css.css({
5109
5109
  display: "flex",
5110
5110
  alignItems: "center",
@@ -5143,7 +5143,7 @@ const AdHocCombobox = React.forwardRef(function AdHocCombobox2({ filter, model,
5143
5143
  const [activeIndex, setActiveIndex] = React.useState(null);
5144
5144
  const [filterInputType, setInputType] = React.useState(!isAlwaysWip ? "value" : "key");
5145
5145
  const [preventFiltering, setPreventFiltering] = React.useState(!isAlwaysWip && filterInputType === "value");
5146
- const styles = ui.useStyles2(getStyles$c);
5146
+ const styles = ui.useStyles2(getStyles$d);
5147
5147
  const [filterMultiValues, setFilterMultiValues] = React.useState([]);
5148
5148
  const [_, setForceRefresh] = React.useState({});
5149
5149
  const allowCustomValue = (_a = model.state.allowCustomValue) != null ? _a : true;
@@ -5752,7 +5752,7 @@ const AdHocCombobox = React.forwardRef(function AdHocCombobox2({ filter, model,
5752
5752
  }
5753
5753
  ) : null))));
5754
5754
  });
5755
- const getStyles$c = (theme) => ({
5755
+ const getStyles$d = (theme) => ({
5756
5756
  comboboxWrapper: css.css({
5757
5757
  display: "flex",
5758
5758
  flexWrap: "wrap"
@@ -5826,7 +5826,7 @@ const getStyles$c = (theme) => ({
5826
5826
  const LABEL_MAX_VISIBLE_LENGTH = 20;
5827
5827
  function AdHocFilterPill({ filter, model, readOnly, focusOnWipInputRef }) {
5828
5828
  var _a, _b, _c, _d;
5829
- const styles = ui.useStyles2(getStyles$b);
5829
+ const styles = ui.useStyles2(getStyles$c);
5830
5830
  const [viewMode, setViewMode] = React.useState(true);
5831
5831
  const [shouldFocusOnPillWrapper, setShouldFocusOnPillWrapper] = React.useState(false);
5832
5832
  const pillWrapperRef = React.useRef(null);
@@ -6004,7 +6004,7 @@ function AdHocFilterPill({ filter, model, readOnly, focusOnWipInputRef }) {
6004
6004
  }
6005
6005
  );
6006
6006
  }
6007
- const getStyles$b = (theme) => ({
6007
+ const getStyles$c = (theme) => ({
6008
6008
  combinedFilterPill: css.css({
6009
6009
  display: "flex",
6010
6010
  alignItems: "center",
@@ -6088,7 +6088,7 @@ const AdHocFiltersAlwaysWipCombobox = React.forwardRef(function AdHocFiltersAlwa
6088
6088
 
6089
6089
  const AdHocFiltersComboboxRenderer = React.memo(function AdHocFiltersComboboxRenderer2({ model }) {
6090
6090
  const { originFilters, filters, readOnly } = model.useState();
6091
- const styles = ui.useStyles2(getStyles$a);
6091
+ const styles = ui.useStyles2(getStyles$b);
6092
6092
  const focusOnWipInputRef = React.useRef();
6093
6093
  return /* @__PURE__ */ React__default.default.createElement(
6094
6094
  "div",
@@ -6124,7 +6124,7 @@ const AdHocFiltersComboboxRenderer = React.memo(function AdHocFiltersComboboxRen
6124
6124
  !readOnly ? /* @__PURE__ */ React__default.default.createElement(AdHocFiltersAlwaysWipCombobox, { model, ref: focusOnWipInputRef }) : null
6125
6125
  );
6126
6126
  });
6127
- const getStyles$a = (theme) => ({
6127
+ const getStyles$b = (theme) => ({
6128
6128
  comboboxWrapper: css.css({
6129
6129
  display: "flex",
6130
6130
  flexWrap: "wrap",
@@ -6717,13 +6717,13 @@ function renderExpression(builder, filters) {
6717
6717
  }
6718
6718
  function AdHocFiltersVariableRenderer({ model }) {
6719
6719
  const { filters, readOnly, addFilterButtonText } = model.useState();
6720
- const styles = ui.useStyles2(getStyles$9);
6720
+ const styles = ui.useStyles2(getStyles$a);
6721
6721
  if (model.state.layout === "combobox") {
6722
6722
  return /* @__PURE__ */ React__default.default.createElement(AdHocFiltersComboboxRenderer, { model });
6723
6723
  }
6724
6724
  return /* @__PURE__ */ React__default.default.createElement("div", { className: styles.wrapper }, filters.filter((filter) => !filter.hidden).map((filter, index) => /* @__PURE__ */ React__default.default.createElement(React__default.default.Fragment, { key: index }, /* @__PURE__ */ React__default.default.createElement(AdHocFilterRenderer, { filter, model }))), !readOnly && /* @__PURE__ */ React__default.default.createElement(AdHocFilterBuilder, { model, key: "'builder", addFilterButtonText }));
6725
6725
  }
6726
- const getStyles$9 = (theme) => ({
6726
+ const getStyles$a = (theme) => ({
6727
6727
  wrapper: css.css({
6728
6728
  display: "flex",
6729
6729
  flexWrap: "wrap",
@@ -8615,6 +8615,9 @@ function isTextBoxVariable(variable) {
8615
8615
  function isGroupByVariable(variable) {
8616
8616
  return variable.state.type === "groupby";
8617
8617
  }
8618
+ function isSwitchVariable(variable) {
8619
+ return variable.state.type === "switch";
8620
+ }
8618
8621
 
8619
8622
  class ActWhenVariableChanged extends SceneObjectBase {
8620
8623
  constructor() {
@@ -8690,7 +8693,7 @@ function getCursorSyncScope(sceneObject) {
8690
8693
  }
8691
8694
 
8692
8695
  function VizPanelSeriesLimit({ data, showAll, seriesLimit, onShowAllSeries }) {
8693
- const styles = ui.useStyles2(getStyles$8);
8696
+ const styles = ui.useStyles2(getStyles$9);
8694
8697
  const seriesCount = data == null ? void 0 : data.series.length;
8695
8698
  if (seriesCount === void 0 || seriesCount < seriesLimit) {
8696
8699
  return null;
@@ -8720,7 +8723,7 @@ function VizPanelSeriesLimit({ data, showAll, seriesLimit, onShowAllSeries }) {
8720
8723
  /* @__PURE__ */ React__default.default.createElement(ui.Button, { variant: "secondary", size: "sm", onClick: onShowAllSeries }, buttonText)
8721
8724
  ));
8722
8725
  }
8723
- const getStyles$8 = (theme) => ({
8726
+ const getStyles$9 = (theme) => ({
8724
8727
  timeSeriesDisclaimer: css.css({
8725
8728
  label: "time-series-disclaimer",
8726
8729
  display: "flex",
@@ -8745,7 +8748,7 @@ function useUniqueId() {
8745
8748
  const LazyLoader = React__default.default.forwardRef(
8746
8749
  ({ children, onLoad, onChange, className, ...rest }, ref) => {
8747
8750
  const id = useUniqueId();
8748
- const { hideEmpty } = ui.useStyles2(getStyles$7);
8751
+ const { hideEmpty } = ui.useStyles2(getStyles$8);
8749
8752
  const [loaded, setLoaded] = React.useState(false);
8750
8753
  const [isInView, setIsInView] = React.useState(false);
8751
8754
  const innerRef = React.useRef(null);
@@ -8774,7 +8777,7 @@ const LazyLoader = React__default.default.forwardRef(
8774
8777
  return /* @__PURE__ */ React__default.default.createElement("div", { id, ref: innerRef, className: `${hideEmpty} ${className}`, ...rest }, !loaded ? i18n.t("grafana-scenes.components.lazy-loader.placeholder", "\xA0") : /* @__PURE__ */ React__default.default.createElement(LazyLoaderInViewContext.Provider, { value: isInView }, children));
8775
8778
  }
8776
8779
  );
8777
- function getStyles$7() {
8780
+ function getStyles$8() {
8778
8781
  return {
8779
8782
  hideEmpty: css.css({
8780
8783
  "&:empty": {
@@ -9446,17 +9449,19 @@ class SceneDataTransformer extends SceneObjectBase {
9446
9449
  if (!force && this.haveAlreadyTransformedData(data$1)) {
9447
9450
  return;
9448
9451
  }
9449
- const interpolatedTransformations = this._interpolateVariablesInTransformationConfigs(data$1);
9450
- const seriesTransformations = this._filterAndPrepareTransformationsByTopic(
9451
- interpolatedTransformations,
9452
- (topic) => topic == null || topic === data.DataTopic.Series,
9453
- true
9454
- );
9455
- const annotationsTransformations = this._filterAndPrepareTransformationsByTopic(
9456
- interpolatedTransformations,
9457
- data.DataTopic.Annotations,
9458
- false
9459
- );
9452
+ let interpolatedTransformations = this._interpolateVariablesInTransformationConfigs(data$1);
9453
+ const seriesTransformations = interpolatedTransformations.filter((transformation) => {
9454
+ if ("options" in transformation || "topic" in transformation) {
9455
+ return transformation.topic == null || transformation.topic === data.DataTopic.Series;
9456
+ }
9457
+ return true;
9458
+ }).map((transformation) => "operator" in transformation ? transformation.operator : transformation);
9459
+ const annotationsTransformations = interpolatedTransformations.filter((transformation) => {
9460
+ if ("options" in transformation || "topic" in transformation) {
9461
+ return transformation.topic === data.DataTopic.Annotations;
9462
+ }
9463
+ return false;
9464
+ }).map((transformation) => "operator" in transformation ? transformation.operator : transformation);
9460
9465
  if (this._transformSub) {
9461
9466
  this._transformSub.unsubscribe();
9462
9467
  }
@@ -9466,11 +9471,13 @@ class SceneDataTransformer extends SceneObjectBase {
9466
9471
  return sceneGraph.interpolate(this, value, { ...(_a2 = data$1.request) == null ? void 0 : _a2.scopedVars, ...scopedVars });
9467
9472
  }
9468
9473
  };
9469
- const seriesStream = data.transformDataFrame(seriesTransformations, data$1.series, ctx);
9470
- const annotationsStream = data.transformDataFrame(annotationsTransformations, (_a = data$1.annotations) != null ? _a : []);
9474
+ let streams = [data.transformDataFrame(seriesTransformations, data$1.series, ctx)];
9475
+ if (data$1.annotations && data$1.annotations.length > 0 && annotationsTransformations.length > 0) {
9476
+ streams.push(data.transformDataFrame(annotationsTransformations, (_a = data$1.annotations) != null ? _a : []));
9477
+ }
9471
9478
  let series = [];
9472
9479
  let annotations = [];
9473
- this._transformSub = rxjs.forkJoin([seriesStream, annotationsStream]).pipe(
9480
+ this._transformSub = rxjs.forkJoin(streams).pipe(
9474
9481
  rxjs.map((results) => {
9475
9482
  results.forEach((frames) => {
9476
9483
  var _a2;
@@ -9519,15 +9526,6 @@ class SceneDataTransformer extends SceneObjectBase {
9519
9526
  return typeof t === "object" ? JSON.parse(sceneGraph.interpolate(this, JSON.stringify(t), (_a2 = data.request) == null ? void 0 : _a2.scopedVars)) : t;
9520
9527
  });
9521
9528
  }
9522
- _filterAndPrepareTransformationsByTopic(interpolatedTransformations, topic, includeByDefault) {
9523
- const topicCheckFn = typeof topic === "function" ? topic : (t) => t === topic;
9524
- return interpolatedTransformations.filter((transformation) => {
9525
- if ("options" in transformation || "topic" in transformation) {
9526
- return topicCheckFn(transformation.topic);
9527
- }
9528
- return includeByDefault;
9529
- }).map((transformation) => "operator" in transformation ? transformation.operator : transformation);
9530
- }
9531
9529
  }
9532
9530
 
9533
9531
  class VizPanel extends SceneObjectBase {
@@ -11115,11 +11113,13 @@ class CustomVariable extends MultiValueVariable {
11115
11113
  statePaths: ["query"]
11116
11114
  });
11117
11115
  }
11118
- getValueOptions(args) {
11116
+ // We expose this publicly as we also need it outside the variable
11117
+ // The interpolate flag is needed since we don't always want to get the interpolated options
11118
+ transformQueryToOptions(interpolate = true) {
11119
11119
  var _a;
11120
- const interpolated = sceneGraph.interpolate(this, this.state.query);
11121
- const match = (_a = interpolated.match(/(?:\\,|[^,])+/g)) != null ? _a : [];
11122
- const options = match.map((text) => {
11120
+ const query = interpolate ? sceneGraph.interpolate(this, this.state.query) : this.state.query;
11121
+ const match = (_a = query.match(/(?:\\,|[^,])+/g)) != null ? _a : [];
11122
+ return match.map((text) => {
11123
11123
  var _a2;
11124
11124
  text = text.replace(/\\,/g, ",");
11125
11125
  const textMatch = (_a2 = /^\s*(.+)\s:\s(.+)$/g.exec(text)) != null ? _a2 : [];
@@ -11130,6 +11130,9 @@ class CustomVariable extends MultiValueVariable {
11130
11130
  return { label: text.trim(), value: text.trim() };
11131
11131
  }
11132
11132
  });
11133
+ }
11134
+ getValueOptions(args) {
11135
+ const options = this.transformQueryToOptions();
11133
11136
  if (!options.length) {
11134
11137
  this.skipNextValidation = true;
11135
11138
  }
@@ -11140,6 +11143,104 @@ CustomVariable.Component = ({ model }) => {
11140
11143
  return /* @__PURE__ */ React__default.default.createElement(MultiOrSingleValueSelect, { model });
11141
11144
  };
11142
11145
 
11146
+ class SwitchVariable extends SceneObjectBase {
11147
+ constructor(initialState) {
11148
+ super({
11149
+ // TODO: remove this once switch is in the schema @leventebalogh
11150
+ // @ts-expect-error - switch is a valid variable type, but not in the schema yet
11151
+ type: "switch",
11152
+ value: "false",
11153
+ enabledValue: "true",
11154
+ disabledValue: "false",
11155
+ name: "",
11156
+ ...initialState
11157
+ });
11158
+ this._prevValue = "";
11159
+ this._urlSync = new SceneObjectUrlSyncConfig(this, { keys: () => this.getKeys() });
11160
+ }
11161
+ /**
11162
+ * This function is called on when SceneVariableSet is activated or when a dependency changes.
11163
+ */
11164
+ validateAndUpdate() {
11165
+ const newValue = this.getValue();
11166
+ if (this._prevValue !== newValue) {
11167
+ this._prevValue = newValue;
11168
+ this.publishEvent(new SceneVariableValueChangedEvent(this), true);
11169
+ }
11170
+ return rxjs.of({});
11171
+ }
11172
+ setValue(newValue) {
11173
+ if (this.getValue() === newValue) {
11174
+ return;
11175
+ }
11176
+ if ([this.state.enabledValue, this.state.disabledValue].includes(newValue)) {
11177
+ this.setState({ value: newValue });
11178
+ this.publishEvent(new SceneVariableValueChangedEvent(this), true);
11179
+ } else {
11180
+ console.error(
11181
+ `Invalid value for switch variable: "${newValue}". Valid values are: "${this.state.enabledValue}" and "${this.state.disabledValue}".`
11182
+ );
11183
+ }
11184
+ }
11185
+ getValue() {
11186
+ return this.state.value;
11187
+ }
11188
+ isEnabled() {
11189
+ return this.state.value === this.state.enabledValue;
11190
+ }
11191
+ isDisabled() {
11192
+ return this.state.value === this.state.disabledValue;
11193
+ }
11194
+ getKey() {
11195
+ return `var-${this.state.name}`;
11196
+ }
11197
+ getKeys() {
11198
+ if (this.state.skipUrlSync) {
11199
+ return [];
11200
+ }
11201
+ return [this.getKey()];
11202
+ }
11203
+ getUrlState() {
11204
+ if (this.state.skipUrlSync) {
11205
+ return {};
11206
+ }
11207
+ return { [this.getKey()]: this.state.value };
11208
+ }
11209
+ updateFromUrl(values) {
11210
+ const val = values[this.getKey()];
11211
+ if (typeof val === "string") {
11212
+ this.setValue(val);
11213
+ }
11214
+ }
11215
+ }
11216
+ SwitchVariable.Component = SwitchVariableRenderer;
11217
+ function SwitchVariableRenderer({ model }) {
11218
+ const state = model.useState();
11219
+ const styles = ui.useStyles2(getStyles$7);
11220
+ return /* @__PURE__ */ React__default.default.createElement("div", { className: styles.container }, /* @__PURE__ */ React__default.default.createElement(
11221
+ ui.Switch,
11222
+ {
11223
+ value: state.value === state.enabledValue,
11224
+ onChange: (event) => {
11225
+ model.setValue(event.currentTarget.checked ? state.enabledValue : state.disabledValue);
11226
+ }
11227
+ }
11228
+ ));
11229
+ }
11230
+ function getStyles$7(theme) {
11231
+ return {
11232
+ container: css.css({
11233
+ display: "flex",
11234
+ alignItems: "center",
11235
+ padding: theme.spacing(0, 1),
11236
+ height: theme.spacing(theme.components.height.md),
11237
+ borderRadius: theme.shape.radius.default,
11238
+ border: `1px solid ${theme.components.input.borderColor}`,
11239
+ background: theme.colors.background.primary
11240
+ })
11241
+ };
11242
+ }
11243
+
11143
11244
  class DataSourceVariable extends MultiValueVariable {
11144
11245
  constructor(initialState) {
11145
11246
  super({
@@ -15322,6 +15423,7 @@ const sceneUtils = {
15322
15423
  isQueryVariable,
15323
15424
  isTextBoxVariable,
15324
15425
  isGroupByVariable,
15426
+ isSwitchVariable,
15325
15427
  isRepeatCloneOrChildOf,
15326
15428
  buildPathIdFor
15327
15429
  };
@@ -15390,6 +15492,7 @@ exports.SceneVariableSet = SceneVariableSet;
15390
15492
  exports.SceneVariableValueChangedEvent = SceneVariableValueChangedEvent;
15391
15493
  exports.ScopesVariable = ScopesVariable;
15392
15494
  exports.SplitLayout = SplitLayout;
15495
+ exports.SwitchVariable = SwitchVariable;
15393
15496
  exports.TestVariable = TestVariable;
15394
15497
  exports.TextBoxVariable = TextBoxVariable;
15395
15498
  exports.UrlSyncContextProvider = UrlSyncContextProvider;