@grafana/scenes 5.31.0--canary.998.12301751531.0 → 5.32.0

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,27 @@
1
+ # v5.32.0 (Fri Dec 13 2024)
2
+
3
+ #### 🚀 Enhancement
4
+
5
+ - Supply fixed now to datemath caluclations [#981](https://github.com/grafana/scenes/pull/981) ([@oscarkilhed](https://github.com/oscarkilhed))
6
+
7
+ #### Authors: 1
8
+
9
+ - Oscar Kilhed ([@oscarkilhed](https://github.com/oscarkilhed))
10
+
11
+ ---
12
+
13
+ # v5.31.0 (Thu Dec 12 2024)
14
+
15
+ #### 🐛 Bug Fix
16
+
17
+ - GroupBy: Add <Select /> for single selection option [#983](https://github.com/grafana/scenes/pull/983) ([@joannaWebDev](https://github.com/joannaWebDev))
18
+
19
+ #### Authors: 1
20
+
21
+ - Joanna ([@joannaWebDev](https://github.com/joannaWebDev))
22
+
23
+ ---
24
+
1
25
  # v5.30.0 (Tue Dec 10 2024)
2
26
 
3
27
  #### 🚀 Enhancement
@@ -2,9 +2,27 @@ import { dateMath } from '@grafana/data';
2
2
 
3
3
  function evaluateTimeRange(from, to, timeZone, fiscalYearStartMonth, delay) {
4
4
  const hasDelay = delay && to === "now";
5
+ const now = Date.now();
6
+ const parseOrToDateTime = (val, options) => {
7
+ if (dateMath.toDateTime) {
8
+ return dateMath.toDateTime(val, options);
9
+ } else {
10
+ return dateMath.parse(val, options.roundUp, options.timezone, options.fiscalYearStartMonth);
11
+ }
12
+ };
5
13
  return {
6
- from: dateMath.parse(from, false, timeZone, fiscalYearStartMonth),
7
- to: dateMath.parse(hasDelay ? "now-" + delay : to, true, timeZone, fiscalYearStartMonth),
14
+ to: parseOrToDateTime(hasDelay ? "now-" + delay : to, {
15
+ roundUp: true,
16
+ timezone: timeZone,
17
+ fiscalYearStartMonth,
18
+ now
19
+ }),
20
+ from: parseOrToDateTime(from, {
21
+ roundUp: false,
22
+ timezone: timeZone,
23
+ fiscalYearStartMonth,
24
+ now
25
+ }),
8
26
  raw: {
9
27
  from,
10
28
  to
@@ -1 +1 @@
1
- {"version":3,"file":"evaluateTimeRange.js","sources":["../../../src/utils/evaluateTimeRange.ts"],"sourcesContent":["import { dateMath, DateTime, TimeRange } from '@grafana/data';\nimport { TimeZone } from '@grafana/schema';\n\nexport function evaluateTimeRange(\n from: string | DateTime,\n to: string | DateTime,\n timeZone: TimeZone,\n fiscalYearStartMonth?: number,\n delay?: string\n): TimeRange {\n const hasDelay = delay && to === 'now';\n\n return {\n from: dateMath.parse(from, false, timeZone, fiscalYearStartMonth)!,\n to: dateMath.parse(hasDelay ? 'now-' + delay : to, true, timeZone, fiscalYearStartMonth)!,\n raw: {\n from: from,\n to: to,\n },\n };\n}\n"],"names":[],"mappings":";;AAGO,SAAS,iBACd,CAAA,IAAA,EACA,EACA,EAAA,QAAA,EACA,sBACA,KACW,EAAA;AACX,EAAM,MAAA,QAAA,GAAW,SAAS,EAAO,KAAA,KAAA,CAAA;AAEjC,EAAO,OAAA;AAAA,IACL,MAAM,QAAS,CAAA,KAAA,CAAM,IAAM,EAAA,KAAA,EAAO,UAAU,oBAAoB,CAAA;AAAA,IAChE,EAAA,EAAI,SAAS,KAAM,CAAA,QAAA,GAAW,SAAS,KAAQ,GAAA,EAAA,EAAI,IAAM,EAAA,QAAA,EAAU,oBAAoB,CAAA;AAAA,IACvF,GAAK,EAAA;AAAA,MACH,IAAA;AAAA,MACA,EAAA;AAAA,KACF;AAAA,GACF,CAAA;AACF;;;;"}
1
+ {"version":3,"file":"evaluateTimeRange.js","sources":["../../../src/utils/evaluateTimeRange.ts"],"sourcesContent":["import { dateMath, DateTime, DateTimeInput, TimeRange } from '@grafana/data';\nimport { TimeZone } from '@grafana/schema';\n\nexport function evaluateTimeRange(\n from: string | DateTime,\n to: string | DateTime,\n timeZone: TimeZone,\n fiscalYearStartMonth?: number,\n delay?: string\n): TimeRange {\n const hasDelay = delay && to === 'now';\n const now = Date.now();\n\n /** This tries to use dateMath.toDateTime if available, otherwise falls back to dateMath.parse.\n * Using dateMath.parse can potentially result in to and from being calculated using two different timestamps.\n * If two different timestamps are used, the time range \"now-24h to now\" will potentially be 24h +- number of milliseconds it takes between calculations.\n */\n const parseOrToDateTime = (\n val: string | DateTime,\n options: { roundUp: boolean; timezone: TimeZone; fiscalYearStartMonth?: number; now?: DateTimeInput }\n ) => {\n // @ts-ignore\n if (dateMath.toDateTime) {\n // @ts-ignore\n return dateMath.toDateTime(val, options);\n } else {\n return dateMath.parse(val, options.roundUp, options.timezone, options.fiscalYearStartMonth);\n }\n };\n\n /** The order of calculating to and from is important. This is because if we're using the old dateMath.parse we could potentially get two different timestamps.\n * If we calculate to first, then from. The timerange \"now-24h to now\" will err on the side of being shorter than 24h. This will aleviate some of the issues arising\n * from the timerange indeterminently alternating between less than or equal to 24h and being greater than 24h.\n */\n return {\n to: parseOrToDateTime(hasDelay ? 'now-' + delay : to, {\n roundUp: true,\n timezone: timeZone,\n fiscalYearStartMonth: fiscalYearStartMonth,\n now: now,\n })!,\n from: parseOrToDateTime(from, {\n roundUp: false,\n timezone: timeZone,\n fiscalYearStartMonth: fiscalYearStartMonth,\n now: now,\n })!,\n raw: {\n from: from,\n to: to,\n },\n };\n}\n"],"names":[],"mappings":";;AAGO,SAAS,iBACd,CAAA,IAAA,EACA,EACA,EAAA,QAAA,EACA,sBACA,KACW,EAAA;AACX,EAAM,MAAA,QAAA,GAAW,SAAS,EAAO,KAAA,KAAA,CAAA;AACjC,EAAM,MAAA,GAAA,GAAM,KAAK,GAAI,EAAA,CAAA;AAMrB,EAAM,MAAA,iBAAA,GAAoB,CACxB,GAAA,EACA,OACG,KAAA;AAEH,IAAA,IAAI,SAAS,UAAY,EAAA;AAEvB,MAAO,OAAA,QAAA,CAAS,UAAW,CAAA,GAAA,EAAK,OAAO,CAAA,CAAA;AAAA,KAClC,MAAA;AACL,MAAO,OAAA,QAAA,CAAS,MAAM,GAAK,EAAA,OAAA,CAAQ,SAAS,OAAQ,CAAA,QAAA,EAAU,QAAQ,oBAAoB,CAAA,CAAA;AAAA,KAC5F;AAAA,GACF,CAAA;AAMA,EAAO,OAAA;AAAA,IACL,EAAI,EAAA,iBAAA,CAAkB,QAAW,GAAA,MAAA,GAAS,QAAQ,EAAI,EAAA;AAAA,MACpD,OAAS,EAAA,IAAA;AAAA,MACT,QAAU,EAAA,QAAA;AAAA,MACV,oBAAA;AAAA,MACA,GAAA;AAAA,KACD,CAAA;AAAA,IACD,IAAA,EAAM,kBAAkB,IAAM,EAAA;AAAA,MAC5B,OAAS,EAAA,KAAA;AAAA,MACT,QAAU,EAAA,QAAA;AAAA,MACV,oBAAA;AAAA,MACA,GAAA;AAAA,KACD,CAAA;AAAA,IACD,GAAK,EAAA;AAAA,MACH,IAAA;AAAA,MACA,EAAA;AAAA,KACF;AAAA,GACF,CAAA;AACF;;;;"}
package/dist/index.js CHANGED
@@ -718,9 +718,27 @@ function parseUrlParam(value) {
718
718
 
719
719
  function evaluateTimeRange(from, to, timeZone, fiscalYearStartMonth, delay) {
720
720
  const hasDelay = delay && to === "now";
721
+ const now = Date.now();
722
+ const parseOrToDateTime = (val, options) => {
723
+ if (data.dateMath.toDateTime) {
724
+ return data.dateMath.toDateTime(val, options);
725
+ } else {
726
+ return data.dateMath.parse(val, options.roundUp, options.timezone, options.fiscalYearStartMonth);
727
+ }
728
+ };
721
729
  return {
722
- from: data.dateMath.parse(from, false, timeZone, fiscalYearStartMonth),
723
- to: data.dateMath.parse(hasDelay ? "now-" + delay : to, true, timeZone, fiscalYearStartMonth),
730
+ to: parseOrToDateTime(hasDelay ? "now-" + delay : to, {
731
+ roundUp: true,
732
+ timezone: timeZone,
733
+ fiscalYearStartMonth,
734
+ now
735
+ }),
736
+ from: parseOrToDateTime(from, {
737
+ roundUp: false,
738
+ timezone: timeZone,
739
+ fiscalYearStartMonth,
740
+ now
741
+ }),
724
742
  raw: {
725
743
  from,
726
744
  to