@quillsql/react 2.16.27 → 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.cjs CHANGED
@@ -290,28 +290,10 @@ var init_valueFormatter = __esm({
290
290
  }
291
291
  let weekStart = (0, import_date_fns.startOfWeek)(utcDate, { weekStartsOn });
292
292
  let weekEnd = (0, import_date_fns.endOfWeek)(utcDate, { weekStartsOn });
293
- if (dateRange && dateRange.start && dateRange.end) {
294
- const utcStartString = dateRange.start.toISOString().split("T")[0];
295
- const utcEndString = dateRange.end.toISOString().split("T")[0];
296
- if (utcStartString && utcEndString) {
297
- const utcStart = (0, import_date_fns.parseISO)(utcStartString);
298
- const utcEnd = (0, import_date_fns.parseISO)(utcEndString);
299
- if ((0, import_date_fns.isBefore)(weekStart, utcStart)) {
300
- weekStart = utcStart;
301
- }
302
- if ((0, import_date_fns.isAfter)(weekEnd, utcEnd)) {
303
- weekEnd = utcEnd;
304
- }
305
- if ((0, import_date_fns.isAfter)(weekStart, utcEnd) || (0, import_date_fns.isBefore)(weekEnd, utcStart)) {
306
- return "Date outside range";
307
- }
308
- }
309
- }
310
293
  if ((0, import_date_fns.format)(weekStart, "MMM") === (0, import_date_fns.format)(weekEnd, "MMM")) {
311
294
  return `${(0, import_date_fns.format)(weekStart, "MMM d")} - ${(0, import_date_fns.format)(weekEnd, "d")}`;
312
- } else {
313
- return `${(0, import_date_fns.format)(weekStart, "MMM d")} - ${(0, import_date_fns.format)(weekEnd, "MMM d")}`;
314
295
  }
296
+ return `${(0, import_date_fns.format)(weekStart, "MMM d")} - ${(0, import_date_fns.format)(weekEnd, "MMM d")}`;
315
297
  };
316
298
  format_MMM_dd_hh_mm_ap_pm = (value) => {
317
299
  const utcDate = (0, import_date_fns_tz.utcToZonedTime)(new Date(value), "UTC");
@@ -1277,12 +1259,18 @@ var init_chart = __esm({
1277
1259
  });
1278
1260
 
1279
1261
  // src/DateRangePicker/dateRangePickerUtils.ts
1280
- var import_date_fns2, primaryRangeCustomIntervals, adjustForLeapYear, convertCustomIntervalToDateRange, getLabelForCustomInterval, convertPresetOptionsToSelectableList, PRIMARY_RANGE, COMPARISON_OPTIONS, COMPARISON_RANGE, defaultOptionsV2, reportBuilderOptions, getRangeFromPresetOptions;
1262
+ var import_date_fns2, import_date_fns_tz2, PRESET_TIME_ZONE, getPresetNow, fromPresetTimeToUtc, startOfToday, endOfToday, primaryRangeCustomIntervals, adjustForLeapYear, convertCustomIntervalToDateRange, getLabelForCustomInterval, convertPresetOptionsToSelectableList, PRIMARY_RANGE, COMPARISON_OPTIONS, COMPARISON_RANGE, defaultOptionsV2, reportBuilderOptions, getRangeFromPresetOptions;
1281
1263
  var init_dateRangePickerUtils = __esm({
1282
1264
  "src/DateRangePicker/dateRangePickerUtils.ts"() {
1283
1265
  "use strict";
1284
1266
  import_date_fns2 = require("date-fns");
1267
+ import_date_fns_tz2 = require("date-fns-tz");
1285
1268
  init_chart();
1269
+ PRESET_TIME_ZONE = "America/Los_Angeles";
1270
+ getPresetNow = () => (0, import_date_fns_tz2.utcToZonedTime)(/* @__PURE__ */ new Date(), PRESET_TIME_ZONE);
1271
+ fromPresetTimeToUtc = (date) => (0, import_date_fns_tz2.zonedTimeToUtc)(date, PRESET_TIME_ZONE);
1272
+ startOfToday = () => (0, import_date_fns2.startOfDay)(getPresetNow());
1273
+ endOfToday = () => (0, import_date_fns2.endOfDay)(getPresetNow());
1286
1274
  primaryRangeCustomIntervals = [
1287
1275
  {
1288
1276
  type: "week"
@@ -1415,7 +1403,7 @@ var init_dateRangePickerUtils = __esm({
1415
1403
  ];
1416
1404
  adjustForLeapYear = (date) => {
1417
1405
  if (date.month === 2 && date.day === 29) {
1418
- const year = (/* @__PURE__ */ new Date()).getFullYear();
1406
+ const year = getPresetNow().getFullYear();
1419
1407
  if (!(year % 4 === 0 && year % 100 !== 0 || year % 400 === 0)) {
1420
1408
  date.day = 28;
1421
1409
  }
@@ -1423,68 +1411,60 @@ var init_dateRangePickerUtils = __esm({
1423
1411
  return date;
1424
1412
  };
1425
1413
  convertCustomIntervalToDateRange = (interval) => {
1414
+ const toUtcRange = (startDate, endDate) => ({
1415
+ startDate: fromPresetTimeToUtc(startDate),
1416
+ endDate: fromPresetTimeToUtc(endDate)
1417
+ });
1426
1418
  switch (interval.type) {
1427
1419
  case "week":
1428
- return { startDate: (0, import_date_fns2.startOfWeek)((0, import_date_fns2.startOfToday)()), endDate: (0, import_date_fns2.endOfToday)() };
1420
+ return toUtcRange((0, import_date_fns2.startOfWeek)(startOfToday()), endOfToday());
1429
1421
  case "static": {
1430
1422
  const startDate = adjustForLeapYear(interval.startDate);
1431
1423
  const endDate = adjustForLeapYear(interval.endDate);
1432
- return {
1433
- startDate: (0, import_date_fns2.set)(/* @__PURE__ */ new Date(), {
1424
+ return toUtcRange(
1425
+ (0, import_date_fns2.set)(getPresetNow(), {
1434
1426
  month: startDate.month - 1,
1435
1427
  date: startDate.day,
1436
1428
  minutes: 0,
1437
1429
  hours: 0,
1438
1430
  seconds: 0
1439
1431
  }),
1440
- endDate: (0, import_date_fns2.set)(/* @__PURE__ */ new Date(), {
1432
+ (0, import_date_fns2.set)(getPresetNow(), {
1441
1433
  month: endDate.month - 1,
1442
1434
  date: endDate.day,
1443
1435
  minutes: 59,
1444
1436
  hours: 23,
1445
1437
  seconds: 59
1446
1438
  })
1447
- };
1439
+ );
1448
1440
  }
1449
1441
  case "relative": {
1450
1442
  if (interval.unit === "months" && interval.value === 1 && (!interval.label || interval.label === "Last month")) {
1451
- const lastMonth = (0, import_date_fns2.subMonths)((0, import_date_fns2.startOfToday)(), 1);
1452
- return {
1453
- startDate: (0, import_date_fns2.startOfMonth)(lastMonth),
1454
- endDate: (0, import_date_fns2.endOfMonth)(lastMonth)
1455
- };
1443
+ const lastMonth = (0, import_date_fns2.subMonths)(startOfToday(), 1);
1444
+ return toUtcRange((0, import_date_fns2.startOfMonth)(lastMonth), (0, import_date_fns2.endOfMonth)(lastMonth));
1456
1445
  }
1457
- return {
1458
- startDate: (0, import_date_fns2.sub)((0, import_date_fns2.startOfToday)(), { [interval.unit]: interval.value }),
1459
- endDate: (0, import_date_fns2.endOfToday)()
1460
- };
1446
+ return toUtcRange(
1447
+ (0, import_date_fns2.sub)(startOfToday(), { [interval.unit]: interval.value }),
1448
+ endOfToday()
1449
+ );
1461
1450
  }
1462
1451
  case "previous_month": {
1463
- const lastMonth = (0, import_date_fns2.subMonths)((0, import_date_fns2.startOfToday)(), 1);
1464
- return {
1465
- startDate: (0, import_date_fns2.startOfMonth)(lastMonth),
1466
- endDate: (0, import_date_fns2.endOfMonth)(lastMonth)
1467
- };
1452
+ const lastMonth = (0, import_date_fns2.subMonths)(startOfToday(), 1);
1453
+ return toUtcRange((0, import_date_fns2.startOfMonth)(lastMonth), (0, import_date_fns2.endOfMonth)(lastMonth));
1468
1454
  }
1469
1455
  case "previous_quarter": {
1470
- const lastQuarter = (0, import_date_fns2.subQuarters)((0, import_date_fns2.startOfToday)(), 1);
1471
- return {
1472
- startDate: (0, import_date_fns2.startOfQuarter)(lastQuarter),
1473
- endDate: (0, import_date_fns2.endOfQuarter)(lastQuarter)
1474
- };
1456
+ const lastQuarter = (0, import_date_fns2.subQuarters)(startOfToday(), 1);
1457
+ return toUtcRange((0, import_date_fns2.startOfQuarter)(lastQuarter), (0, import_date_fns2.endOfQuarter)(lastQuarter));
1475
1458
  }
1476
1459
  case "previous_year": {
1477
- const lastYear = (0, import_date_fns2.subYears)((0, import_date_fns2.startOfToday)(), 1);
1478
- return {
1479
- startDate: (0, import_date_fns2.startOfYear)(lastYear),
1480
- endDate: (0, import_date_fns2.endOfYear)(lastYear)
1481
- };
1460
+ const lastYear = (0, import_date_fns2.subYears)(startOfToday(), 1);
1461
+ return toUtcRange((0, import_date_fns2.startOfYear)(lastYear), (0, import_date_fns2.endOfYear)(lastYear));
1482
1462
  }
1483
1463
  case "repeating": {
1484
- const currentDate = /* @__PURE__ */ new Date();
1464
+ const currentDate = getPresetNow();
1485
1465
  const currentYear = currentDate.getFullYear();
1486
1466
  const currentSubInterval = interval.subIntervals.find((subInterval) => {
1487
- const intervalStart = (0, import_date_fns2.set)(/* @__PURE__ */ new Date(), {
1467
+ const intervalStart = (0, import_date_fns2.set)(getPresetNow(), {
1488
1468
  year: currentYear,
1489
1469
  month: subInterval.startDate.month - 1,
1490
1470
  // convert 1-index to 0-index
@@ -1493,7 +1473,7 @@ var init_dateRangePickerUtils = __esm({
1493
1473
  minutes: 0,
1494
1474
  seconds: 0
1495
1475
  });
1496
- const intervalEnd = (0, import_date_fns2.set)(/* @__PURE__ */ new Date(), {
1476
+ const intervalEnd = (0, import_date_fns2.set)(getPresetNow(), {
1497
1477
  year: currentYear,
1498
1478
  month: subInterval.endDate.month - 1,
1499
1479
  // convert 1-index to 0-index
@@ -1508,16 +1488,16 @@ var init_dateRangePickerUtils = __esm({
1508
1488
  throw new Error("Date is not valid in this interval");
1509
1489
  }
1510
1490
  const startDate = adjustForLeapYear(currentSubInterval.startDate);
1511
- return {
1512
- startDate: (0, import_date_fns2.set)(/* @__PURE__ */ new Date(), {
1491
+ return toUtcRange(
1492
+ (0, import_date_fns2.set)(getPresetNow(), {
1513
1493
  month: startDate.month - 1,
1514
1494
  date: startDate.day,
1515
1495
  minutes: 0,
1516
1496
  hours: 0,
1517
1497
  seconds: 0
1518
1498
  }),
1519
- endDate: /* @__PURE__ */ new Date()
1520
- };
1499
+ endOfToday()
1500
+ );
1521
1501
  }
1522
1502
  }
1523
1503
  };
@@ -1708,7 +1688,7 @@ var init_dateRangePickerUtils = __esm({
1708
1688
  unit: "months"
1709
1689
  }
1710
1690
  ];
1711
- } else if (normalizedLabel === "last month") {
1691
+ } else if (normalizedLabel === "last month" || normalizedLabel === "previous month") {
1712
1692
  createdIntervals = [
1713
1693
  {
1714
1694
  type: "previous_month",
@@ -1742,12 +1722,12 @@ var init_dateRangePickerUtils = __esm({
1742
1722
  const selectableOptions = (defaultCustomIntervals ?? []).concat(customIntervals ?? []).flatMap((option) => {
1743
1723
  if (option.type === "repeating" && option.loopStart) {
1744
1724
  const presets = [];
1745
- let currentDate = (0, import_date_fns2.endOfDay)(option.loopEnd ?? /* @__PURE__ */ new Date());
1725
+ let currentDate = (0, import_date_fns2.endOfDay)(option.loopEnd ?? getPresetNow());
1746
1726
  const cutoffDate = option.loopStart;
1747
1727
  while (currentDate > cutoffDate) {
1748
1728
  const loopCurrentYear = currentDate.getFullYear();
1749
1729
  const currentSubInterval = option.subIntervals.find((subInterval) => {
1750
- const intervalStart2 = (0, import_date_fns2.set)(/* @__PURE__ */ new Date(), {
1730
+ const intervalStart2 = (0, import_date_fns2.set)(getPresetNow(), {
1751
1731
  year: loopCurrentYear,
1752
1732
  month: subInterval.startDate.month - 1,
1753
1733
  // convert 1-index to 0-index
@@ -1756,7 +1736,7 @@ var init_dateRangePickerUtils = __esm({
1756
1736
  minutes: 0,
1757
1737
  seconds: 0
1758
1738
  });
1759
- const intervalEnd = (0, import_date_fns2.set)(/* @__PURE__ */ new Date(), {
1739
+ const intervalEnd = (0, import_date_fns2.set)(getPresetNow(), {
1760
1740
  year: loopCurrentYear,
1761
1741
  month: subInterval.endDate.month - 1,
1762
1742
  // convert 1-index to 0-index
@@ -1792,26 +1772,30 @@ var init_dateRangePickerUtils = __esm({
1792
1772
  presets.push({
1793
1773
  label: customLabel2 || baseLabel,
1794
1774
  value: getLabelForSubInterval(currentSubInterval).toUpperCase().replace(/ /g, "_") ?? "",
1795
- startDate: (0, import_date_fns2.set)(/* @__PURE__ */ new Date(), {
1796
- year: currentYear,
1797
- month: currentSubInterval.startDate.month - 1,
1798
- // convert 1-index to 0-index
1799
- date: currentSubInterval.startDate.day,
1800
- minutes: 0,
1801
- hours: 0,
1802
- seconds: 0
1803
- }),
1804
- endDate: (0, import_date_fns2.set)(/* @__PURE__ */ new Date(), {
1805
- year: currentYear,
1806
- month: currentSubInterval.endDate.month - 1,
1807
- // convert 1-index to 0-index
1808
- date: currentSubInterval.endDate.day,
1809
- minutes: 59,
1810
- hours: 23,
1811
- seconds: 59
1812
- })
1775
+ startDate: fromPresetTimeToUtc(
1776
+ (0, import_date_fns2.set)(getPresetNow(), {
1777
+ year: currentYear,
1778
+ month: currentSubInterval.startDate.month - 1,
1779
+ // convert 1-index to 0-index
1780
+ date: currentSubInterval.startDate.day,
1781
+ minutes: 0,
1782
+ hours: 0,
1783
+ seconds: 0
1784
+ })
1785
+ ),
1786
+ endDate: fromPresetTimeToUtc(
1787
+ (0, import_date_fns2.set)(getPresetNow(), {
1788
+ year: currentYear,
1789
+ month: currentSubInterval.endDate.month - 1,
1790
+ // convert 1-index to 0-index
1791
+ date: currentSubInterval.endDate.day,
1792
+ minutes: 59,
1793
+ hours: 23,
1794
+ seconds: 59
1795
+ })
1796
+ )
1813
1797
  });
1814
- const intervalStart = (0, import_date_fns2.set)(/* @__PURE__ */ new Date(), {
1798
+ const intervalStart = (0, import_date_fns2.set)(getPresetNow(), {
1815
1799
  year: currentYear,
1816
1800
  month: currentSubInterval.startDate.month - 1,
1817
1801
  // convert 1-index to 0-index
@@ -1896,6 +1880,10 @@ var init_dateRangePickerUtils = __esm({
1896
1880
  primaryRangeCustomIntervals[7]
1897
1881
  ),
1898
1882
  LAST_MONTH: convertCustomIntervalToDateRange(primaryRangeCustomIntervals[8]),
1883
+ // Backward-compatible alias used by some environments.
1884
+ PREVIOUS_MONTH: convertCustomIntervalToDateRange(
1885
+ primaryRangeCustomIntervals[8]
1886
+ ),
1899
1887
  ALL_TIME: { startDate: void 0, endDate: void 0 }
1900
1888
  };
1901
1889
  COMPARISON_OPTIONS = [
@@ -16204,14 +16192,6 @@ async function generatePivotWithSQL({
16204
16192
  rows.forEach((row) => {
16205
16193
  row.__quillRawDate = typeof row[pivot.rowField || ""] === "object" ? row[pivot.rowField || ""].value : row[pivot.rowField || ""];
16206
16194
  let value = typeof row[pivot.rowField || ""] === "object" ? row[pivot.rowField || ""].value : row[pivot.rowField || ""];
16207
- if (dateBucket === "week" && dateFilter?.startDate && dateFilter?.endDate) {
16208
- const rowDate = new Date(value);
16209
- if (rowDate < dateFilter.startDate) {
16210
- value = dateFilter.startDate.toISOString();
16211
- } else if (rowDate > dateFilter.endDate) {
16212
- value = dateFilter.endDate.toISOString();
16213
- }
16214
- }
16215
16195
  const dateString = getDateString(
16216
16196
  value,
16217
16197
  dateFilter?.startDate && dateFilter?.endDate ? { start: dateFilter.startDate, end: dateFilter.endDate } : void 0,
@@ -16220,26 +16200,6 @@ async function generatePivotWithSQL({
16220
16200
  );
16221
16201
  row[pivot.rowField || ""] = dateString;
16222
16202
  });
16223
- if (pivot.rowField && pivot.rowFieldType && !isStringType(pivot.rowFieldType) && dateFilter?.startDate && dateFilter?.endDate) {
16224
- const dateSet = new Set(
16225
- rows.map((row) => row[pivot.rowField || ""])
16226
- );
16227
- for (let date = dateFilter.startDate; date <= dateFilter.endDate; date = new Date(date.getTime() + 24 * 60 * 60 * 1e3)) {
16228
- const formattedDate = getDateString(
16229
- date.toISOString(),
16230
- { start: dateFilter.startDate, end: dateFilter.endDate },
16231
- dateBucket,
16232
- databaseType
16233
- );
16234
- if (!dateSet.has(formattedDate)) {
16235
- const newRow = {};
16236
- newRow[pivot.rowField] = formattedDate;
16237
- newRow.__quillRawDate = date.toISOString();
16238
- rows.push(newRow);
16239
- dateSet.add(formattedDate);
16240
- }
16241
- }
16242
- }
16243
16203
  if (!pivot.sort || pivot.sortField === pivot.rowField) {
16244
16204
  rows.sort((a, b) => {
16245
16205
  const direction = pivot.sort && pivot.sortDirection === "DESC" ? -1 : 1;
@@ -16417,14 +16377,6 @@ function processPivotData({
16417
16377
  rows.forEach((row) => {
16418
16378
  row.__quillRawDate = typeof row[pivot.rowField || ""] === "object" ? row[pivot.rowField || ""].value : row[pivot.rowField || ""];
16419
16379
  let value = typeof row[pivot.rowField || ""] === "object" ? row[pivot.rowField || ""].value : row[pivot.rowField || ""];
16420
- if (dateBucket === "week" && dateFilter?.startDate && dateFilter?.endDate) {
16421
- const rowDate = new Date(value);
16422
- if (rowDate < dateFilter.startDate) {
16423
- value = dateFilter.startDate.toISOString();
16424
- } else if (rowDate > dateFilter.endDate) {
16425
- value = dateFilter.endDate.toISOString();
16426
- }
16427
- }
16428
16380
  const dateString = getDateString(
16429
16381
  value,
16430
16382
  dateFilter?.startDate && dateFilter?.endDate ? { start: dateFilter.startDate, end: dateFilter.endDate } : void 0,
@@ -16433,26 +16385,6 @@ function processPivotData({
16433
16385
  );
16434
16386
  row[pivot.rowField || ""] = dateString;
16435
16387
  });
16436
- if (pivot.rowField && pivot.rowFieldType && !isStringType(pivot.rowFieldType) && dateFilter?.startDate && dateFilter?.endDate) {
16437
- const dateSet = new Set(
16438
- rows.map((row) => row[pivot.rowField || ""])
16439
- );
16440
- for (let date = dateFilter.startDate; date <= dateFilter.endDate; date = new Date(date.getTime() + 24 * 60 * 60 * 1e3)) {
16441
- const formattedDate = getDateString(
16442
- date.toISOString(),
16443
- { start: dateFilter.startDate, end: dateFilter.endDate },
16444
- dateBucket,
16445
- databaseType
16446
- );
16447
- if (!dateSet.has(formattedDate)) {
16448
- const newRow = {};
16449
- newRow[pivot.rowField] = formattedDate;
16450
- newRow.__quillRawDate = date.toISOString();
16451
- rows.push(newRow);
16452
- dateSet.add(formattedDate);
16453
- }
16454
- }
16455
- }
16456
16388
  if (!pivot.sort || pivot.sortField === pivot.rowField) {
16457
16389
  rows.sort((a, b) => {
16458
16390
  const direction = pivot.sort && pivot.sortDirection === "DESC" ? -1 : 1;
@@ -19953,6 +19885,8 @@ async function cleanDashboardItem({
19953
19885
  columnInternal,
19954
19886
  columnsWithCustomFields,
19955
19887
  chartType: item.chartType,
19888
+ isCacheable: item.isCacheable,
19889
+ isCacheableReason: item.isCacheableReason,
19956
19890
  dateField: item.dateField,
19957
19891
  pivot: pivotError ? void 0 : item.pivot ? {
19958
19892
  ...item.pivot,
@@ -22347,12 +22281,16 @@ function generateBucketKeys(start, end, bucket) {
22347
22281
  }
22348
22282
  return Array.from(keys).sort((a, b) => parseInt(a) - parseInt(b));
22349
22283
  }
22284
+ function getDisambiguationSuffix(aggregationType, multiAgg) {
22285
+ if (!multiAgg || aggregationType === "count") return "";
22286
+ return `_${aggregationType}`;
22287
+ }
22350
22288
  function buildEmptyAggRow(aggregations) {
22351
22289
  const multiAgg = aggregations.length > 1;
22352
22290
  const empty = {};
22353
22291
  aggregations.forEach((agg) => {
22354
22292
  const { aggregationType: type, valueField } = agg;
22355
- const key = !valueField ? `${type}` + (multiAgg ? `_${type}` : "") : `${valueField}` + (multiAgg ? `_${type}` : "");
22293
+ const key = `${valueField ?? type}` + getDisambiguationSuffix(type, multiAgg);
22356
22294
  empty[key] = 0;
22357
22295
  });
22358
22296
  return empty;
@@ -22431,8 +22369,9 @@ function getDateKey(date, bucket) {
22431
22369
  }
22432
22370
  function sortRows(rows, pivot) {
22433
22371
  try {
22434
- const { sort, sortField, sortFieldType, sortDirection } = pivot;
22435
- if (!sort || sortField == null || sortFieldType == null) return rows;
22372
+ const { sort, sortField, sortDirection } = pivot;
22373
+ if (!sort || sortField == null || !rows[0]) return rows;
22374
+ const sortFieldType = pivot.sortFieldType ?? typeof rows[0][sortField];
22436
22375
  const sortFunc = isBoolType(sortFieldType) ? (a, b) => a === b ? 0 : a ? 1 : -1 : isDateType(sortFieldType) ? (a, b) => {
22437
22376
  const ta = new Date(a), tb = new Date(b);
22438
22377
  const aValid = isValidDate3(ta), bValid = isValidDate3(tb);
@@ -22577,11 +22516,12 @@ function getFinalAggregationValue({
22577
22516
  } else {
22578
22517
  switch (type) {
22579
22518
  case "sum":
22580
- final = acc.sum;
22519
+ final = +acc.sum.toFixed(2);
22581
22520
  break;
22582
22521
  case "average":
22583
22522
  case "avg":
22584
- final = acc.count ? acc.sum / acc.count : 0;
22523
+ const temp = acc.count ? acc.sum / acc.count : 0;
22524
+ final = temp;
22585
22525
  break;
22586
22526
  case "min":
22587
22527
  final = acc.hasVal ? acc.min : 0;
@@ -22660,6 +22600,7 @@ function aggregateWithColumn(rows, colKey, aggregations, getGroupKey) {
22660
22600
  rows.forEach((row) => {
22661
22601
  const groupKey = getGroupKey(row);
22662
22602
  const colVal = row[colKey];
22603
+ if (colVal === null || colVal === void 0) return;
22663
22604
  if (!accs[groupKey]) accs[groupKey] = {};
22664
22605
  if (!accs[groupKey][colVal]) {
22665
22606
  accs[groupKey][colVal] = {
@@ -22690,7 +22631,7 @@ function aggregateWithColumn(rows, colKey, aggregations, getGroupKey) {
22690
22631
  );
22691
22632
  Object.keys(accs[groupKey]).forEach((colVal) => {
22692
22633
  const acc = accs[groupKey][colVal];
22693
- const finalKey = `${colVal}` + (multiAgg ? `_${type}` : "");
22634
+ const finalKey = `${colVal}` + getDisambiguationSuffix(type, multiAgg);
22694
22635
  seen[groupKey][finalKey] = getFinalAggregationValue({
22695
22636
  type,
22696
22637
  valueFieldType,
@@ -22719,7 +22660,7 @@ function aggregateWithoutColumn(rows, aggregations, getGroupKey) {
22719
22660
  if (!valueField) {
22720
22661
  if (type !== "count" && type !== "percentage") return;
22721
22662
  }
22722
- const finalKey = !valueField ? `${type}` + (multiAgg ? `_${type}` : "") : `${valueField}` + (multiAgg ? `_${type}` : "");
22663
+ const finalKey = `${valueField ?? type}` + getDisambiguationSuffix(type, multiAgg);
22723
22664
  const distinctDenom = !!valueField2 && !!valueField2Type && valueField !== valueField2;
22724
22665
  const accs = {};
22725
22666
  rows.forEach((row) => {
@@ -22780,7 +22721,10 @@ function applyPivotInMemory(rows, pivot, filters) {
22780
22721
  const rawDateFromQuill = row.__quillRawDate;
22781
22722
  const rawDateValue = rawDateFromQuill ?? (rawValue !== null && typeof rawValue === "object" && rawValue.value ? rawValue.value : rawValue);
22782
22723
  return getDateKey(new Date(rawDateValue), dateBucket);
22783
- } : (row) => row[rowField];
22724
+ } : (row) => {
22725
+ const value = row[rowField];
22726
+ return value === null ? "-" : value;
22727
+ };
22784
22728
  const aggregated = columnField ? aggregateWithColumn(rows, columnField, aggregations, getRowKey) : aggregateWithoutColumn(rows, aggregations, getRowKey);
22785
22729
  const aggregatedRows = aggregated || {};
22786
22730
  if (rows.length === 0 && dateBucket && dateRange && !columnField) {
@@ -22865,24 +22809,65 @@ function generatePivotColumnsInMemory({
22865
22809
  // src/utils/cacheCab.ts
22866
22810
  var import_idb = require("idb");
22867
22811
  var import_date_fns9 = require("date-fns");
22868
- var import_date_fns_tz2 = require("date-fns-tz");
22812
+ var import_date_fns_tz3 = require("date-fns-tz");
22869
22813
  var TZ = "America/Los_Angeles";
22814
+ var DEFAULT_MAX_ROWS = 1e5;
22870
22815
  var CacheCab = class {
22871
22816
  fetchedRange = {};
22872
22817
  cachedReportIds = [];
22873
22818
  uncacheableReportIDs = [];
22874
22819
  uncacheableInFlight = /* @__PURE__ */ new Map();
22875
22820
  storage;
22821
+ maxRows = {};
22822
+ cacheableLoaded;
22876
22823
  META_KEY = "cachecab:meta";
22877
22824
  DATA_PREFIX = "cachecab:data:";
22878
22825
  UNCACHEABLE_PREFIX = "cachecab:uncacheable:";
22879
22826
  constructor({
22880
- storageType = "memory"
22881
- } = {}) {
22882
- this.storage = storageType !== "idb" ? new MemoryStorage() : new IdbStorage();
22883
- void this.loadMetaFromStorage();
22827
+ storageType = "memory",
22828
+ client,
22829
+ tenants,
22830
+ dashboards = [],
22831
+ getToken
22832
+ }) {
22833
+ this.storage = storageType !== "indexedDB" ? new MemoryStorage() : new IdbStorage();
22834
+ this.cacheableLoaded = (async () => {
22835
+ await this.loadMetaFromStorage();
22836
+ try {
22837
+ const result = await quillFetch({
22838
+ client,
22839
+ task: "get-dashboards-and-reports",
22840
+ method: "POST",
22841
+ metadata: {
22842
+ tenants
22843
+ },
22844
+ getToken
22845
+ });
22846
+ const tasks = result?.data?.tasks ?? [];
22847
+ const uncacheable = tasks?.filter((x) => x.isCacheable !== true && x.useReport).map((y) => y.reportId) ?? [];
22848
+ this.uncacheableReportIDs = uncacheable;
22849
+ const temp = tasks.map((x) => {
22850
+ return { name: x.dashboard.name, id: x.reportId };
22851
+ });
22852
+ temp.forEach((r) => {
22853
+ if (!this.maxRows[r.id]) {
22854
+ const d = dashboards.find((x) => x.name === r.name);
22855
+ this.maxRows[r.id] = d.totalCachedRows ?? DEFAULT_MAX_ROWS;
22856
+ }
22857
+ });
22858
+ } catch {
22859
+ }
22860
+ })();
22861
+ }
22862
+ async ensureReady() {
22863
+ await this.cacheableLoaded;
22884
22864
  }
22885
22865
  async get(reportId, dashboardFilters, customFilters, pivot, client, tenants, flags, pageSize, getToken, eventTracking, forceRefresh) {
22866
+ await this.ensureReady();
22867
+ if (!this.isCacheable(reportId)) {
22868
+ return EMPTY_INTERNAL_REPORT;
22869
+ }
22870
+ ;
22886
22871
  if (this.isCached(reportId, tenants) && !forceRefresh) {
22887
22872
  return this.getFromCache(reportId, dashboardFilters, customFilters, pivot, client, tenants, flags, getToken, eventTracking);
22888
22873
  } else {
@@ -22895,39 +22880,8 @@ var CacheCab = class {
22895
22880
  isCacheable(reportId) {
22896
22881
  return !this.uncacheableReportIDs.includes(reportId);
22897
22882
  }
22898
- async getUncacheableResult(reportId, client, tenants, flags, filters, additionalProcessing, pivot) {
22899
- const key = this.getUncacheableRequestKey(
22900
- reportId,
22901
- client,
22902
- tenants,
22903
- flags,
22904
- filters,
22905
- additionalProcessing,
22906
- pivot
22907
- );
22908
- try {
22909
- const raw = await this.storage.getItem(key);
22910
- return raw ? JSON.parse(raw) : null;
22911
- } catch {
22912
- return null;
22913
- }
22914
- }
22915
- async setUncacheableResult(reportId, client, tenants, flags, filters, additionalProcessing, pivot, report) {
22916
- const key = this.getUncacheableRequestKey(
22917
- reportId,
22918
- client,
22919
- tenants,
22920
- flags,
22921
- filters,
22922
- additionalProcessing,
22923
- pivot
22924
- );
22925
- try {
22926
- await this.storage.setItem(key, JSON.stringify(report));
22927
- } catch {
22928
- }
22929
- }
22930
22883
  async getOrFetchUncacheableResult(reportId, client, tenants, flags, filters, additionalProcessing, pivot, fetcher, forceRefresh = false) {
22884
+ await this.ensureReady();
22931
22885
  const key = this.getUncacheableRequestKey(
22932
22886
  reportId,
22933
22887
  client,
@@ -23197,7 +23151,7 @@ var CacheCab = class {
23197
23151
  clientId: client.publicKey,
23198
23152
  databaseType: client.databaseType,
23199
23153
  filters: adjusted,
23200
- additionalProcessing: { page: { rowsPerPage: 1e3, rowsPerRequest: 1e5 } },
23154
+ additionalProcessing: { page: { rowsPerPage: Math.min(this.maxRows[reportId] ?? 1e3, 1e3), rowsPerRequest: this.maxRows[reportId] ?? DEFAULT_MAX_ROWS } },
23201
23155
  useNewNodeSql: true,
23202
23156
  tenants,
23203
23157
  flags,
@@ -23205,6 +23159,10 @@ var CacheCab = class {
23205
23159
  },
23206
23160
  getToken
23207
23161
  });
23162
+ if (!fetchResp.data?.isCacheable) {
23163
+ this.uncacheableReportIDs.push(reportId);
23164
+ return EMPTY_INTERNAL_REPORT;
23165
+ }
23208
23166
  const resp = await parseFetchResponse(
23209
23167
  client,
23210
23168
  "report",
@@ -23212,12 +23170,16 @@ var CacheCab = class {
23212
23170
  getToken,
23213
23171
  true
23214
23172
  );
23173
+ if (resp.rowCount > (this.maxRows[reportId] ?? DEFAULT_MAX_ROWS)) {
23174
+ this.uncacheableReportIDs.push(reportId);
23175
+ return EMPTY_INTERNAL_REPORT;
23176
+ }
23215
23177
  reportInfo = await processReportResponse({
23216
23178
  resp,
23217
23179
  client,
23218
23180
  filters: adjusted,
23219
23181
  dateBucket: resp?.dateBucket,
23220
- additionalProcessing: { page: { rowsPerPage: 1e3, rowsPerRequest: 1e5 } },
23182
+ additionalProcessing: { page: { rowsPerPage: Math.min(this.maxRows[reportId] ?? 1e3, 1e3), rowsPerRequest: this.maxRows[reportId] ?? DEFAULT_MAX_ROWS } },
23221
23183
  getToken,
23222
23184
  eventTracking,
23223
23185
  tenants,
@@ -23226,8 +23188,16 @@ var CacheCab = class {
23226
23188
  overwriteCache: forceRefresh ?? false
23227
23189
  });
23228
23190
  const dateField = reportInfo.dateField?.field;
23191
+ const dateTable = removeQuotes(reportInfo.dateField?.table ?? "");
23229
23192
  if (!isAllTime && dateField !== void 0 && reportInfo.rows.length > 0) {
23230
23193
  const cleanedDateField = removeQuotes(dateField);
23194
+ if (reportInfo.referencedColumns && dateTable) {
23195
+ const refs = reportInfo.referencedColumns[dateTable];
23196
+ if (refs && !refs.some((x) => x && removeQuotes(x) == cleanedDateField)) {
23197
+ this.uncacheableReportIDs.push(reportId);
23198
+ return EMPTY_INTERNAL_REPORT;
23199
+ }
23200
+ }
23231
23201
  const missingDateFieldCount = reportInfo.rows.some((row) => row[cleanedDateField] === void 0);
23232
23202
  if (missingDateFieldCount) {
23233
23203
  this.uncacheableReportIDs.push(reportId);
@@ -23301,12 +23271,12 @@ var CacheCab = class {
23301
23271
  return [];
23302
23272
  }
23303
23273
  const dbDateFilter = dashboardFilters.find((x) => x.filterType === "date_range");
23304
- if (report.dateField && dbDateFilter?.startDate) {
23305
- const { start: startDate, end: endDate } = normalizePSTRanges(
23306
- new Date(dbDateFilter.startDate),
23307
- dbDateFilter.endDate ? new Date(dbDateFilter.endDate) : void 0
23308
- );
23274
+ if (report.dateField && dbDateFilter?.startDate && dbDateFilter?.endDate) {
23309
23275
  const fieldToUse = report.rows[0] && report.rows[0]["__quillRawDate"] ? "__quillRawDate" : removeQuotes(report.dateField.field);
23276
+ const useDateOnly = report.columnInternal.find((x) => x.field === fieldToUse)?.dataTypeID === 1082;
23277
+ const rawStart = new Date(dbDateFilter.startDate);
23278
+ const startDate = useDateOnly ? new Date(Date.UTC(rawStart.getUTCFullYear(), rawStart.getUTCMonth(), rawStart.getUTCDate(), 0, 0, 0, 0)) : rawStart;
23279
+ const endDate = new Date(dbDateFilter.endDate);
23310
23280
  const dateFilteredRows = report.rows.filter((x) => {
23311
23281
  const rowDate = new Date(x[fieldToUse]);
23312
23282
  return startDate <= rowDate && (endDate ? rowDate <= endDate : true);
@@ -23349,7 +23319,6 @@ var CacheCab = class {
23349
23319
  try {
23350
23320
  const parsed = JSON.parse(meta);
23351
23321
  this.cachedReportIds = parsed.cached || [];
23352
- this.uncacheableReportIDs = parsed.cannotBeCached;
23353
23322
  this.fetchedRange = Object.fromEntries(
23354
23323
  Object.entries(parsed.fetchedRange || {}).map(([id, range]) => [
23355
23324
  id,
@@ -23371,8 +23340,7 @@ var CacheCab = class {
23371
23340
  this.META_KEY,
23372
23341
  JSON.stringify({
23373
23342
  fetchedRange: serializableRange,
23374
- cached: this.cachedReportIds,
23375
- cannotBeCached: this.uncacheableReportIDs
23343
+ cached: this.cachedReportIds
23376
23344
  })
23377
23345
  );
23378
23346
  }
@@ -23496,14 +23464,14 @@ function canonicalizeFilterForUncacheableKey(filter) {
23496
23464
  return canonicalizeForKey(base);
23497
23465
  }
23498
23466
  function startOfDayPST(date) {
23499
- const pstDate = (0, import_date_fns_tz2.utcToZonedTime)(date, TZ);
23467
+ const pstDate = (0, import_date_fns_tz3.utcToZonedTime)(date, TZ);
23500
23468
  const startPst = (0, import_date_fns9.startOfDay)(pstDate);
23501
- return (0, import_date_fns_tz2.zonedTimeToUtc)(startPst, TZ);
23469
+ return (0, import_date_fns_tz3.zonedTimeToUtc)(startPst, TZ);
23502
23470
  }
23503
23471
  function endOfDayPST(date) {
23504
- const pstDate = (0, import_date_fns_tz2.utcToZonedTime)(date, TZ);
23472
+ const pstDate = (0, import_date_fns_tz3.utcToZonedTime)(date, TZ);
23505
23473
  const endPst = (0, import_date_fns9.endOfDay)(pstDate);
23506
- return (0, import_date_fns_tz2.zonedTimeToUtc)(endPst, TZ);
23474
+ return (0, import_date_fns_tz3.zonedTimeToUtc)(endPst, TZ);
23507
23475
  }
23508
23476
  function normalizePSTRanges(start, end) {
23509
23477
  return {
@@ -23937,7 +23905,18 @@ var EventTrackingContext = (0, import_react.createContext)({
23937
23905
  eventTracking: null
23938
23906
  });
23939
23907
  var CacheCabContext = (0, import_react.createContext)({
23940
- getCacheCab: (storageType) => new CacheCab({ storageType })
23908
+ getCacheCab: (storageType) => new CacheCab({
23909
+ storageType,
23910
+ client: {
23911
+ clientId: "",
23912
+ queryEndpoint: "",
23913
+ queryHeaders: void 0,
23914
+ withCredentials: false
23915
+ },
23916
+ tenants: [],
23917
+ dashboards: [],
23918
+ getToken: async () => ""
23919
+ })
23941
23920
  });
23942
23921
  var ContextProvider = ({
23943
23922
  children,
@@ -23952,14 +23931,6 @@ var ContextProvider = ({
23952
23931
  getAuthorizationToken = async () => "",
23953
23932
  eventTracking = null
23954
23933
  }) => {
23955
- const cacheCabByTypeRef = (0, import_react.useRef)({});
23956
- const getCacheCab = (0, import_react.useCallback)((storageType) => {
23957
- const key = storageType === "idb" ? "idb" : "memory";
23958
- if (!cacheCabByTypeRef.current[key]) {
23959
- cacheCabByTypeRef.current[key] = new CacheCab({ storageType: key });
23960
- }
23961
- return cacheCabByTypeRef.current[key];
23962
- }, []);
23963
23934
  const [client, setClient] = (0, import_react.useState)(
23964
23935
  typeof window !== "undefined" && sessionStorage ? JSON.parse(sessionStorage.getItem("quill-client") ?? "null") : null
23965
23936
  );
@@ -23988,6 +23959,7 @@ var ContextProvider = ({
23988
23959
  const [isClientLoading, setIsClientLoading] = (0, import_react.useState)(false);
23989
23960
  const [isDashboardsLoading, setIsDashboardsLoading] = (0, import_react.useState)(true);
23990
23961
  const [theme, setTheme] = (0, import_react.useState)(null);
23962
+ const [rawDashboards, setRawDashboards] = (0, import_react.useState)(void 0);
23991
23963
  const [schemaData, setSchemaData] = (0, import_react.useState)({
23992
23964
  schema: [],
23993
23965
  customFields: null,
@@ -24862,14 +24834,12 @@ var ContextProvider = ({
24862
24834
  }
24863
24835
  acc[dashboard2.name] = {};
24864
24836
  if (dashboard2.dateFilter) {
24837
+ const primaryRangeValue = dashboard2.dateFilter.primaryRange?.value;
24838
+ const selectedPresetRange = presetOptions.find((elem) => elem.value === primaryRangeValue) ?? PRIMARY_RANGE[primaryRangeValue ?? "LAST_30_DAYS"];
24865
24839
  dashboard2.dateFilter = {
24866
24840
  ...dashboard2.dateFilter,
24867
- startDate: presetOptions.find(
24868
- (elem) => elem.value === dashboard2.dateFilter.primaryRange?.value
24869
- )?.startDate,
24870
- endDate: presetOptions.find(
24871
- (elem) => elem.value === dashboard2.dateFilter.primaryRange?.value
24872
- )?.endDate,
24841
+ startDate: selectedPresetRange?.startDate,
24842
+ endDate: selectedPresetRange?.endDate,
24873
24843
  filterType: "date_range",
24874
24844
  presetOptions: dashboard2.dateFilter.presetOptions?.map(
24875
24845
  (preset) => ({
@@ -25205,15 +25175,13 @@ var ContextProvider = ({
25205
25175
  }
25206
25176
  acc[dashboard2.name] = {};
25207
25177
  if (dashboard2.dateFilter) {
25178
+ const primaryRangeValue = dashboard2.dateFilter.primaryRange?.value;
25179
+ const selectedPresetRange = presetOptions.find((elem) => elem.value === primaryRangeValue) ?? PRIMARY_RANGE[primaryRangeValue ?? "LAST_30_DAYS"];
25208
25180
  dashboard2.dateFilter = {
25209
25181
  ...dashboard2.dateFilter,
25210
25182
  initialCacheDateRange: dashboard2.initialCacheDateRange ? { ...dashboard2.initialCacheDateRange } : void 0,
25211
- startDate: presetOptions.find(
25212
- (elem) => elem.value === dashboard2.dateFilter.primaryRange?.value
25213
- )?.startDate,
25214
- endDate: presetOptions.find(
25215
- (elem) => elem.value === dashboard2.dateFilter.primaryRange?.value
25216
- )?.endDate,
25183
+ startDate: selectedPresetRange?.startDate,
25184
+ endDate: selectedPresetRange?.endDate,
25217
25185
  filterType: "date_range",
25218
25186
  presetOptions: dashboard2.dateFilter.presetOptions?.map(
25219
25187
  (preset) => ({
@@ -25283,6 +25251,33 @@ var ContextProvider = ({
25283
25251
  });
25284
25252
  });
25285
25253
  }
25254
+ const cacheCabByTypeRef = (0, import_react.useRef)({});
25255
+ const getCacheCab = (0, import_react.useCallback)((storageType) => {
25256
+ const key = storageType === "indexedDB" ? "indexedDB" : "memory";
25257
+ if (!cacheCabByTypeRef.current[key]) {
25258
+ cacheCabByTypeRef.current[key] = new CacheCab({
25259
+ storageType: key,
25260
+ client: {
25261
+ clientId: publicKey,
25262
+ queryEndpoint,
25263
+ queryHeaders,
25264
+ withCredentials: !!withCredentials
25265
+ },
25266
+ tenants,
25267
+ dashboards: rawDashboards,
25268
+ getToken: getAuthorizationToken
25269
+ });
25270
+ }
25271
+ return cacheCabByTypeRef.current[key];
25272
+ }, [
25273
+ publicKey,
25274
+ queryEndpoint,
25275
+ queryHeaders,
25276
+ withCredentials,
25277
+ tenants,
25278
+ getAuthorizationToken,
25279
+ rawDashboards
25280
+ ]);
25286
25281
  (0, import_react.useEffect)(() => {
25287
25282
  async function fetchEnvironment(publicKey2) {
25288
25283
  if (!publicKey2) return;
@@ -25347,6 +25342,8 @@ var ContextProvider = ({
25347
25342
  });
25348
25343
  }
25349
25344
  if (envData) {
25345
+ const dashboardsFromEnv = envData.dashboards ?? envData.data?.dashboards ?? envData.environment?.dashboards ?? envData.dashboardsResponse ?? [];
25346
+ setRawDashboards(dashboardsFromEnv);
25350
25347
  const normalizeSchema = (schema2) => {
25351
25348
  if (!schema2) return [];
25352
25349
  const tables = Array.isArray(schema2) ? schema2 : schema2?.tables && Array.isArray(schema2.tables) ? schema2.tables : [];
@@ -25391,9 +25388,7 @@ var ContextProvider = ({
25391
25388
  reportFiltersDispatch({ type: "CLEAR_REPORT_FILTERS" });
25392
25389
  reportsDispatch({ type: "CLEAR_REPORTS" });
25393
25390
  backfilledDashboards.current.clear();
25394
- hydrateDashboardsFromResponse(
25395
- envData.dashboards ?? envData.data?.dashboards ?? envData.environment?.dashboards ?? envData.dashboardsResponse ?? []
25396
- );
25391
+ hydrateDashboardsFromResponse(dashboardsFromEnv);
25397
25392
  environmentHydratedRef.current = true;
25398
25393
  }
25399
25394
  } catch (error) {
@@ -25580,7 +25575,7 @@ init_filterProcessing();
25580
25575
  // src/utils/merge.ts
25581
25576
  var import_date_fns10 = require("date-fns");
25582
25577
  init_columnType();
25583
- var import_date_fns_tz3 = require("date-fns-tz");
25578
+ var import_date_fns_tz4 = require("date-fns-tz");
25584
25579
  function mergeComparisonRange(resp) {
25585
25580
  if (resp.chartType === "table") return resp;
25586
25581
  const compRows = resp.compareRows;
@@ -26256,7 +26251,7 @@ var useDashboards = () => {
26256
26251
  };
26257
26252
  };
26258
26253
  var useDashboard = (dashboardName, config) => {
26259
- const logCacheStatistics = config?.showCacheLogs || false;
26254
+ const logCacheStatistics = config?.frontendCacheConfig?.showCacheLogs || false;
26260
26255
  const { data, dashboardFilters, reload, isLoading } = useDashboardInternal(dashboardName);
26261
26256
  const [lastUpdated, setLastUpdated] = (0, import_react2.useState)(0);
26262
26257
  const { customFilterDispatch } = (0, import_react2.useContext)(DashboardFiltersContext);
@@ -26275,10 +26270,10 @@ var useDashboard = (dashboardName, config) => {
26275
26270
  const pendingNameChangeReload = (0, import_react2.useRef)(false);
26276
26271
  const [loadedDashes, setLoadedDashes] = (0, import_react2.useState)([]);
26277
26272
  const [lastUpdatedDict, setLastUpdatedDict] = (0, import_react2.useState)({});
26278
- const cacheEnabled = config?.cacheEnabled ?? false;
26273
+ const cacheEnabled = config?.frontendCacheConfig?.cacheType !== void 0;
26279
26274
  const cacheCab = (0, import_react2.useMemo)(
26280
- () => getCacheCab(config?.cacheType),
26281
- [getCacheCab, config?.cacheType]
26275
+ () => getCacheCab(config?.frontendCacheConfig?.cacheType),
26276
+ [getCacheCab, config?.frontendCacheConfig?.cacheType]
26282
26277
  );
26283
26278
  (0, import_react2.useEffect)(() => {
26284
26279
  const nameChanged = dashboardName !== lastDashboardName.current;
@@ -26344,13 +26339,13 @@ var useDashboard = (dashboardName, config) => {
26344
26339
  (0, import_react2.useEffect)(() => {
26345
26340
  if (!fetchedInitialReports.current && data && dashboardFilters !== null) {
26346
26341
  fetchedInitialReports.current = true;
26347
- fetchReports([], dashboardFilters ?? [], config?.pageSize);
26342
+ fetchReports([], dashboardFilters ?? [], config?.pageSize, config?.disableBackendCache ?? true);
26348
26343
  }
26349
26344
  }, [fetchedInitialReports, data, dashboardFilters, customFiltersLoaded]);
26350
26345
  (0, import_react2.useEffect)(() => {
26351
26346
  if (customFiltersLoaded && data && dashboardFilters !== null) {
26352
26347
  fetchedInitialReports.current = true;
26353
- fetchReports([], dashboardFilters ?? [], config?.pageSize);
26348
+ fetchReports([], dashboardFilters ?? [], config?.pageSize, config?.disableBackendCache ?? true);
26354
26349
  }
26355
26350
  }, [customFiltersLoaded]);
26356
26351
  const applyDashboardFilters = (filtersToUpdate) => {
@@ -26461,13 +26456,13 @@ var useDashboard = (dashboardName, config) => {
26461
26456
  const customFilters = filters2.filter(isFilter2);
26462
26457
  const newCustomFilters = applyCustomFilters(customFilters);
26463
26458
  const newDashboardFilters = applyDashboardFilters(dashboardFilters2);
26464
- fetchReports(newCustomFilters, newDashboardFilters);
26459
+ fetchReports(newCustomFilters, newDashboardFilters, void 0, config?.disableBackendCache ?? true);
26465
26460
  };
26466
26461
  const forceCacheRefresh = () => {
26467
26462
  if (!cacheEnabled) return;
26468
- fetchReports([], dashboardFilters ?? [], config?.pageSize, true);
26463
+ fetchReports([], dashboardFilters ?? [], config?.pageSize, false);
26469
26464
  };
26470
- const fetchReports = async (customFilters, dashboardFilters2, pageSize, forceCacheToRefresh = false) => {
26465
+ const fetchReports = async (customFilters, dashboardFilters2, pageSize, useBackendCache = true) => {
26471
26466
  if (!client || !sections) return;
26472
26467
  const allReports = Object.values(sections).flat();
26473
26468
  const fetchStartTime = Date.now();
@@ -26494,7 +26489,7 @@ var useDashboard = (dashboardName, config) => {
26494
26489
  const additionalProcessing = {
26495
26490
  page: pagination
26496
26491
  };
26497
- const usePivotTask = !cacheEnabled && !!reportInfo.pivot;
26492
+ const usePivotTask = !!reportInfo.pivot;
26498
26493
  const allFilters = dashboardFilters2.concat(customFilters).concat(customReportFiltersArray);
26499
26494
  const applyInMemoryPivotIfNeeded = (report2) => {
26500
26495
  const pivotToApply = reportInfo.pivot ?? report2.pivot;
@@ -26519,31 +26514,32 @@ var useDashboard = (dashboardName, config) => {
26519
26514
  pivotRowCount: pivotRows.length
26520
26515
  };
26521
26516
  };
26522
- if (cacheEnabled && cacheCab.isCacheable(reportId)) {
26523
- const report2 = await cacheCab.get(reportId, dashboardFilters2, customFilters.concat(customReportFiltersArray), reportInfo.pivot, client, tenants, flags, pageSize, getToken, eventTracking, forceCacheToRefresh);
26524
- if (reportRequestIds.current[reportId] !== requestId) {
26525
- return null;
26526
- }
26517
+ if (cacheEnabled) {
26518
+ await cacheCab.ensureReady();
26527
26519
  if (cacheCab.isCacheable(reportId)) {
26528
- reportsDispatch({
26529
- type: "UPDATE_REPORT",
26530
- id: reportId,
26531
- data: {
26532
- ...report2,
26533
- pagination,
26534
- triggerReload: false
26535
- }
26536
- });
26537
- reportsLoadingStateDispatch({
26538
- type: "SET_REPORT_LOADING",
26539
- id: reportId,
26540
- data: false
26541
- });
26542
- totalCached += 1;
26543
- return report2;
26520
+ const report2 = await cacheCab.get(reportId, dashboardFilters2, customFilters.concat(customReportFiltersArray), reportInfo.pivot, client, tenants, flags, pageSize, getToken, eventTracking, !useBackendCache);
26521
+ if (reportRequestIds.current[reportId] !== requestId) {
26522
+ return null;
26523
+ }
26524
+ if (cacheCab.isCacheable(reportId)) {
26525
+ reportsDispatch({
26526
+ type: "UPDATE_REPORT",
26527
+ id: reportId,
26528
+ data: {
26529
+ ...report2,
26530
+ pagination,
26531
+ triggerReload: false
26532
+ }
26533
+ });
26534
+ reportsLoadingStateDispatch({
26535
+ type: "SET_REPORT_LOADING",
26536
+ id: reportId,
26537
+ data: false
26538
+ });
26539
+ totalCached += 1;
26540
+ return report2;
26541
+ }
26544
26542
  }
26545
- }
26546
- if (cacheEnabled && !cacheCab.isCacheable(reportId)) {
26547
26543
  try {
26548
26544
  const { report: uncacheableReport, fromCache } = await cacheCab.getOrFetchUncacheableResult(
26549
26545
  reportId,
@@ -26559,19 +26555,20 @@ var useDashboard = (dashboardName, config) => {
26559
26555
  client,
26560
26556
  tenants,
26561
26557
  flags,
26562
- additionalProcessing,
26558
+ additionalProcessing: usePivotTask ? additionalProcessing : { page: { rowsPerPage: 1e3, rowsPerRequest: 1e5 } },
26559
+ // TODO wire maxRows from cacheCab state into here
26563
26560
  filters: allFilters,
26564
26561
  getToken,
26565
26562
  eventTracking,
26566
26563
  usePivotTask,
26567
- overwriteCache: forceCacheToRefresh
26564
+ overwriteCache: !useBackendCache
26568
26565
  });
26569
26566
  if (error2 || !report2) {
26570
26567
  throw error2 ?? new Error("Failed to fetch uncacheable report");
26571
26568
  }
26572
26569
  return report2;
26573
26570
  },
26574
- forceCacheToRefresh
26571
+ !useBackendCache
26575
26572
  );
26576
26573
  if (reportRequestIds.current[reportId] !== requestId) {
26577
26574
  return null;
@@ -26603,7 +26600,7 @@ var useDashboard = (dashboardName, config) => {
26603
26600
  filters: allFilters,
26604
26601
  getToken,
26605
26602
  additionalProcessing,
26606
- overwriteCache: forceCacheToRefresh
26603
+ overwriteCache: !useBackendCache
26607
26604
  }).then(({ rows, rowCount, columns, fields }) => {
26608
26605
  if (reportRequestIds.current[reportId] !== requestId) {
26609
26606
  return;
@@ -26636,7 +26633,7 @@ var useDashboard = (dashboardName, config) => {
26636
26633
  return uncacheableReportWithPivot;
26637
26634
  } catch (error2) {
26638
26635
  console.error(error2);
26639
- const errorMessage = error2 instanceof Error ? error2.message : "Failed to fetch report";
26636
+ const errorMessage = error2 instanceof Error ? error2.message : typeof error2 == "string" ? error2 : "Failed to fetch report";
26640
26637
  reportsDispatch({
26641
26638
  type: "UPDATE_REPORT",
26642
26639
  id: reportId,
@@ -26664,7 +26661,7 @@ var useDashboard = (dashboardName, config) => {
26664
26661
  getToken,
26665
26662
  eventTracking,
26666
26663
  usePivotTask,
26667
- overwriteCache: forceCacheToRefresh
26664
+ overwriteCache: !useBackendCache
26668
26665
  // usePivotTask: false,
26669
26666
  });
26670
26667
  if (reportRequestIds.current[reportId] !== requestId) {
@@ -26699,7 +26696,7 @@ var useDashboard = (dashboardName, config) => {
26699
26696
  filters: allFilters,
26700
26697
  getToken,
26701
26698
  additionalProcessing,
26702
- overwriteCache: forceCacheToRefresh
26699
+ overwriteCache: !useBackendCache
26703
26700
  }).then(({ rows, rowCount, columns, fields }) => {
26704
26701
  if (reportRequestIds.current[reportId] !== requestId) {
26705
26702
  return;
@@ -26732,12 +26729,12 @@ var useDashboard = (dashboardName, config) => {
26732
26729
  return report;
26733
26730
  })
26734
26731
  );
26735
- if (!loadedDashes.includes(dashboardName) || !cacheEnabled || forceCacheToRefresh) {
26732
+ if (!loadedDashes.includes(dashboardName) || !cacheEnabled || !useBackendCache) {
26736
26733
  setLoadedDashes((prev) => prev.includes(dashboardName) ? prev : [...prev, dashboardName]);
26737
26734
  setLastUpdatedDict((prev) => ({ ...prev, [dashboardName]: Date.now() }));
26738
26735
  }
26739
26736
  if (logCacheStatistics) {
26740
- console.log(`Dashboard "${dashboardName}": Cache Rate: ${(100 * totalCached / allReports.length).toFixed(1)}%, load time: ${((Date.now() - fetchStartTime) / 1e3).toFixed(2)} secs`);
26737
+ console.log(`Dashboard "${dashboardName}": Cache Rate: ${(100 * totalCached / Math.max(1, allReports.length)).toFixed(1)}%, load time: ${((Date.now() - fetchStartTime) / 1e3).toFixed(2)} secs`);
26741
26738
  }
26742
26739
  };
26743
26740
  return {
@@ -31292,7 +31289,7 @@ init_valueFormatter();
31292
31289
 
31293
31290
  // src/utils/axisFormatter.ts
31294
31291
  var import_date_fns11 = require("date-fns");
31295
- var import_date_fns_tz4 = require("date-fns-tz");
31292
+ var import_date_fns_tz5 = require("date-fns-tz");
31296
31293
  var axisFormatter = ({ value, field, fields }) => {
31297
31294
  if (field === void 0 || field === null) return "";
31298
31295
  if (value === void 0 || value === null) return "";
@@ -31408,7 +31405,7 @@ var formatPercent2 = (value) => {
31408
31405
  return formatter.format(Number(value));
31409
31406
  };
31410
31407
  var _getUTCDateHelper2 = (value, fmt) => {
31411
- const utcDate = (0, import_date_fns_tz4.utcToZonedTime)(new Date(value), "UTC");
31408
+ const utcDate = (0, import_date_fns_tz5.utcToZonedTime)(new Date(value), "UTC");
31412
31409
  if (!(0, import_date_fns11.isValid)(utcDate)) return "Invalid date";
31413
31410
  return (0, import_date_fns11.format)(utcDate, fmt);
31414
31411
  };
@@ -31418,7 +31415,7 @@ var format_MMM_yyyy2 = (value) => _getUTCDateHelper2(value, "MMM yyyy");
31418
31415
  var format_hh_ap_pm2 = (value) => _getUTCDateHelper2(value, "hh:mm aa");
31419
31416
  var format_MMM_dd_yyyy2 = (value) => _getUTCDateHelper2(value, "dd MMM yyyy");
31420
31417
  var format_MMM_dd_MMM_dd = (value) => {
31421
- const utcDate = (0, import_date_fns_tz4.utcToZonedTime)(new Date(value), "UTC");
31418
+ const utcDate = (0, import_date_fns_tz5.utcToZonedTime)(new Date(value), "UTC");
31422
31419
  if (!(0, import_date_fns11.isValid)(utcDate)) return "Invalid date";
31423
31420
  const monday = (0, import_date_fns11.startOfWeek)(utcDate, { weekStartsOn: 1 });
31424
31421
  const sunday = (0, import_date_fns11.endOfWeek)(utcDate, { weekStartsOn: 1 });
@@ -31429,14 +31426,14 @@ var format_MMM_dd_MMM_dd = (value) => {
31429
31426
  }
31430
31427
  };
31431
31428
  var format_MMM_dd_hh_mm_ap_pm2 = (value) => {
31432
- const utcDate = (0, import_date_fns_tz4.utcToZonedTime)(new Date(value), "UTC");
31429
+ const utcDate = (0, import_date_fns_tz5.utcToZonedTime)(new Date(value), "UTC");
31433
31430
  if (!(0, import_date_fns11.isValid)(utcDate)) return "Invalid date";
31434
31431
  const formatStr = utcDate.getMinutes() === 0 ? "MMM do h a" : "MMM do h:mm a";
31435
31432
  const res = (0, import_date_fns11.format)(utcDate, formatStr);
31436
31433
  return res.slice(0, -2) + res.slice(-2).toLowerCase();
31437
31434
  };
31438
31435
  var format_wo_yyyy2 = (value) => {
31439
- const utcDate = (0, import_date_fns_tz4.utcToZonedTime)(new Date(value), "UTC");
31436
+ const utcDate = (0, import_date_fns_tz5.utcToZonedTime)(new Date(value), "UTC");
31440
31437
  if (!(0, import_date_fns11.isValid)(utcDate)) return "Invalid date";
31441
31438
  return `${(0, import_date_fns11.getWeek)(utcDate)},${utcDate.getFullYear()}`;
31442
31439
  };
@@ -37808,6 +37805,10 @@ function Chart({
37808
37805
  if (!shouldShowCloudCacheValidationErrors) return false;
37809
37806
  return reportUsesLimitClause(report);
37810
37807
  }, [report, shouldShowCloudCacheValidationErrors]);
37808
+ const hasUncacheableReason = (0, import_react31.useMemo)(() => {
37809
+ if (!shouldShowCloudCacheValidationErrors) return false;
37810
+ return !!(report?.isCacheableReason && !report.isCacheable);
37811
+ }, [report, shouldShowCloudCacheValidationErrors]);
37811
37812
  const missingDashboardFilterFields = (0, import_react31.useMemo)(() => {
37812
37813
  if (!shouldShowCloudCacheValidationErrors || !report) return [];
37813
37814
  return getMissingDashboardFilterFields({
@@ -37955,6 +37956,14 @@ function Chart({
37955
37956
  if (report?.error || error) {
37956
37957
  return /* @__PURE__ */ (0, import_jsx_runtime49.jsx)("div", { style: containerStyle, className, children: /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(ChartError, { errorMessage: report?.error ?? error }) });
37957
37958
  }
37959
+ if (hasUncacheableReason) {
37960
+ return /* @__PURE__ */ (0, import_jsx_runtime49.jsx)("div", { style: containerStyle, className, children: /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
37961
+ ChartError,
37962
+ {
37963
+ errorMessage: `The query for this report cannot be cached: ${report?.isCacheableReason}.`
37964
+ }
37965
+ ) });
37966
+ }
37958
37967
  if (isMissingDateField) {
37959
37968
  return /* @__PURE__ */ (0, import_jsx_runtime49.jsx)("div", { style: containerStyle, className, children: /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
37960
37969
  ChartError,