@grafana/scenes 5.34.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/CHANGELOG.md +0 -12
- package/dist/esm/components/VizPanel/VizPanel.js +2 -1
- package/dist/esm/components/VizPanel/VizPanel.js.map +1 -1
- package/dist/esm/core/SceneTimeRange.js +12 -29
- package/dist/esm/core/SceneTimeRange.js.map +1 -1
- package/dist/esm/core/SceneTimeZoneOverride.js +9 -6
- package/dist/esm/core/SceneTimeZoneOverride.js.map +1 -1
- package/dist/esm/utils/evaluateTimeRange.js +12 -2
- package/dist/esm/utils/evaluateTimeRange.js.map +1 -1
- package/dist/esm/variables/variants/query/createQueryVariableRunner.js +1 -27
- package/dist/esm/variables/variants/query/createQueryVariableRunner.js.map +1 -1
- package/dist/esm/variables/variants/query/guards.js +1 -7
- package/dist/esm/variables/variants/query/guards.js.map +1 -1
- package/dist/index.js +33 -68
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
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.
|
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.
|
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
|
}
|
@@ -6105,12 +6098,6 @@ const hasCustomVariableSupport = (datasource) => {
|
|
6105
6098
|
const variableSupport = datasource.variables;
|
6106
6099
|
return "query" in variableSupport && "editor" in variableSupport && Boolean(variableSupport.query) && Boolean(variableSupport.editor);
|
6107
6100
|
};
|
6108
|
-
const hasDataSourceVariableSupport = (datasource) => {
|
6109
|
-
if (!datasource.variables) {
|
6110
|
-
return false;
|
6111
|
-
}
|
6112
|
-
return datasource.variables.getType() === data.VariableSupportType.Datasource;
|
6113
|
-
};
|
6114
6101
|
|
6115
6102
|
var __defProp$w = Object.defineProperty;
|
6116
6103
|
var __defProps$k = Object.defineProperties;
|
@@ -6206,29 +6193,6 @@ class CustomQueryRunner {
|
|
6206
6193
|
return this._runRequest(this.datasource, request, this.datasource.variables.query.bind(this.datasource.variables));
|
6207
6194
|
}
|
6208
6195
|
}
|
6209
|
-
const variableDummyRefId = "variable-query";
|
6210
|
-
class DatasourceQueryRunner {
|
6211
|
-
constructor(datasource, _runRequest = runtime.getRunRequest()) {
|
6212
|
-
this.datasource = datasource;
|
6213
|
-
this._runRequest = _runRequest;
|
6214
|
-
}
|
6215
|
-
getTarget(variable) {
|
6216
|
-
var _a;
|
6217
|
-
if (hasDataSourceVariableSupport(this.datasource)) {
|
6218
|
-
if (typeof variable.state.query === "string") {
|
6219
|
-
return variable.state.query;
|
6220
|
-
}
|
6221
|
-
return __spreadProps$k(__spreadValues$w({}, variable.state.query), { refId: (_a = variable.state.query.refId) != null ? _a : variableDummyRefId });
|
6222
|
-
}
|
6223
|
-
throw new Error("Couldn't create a target with supplied arguments.");
|
6224
|
-
}
|
6225
|
-
runRequest(_, request) {
|
6226
|
-
if (!hasDataSourceVariableSupport(this.datasource)) {
|
6227
|
-
return getEmptyMetricFindValueObservable();
|
6228
|
-
}
|
6229
|
-
return this._runRequest(this.datasource, request, this.datasource.query);
|
6230
|
-
}
|
6231
|
-
}
|
6232
6196
|
function getEmptyMetricFindValueObservable() {
|
6233
6197
|
return rxjs.of({ state: data.LoadingState.Done, series: [], timeRange: data.getDefaultTimeRange() });
|
6234
6198
|
}
|
@@ -6242,9 +6206,6 @@ function createQueryVariableRunnerFactory(datasource) {
|
|
6242
6206
|
if (hasCustomVariableSupport(datasource)) {
|
6243
6207
|
return new CustomQueryRunner(datasource);
|
6244
6208
|
}
|
6245
|
-
if (hasDataSourceVariableSupport(datasource)) {
|
6246
|
-
return new DatasourceQueryRunner(datasource);
|
6247
|
-
}
|
6248
6209
|
throw new Error(`Couldn't create a query runner for datasource ${datasource.type}`);
|
6249
6210
|
}
|
6250
6211
|
let createQueryVariableRunner = createQueryVariableRunnerFactory;
|
@@ -7596,7 +7557,8 @@ class VizPanel extends SceneObjectBase {
|
|
7596
7557
|
sceneTimeRange.state.to,
|
7597
7558
|
sceneTimeRange.getTimeZone(),
|
7598
7559
|
sceneTimeRange.state.fiscalYearStartMonth,
|
7599
|
-
sceneTimeRange.state.UNSAFE_nowDelay
|
7560
|
+
sceneTimeRange.state.UNSAFE_nowDelay,
|
7561
|
+
sceneTimeRange.state.weekStart
|
7600
7562
|
);
|
7601
7563
|
}
|
7602
7564
|
const plugin = this.getPlugin();
|
@@ -8707,7 +8669,8 @@ class SceneTimeZoneOverride extends SceneTimeRangeTransformerBase {
|
|
8707
8669
|
timeRange.to,
|
8708
8670
|
this.state.timeZone,
|
8709
8671
|
timeRange.fiscalYearStartMonth,
|
8710
|
-
timeRange.UNSAFE_nowDelay
|
8672
|
+
timeRange.UNSAFE_nowDelay,
|
8673
|
+
timeRange.weekStart
|
8711
8674
|
)
|
8712
8675
|
}));
|
8713
8676
|
}
|
@@ -8715,14 +8678,16 @@ class SceneTimeZoneOverride extends SceneTimeRangeTransformerBase {
|
|
8715
8678
|
return this.state.timeZone;
|
8716
8679
|
}
|
8717
8680
|
onTimeZoneChange(timeZone) {
|
8681
|
+
const parentTimeRange = this.getAncestorTimeRange();
|
8718
8682
|
this.setState({
|
8719
8683
|
timeZone,
|
8720
8684
|
value: evaluateTimeRange(
|
8721
|
-
|
8722
|
-
|
8723
|
-
|
8724
|
-
|
8725
|
-
|
8685
|
+
parentTimeRange.state.from,
|
8686
|
+
parentTimeRange.state.to,
|
8687
|
+
timeZone,
|
8688
|
+
parentTimeRange.state.fiscalYearStartMonth,
|
8689
|
+
parentTimeRange.state.UNSAFE_nowDelay,
|
8690
|
+
parentTimeRange.state.weekStart
|
8726
8691
|
)
|
8727
8692
|
});
|
8728
8693
|
}
|