@quillsql/react 2.16.26 → 2.16.28

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
@@ -42,8 +42,6 @@ import {
42
42
  endOfWeek,
43
43
  format,
44
44
  getWeek,
45
- isAfter,
46
- isBefore,
47
45
  isValid,
48
46
  parse,
49
47
  parseISO,
@@ -304,28 +302,10 @@ var init_valueFormatter = __esm({
304
302
  }
305
303
  let weekStart = startOfWeek(utcDate, { weekStartsOn });
306
304
  let weekEnd = endOfWeek(utcDate, { weekStartsOn });
307
- if (dateRange && dateRange.start && dateRange.end) {
308
- const utcStartString = dateRange.start.toISOString().split("T")[0];
309
- const utcEndString = dateRange.end.toISOString().split("T")[0];
310
- if (utcStartString && utcEndString) {
311
- const utcStart = parseISO(utcStartString);
312
- const utcEnd = parseISO(utcEndString);
313
- if (isBefore(weekStart, utcStart)) {
314
- weekStart = utcStart;
315
- }
316
- if (isAfter(weekEnd, utcEnd)) {
317
- weekEnd = utcEnd;
318
- }
319
- if (isAfter(weekStart, utcEnd) || isBefore(weekEnd, utcStart)) {
320
- return "Date outside range";
321
- }
322
- }
323
- }
324
305
  if (format(weekStart, "MMM") === format(weekEnd, "MMM")) {
325
306
  return `${format(weekStart, "MMM d")} - ${format(weekEnd, "d")}`;
326
- } else {
327
- return `${format(weekStart, "MMM d")} - ${format(weekEnd, "MMM d")}`;
328
307
  }
308
+ return `${format(weekStart, "MMM d")} - ${format(weekEnd, "MMM d")}`;
329
309
  };
330
310
  format_MMM_dd_hh_mm_ap_pm = (value) => {
331
311
  const utcDate = utcToZonedTime(new Date(value), "UTC");
@@ -1298,7 +1278,6 @@ import {
1298
1278
  endOfMonth,
1299
1279
  endOfQuarter,
1300
1280
  endOfYear,
1301
- endOfToday,
1302
1281
  format as format2,
1303
1282
  isEqual,
1304
1283
  isToday,
@@ -1309,18 +1288,23 @@ import {
1309
1288
  startOfMonth,
1310
1289
  startOfQuarter,
1311
1290
  startOfYear,
1312
- startOfToday,
1313
1291
  startOfWeek as startOfWeek2,
1314
1292
  sub,
1315
1293
  subMonths,
1316
1294
  subQuarters,
1317
1295
  subYears
1318
1296
  } from "date-fns";
1319
- var primaryRangeCustomIntervals, adjustForLeapYear, convertCustomIntervalToDateRange, getLabelForCustomInterval, convertPresetOptionsToSelectableList, PRIMARY_RANGE, COMPARISON_OPTIONS, COMPARISON_RANGE, defaultOptionsV2, reportBuilderOptions, getRangeFromPresetOptions;
1297
+ import { utcToZonedTime as utcToZonedTime2, zonedTimeToUtc } from "date-fns-tz";
1298
+ var PRESET_TIME_ZONE, getPresetNow, fromPresetTimeToUtc, startOfToday, endOfToday, primaryRangeCustomIntervals, adjustForLeapYear, convertCustomIntervalToDateRange, getLabelForCustomInterval, convertPresetOptionsToSelectableList, PRIMARY_RANGE, COMPARISON_OPTIONS, COMPARISON_RANGE, defaultOptionsV2, reportBuilderOptions, getRangeFromPresetOptions;
1320
1299
  var init_dateRangePickerUtils = __esm({
1321
1300
  "src/DateRangePicker/dateRangePickerUtils.ts"() {
1322
1301
  "use strict";
1323
1302
  init_chart();
1303
+ PRESET_TIME_ZONE = "America/Los_Angeles";
1304
+ getPresetNow = () => utcToZonedTime2(/* @__PURE__ */ new Date(), PRESET_TIME_ZONE);
1305
+ fromPresetTimeToUtc = (date) => zonedTimeToUtc(date, PRESET_TIME_ZONE);
1306
+ startOfToday = () => startOfDay(getPresetNow());
1307
+ endOfToday = () => endOfDay(getPresetNow());
1324
1308
  primaryRangeCustomIntervals = [
1325
1309
  {
1326
1310
  type: "week"
@@ -1453,7 +1437,7 @@ var init_dateRangePickerUtils = __esm({
1453
1437
  ];
1454
1438
  adjustForLeapYear = (date) => {
1455
1439
  if (date.month === 2 && date.day === 29) {
1456
- const year = (/* @__PURE__ */ new Date()).getFullYear();
1440
+ const year = getPresetNow().getFullYear();
1457
1441
  if (!(year % 4 === 0 && year % 100 !== 0 || year % 400 === 0)) {
1458
1442
  date.day = 28;
1459
1443
  }
@@ -1461,68 +1445,60 @@ var init_dateRangePickerUtils = __esm({
1461
1445
  return date;
1462
1446
  };
1463
1447
  convertCustomIntervalToDateRange = (interval) => {
1448
+ const toUtcRange = (startDate, endDate) => ({
1449
+ startDate: fromPresetTimeToUtc(startDate),
1450
+ endDate: fromPresetTimeToUtc(endDate)
1451
+ });
1464
1452
  switch (interval.type) {
1465
1453
  case "week":
1466
- return { startDate: startOfWeek2(startOfToday()), endDate: endOfToday() };
1454
+ return toUtcRange(startOfWeek2(startOfToday()), endOfToday());
1467
1455
  case "static": {
1468
1456
  const startDate = adjustForLeapYear(interval.startDate);
1469
1457
  const endDate = adjustForLeapYear(interval.endDate);
1470
- return {
1471
- startDate: set(/* @__PURE__ */ new Date(), {
1458
+ return toUtcRange(
1459
+ set(getPresetNow(), {
1472
1460
  month: startDate.month - 1,
1473
1461
  date: startDate.day,
1474
1462
  minutes: 0,
1475
1463
  hours: 0,
1476
1464
  seconds: 0
1477
1465
  }),
1478
- endDate: set(/* @__PURE__ */ new Date(), {
1466
+ set(getPresetNow(), {
1479
1467
  month: endDate.month - 1,
1480
1468
  date: endDate.day,
1481
1469
  minutes: 59,
1482
1470
  hours: 23,
1483
1471
  seconds: 59
1484
1472
  })
1485
- };
1473
+ );
1486
1474
  }
1487
1475
  case "relative": {
1488
1476
  if (interval.unit === "months" && interval.value === 1 && (!interval.label || interval.label === "Last month")) {
1489
1477
  const lastMonth = subMonths(startOfToday(), 1);
1490
- return {
1491
- startDate: startOfMonth(lastMonth),
1492
- endDate: endOfMonth(lastMonth)
1493
- };
1478
+ return toUtcRange(startOfMonth(lastMonth), endOfMonth(lastMonth));
1494
1479
  }
1495
- return {
1496
- startDate: sub(startOfToday(), { [interval.unit]: interval.value }),
1497
- endDate: endOfToday()
1498
- };
1480
+ return toUtcRange(
1481
+ sub(startOfToday(), { [interval.unit]: interval.value }),
1482
+ endOfToday()
1483
+ );
1499
1484
  }
1500
1485
  case "previous_month": {
1501
1486
  const lastMonth = subMonths(startOfToday(), 1);
1502
- return {
1503
- startDate: startOfMonth(lastMonth),
1504
- endDate: endOfMonth(lastMonth)
1505
- };
1487
+ return toUtcRange(startOfMonth(lastMonth), endOfMonth(lastMonth));
1506
1488
  }
1507
1489
  case "previous_quarter": {
1508
1490
  const lastQuarter = subQuarters(startOfToday(), 1);
1509
- return {
1510
- startDate: startOfQuarter(lastQuarter),
1511
- endDate: endOfQuarter(lastQuarter)
1512
- };
1491
+ return toUtcRange(startOfQuarter(lastQuarter), endOfQuarter(lastQuarter));
1513
1492
  }
1514
1493
  case "previous_year": {
1515
1494
  const lastYear = subYears(startOfToday(), 1);
1516
- return {
1517
- startDate: startOfYear(lastYear),
1518
- endDate: endOfYear(lastYear)
1519
- };
1495
+ return toUtcRange(startOfYear(lastYear), endOfYear(lastYear));
1520
1496
  }
1521
1497
  case "repeating": {
1522
- const currentDate = /* @__PURE__ */ new Date();
1498
+ const currentDate = getPresetNow();
1523
1499
  const currentYear = currentDate.getFullYear();
1524
1500
  const currentSubInterval = interval.subIntervals.find((subInterval) => {
1525
- const intervalStart = set(/* @__PURE__ */ new Date(), {
1501
+ const intervalStart = set(getPresetNow(), {
1526
1502
  year: currentYear,
1527
1503
  month: subInterval.startDate.month - 1,
1528
1504
  // convert 1-index to 0-index
@@ -1531,7 +1507,7 @@ var init_dateRangePickerUtils = __esm({
1531
1507
  minutes: 0,
1532
1508
  seconds: 0
1533
1509
  });
1534
- const intervalEnd = set(/* @__PURE__ */ new Date(), {
1510
+ const intervalEnd = set(getPresetNow(), {
1535
1511
  year: currentYear,
1536
1512
  month: subInterval.endDate.month - 1,
1537
1513
  // convert 1-index to 0-index
@@ -1546,16 +1522,16 @@ var init_dateRangePickerUtils = __esm({
1546
1522
  throw new Error("Date is not valid in this interval");
1547
1523
  }
1548
1524
  const startDate = adjustForLeapYear(currentSubInterval.startDate);
1549
- return {
1550
- startDate: set(/* @__PURE__ */ new Date(), {
1525
+ return toUtcRange(
1526
+ set(getPresetNow(), {
1551
1527
  month: startDate.month - 1,
1552
1528
  date: startDate.day,
1553
1529
  minutes: 0,
1554
1530
  hours: 0,
1555
1531
  seconds: 0
1556
1532
  }),
1557
- endDate: /* @__PURE__ */ new Date()
1558
- };
1533
+ endOfToday()
1534
+ );
1559
1535
  }
1560
1536
  }
1561
1537
  };
@@ -1746,7 +1722,7 @@ var init_dateRangePickerUtils = __esm({
1746
1722
  unit: "months"
1747
1723
  }
1748
1724
  ];
1749
- } else if (normalizedLabel === "last month") {
1725
+ } else if (normalizedLabel === "last month" || normalizedLabel === "previous month") {
1750
1726
  createdIntervals = [
1751
1727
  {
1752
1728
  type: "previous_month",
@@ -1780,12 +1756,12 @@ var init_dateRangePickerUtils = __esm({
1780
1756
  const selectableOptions = (defaultCustomIntervals ?? []).concat(customIntervals ?? []).flatMap((option) => {
1781
1757
  if (option.type === "repeating" && option.loopStart) {
1782
1758
  const presets = [];
1783
- let currentDate = endOfDay(option.loopEnd ?? /* @__PURE__ */ new Date());
1759
+ let currentDate = endOfDay(option.loopEnd ?? getPresetNow());
1784
1760
  const cutoffDate = option.loopStart;
1785
1761
  while (currentDate > cutoffDate) {
1786
1762
  const loopCurrentYear = currentDate.getFullYear();
1787
1763
  const currentSubInterval = option.subIntervals.find((subInterval) => {
1788
- const intervalStart2 = set(/* @__PURE__ */ new Date(), {
1764
+ const intervalStart2 = set(getPresetNow(), {
1789
1765
  year: loopCurrentYear,
1790
1766
  month: subInterval.startDate.month - 1,
1791
1767
  // convert 1-index to 0-index
@@ -1794,7 +1770,7 @@ var init_dateRangePickerUtils = __esm({
1794
1770
  minutes: 0,
1795
1771
  seconds: 0
1796
1772
  });
1797
- const intervalEnd = set(/* @__PURE__ */ new Date(), {
1773
+ const intervalEnd = set(getPresetNow(), {
1798
1774
  year: loopCurrentYear,
1799
1775
  month: subInterval.endDate.month - 1,
1800
1776
  // convert 1-index to 0-index
@@ -1830,26 +1806,30 @@ var init_dateRangePickerUtils = __esm({
1830
1806
  presets.push({
1831
1807
  label: customLabel2 || baseLabel,
1832
1808
  value: getLabelForSubInterval(currentSubInterval).toUpperCase().replace(/ /g, "_") ?? "",
1833
- startDate: set(/* @__PURE__ */ new Date(), {
1834
- year: currentYear,
1835
- month: currentSubInterval.startDate.month - 1,
1836
- // convert 1-index to 0-index
1837
- date: currentSubInterval.startDate.day,
1838
- minutes: 0,
1839
- hours: 0,
1840
- seconds: 0
1841
- }),
1842
- endDate: set(/* @__PURE__ */ new Date(), {
1843
- year: currentYear,
1844
- month: currentSubInterval.endDate.month - 1,
1845
- // convert 1-index to 0-index
1846
- date: currentSubInterval.endDate.day,
1847
- minutes: 59,
1848
- hours: 23,
1849
- seconds: 59
1850
- })
1809
+ startDate: fromPresetTimeToUtc(
1810
+ set(getPresetNow(), {
1811
+ year: currentYear,
1812
+ month: currentSubInterval.startDate.month - 1,
1813
+ // convert 1-index to 0-index
1814
+ date: currentSubInterval.startDate.day,
1815
+ minutes: 0,
1816
+ hours: 0,
1817
+ seconds: 0
1818
+ })
1819
+ ),
1820
+ endDate: fromPresetTimeToUtc(
1821
+ set(getPresetNow(), {
1822
+ year: currentYear,
1823
+ month: currentSubInterval.endDate.month - 1,
1824
+ // convert 1-index to 0-index
1825
+ date: currentSubInterval.endDate.day,
1826
+ minutes: 59,
1827
+ hours: 23,
1828
+ seconds: 59
1829
+ })
1830
+ )
1851
1831
  });
1852
- const intervalStart = set(/* @__PURE__ */ new Date(), {
1832
+ const intervalStart = set(getPresetNow(), {
1853
1833
  year: currentYear,
1854
1834
  month: currentSubInterval.startDate.month - 1,
1855
1835
  // convert 1-index to 0-index
@@ -1934,6 +1914,10 @@ var init_dateRangePickerUtils = __esm({
1934
1914
  primaryRangeCustomIntervals[7]
1935
1915
  ),
1936
1916
  LAST_MONTH: convertCustomIntervalToDateRange(primaryRangeCustomIntervals[8]),
1917
+ // Backward-compatible alias used by some environments.
1918
+ PREVIOUS_MONTH: convertCustomIntervalToDateRange(
1919
+ primaryRangeCustomIntervals[8]
1920
+ ),
1937
1921
  ALL_TIME: { startDate: void 0, endDate: void 0 }
1938
1922
  };
1939
1923
  COMPARISON_OPTIONS = [
@@ -16250,14 +16234,6 @@ async function generatePivotWithSQL({
16250
16234
  rows.forEach((row) => {
16251
16235
  row.__quillRawDate = typeof row[pivot.rowField || ""] === "object" ? row[pivot.rowField || ""].value : row[pivot.rowField || ""];
16252
16236
  let value = typeof row[pivot.rowField || ""] === "object" ? row[pivot.rowField || ""].value : row[pivot.rowField || ""];
16253
- if (dateBucket === "week" && dateFilter?.startDate && dateFilter?.endDate) {
16254
- const rowDate = new Date(value);
16255
- if (rowDate < dateFilter.startDate) {
16256
- value = dateFilter.startDate.toISOString();
16257
- } else if (rowDate > dateFilter.endDate) {
16258
- value = dateFilter.endDate.toISOString();
16259
- }
16260
- }
16261
16237
  const dateString = getDateString(
16262
16238
  value,
16263
16239
  dateFilter?.startDate && dateFilter?.endDate ? { start: dateFilter.startDate, end: dateFilter.endDate } : void 0,
@@ -16266,26 +16242,6 @@ async function generatePivotWithSQL({
16266
16242
  );
16267
16243
  row[pivot.rowField || ""] = dateString;
16268
16244
  });
16269
- if (pivot.rowField && pivot.rowFieldType && !isStringType(pivot.rowFieldType) && dateFilter?.startDate && dateFilter?.endDate) {
16270
- const dateSet = new Set(
16271
- rows.map((row) => row[pivot.rowField || ""])
16272
- );
16273
- for (let date = dateFilter.startDate; date <= dateFilter.endDate; date = new Date(date.getTime() + 24 * 60 * 60 * 1e3)) {
16274
- const formattedDate = getDateString(
16275
- date.toISOString(),
16276
- { start: dateFilter.startDate, end: dateFilter.endDate },
16277
- dateBucket,
16278
- databaseType
16279
- );
16280
- if (!dateSet.has(formattedDate)) {
16281
- const newRow = {};
16282
- newRow[pivot.rowField] = formattedDate;
16283
- newRow.__quillRawDate = date.toISOString();
16284
- rows.push(newRow);
16285
- dateSet.add(formattedDate);
16286
- }
16287
- }
16288
- }
16289
16245
  if (!pivot.sort || pivot.sortField === pivot.rowField) {
16290
16246
  rows.sort((a, b) => {
16291
16247
  const direction = pivot.sort && pivot.sortDirection === "DESC" ? -1 : 1;
@@ -16463,14 +16419,6 @@ function processPivotData({
16463
16419
  rows.forEach((row) => {
16464
16420
  row.__quillRawDate = typeof row[pivot.rowField || ""] === "object" ? row[pivot.rowField || ""].value : row[pivot.rowField || ""];
16465
16421
  let value = typeof row[pivot.rowField || ""] === "object" ? row[pivot.rowField || ""].value : row[pivot.rowField || ""];
16466
- if (dateBucket === "week" && dateFilter?.startDate && dateFilter?.endDate) {
16467
- const rowDate = new Date(value);
16468
- if (rowDate < dateFilter.startDate) {
16469
- value = dateFilter.startDate.toISOString();
16470
- } else if (rowDate > dateFilter.endDate) {
16471
- value = dateFilter.endDate.toISOString();
16472
- }
16473
- }
16474
16422
  const dateString = getDateString(
16475
16423
  value,
16476
16424
  dateFilter?.startDate && dateFilter?.endDate ? { start: dateFilter.startDate, end: dateFilter.endDate } : void 0,
@@ -16479,26 +16427,6 @@ function processPivotData({
16479
16427
  );
16480
16428
  row[pivot.rowField || ""] = dateString;
16481
16429
  });
16482
- if (pivot.rowField && pivot.rowFieldType && !isStringType(pivot.rowFieldType) && dateFilter?.startDate && dateFilter?.endDate) {
16483
- const dateSet = new Set(
16484
- rows.map((row) => row[pivot.rowField || ""])
16485
- );
16486
- for (let date = dateFilter.startDate; date <= dateFilter.endDate; date = new Date(date.getTime() + 24 * 60 * 60 * 1e3)) {
16487
- const formattedDate = getDateString(
16488
- date.toISOString(),
16489
- { start: dateFilter.startDate, end: dateFilter.endDate },
16490
- dateBucket,
16491
- databaseType
16492
- );
16493
- if (!dateSet.has(formattedDate)) {
16494
- const newRow = {};
16495
- newRow[pivot.rowField] = formattedDate;
16496
- newRow.__quillRawDate = date.toISOString();
16497
- rows.push(newRow);
16498
- dateSet.add(formattedDate);
16499
- }
16500
- }
16501
- }
16502
16430
  if (!pivot.sort || pivot.sortField === pivot.rowField) {
16503
16431
  rows.sort((a, b) => {
16504
16432
  const direction = pivot.sort && pivot.sortDirection === "DESC" ? -1 : 1;
@@ -19969,6 +19897,8 @@ async function cleanDashboardItem({
19969
19897
  columnInternal,
19970
19898
  columnsWithCustomFields,
19971
19899
  chartType: item.chartType,
19900
+ isCacheable: item.isCacheable,
19901
+ isCacheableReason: item.isCacheableReason,
19972
19902
  dateField: item.dateField,
19973
19903
  pivot: pivotError ? void 0 : item.pivot ? {
19974
19904
  ...item.pivot,
@@ -22381,12 +22311,16 @@ function generateBucketKeys(start, end, bucket) {
22381
22311
  }
22382
22312
  return Array.from(keys).sort((a, b) => parseInt(a) - parseInt(b));
22383
22313
  }
22314
+ function getDisambiguationSuffix(aggregationType, multiAgg) {
22315
+ if (!multiAgg || aggregationType === "count") return "";
22316
+ return `_${aggregationType}`;
22317
+ }
22384
22318
  function buildEmptyAggRow(aggregations) {
22385
22319
  const multiAgg = aggregations.length > 1;
22386
22320
  const empty = {};
22387
22321
  aggregations.forEach((agg) => {
22388
22322
  const { aggregationType: type, valueField } = agg;
22389
- const key = !valueField ? `${type}` + (multiAgg ? `_${type}` : "") : `${valueField}` + (multiAgg ? `_${type}` : "");
22323
+ const key = `${valueField ?? type}` + getDisambiguationSuffix(type, multiAgg);
22390
22324
  empty[key] = 0;
22391
22325
  });
22392
22326
  return empty;
@@ -22465,8 +22399,9 @@ function getDateKey(date, bucket) {
22465
22399
  }
22466
22400
  function sortRows(rows, pivot) {
22467
22401
  try {
22468
- const { sort, sortField, sortFieldType, sortDirection } = pivot;
22469
- if (!sort || sortField == null || sortFieldType == null) return rows;
22402
+ const { sort, sortField, sortDirection } = pivot;
22403
+ if (!sort || sortField == null || !rows[0]) return rows;
22404
+ const sortFieldType = pivot.sortFieldType ?? typeof rows[0][sortField];
22470
22405
  const sortFunc = isBoolType(sortFieldType) ? (a, b) => a === b ? 0 : a ? 1 : -1 : isDateType(sortFieldType) ? (a, b) => {
22471
22406
  const ta = new Date(a), tb = new Date(b);
22472
22407
  const aValid = isValidDate3(ta), bValid = isValidDate3(tb);
@@ -22611,11 +22546,12 @@ function getFinalAggregationValue({
22611
22546
  } else {
22612
22547
  switch (type) {
22613
22548
  case "sum":
22614
- final = acc.sum;
22549
+ final = +acc.sum.toFixed(2);
22615
22550
  break;
22616
22551
  case "average":
22617
22552
  case "avg":
22618
- final = acc.count ? acc.sum / acc.count : 0;
22553
+ const temp = acc.count ? acc.sum / acc.count : 0;
22554
+ final = temp;
22619
22555
  break;
22620
22556
  case "min":
22621
22557
  final = acc.hasVal ? acc.min : 0;
@@ -22694,6 +22630,7 @@ function aggregateWithColumn(rows, colKey, aggregations, getGroupKey) {
22694
22630
  rows.forEach((row) => {
22695
22631
  const groupKey = getGroupKey(row);
22696
22632
  const colVal = row[colKey];
22633
+ if (colVal === null || colVal === void 0) return;
22697
22634
  if (!accs[groupKey]) accs[groupKey] = {};
22698
22635
  if (!accs[groupKey][colVal]) {
22699
22636
  accs[groupKey][colVal] = {
@@ -22724,7 +22661,7 @@ function aggregateWithColumn(rows, colKey, aggregations, getGroupKey) {
22724
22661
  );
22725
22662
  Object.keys(accs[groupKey]).forEach((colVal) => {
22726
22663
  const acc = accs[groupKey][colVal];
22727
- const finalKey = `${colVal}` + (multiAgg ? `_${type}` : "");
22664
+ const finalKey = `${colVal}` + getDisambiguationSuffix(type, multiAgg);
22728
22665
  seen[groupKey][finalKey] = getFinalAggregationValue({
22729
22666
  type,
22730
22667
  valueFieldType,
@@ -22753,7 +22690,7 @@ function aggregateWithoutColumn(rows, aggregations, getGroupKey) {
22753
22690
  if (!valueField) {
22754
22691
  if (type !== "count" && type !== "percentage") return;
22755
22692
  }
22756
- const finalKey = !valueField ? `${type}` + (multiAgg ? `_${type}` : "") : `${valueField}` + (multiAgg ? `_${type}` : "");
22693
+ const finalKey = `${valueField ?? type}` + getDisambiguationSuffix(type, multiAgg);
22757
22694
  const distinctDenom = !!valueField2 && !!valueField2Type && valueField !== valueField2;
22758
22695
  const accs = {};
22759
22696
  rows.forEach((row) => {
@@ -22814,7 +22751,10 @@ function applyPivotInMemory(rows, pivot, filters) {
22814
22751
  const rawDateFromQuill = row.__quillRawDate;
22815
22752
  const rawDateValue = rawDateFromQuill ?? (rawValue !== null && typeof rawValue === "object" && rawValue.value ? rawValue.value : rawValue);
22816
22753
  return getDateKey(new Date(rawDateValue), dateBucket);
22817
- } : (row) => row[rowField];
22754
+ } : (row) => {
22755
+ const value = row[rowField];
22756
+ return value === null ? "-" : value;
22757
+ };
22818
22758
  const aggregated = columnField ? aggregateWithColumn(rows, columnField, aggregations, getRowKey) : aggregateWithoutColumn(rows, aggregations, getRowKey);
22819
22759
  const aggregatedRows = aggregated || {};
22820
22760
  if (rows.length === 0 && dateBucket && dateRange && !columnField) {
@@ -22899,24 +22839,65 @@ function generatePivotColumnsInMemory({
22899
22839
  // src/utils/cacheCab.ts
22900
22840
  import { openDB } from "idb";
22901
22841
  import { endOfDay as endOfDay3, max as maxDate, subMonths as subMonths4, min as minDate, startOfDay as startOfDay4 } from "date-fns";
22902
- import { utcToZonedTime as utcToZonedTime2, zonedTimeToUtc } from "date-fns-tz";
22842
+ import { utcToZonedTime as utcToZonedTime3, zonedTimeToUtc as zonedTimeToUtc2 } from "date-fns-tz";
22903
22843
  var TZ = "America/Los_Angeles";
22844
+ var DEFAULT_MAX_ROWS = 1e5;
22904
22845
  var CacheCab = class {
22905
22846
  fetchedRange = {};
22906
22847
  cachedReportIds = [];
22907
22848
  uncacheableReportIDs = [];
22908
22849
  uncacheableInFlight = /* @__PURE__ */ new Map();
22909
22850
  storage;
22851
+ maxRows = {};
22852
+ cacheableLoaded;
22910
22853
  META_KEY = "cachecab:meta";
22911
22854
  DATA_PREFIX = "cachecab:data:";
22912
22855
  UNCACHEABLE_PREFIX = "cachecab:uncacheable:";
22913
22856
  constructor({
22914
- storageType = "memory"
22915
- } = {}) {
22916
- this.storage = storageType !== "idb" ? new MemoryStorage() : new IdbStorage();
22917
- void this.loadMetaFromStorage();
22857
+ storageType = "memory",
22858
+ client,
22859
+ tenants,
22860
+ dashboards = [],
22861
+ getToken
22862
+ }) {
22863
+ this.storage = storageType !== "indexedDB" ? new MemoryStorage() : new IdbStorage();
22864
+ this.cacheableLoaded = (async () => {
22865
+ await this.loadMetaFromStorage();
22866
+ try {
22867
+ const result = await quillFetch({
22868
+ client,
22869
+ task: "get-dashboards-and-reports",
22870
+ method: "POST",
22871
+ metadata: {
22872
+ tenants
22873
+ },
22874
+ getToken
22875
+ });
22876
+ const tasks = result?.data?.tasks ?? [];
22877
+ const uncacheable = tasks?.filter((x) => x.isCacheable !== true && x.useReport).map((y) => y.reportId) ?? [];
22878
+ this.uncacheableReportIDs = uncacheable;
22879
+ const temp = tasks.map((x) => {
22880
+ return { name: x.dashboard.name, id: x.reportId };
22881
+ });
22882
+ temp.forEach((r) => {
22883
+ if (!this.maxRows[r.id]) {
22884
+ const d = dashboards.find((x) => x.name === r.name);
22885
+ this.maxRows[r.id] = d.totalCachedRows ?? DEFAULT_MAX_ROWS;
22886
+ }
22887
+ });
22888
+ } catch {
22889
+ }
22890
+ })();
22891
+ }
22892
+ async ensureReady() {
22893
+ await this.cacheableLoaded;
22918
22894
  }
22919
22895
  async get(reportId, dashboardFilters, customFilters, pivot, client, tenants, flags, pageSize, getToken, eventTracking, forceRefresh) {
22896
+ await this.ensureReady();
22897
+ if (!this.isCacheable(reportId)) {
22898
+ return EMPTY_INTERNAL_REPORT;
22899
+ }
22900
+ ;
22920
22901
  if (this.isCached(reportId, tenants) && !forceRefresh) {
22921
22902
  return this.getFromCache(reportId, dashboardFilters, customFilters, pivot, client, tenants, flags, getToken, eventTracking);
22922
22903
  } else {
@@ -22929,39 +22910,8 @@ var CacheCab = class {
22929
22910
  isCacheable(reportId) {
22930
22911
  return !this.uncacheableReportIDs.includes(reportId);
22931
22912
  }
22932
- async getUncacheableResult(reportId, client, tenants, flags, filters, additionalProcessing, pivot) {
22933
- const key = this.getUncacheableRequestKey(
22934
- reportId,
22935
- client,
22936
- tenants,
22937
- flags,
22938
- filters,
22939
- additionalProcessing,
22940
- pivot
22941
- );
22942
- try {
22943
- const raw = await this.storage.getItem(key);
22944
- return raw ? JSON.parse(raw) : null;
22945
- } catch {
22946
- return null;
22947
- }
22948
- }
22949
- async setUncacheableResult(reportId, client, tenants, flags, filters, additionalProcessing, pivot, report) {
22950
- const key = this.getUncacheableRequestKey(
22951
- reportId,
22952
- client,
22953
- tenants,
22954
- flags,
22955
- filters,
22956
- additionalProcessing,
22957
- pivot
22958
- );
22959
- try {
22960
- await this.storage.setItem(key, JSON.stringify(report));
22961
- } catch {
22962
- }
22963
- }
22964
22913
  async getOrFetchUncacheableResult(reportId, client, tenants, flags, filters, additionalProcessing, pivot, fetcher, forceRefresh = false) {
22914
+ await this.ensureReady();
22965
22915
  const key = this.getUncacheableRequestKey(
22966
22916
  reportId,
22967
22917
  client,
@@ -23231,7 +23181,7 @@ var CacheCab = class {
23231
23181
  clientId: client.publicKey,
23232
23182
  databaseType: client.databaseType,
23233
23183
  filters: adjusted,
23234
- additionalProcessing: { page: { rowsPerPage: 1e3, rowsPerRequest: 1e5 } },
23184
+ additionalProcessing: { page: { rowsPerPage: Math.min(this.maxRows[reportId] ?? 1e3, 1e3), rowsPerRequest: this.maxRows[reportId] ?? DEFAULT_MAX_ROWS } },
23235
23185
  useNewNodeSql: true,
23236
23186
  tenants,
23237
23187
  flags,
@@ -23239,6 +23189,10 @@ var CacheCab = class {
23239
23189
  },
23240
23190
  getToken
23241
23191
  });
23192
+ if (!fetchResp.data?.isCacheable) {
23193
+ this.uncacheableReportIDs.push(reportId);
23194
+ return EMPTY_INTERNAL_REPORT;
23195
+ }
23242
23196
  const resp = await parseFetchResponse(
23243
23197
  client,
23244
23198
  "report",
@@ -23246,12 +23200,16 @@ var CacheCab = class {
23246
23200
  getToken,
23247
23201
  true
23248
23202
  );
23203
+ if (resp.rowCount > (this.maxRows[reportId] ?? DEFAULT_MAX_ROWS)) {
23204
+ this.uncacheableReportIDs.push(reportId);
23205
+ return EMPTY_INTERNAL_REPORT;
23206
+ }
23249
23207
  reportInfo = await processReportResponse({
23250
23208
  resp,
23251
23209
  client,
23252
23210
  filters: adjusted,
23253
23211
  dateBucket: resp?.dateBucket,
23254
- additionalProcessing: { page: { rowsPerPage: 1e3, rowsPerRequest: 1e5 } },
23212
+ additionalProcessing: { page: { rowsPerPage: Math.min(this.maxRows[reportId] ?? 1e3, 1e3), rowsPerRequest: this.maxRows[reportId] ?? DEFAULT_MAX_ROWS } },
23255
23213
  getToken,
23256
23214
  eventTracking,
23257
23215
  tenants,
@@ -23260,8 +23218,16 @@ var CacheCab = class {
23260
23218
  overwriteCache: forceRefresh ?? false
23261
23219
  });
23262
23220
  const dateField = reportInfo.dateField?.field;
23221
+ const dateTable = removeQuotes(reportInfo.dateField?.table ?? "");
23263
23222
  if (!isAllTime && dateField !== void 0 && reportInfo.rows.length > 0) {
23264
23223
  const cleanedDateField = removeQuotes(dateField);
23224
+ if (reportInfo.referencedColumns && dateTable) {
23225
+ const refs = reportInfo.referencedColumns[dateTable];
23226
+ if (refs && !refs.some((x) => x && removeQuotes(x) == cleanedDateField)) {
23227
+ this.uncacheableReportIDs.push(reportId);
23228
+ return EMPTY_INTERNAL_REPORT;
23229
+ }
23230
+ }
23265
23231
  const missingDateFieldCount = reportInfo.rows.some((row) => row[cleanedDateField] === void 0);
23266
23232
  if (missingDateFieldCount) {
23267
23233
  this.uncacheableReportIDs.push(reportId);
@@ -23335,12 +23301,12 @@ var CacheCab = class {
23335
23301
  return [];
23336
23302
  }
23337
23303
  const dbDateFilter = dashboardFilters.find((x) => x.filterType === "date_range");
23338
- if (report.dateField && dbDateFilter?.startDate) {
23339
- const { start: startDate, end: endDate } = normalizePSTRanges(
23340
- new Date(dbDateFilter.startDate),
23341
- dbDateFilter.endDate ? new Date(dbDateFilter.endDate) : void 0
23342
- );
23304
+ if (report.dateField && dbDateFilter?.startDate && dbDateFilter?.endDate) {
23343
23305
  const fieldToUse = report.rows[0] && report.rows[0]["__quillRawDate"] ? "__quillRawDate" : removeQuotes(report.dateField.field);
23306
+ const useDateOnly = report.columnInternal.find((x) => x.field === fieldToUse)?.dataTypeID === 1082;
23307
+ const rawStart = new Date(dbDateFilter.startDate);
23308
+ const startDate = useDateOnly ? new Date(Date.UTC(rawStart.getUTCFullYear(), rawStart.getUTCMonth(), rawStart.getUTCDate(), 0, 0, 0, 0)) : rawStart;
23309
+ const endDate = new Date(dbDateFilter.endDate);
23344
23310
  const dateFilteredRows = report.rows.filter((x) => {
23345
23311
  const rowDate = new Date(x[fieldToUse]);
23346
23312
  return startDate <= rowDate && (endDate ? rowDate <= endDate : true);
@@ -23383,7 +23349,6 @@ var CacheCab = class {
23383
23349
  try {
23384
23350
  const parsed = JSON.parse(meta);
23385
23351
  this.cachedReportIds = parsed.cached || [];
23386
- this.uncacheableReportIDs = parsed.cannotBeCached;
23387
23352
  this.fetchedRange = Object.fromEntries(
23388
23353
  Object.entries(parsed.fetchedRange || {}).map(([id, range]) => [
23389
23354
  id,
@@ -23405,8 +23370,7 @@ var CacheCab = class {
23405
23370
  this.META_KEY,
23406
23371
  JSON.stringify({
23407
23372
  fetchedRange: serializableRange,
23408
- cached: this.cachedReportIds,
23409
- cannotBeCached: this.uncacheableReportIDs
23373
+ cached: this.cachedReportIds
23410
23374
  })
23411
23375
  );
23412
23376
  }
@@ -23530,14 +23494,14 @@ function canonicalizeFilterForUncacheableKey(filter) {
23530
23494
  return canonicalizeForKey(base);
23531
23495
  }
23532
23496
  function startOfDayPST(date) {
23533
- const pstDate = utcToZonedTime2(date, TZ);
23497
+ const pstDate = utcToZonedTime3(date, TZ);
23534
23498
  const startPst = startOfDay4(pstDate);
23535
- return zonedTimeToUtc(startPst, TZ);
23499
+ return zonedTimeToUtc2(startPst, TZ);
23536
23500
  }
23537
23501
  function endOfDayPST(date) {
23538
- const pstDate = utcToZonedTime2(date, TZ);
23502
+ const pstDate = utcToZonedTime3(date, TZ);
23539
23503
  const endPst = endOfDay3(pstDate);
23540
- return zonedTimeToUtc(endPst, TZ);
23504
+ return zonedTimeToUtc2(endPst, TZ);
23541
23505
  }
23542
23506
  function normalizePSTRanges(start, end) {
23543
23507
  return {
@@ -23971,7 +23935,18 @@ var EventTrackingContext = createContext({
23971
23935
  eventTracking: null
23972
23936
  });
23973
23937
  var CacheCabContext = createContext({
23974
- getCacheCab: (storageType) => new CacheCab({ storageType })
23938
+ getCacheCab: (storageType) => new CacheCab({
23939
+ storageType,
23940
+ client: {
23941
+ clientId: "",
23942
+ queryEndpoint: "",
23943
+ queryHeaders: void 0,
23944
+ withCredentials: false
23945
+ },
23946
+ tenants: [],
23947
+ dashboards: [],
23948
+ getToken: async () => ""
23949
+ })
23975
23950
  });
23976
23951
  var ContextProvider = ({
23977
23952
  children,
@@ -23986,14 +23961,6 @@ var ContextProvider = ({
23986
23961
  getAuthorizationToken = async () => "",
23987
23962
  eventTracking = null
23988
23963
  }) => {
23989
- const cacheCabByTypeRef = useRef({});
23990
- const getCacheCab = useCallback((storageType) => {
23991
- const key = storageType === "idb" ? "idb" : "memory";
23992
- if (!cacheCabByTypeRef.current[key]) {
23993
- cacheCabByTypeRef.current[key] = new CacheCab({ storageType: key });
23994
- }
23995
- return cacheCabByTypeRef.current[key];
23996
- }, []);
23997
23964
  const [client, setClient] = useState(
23998
23965
  typeof window !== "undefined" && sessionStorage ? JSON.parse(sessionStorage.getItem("quill-client") ?? "null") : null
23999
23966
  );
@@ -24022,6 +23989,7 @@ var ContextProvider = ({
24022
23989
  const [isClientLoading, setIsClientLoading] = useState(false);
24023
23990
  const [isDashboardsLoading, setIsDashboardsLoading] = useState(true);
24024
23991
  const [theme, setTheme] = useState(null);
23992
+ const [rawDashboards, setRawDashboards] = useState(void 0);
24025
23993
  const [schemaData, setSchemaData] = useState({
24026
23994
  schema: [],
24027
23995
  customFields: null,
@@ -24896,14 +24864,12 @@ var ContextProvider = ({
24896
24864
  }
24897
24865
  acc[dashboard2.name] = {};
24898
24866
  if (dashboard2.dateFilter) {
24867
+ const primaryRangeValue = dashboard2.dateFilter.primaryRange?.value;
24868
+ const selectedPresetRange = presetOptions.find((elem) => elem.value === primaryRangeValue) ?? PRIMARY_RANGE[primaryRangeValue ?? "LAST_30_DAYS"];
24899
24869
  dashboard2.dateFilter = {
24900
24870
  ...dashboard2.dateFilter,
24901
- startDate: presetOptions.find(
24902
- (elem) => elem.value === dashboard2.dateFilter.primaryRange?.value
24903
- )?.startDate,
24904
- endDate: presetOptions.find(
24905
- (elem) => elem.value === dashboard2.dateFilter.primaryRange?.value
24906
- )?.endDate,
24871
+ startDate: selectedPresetRange?.startDate,
24872
+ endDate: selectedPresetRange?.endDate,
24907
24873
  filterType: "date_range",
24908
24874
  presetOptions: dashboard2.dateFilter.presetOptions?.map(
24909
24875
  (preset) => ({
@@ -25239,15 +25205,13 @@ var ContextProvider = ({
25239
25205
  }
25240
25206
  acc[dashboard2.name] = {};
25241
25207
  if (dashboard2.dateFilter) {
25208
+ const primaryRangeValue = dashboard2.dateFilter.primaryRange?.value;
25209
+ const selectedPresetRange = presetOptions.find((elem) => elem.value === primaryRangeValue) ?? PRIMARY_RANGE[primaryRangeValue ?? "LAST_30_DAYS"];
25242
25210
  dashboard2.dateFilter = {
25243
25211
  ...dashboard2.dateFilter,
25244
25212
  initialCacheDateRange: dashboard2.initialCacheDateRange ? { ...dashboard2.initialCacheDateRange } : void 0,
25245
- startDate: presetOptions.find(
25246
- (elem) => elem.value === dashboard2.dateFilter.primaryRange?.value
25247
- )?.startDate,
25248
- endDate: presetOptions.find(
25249
- (elem) => elem.value === dashboard2.dateFilter.primaryRange?.value
25250
- )?.endDate,
25213
+ startDate: selectedPresetRange?.startDate,
25214
+ endDate: selectedPresetRange?.endDate,
25251
25215
  filterType: "date_range",
25252
25216
  presetOptions: dashboard2.dateFilter.presetOptions?.map(
25253
25217
  (preset) => ({
@@ -25317,6 +25281,33 @@ var ContextProvider = ({
25317
25281
  });
25318
25282
  });
25319
25283
  }
25284
+ const cacheCabByTypeRef = useRef({});
25285
+ const getCacheCab = useCallback((storageType) => {
25286
+ const key = storageType === "indexedDB" ? "indexedDB" : "memory";
25287
+ if (!cacheCabByTypeRef.current[key]) {
25288
+ cacheCabByTypeRef.current[key] = new CacheCab({
25289
+ storageType: key,
25290
+ client: {
25291
+ clientId: publicKey,
25292
+ queryEndpoint,
25293
+ queryHeaders,
25294
+ withCredentials: !!withCredentials
25295
+ },
25296
+ tenants,
25297
+ dashboards: rawDashboards,
25298
+ getToken: getAuthorizationToken
25299
+ });
25300
+ }
25301
+ return cacheCabByTypeRef.current[key];
25302
+ }, [
25303
+ publicKey,
25304
+ queryEndpoint,
25305
+ queryHeaders,
25306
+ withCredentials,
25307
+ tenants,
25308
+ getAuthorizationToken,
25309
+ rawDashboards
25310
+ ]);
25320
25311
  useEffect(() => {
25321
25312
  async function fetchEnvironment(publicKey2) {
25322
25313
  if (!publicKey2) return;
@@ -25381,6 +25372,8 @@ var ContextProvider = ({
25381
25372
  });
25382
25373
  }
25383
25374
  if (envData) {
25375
+ const dashboardsFromEnv = envData.dashboards ?? envData.data?.dashboards ?? envData.environment?.dashboards ?? envData.dashboardsResponse ?? [];
25376
+ setRawDashboards(dashboardsFromEnv);
25384
25377
  const normalizeSchema = (schema2) => {
25385
25378
  if (!schema2) return [];
25386
25379
  const tables = Array.isArray(schema2) ? schema2 : schema2?.tables && Array.isArray(schema2.tables) ? schema2.tables : [];
@@ -25425,9 +25418,7 @@ var ContextProvider = ({
25425
25418
  reportFiltersDispatch({ type: "CLEAR_REPORT_FILTERS" });
25426
25419
  reportsDispatch({ type: "CLEAR_REPORTS" });
25427
25420
  backfilledDashboards.current.clear();
25428
- hydrateDashboardsFromResponse(
25429
- envData.dashboards ?? envData.data?.dashboards ?? envData.environment?.dashboards ?? envData.dashboardsResponse ?? []
25430
- );
25421
+ hydrateDashboardsFromResponse(dashboardsFromEnv);
25431
25422
  environmentHydratedRef.current = true;
25432
25423
  }
25433
25424
  } catch (error) {
@@ -25620,7 +25611,7 @@ import {
25620
25611
  startOfWeek as startOfWeek4,
25621
25612
  startOfYear as startOfYear3
25622
25613
  } from "date-fns";
25623
- import { utcToZonedTime as utcToZonedTime3 } from "date-fns-tz";
25614
+ import { utcToZonedTime as utcToZonedTime4 } from "date-fns-tz";
25624
25615
  function mergeComparisonRange(resp) {
25625
25616
  if (resp.chartType === "table") return resp;
25626
25617
  const compRows = resp.compareRows;
@@ -26296,7 +26287,7 @@ var useDashboards = () => {
26296
26287
  };
26297
26288
  };
26298
26289
  var useDashboard = (dashboardName, config) => {
26299
- const logCacheStatistics = config?.showCacheLogs || false;
26290
+ const logCacheStatistics = config?.frontendCacheConfig?.showCacheLogs || false;
26300
26291
  const { data, dashboardFilters, reload, isLoading } = useDashboardInternal(dashboardName);
26301
26292
  const [lastUpdated, setLastUpdated] = useState2(0);
26302
26293
  const { customFilterDispatch } = useContext(DashboardFiltersContext);
@@ -26315,10 +26306,10 @@ var useDashboard = (dashboardName, config) => {
26315
26306
  const pendingNameChangeReload = useRef2(false);
26316
26307
  const [loadedDashes, setLoadedDashes] = useState2([]);
26317
26308
  const [lastUpdatedDict, setLastUpdatedDict] = useState2({});
26318
- const cacheEnabled = config?.cacheEnabled ?? false;
26309
+ const cacheEnabled = config?.frontendCacheConfig?.cacheType !== void 0;
26319
26310
  const cacheCab = useMemo2(
26320
- () => getCacheCab(config?.cacheType),
26321
- [getCacheCab, config?.cacheType]
26311
+ () => getCacheCab(config?.frontendCacheConfig?.cacheType),
26312
+ [getCacheCab, config?.frontendCacheConfig?.cacheType]
26322
26313
  );
26323
26314
  useEffect2(() => {
26324
26315
  const nameChanged = dashboardName !== lastDashboardName.current;
@@ -26384,13 +26375,13 @@ var useDashboard = (dashboardName, config) => {
26384
26375
  useEffect2(() => {
26385
26376
  if (!fetchedInitialReports.current && data && dashboardFilters !== null) {
26386
26377
  fetchedInitialReports.current = true;
26387
- fetchReports([], dashboardFilters ?? [], config?.pageSize);
26378
+ fetchReports([], dashboardFilters ?? [], config?.pageSize, config?.disableBackendCache ?? true);
26388
26379
  }
26389
26380
  }, [fetchedInitialReports, data, dashboardFilters, customFiltersLoaded]);
26390
26381
  useEffect2(() => {
26391
26382
  if (customFiltersLoaded && data && dashboardFilters !== null) {
26392
26383
  fetchedInitialReports.current = true;
26393
- fetchReports([], dashboardFilters ?? [], config?.pageSize);
26384
+ fetchReports([], dashboardFilters ?? [], config?.pageSize, config?.disableBackendCache ?? true);
26394
26385
  }
26395
26386
  }, [customFiltersLoaded]);
26396
26387
  const applyDashboardFilters = (filtersToUpdate) => {
@@ -26501,13 +26492,13 @@ var useDashboard = (dashboardName, config) => {
26501
26492
  const customFilters = filters2.filter(isFilter2);
26502
26493
  const newCustomFilters = applyCustomFilters(customFilters);
26503
26494
  const newDashboardFilters = applyDashboardFilters(dashboardFilters2);
26504
- fetchReports(newCustomFilters, newDashboardFilters);
26495
+ fetchReports(newCustomFilters, newDashboardFilters, void 0, config?.disableBackendCache ?? true);
26505
26496
  };
26506
26497
  const forceCacheRefresh = () => {
26507
26498
  if (!cacheEnabled) return;
26508
- fetchReports([], dashboardFilters ?? [], config?.pageSize, true);
26499
+ fetchReports([], dashboardFilters ?? [], config?.pageSize, false);
26509
26500
  };
26510
- const fetchReports = async (customFilters, dashboardFilters2, pageSize, forceCacheToRefresh = false) => {
26501
+ const fetchReports = async (customFilters, dashboardFilters2, pageSize, useBackendCache = true) => {
26511
26502
  if (!client || !sections) return;
26512
26503
  const allReports = Object.values(sections).flat();
26513
26504
  const fetchStartTime = Date.now();
@@ -26534,7 +26525,7 @@ var useDashboard = (dashboardName, config) => {
26534
26525
  const additionalProcessing = {
26535
26526
  page: pagination
26536
26527
  };
26537
- const usePivotTask = !cacheEnabled && !!reportInfo.pivot;
26528
+ const usePivotTask = !!reportInfo.pivot;
26538
26529
  const allFilters = dashboardFilters2.concat(customFilters).concat(customReportFiltersArray);
26539
26530
  const applyInMemoryPivotIfNeeded = (report2) => {
26540
26531
  const pivotToApply = reportInfo.pivot ?? report2.pivot;
@@ -26559,31 +26550,32 @@ var useDashboard = (dashboardName, config) => {
26559
26550
  pivotRowCount: pivotRows.length
26560
26551
  };
26561
26552
  };
26562
- if (cacheEnabled && cacheCab.isCacheable(reportId)) {
26563
- const report2 = await cacheCab.get(reportId, dashboardFilters2, customFilters.concat(customReportFiltersArray), reportInfo.pivot, client, tenants, flags, pageSize, getToken, eventTracking, forceCacheToRefresh);
26564
- if (reportRequestIds.current[reportId] !== requestId) {
26565
- return null;
26566
- }
26553
+ if (cacheEnabled) {
26554
+ await cacheCab.ensureReady();
26567
26555
  if (cacheCab.isCacheable(reportId)) {
26568
- reportsDispatch({
26569
- type: "UPDATE_REPORT",
26570
- id: reportId,
26571
- data: {
26572
- ...report2,
26573
- pagination,
26574
- triggerReload: false
26575
- }
26576
- });
26577
- reportsLoadingStateDispatch({
26578
- type: "SET_REPORT_LOADING",
26579
- id: reportId,
26580
- data: false
26581
- });
26582
- totalCached += 1;
26583
- return report2;
26556
+ const report2 = await cacheCab.get(reportId, dashboardFilters2, customFilters.concat(customReportFiltersArray), reportInfo.pivot, client, tenants, flags, pageSize, getToken, eventTracking, !useBackendCache);
26557
+ if (reportRequestIds.current[reportId] !== requestId) {
26558
+ return null;
26559
+ }
26560
+ if (cacheCab.isCacheable(reportId)) {
26561
+ reportsDispatch({
26562
+ type: "UPDATE_REPORT",
26563
+ id: reportId,
26564
+ data: {
26565
+ ...report2,
26566
+ pagination,
26567
+ triggerReload: false
26568
+ }
26569
+ });
26570
+ reportsLoadingStateDispatch({
26571
+ type: "SET_REPORT_LOADING",
26572
+ id: reportId,
26573
+ data: false
26574
+ });
26575
+ totalCached += 1;
26576
+ return report2;
26577
+ }
26584
26578
  }
26585
- }
26586
- if (cacheEnabled && !cacheCab.isCacheable(reportId)) {
26587
26579
  try {
26588
26580
  const { report: uncacheableReport, fromCache } = await cacheCab.getOrFetchUncacheableResult(
26589
26581
  reportId,
@@ -26599,19 +26591,20 @@ var useDashboard = (dashboardName, config) => {
26599
26591
  client,
26600
26592
  tenants,
26601
26593
  flags,
26602
- additionalProcessing,
26594
+ additionalProcessing: usePivotTask ? additionalProcessing : { page: { rowsPerPage: 1e3, rowsPerRequest: 1e5 } },
26595
+ // TODO wire maxRows from cacheCab state into here
26603
26596
  filters: allFilters,
26604
26597
  getToken,
26605
26598
  eventTracking,
26606
26599
  usePivotTask,
26607
- overwriteCache: forceCacheToRefresh
26600
+ overwriteCache: !useBackendCache
26608
26601
  });
26609
26602
  if (error2 || !report2) {
26610
26603
  throw error2 ?? new Error("Failed to fetch uncacheable report");
26611
26604
  }
26612
26605
  return report2;
26613
26606
  },
26614
- forceCacheToRefresh
26607
+ !useBackendCache
26615
26608
  );
26616
26609
  if (reportRequestIds.current[reportId] !== requestId) {
26617
26610
  return null;
@@ -26643,7 +26636,7 @@ var useDashboard = (dashboardName, config) => {
26643
26636
  filters: allFilters,
26644
26637
  getToken,
26645
26638
  additionalProcessing,
26646
- overwriteCache: forceCacheToRefresh
26639
+ overwriteCache: !useBackendCache
26647
26640
  }).then(({ rows, rowCount, columns, fields }) => {
26648
26641
  if (reportRequestIds.current[reportId] !== requestId) {
26649
26642
  return;
@@ -26676,7 +26669,7 @@ var useDashboard = (dashboardName, config) => {
26676
26669
  return uncacheableReportWithPivot;
26677
26670
  } catch (error2) {
26678
26671
  console.error(error2);
26679
- const errorMessage = error2 instanceof Error ? error2.message : "Failed to fetch report";
26672
+ const errorMessage = error2 instanceof Error ? error2.message : typeof error2 == "string" ? error2 : "Failed to fetch report";
26680
26673
  reportsDispatch({
26681
26674
  type: "UPDATE_REPORT",
26682
26675
  id: reportId,
@@ -26704,7 +26697,7 @@ var useDashboard = (dashboardName, config) => {
26704
26697
  getToken,
26705
26698
  eventTracking,
26706
26699
  usePivotTask,
26707
- overwriteCache: forceCacheToRefresh
26700
+ overwriteCache: !useBackendCache
26708
26701
  // usePivotTask: false,
26709
26702
  });
26710
26703
  if (reportRequestIds.current[reportId] !== requestId) {
@@ -26739,7 +26732,7 @@ var useDashboard = (dashboardName, config) => {
26739
26732
  filters: allFilters,
26740
26733
  getToken,
26741
26734
  additionalProcessing,
26742
- overwriteCache: forceCacheToRefresh
26735
+ overwriteCache: !useBackendCache
26743
26736
  }).then(({ rows, rowCount, columns, fields }) => {
26744
26737
  if (reportRequestIds.current[reportId] !== requestId) {
26745
26738
  return;
@@ -26772,12 +26765,12 @@ var useDashboard = (dashboardName, config) => {
26772
26765
  return report;
26773
26766
  })
26774
26767
  );
26775
- if (!loadedDashes.includes(dashboardName) || !cacheEnabled || forceCacheToRefresh) {
26768
+ if (!loadedDashes.includes(dashboardName) || !cacheEnabled || !useBackendCache) {
26776
26769
  setLoadedDashes((prev) => prev.includes(dashboardName) ? prev : [...prev, dashboardName]);
26777
26770
  setLastUpdatedDict((prev) => ({ ...prev, [dashboardName]: Date.now() }));
26778
26771
  }
26779
26772
  if (logCacheStatistics) {
26780
- console.log(`Dashboard "${dashboardName}": Cache Rate: ${(100 * totalCached / allReports.length).toFixed(1)}%, load time: ${((Date.now() - fetchStartTime) / 1e3).toFixed(2)} secs`);
26773
+ console.log(`Dashboard "${dashboardName}": Cache Rate: ${(100 * totalCached / Math.max(1, allReports.length)).toFixed(1)}%, load time: ${((Date.now() - fetchStartTime) / 1e3).toFixed(2)} secs`);
26781
26774
  }
26782
26775
  };
26783
26776
  return {
@@ -31353,7 +31346,7 @@ import {
31353
31346
 
31354
31347
  // src/utils/axisFormatter.ts
31355
31348
  import { endOfWeek as endOfWeek2, format as format5, getWeek as getWeek2, isValid as isValid5, startOfWeek as startOfWeek5 } from "date-fns";
31356
- import { utcToZonedTime as utcToZonedTime4 } from "date-fns-tz";
31349
+ import { utcToZonedTime as utcToZonedTime5 } from "date-fns-tz";
31357
31350
  var axisFormatter = ({ value, field, fields }) => {
31358
31351
  if (field === void 0 || field === null) return "";
31359
31352
  if (value === void 0 || value === null) return "";
@@ -31469,7 +31462,7 @@ var formatPercent2 = (value) => {
31469
31462
  return formatter.format(Number(value));
31470
31463
  };
31471
31464
  var _getUTCDateHelper2 = (value, fmt) => {
31472
- const utcDate = utcToZonedTime4(new Date(value), "UTC");
31465
+ const utcDate = utcToZonedTime5(new Date(value), "UTC");
31473
31466
  if (!isValid5(utcDate)) return "Invalid date";
31474
31467
  return format5(utcDate, fmt);
31475
31468
  };
@@ -31479,7 +31472,7 @@ var format_MMM_yyyy2 = (value) => _getUTCDateHelper2(value, "MMM yyyy");
31479
31472
  var format_hh_ap_pm2 = (value) => _getUTCDateHelper2(value, "hh:mm aa");
31480
31473
  var format_MMM_dd_yyyy2 = (value) => _getUTCDateHelper2(value, "dd MMM yyyy");
31481
31474
  var format_MMM_dd_MMM_dd = (value) => {
31482
- const utcDate = utcToZonedTime4(new Date(value), "UTC");
31475
+ const utcDate = utcToZonedTime5(new Date(value), "UTC");
31483
31476
  if (!isValid5(utcDate)) return "Invalid date";
31484
31477
  const monday = startOfWeek5(utcDate, { weekStartsOn: 1 });
31485
31478
  const sunday = endOfWeek2(utcDate, { weekStartsOn: 1 });
@@ -31490,14 +31483,14 @@ var format_MMM_dd_MMM_dd = (value) => {
31490
31483
  }
31491
31484
  };
31492
31485
  var format_MMM_dd_hh_mm_ap_pm2 = (value) => {
31493
- const utcDate = utcToZonedTime4(new Date(value), "UTC");
31486
+ const utcDate = utcToZonedTime5(new Date(value), "UTC");
31494
31487
  if (!isValid5(utcDate)) return "Invalid date";
31495
31488
  const formatStr = utcDate.getMinutes() === 0 ? "MMM do h a" : "MMM do h:mm a";
31496
31489
  const res = format5(utcDate, formatStr);
31497
31490
  return res.slice(0, -2) + res.slice(-2).toLowerCase();
31498
31491
  };
31499
31492
  var format_wo_yyyy2 = (value) => {
31500
- const utcDate = utcToZonedTime4(new Date(value), "UTC");
31493
+ const utcDate = utcToZonedTime5(new Date(value), "UTC");
31501
31494
  if (!isValid5(utcDate)) return "Invalid date";
31502
31495
  return `${getWeek2(utcDate)},${utcDate.getFullYear()}`;
31503
31496
  };
@@ -32826,8 +32819,8 @@ import {
32826
32819
  differenceInDays as differenceInDays3,
32827
32820
  startOfDay as startOfDay6,
32828
32821
  addMonths as addMonths2,
32829
- isBefore as isBefore2,
32830
- isAfter as isAfter2
32822
+ isBefore,
32823
+ isAfter
32831
32824
  } from "date-fns";
32832
32825
 
32833
32826
  // src/components/QuillSelect.tsx
@@ -33619,7 +33612,7 @@ function DayPicker({
33619
33612
  }) {
33620
33613
  const isStartDate = differenceInDays3(startOfDay6(date), startOfDay6(localStartDate || 0)) === 0;
33621
33614
  const isEndDate = differenceInDays3(startOfDay6(date), startOfDay6(localEndDate || 0)) === 0;
33622
- const isBetweenStartAndEnd = isBefore2(date, localEndDate || 0) && isAfter2(date, localStartDate || 0);
33615
+ const isBetweenStartAndEnd = isBefore(date, localEndDate || 0) && isAfter(date, localStartDate || 0);
33623
33616
  const isBeginningOfWeek = differenceInDays3(startOfWeek6(date), date) === 0;
33624
33617
  const isEndOfWeek = differenceInDays3(endOfWeek3(date), date) === 0;
33625
33618
  return /* @__PURE__ */ jsx40(
@@ -33653,7 +33646,7 @@ function DayPicker({
33653
33646
  });
33654
33647
  setLocalPreset("");
33655
33648
  }
33656
- if (localStartDate && localEndDate && isAfter2(date, localStartDate)) {
33649
+ if (localStartDate && localEndDate && isAfter(date, localStartDate)) {
33657
33650
  setLocalEndDate(date);
33658
33651
  updateDateFilter({
33659
33652
  startDate: startOfDay6(localStartDate),
@@ -33661,7 +33654,7 @@ function DayPicker({
33661
33654
  });
33662
33655
  setLocalPreset("");
33663
33656
  }
33664
- if (localStartDate && localEndDate && isBefore2(date, localStartDate)) {
33657
+ if (localStartDate && localEndDate && isBefore(date, localStartDate)) {
33665
33658
  setLocalStartDate(date);
33666
33659
  updateDateFilter({
33667
33660
  startDate: startOfDay6(date),
@@ -37915,6 +37908,10 @@ function Chart({
37915
37908
  if (!shouldShowCloudCacheValidationErrors) return false;
37916
37909
  return reportUsesLimitClause(report);
37917
37910
  }, [report, shouldShowCloudCacheValidationErrors]);
37911
+ const hasUncacheableReason = useMemo14(() => {
37912
+ if (!shouldShowCloudCacheValidationErrors) return false;
37913
+ return !!(report?.isCacheableReason && !report.isCacheable);
37914
+ }, [report, shouldShowCloudCacheValidationErrors]);
37918
37915
  const missingDashboardFilterFields = useMemo14(() => {
37919
37916
  if (!shouldShowCloudCacheValidationErrors || !report) return [];
37920
37917
  return getMissingDashboardFilterFields({
@@ -38062,6 +38059,14 @@ function Chart({
38062
38059
  if (report?.error || error) {
38063
38060
  return /* @__PURE__ */ jsx49("div", { style: containerStyle, className, children: /* @__PURE__ */ jsx49(ChartError, { errorMessage: report?.error ?? error }) });
38064
38061
  }
38062
+ if (hasUncacheableReason) {
38063
+ return /* @__PURE__ */ jsx49("div", { style: containerStyle, className, children: /* @__PURE__ */ jsx49(
38064
+ ChartError,
38065
+ {
38066
+ errorMessage: `The query for this report cannot be cached: ${report?.isCacheableReason}.`
38067
+ }
38068
+ ) });
38069
+ }
38065
38070
  if (isMissingDateField) {
38066
38071
  return /* @__PURE__ */ jsx49("div", { style: containerStyle, className, children: /* @__PURE__ */ jsx49(
38067
38072
  ChartError,
@@ -41874,7 +41879,6 @@ var styles = {
41874
41879
  gridTemplateColumns: "repeat(auto-fill,minmax(400px, 1fr))",
41875
41880
  gridTemplateRows: `repeat(${170}px)`
41876
41881
  },
41877
- chartColumn: { display: "contents" },
41878
41882
  emptyCard: {
41879
41883
  backgroundColor: "#ffffff",
41880
41884
  padding: 24,
@@ -41931,9 +41935,6 @@ var styles = {
41931
41935
  minHeight: 300,
41932
41936
  boxSizing: "content-box"
41933
41937
  },
41934
- metricGrid: {
41935
- display: "contents"
41936
- },
41937
41938
  metricEmpty: {
41938
41939
  backgroundColor: "#ffffff",
41939
41940
  padding: 24,
@@ -42346,8 +42347,8 @@ function DashboardContent({
42346
42347
  return aIndex - bIndex;
42347
42348
  });
42348
42349
  }, [sections, sectionOrder]);
42349
- return /* @__PURE__ */ jsx60("div", { style: styles.contentWrap, children: /* @__PURE__ */ jsxs43("div", { style: styles.splitGrid, children: [
42350
- metricReports.length === 0 ? null : /* @__PURE__ */ jsx60("section", { style: styles.metricGrid, children: metricReports.map((report) => /* @__PURE__ */ jsxs43(
42350
+ return /* @__PURE__ */ jsxs43("div", { style: styles.contentWrap, children: [
42351
+ metricReports.length === 0 ? null : /* @__PURE__ */ jsx60("div", { style: styles.splitGrid, children: /* @__PURE__ */ jsx60("section", { children: metricReports.map((report) => /* @__PURE__ */ jsxs43(
42351
42352
  "div",
42352
42353
  {
42353
42354
  onClick: () => onClickReport(report),
@@ -42364,8 +42365,8 @@ function DashboardContent({
42364
42365
  ]
42365
42366
  },
42366
42367
  report.id
42367
- )) }),
42368
- chartReports.length === 0 ? null : /* @__PURE__ */ jsx60("section", { style: styles.chartColumn, children: chartReports.map((report) => /* @__PURE__ */ jsxs43(
42368
+ )) }) }),
42369
+ chartReports.length === 0 ? null : /* @__PURE__ */ jsx60("div", { style: styles.splitGrid, children: /* @__PURE__ */ jsx60("section", { children: chartReports.map((report) => /* @__PURE__ */ jsxs43(
42369
42370
  "div",
42370
42371
  {
42371
42372
  onClick: () => onClickReport(report),
@@ -42382,69 +42383,71 @@ function DashboardContent({
42382
42383
  ]
42383
42384
  },
42384
42385
  report.id
42385
- )) }),
42386
- tableReports.length === 0 ? null : /* @__PURE__ */ jsx60("section", { style: styles.tableColumn, children: tableReports.map((report) => /* @__PURE__ */ jsxs43(
42387
- "div",
42388
- {
42389
- onClick: () => onClickReport(report),
42390
- style: styles.tableCard,
42391
- children: [
42392
- /* @__PURE__ */ jsx60("div", { style: styles.tableCardHeader, children: /* @__PURE__ */ jsx60("h3", { style: styles.tableTitle, children: report.name }) }),
42393
- /* @__PURE__ */ jsx60("div", { style: styles.tableContainer, children: /* @__PURE__ */ jsx60(
42394
- StaticChart,
42386
+ )) }) }),
42387
+ tableReports.length === 0 && orderedNonRootSectionEntries.length === 0 ? null : /* @__PURE__ */ jsxs43("div", { style: styles.splitGrid, children: [
42388
+ tableReports.length === 0 ? null : /* @__PURE__ */ jsx60("section", { style: styles.tableColumn, children: tableReports.map((report) => /* @__PURE__ */ jsxs43(
42389
+ "div",
42390
+ {
42391
+ onClick: () => onClickReport(report),
42392
+ style: styles.tableCard,
42393
+ children: [
42394
+ /* @__PURE__ */ jsx60("div", { style: styles.tableCardHeader, children: /* @__PURE__ */ jsx60("h3", { style: styles.tableTitle, children: report.name }) }),
42395
+ /* @__PURE__ */ jsx60("div", { style: styles.tableContainer, children: /* @__PURE__ */ jsx60(
42396
+ StaticChart,
42397
+ {
42398
+ reportId: report.id,
42399
+ containerStyle: { height: "100%", width: "100%" }
42400
+ }
42401
+ ) })
42402
+ ]
42403
+ },
42404
+ report.id
42405
+ )) }),
42406
+ orderedNonRootSectionEntries.length === 0 ? null : /* @__PURE__ */ jsx60("section", { style: styles.tableColumn, children: orderedNonRootSectionEntries.map(([sectionName, sectionReports]) => /* @__PURE__ */ jsxs43("div", { style: styles.tableSectionCard, children: [
42407
+ /* @__PURE__ */ jsx60("h1", { style: styles.tableSectionTitle, children: sectionName }),
42408
+ /* @__PURE__ */ jsx60("div", { style: styles.tableSectionGrid, children: sectionReports.map((report) => {
42409
+ const isMetric = report.chartType === "metric";
42410
+ const isTable = report.chartType === "table";
42411
+ return /* @__PURE__ */ jsxs43(
42412
+ "div",
42395
42413
  {
42396
- reportId: report.id,
42397
- containerStyle: { height: "100%", width: "100%" }
42398
- }
42399
- ) })
42400
- ]
42401
- },
42402
- report.id
42403
- )) }),
42404
- orderedNonRootSectionEntries.length === 0 ? null : /* @__PURE__ */ jsx60("section", { style: styles.tableColumn, children: orderedNonRootSectionEntries.map(([sectionName, sectionReports]) => /* @__PURE__ */ jsxs43("div", { style: styles.tableSectionCard, children: [
42405
- /* @__PURE__ */ jsx60("h1", { style: styles.tableSectionTitle, children: sectionName }),
42406
- /* @__PURE__ */ jsx60("div", { style: styles.tableSectionGrid, children: sectionReports.map((report) => {
42407
- const isMetric = report.chartType === "metric";
42408
- const isTable = report.chartType === "table";
42409
- return /* @__PURE__ */ jsxs43(
42410
- "div",
42411
- {
42412
- onClick: () => onClickReport(report),
42413
- style: isMetric ? styles.metricCard : isTable ? styles.tableCard : styles.chartCard,
42414
- children: [
42415
- /* @__PURE__ */ jsx60(
42416
- "div",
42417
- {
42418
- style: isMetric ? styles.metricHeader : isTable ? styles.tableCardHeader : styles.chartCardHeader,
42419
- children: /* @__PURE__ */ jsx60(
42420
- "h3",
42421
- {
42422
- style: isMetric ? styles.metricTitle : isTable ? styles.tableTitle : styles.chartTitle,
42423
- children: report.name
42424
- }
42425
- )
42426
- }
42427
- ),
42428
- /* @__PURE__ */ jsx60(
42429
- "div",
42430
- {
42431
- style: isMetric ? styles.metricChartWrap : isTable ? styles.tableContainer : styles.chartContainer,
42432
- children: /* @__PURE__ */ jsx60(
42433
- StaticChart,
42434
- {
42435
- reportId: report.id,
42436
- containerStyle: isMetric ? { height: 100, width: "100%" } : isTable ? { height: "100%", width: "100%" } : { height: 300, width: "100%" }
42437
- }
42438
- )
42439
- }
42440
- )
42441
- ]
42442
- },
42443
- report.id
42444
- );
42445
- }) })
42446
- ] }, sectionName)) })
42447
- ] }) });
42414
+ onClick: () => onClickReport(report),
42415
+ style: isMetric ? styles.metricCard : isTable ? styles.tableCard : styles.chartCard,
42416
+ children: [
42417
+ /* @__PURE__ */ jsx60(
42418
+ "div",
42419
+ {
42420
+ style: isMetric ? styles.metricHeader : isTable ? styles.tableCardHeader : styles.chartCardHeader,
42421
+ children: /* @__PURE__ */ jsx60(
42422
+ "h3",
42423
+ {
42424
+ style: isMetric ? styles.metricTitle : isTable ? styles.tableTitle : styles.chartTitle,
42425
+ children: report.name
42426
+ }
42427
+ )
42428
+ }
42429
+ ),
42430
+ /* @__PURE__ */ jsx60(
42431
+ "div",
42432
+ {
42433
+ style: isMetric ? styles.metricChartWrap : isTable ? styles.tableContainer : styles.chartContainer,
42434
+ children: /* @__PURE__ */ jsx60(
42435
+ StaticChart,
42436
+ {
42437
+ reportId: report.id,
42438
+ containerStyle: isMetric ? { height: 100, width: "100%" } : isTable ? { height: "100%", width: "100%" } : { height: 300, width: "100%" }
42439
+ }
42440
+ )
42441
+ }
42442
+ )
42443
+ ]
42444
+ },
42445
+ report.id
42446
+ );
42447
+ }) })
42448
+ ] }, sectionName)) })
42449
+ ] })
42450
+ ] });
42448
42451
  }
42449
42452
 
42450
42453
  // src/QuillProvider.tsx