@grafana/scenes 5.34.0--canary.1004.12360255549.0 → 5.35.0--canary.1007.12374452740.0

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.js CHANGED
@@ -716,9 +716,12 @@ function parseUrlParam(value) {
716
716
  return null;
717
717
  }
718
718
 
719
- function evaluateTimeRange(from, to, timeZone, fiscalYearStartMonth, delay) {
719
+ function evaluateTimeRange(from, to, timeZone, fiscalYearStartMonth, delay, weekStart) {
720
720
  const hasDelay = delay && to === "now";
721
721
  const now = Date.now();
722
+ if (weekStart) {
723
+ setWeekStartIfDifferent(weekStart);
724
+ }
722
725
  const parseOrToDateTime = (val, options) => {
723
726
  if (data.dateMath.toDateTime) {
724
727
  return data.dateMath.toDateTime(val, options);
@@ -745,6 +748,13 @@ function evaluateTimeRange(from, to, timeZone, fiscalYearStartMonth, delay) {
745
748
  }
746
749
  };
747
750
  }
751
+ let prevWeekStart;
752
+ function setWeekStartIfDifferent(weekStart) {
753
+ if (weekStart !== prevWeekStart) {
754
+ prevWeekStart = weekStart;
755
+ data.setWeekStart(weekStart);
756
+ }
757
+ }
748
758
 
749
759
  function isValid$1(value, roundUp, timeZone) {
750
760
  if (data.isDateTime(value)) {
@@ -784,7 +794,8 @@ class SceneTimeRange extends SceneObjectBase {
784
794
  to,
785
795
  timeZone || data.getTimeZone(),
786
796
  state.fiscalYearStartMonth,
787
- state.UNSAFE_nowDelay
797
+ state.UNSAFE_nowDelay,
798
+ state.weekStart
788
799
  );
789
800
  const refreshOnActivate = (_a = state.refreshOnActivate) != null ? _a : { percent: 10 };
790
801
  super(__spreadValues$K({ from, to, timeZone, value, refreshOnActivate }, state));
@@ -806,7 +817,8 @@ class SceneTimeRange extends SceneObjectBase {
806
817
  update.to,
807
818
  this.getTimeZone(),
808
819
  this.state.fiscalYearStartMonth,
809
- this.state.UNSAFE_nowDelay
820
+ this.state.UNSAFE_nowDelay,
821
+ this.state.weekStart
810
822
  );
811
823
  if (update.from !== this.state.from || update.to !== this.state.to) {
812
824
  this._urlSync.performBrowserHistoryAction(() => {
@@ -820,15 +832,7 @@ class SceneTimeRange extends SceneObjectBase {
820
832
  });
821
833
  };
822
834
  this.onRefresh = () => {
823
- this.setState({
824
- value: evaluateTimeRange(
825
- this.state.from,
826
- this.state.to,
827
- this.getTimeZone(),
828
- this.state.fiscalYearStartMonth,
829
- this.state.UNSAFE_nowDelay
830
- )
831
- });
835
+ this.refreshRange(0);
832
836
  this.publishEvent(new runtime.RefreshEvent(), true);
833
837
  };
834
838
  this.addActivationHandler(this._onActivate.bind(this));
@@ -840,23 +844,12 @@ class SceneTimeRange extends SceneObjectBase {
840
844
  this._subs.add(
841
845
  timeZoneSource.subscribeToState((n, p) => {
842
846
  if (n.timeZone !== void 0 && n.timeZone !== p.timeZone) {
843
- this.setState({
844
- value: evaluateTimeRange(
845
- this.state.from,
846
- this.state.to,
847
- timeZoneSource.getTimeZone(),
848
- this.state.fiscalYearStartMonth,
849
- this.state.UNSAFE_nowDelay
850
- )
851
- });
847
+ this.refreshRange(0);
852
848
  }
853
849
  })
854
850
  );
855
851
  }
856
852
  }
857
- if (this.state.weekStart) {
858
- data.setWeekStart(this.state.weekStart);
859
- }
860
853
  if (data.rangeUtil.isRelativeTimeRange(this.state.value.raw)) {
861
854
  this.refreshIfStale();
862
855
  }
@@ -901,13 +894,12 @@ class SceneTimeRange extends SceneObjectBase {
901
894
  this.state.to,
902
895
  (_a = this.state.timeZone) != null ? _a : data.getTimeZone(),
903
896
  this.state.fiscalYearStartMonth,
904
- this.state.UNSAFE_nowDelay
897
+ this.state.UNSAFE_nowDelay,
898
+ this.state.weekStart
905
899
  );
906
900
  const diff = value.to.diff(this.state.value.to, "milliseconds");
907
901
  if (diff >= refreshAfterMs) {
908
- this.setState({
909
- value
910
- });
902
+ this.setState({ value });
911
903
  }
912
904
  }
913
905
  calculatePercentOfInterval(percent) {
@@ -966,7 +958,8 @@ class SceneTimeRange extends SceneObjectBase {
966
958
  (_b = update.to) != null ? _b : this.state.to,
967
959
  (_c = update.timeZone) != null ? _c : this.getTimeZone(),
968
960
  this.state.fiscalYearStartMonth,
969
- this.state.UNSAFE_nowDelay
961
+ this.state.UNSAFE_nowDelay,
962
+ this.state.weekStart
970
963
  );
971
964
  return this.setState(update);
972
965
  }
@@ -5062,14 +5055,14 @@ class AdHocFiltersVariable extends SceneObjectBase {
5062
5055
  patchGetAdhocFilters(this);
5063
5056
  }
5064
5057
  }
5065
- setState(update, options) {
5058
+ setState(update) {
5066
5059
  let filterExpressionChanged = false;
5067
5060
  if (update.filters && update.filters !== this.state.filters && !update.filterExpression) {
5068
5061
  update.filterExpression = renderExpression(this.state.expressionBuilder, update.filters);
5069
5062
  filterExpressionChanged = update.filterExpression !== this.state.filterExpression;
5070
5063
  }
5071
5064
  super.setState(update);
5072
- if (filterExpressionChanged && (options == null ? void 0 : options.skipPublish) !== true) {
5065
+ if (filterExpressionChanged) {
5073
5066
  this.publishEvent(new SceneVariableValueChangedEvent(this), true);
5074
5067
  }
5075
5068
  }
@@ -7564,7 +7557,8 @@ class VizPanel extends SceneObjectBase {
7564
7557
  sceneTimeRange.state.to,
7565
7558
  sceneTimeRange.getTimeZone(),
7566
7559
  sceneTimeRange.state.fiscalYearStartMonth,
7567
- sceneTimeRange.state.UNSAFE_nowDelay
7560
+ sceneTimeRange.state.UNSAFE_nowDelay,
7561
+ sceneTimeRange.state.weekStart
7568
7562
  );
7569
7563
  }
7570
7564
  const plugin = this.getPlugin();
@@ -8675,7 +8669,8 @@ class SceneTimeZoneOverride extends SceneTimeRangeTransformerBase {
8675
8669
  timeRange.to,
8676
8670
  this.state.timeZone,
8677
8671
  timeRange.fiscalYearStartMonth,
8678
- timeRange.UNSAFE_nowDelay
8672
+ timeRange.UNSAFE_nowDelay,
8673
+ timeRange.weekStart
8679
8674
  )
8680
8675
  }));
8681
8676
  }
@@ -8683,14 +8678,16 @@ class SceneTimeZoneOverride extends SceneTimeRangeTransformerBase {
8683
8678
  return this.state.timeZone;
8684
8679
  }
8685
8680
  onTimeZoneChange(timeZone) {
8681
+ const parentTimeRange = this.getAncestorTimeRange();
8686
8682
  this.setState({
8687
8683
  timeZone,
8688
8684
  value: evaluateTimeRange(
8689
- this.state.from,
8690
- this.state.to,
8691
- this.state.timeZone,
8692
- this.getAncestorTimeRange().state.fiscalYearStartMonth,
8693
- this.state.UNSAFE_nowDelay
8685
+ parentTimeRange.state.from,
8686
+ parentTimeRange.state.to,
8687
+ timeZone,
8688
+ parentTimeRange.state.fiscalYearStartMonth,
8689
+ parentTimeRange.state.UNSAFE_nowDelay,
8690
+ parentTimeRange.state.weekStart
8694
8691
  )
8695
8692
  });
8696
8693
  }