@quillsql/react 2.16.21 → 2.16.23

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
@@ -263,6 +263,9 @@ var init_valueFormatter = __esm({
263
263
  maximumFractionDigits: 2
264
264
  });
265
265
  formatPercent = (value) => {
266
+ if (typeof value === "string" && /^\s*[+-]?(?:\d+(?:\.\d+)?|\.\d+)\s*%\s*$/.test(value)) {
267
+ return value;
268
+ }
266
269
  return formatterPercent.format(Number(value));
267
270
  };
268
271
  _getUTCDateHelper = (value, fmt) => {
@@ -1531,6 +1534,7 @@ var init_dateRangePickerUtils = __esm({
1531
1534
  };
1532
1535
  convertPresetOptionsToSelectableList = (customIntervals, defaultIntervals) => {
1533
1536
  const customLabelMap = /* @__PURE__ */ new Map();
1537
+ const displayLabelByValue = /* @__PURE__ */ new Map();
1534
1538
  defaultIntervals.forEach((interval2) => {
1535
1539
  if (interval2.customLabel) {
1536
1540
  customLabelMap.set(interval2.label, interval2.customLabel);
@@ -1700,11 +1704,14 @@ var init_dateRangePickerUtils = __esm({
1700
1704
  }
1701
1705
  ];
1702
1706
  }
1703
- if (interval2.customLabel && createdIntervals.length > 0) {
1704
- return createdIntervals.map((i) => ({
1705
- ...i,
1706
- label: interval2.customLabel
1707
- }));
1707
+ if (createdIntervals.length > 0) {
1708
+ const displayLabel = interval2.customLabel ?? interval2.label;
1709
+ createdIntervals.forEach((createdInterval) => {
1710
+ const canonicalValue = getLabelForCustomInterval(createdInterval).toUpperCase().replace(/ /g, "_");
1711
+ if (displayLabel && canonicalValue) {
1712
+ displayLabelByValue.set(canonicalValue, displayLabel);
1713
+ }
1714
+ });
1708
1715
  }
1709
1716
  return createdIntervals;
1710
1717
  });
@@ -1760,9 +1767,10 @@ var init_dateRangePickerUtils = __esm({
1760
1767
  customLabel2 = customLabelMap.get("This year") || customLabelMap.get("Yearly");
1761
1768
  }
1762
1769
  }
1770
+ const value2 = getLabelForSubInterval(currentSubInterval).toUpperCase().replace(/ /g, "_") ?? "";
1763
1771
  presets.push({
1764
- label: customLabel2 || baseLabel,
1765
- value: getLabelForSubInterval(currentSubInterval).toUpperCase().replace(/ /g, "_") ?? "",
1772
+ label: displayLabelByValue.get(value2) || customLabel2 || baseLabel,
1773
+ value: value2,
1766
1774
  startDate: (0, import_date_fns2.set)(/* @__PURE__ */ new Date(), {
1767
1775
  year: currentYear,
1768
1776
  month: currentSubInterval.startDate.month - 1,
@@ -1794,13 +1802,14 @@ var init_dateRangePickerUtils = __esm({
1794
1802
  }
1795
1803
  const dateRange = convertCustomIntervalToDateRange(option);
1796
1804
  const generatedLabel = getLabelForCustomInterval(option);
1805
+ const value = getLabelForCustomInterval(option).toUpperCase().replace(/ /g, "_") ?? "";
1797
1806
  const customLabel = customLabelMap.get(generatedLabel);
1798
- const finalLabel = customLabel || generatedLabel;
1807
+ const finalLabel = displayLabelByValue.get(value) || customLabel || generatedLabel;
1799
1808
  return [
1800
1809
  {
1801
1810
  label: finalLabel,
1802
1811
  // Value is option label in uppercase with spaces replaced by underscores
1803
- value: getLabelForCustomInterval(option).toUpperCase().replace(/ /g, "_") ?? "",
1812
+ value,
1804
1813
  startDate: dateRange.startDate,
1805
1814
  endDate: dateRange.endDate
1806
1815
  }
@@ -1996,7 +2005,10 @@ var init_dateRangePickerUtils = __esm({
1996
2005
  getRangeFromPresetOptions = (preset, presetOptions) => {
1997
2006
  const foundPreset = presetOptions.find((elem) => elem.value === preset);
1998
2007
  if (foundPreset) {
1999
- return { startDate: foundPreset?.startDate, endDate: foundPreset?.endDate };
2008
+ return {
2009
+ startDate: foundPreset.startDate ? (0, import_date_fns2.startOfDay)(foundPreset.startDate) : foundPreset.startDate,
2010
+ endDate: foundPreset.endDate ? (0, import_date_fns2.endOfDay)(foundPreset.endDate) : foundPreset.endDate
2011
+ };
2000
2012
  } else {
2001
2013
  return { startDate: null, endDate: null };
2002
2014
  }
@@ -19879,11 +19891,12 @@ async function cleanDashboardItem({
19879
19891
  page: DEFAULT_PAGINATION
19880
19892
  };
19881
19893
  if (item.pivot && skipPivotFetch && item.rows && item.fields) {
19894
+ const pivotSourceRows = item.rows.map((row) => ({ ...row }));
19882
19895
  const dateFilter = dashboardFilters?.find(
19883
19896
  (filter) => filter.filterType === "date_range"
19884
19897
  );
19885
19898
  pivotTable = processPivotData({
19886
- rows: item.rows,
19899
+ rows: pivotSourceRows,
19887
19900
  fields: item.fields,
19888
19901
  pivot: {
19889
19902
  ...item.pivot,
@@ -22145,7 +22158,20 @@ var applyFiltersInMemory = (rows, filters, options) => {
22145
22158
  // src/utils/inMemoryPivotEngine.ts
22146
22159
  init_columnType();
22147
22160
  var MS_IN_DAY = 24 * 60 * 60 * 1e3;
22148
- var MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
22161
+ var MONTHS = [
22162
+ "Jan",
22163
+ "Feb",
22164
+ "Mar",
22165
+ "Apr",
22166
+ "May",
22167
+ "Jun",
22168
+ "Jul",
22169
+ "Aug",
22170
+ "Sep",
22171
+ "Oct",
22172
+ "Nov",
22173
+ "Dec"
22174
+ ];
22149
22175
  var INVALID_DATE_KEY = "-2026";
22150
22176
  function singleAggToMultiAgg(pivot) {
22151
22177
  if (pivot.aggregations) {
@@ -22153,7 +22179,12 @@ function singleAggToMultiAgg(pivot) {
22153
22179
  }
22154
22180
  const newPivot = { ...pivot };
22155
22181
  const newAgg = { aggregationType: pivot.aggregationType };
22156
- const fieldsToCopy = ["valueField", "valueFieldType", "valueField2", "valueField2Type"];
22182
+ const fieldsToCopy = [
22183
+ "valueField",
22184
+ "valueFieldType",
22185
+ "valueField2",
22186
+ "valueField2Type"
22187
+ ];
22157
22188
  fieldsToCopy.forEach((x) => {
22158
22189
  if (pivot[x]) {
22159
22190
  newAgg[x] = pivot[x];
@@ -22184,6 +22215,12 @@ function isValidDate3(date) {
22184
22215
  return false;
22185
22216
  }
22186
22217
  }
22218
+ function isDateLikeType(fieldType) {
22219
+ if (!fieldType) {
22220
+ return false;
22221
+ }
22222
+ return isDateType(fieldType) || isDateFormat2(fieldType);
22223
+ }
22187
22224
  function inferDateBucketFromFilters(pivot, filters) {
22188
22225
  if (!pivot?.rowFieldType) {
22189
22226
  return void 0;
@@ -22327,8 +22364,12 @@ function getDateRangeFromFilters(filters) {
22327
22364
  }
22328
22365
  function generateBucketKeys(start2, end, bucket) {
22329
22366
  const keys = /* @__PURE__ */ new Set();
22330
- const startDay = new Date(Date.UTC(start2.getUTCFullYear(), start2.getUTCMonth(), start2.getUTCDate()));
22331
- const endDay = new Date(Date.UTC(end.getUTCFullYear(), end.getUTCMonth(), end.getUTCDate()));
22367
+ const startDay = new Date(
22368
+ Date.UTC(start2.getUTCFullYear(), start2.getUTCMonth(), start2.getUTCDate())
22369
+ );
22370
+ const endDay = new Date(
22371
+ Date.UTC(end.getUTCFullYear(), end.getUTCMonth(), end.getUTCDate())
22372
+ );
22332
22373
  const cur = new Date(startDay);
22333
22374
  while (cur <= endDay) {
22334
22375
  keys.add(getDateKey(cur, bucket));
@@ -22352,7 +22393,9 @@ function getBucketRange(dateKey, bucket) {
22352
22393
  let end = new Date(d);
22353
22394
  switch (bucket) {
22354
22395
  case "day":
22355
- start2 = new Date(Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate()));
22396
+ start2 = new Date(
22397
+ Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate())
22398
+ );
22356
22399
  end = new Date(start2);
22357
22400
  break;
22358
22401
  case "week":
@@ -22394,10 +22437,18 @@ function getDateKey(date, bucket) {
22394
22437
  }
22395
22438
  switch (bucket) {
22396
22439
  case "day":
22397
- return Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate()).toString();
22440
+ return Date.UTC(
22441
+ date.getUTCFullYear(),
22442
+ date.getUTCMonth(),
22443
+ date.getUTCDate()
22444
+ ).toString();
22398
22445
  case "week": {
22399
22446
  const day = date.getUTCDay();
22400
- const mondayUtc = Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate() - (day + 6) % 7);
22447
+ const mondayUtc = Date.UTC(
22448
+ date.getUTCFullYear(),
22449
+ date.getUTCMonth(),
22450
+ date.getUTCDate() - (day + 6) % 7
22451
+ );
22401
22452
  return mondayUtc.toString();
22402
22453
  }
22403
22454
  case "month":
@@ -22461,7 +22512,11 @@ function assembleFinalRows(seen, rowKey, dateBucket, dateRange) {
22461
22512
  if (bucketEnd > dateRange.end) bucketEnd = dateRange.end;
22462
22513
  }
22463
22514
  return {
22464
- [rowKey]: formatBucketNameFromRange(bucketStart, bucketEnd, dateBucket),
22515
+ [rowKey]: formatBucketNameFromRange(
22516
+ bucketStart,
22517
+ bucketEnd,
22518
+ dateBucket
22519
+ ),
22465
22520
  ...filled[k],
22466
22521
  __quillRawDate: bucketStart.toISOString()
22467
22522
  };
@@ -22620,7 +22675,13 @@ function aggregateWithColumn(rows, colKey, aggregations, getGroupKey) {
22620
22675
  const seen = {};
22621
22676
  const multiAgg = aggregations.length > 1;
22622
22677
  aggregations.forEach((agg) => {
22623
- const { aggregationType: type, valueField, valueFieldType, valueField2, valueField2Type } = agg;
22678
+ const {
22679
+ aggregationType: type,
22680
+ valueField,
22681
+ valueFieldType,
22682
+ valueField2,
22683
+ valueField2Type
22684
+ } = agg;
22624
22685
  if (!valueField) {
22625
22686
  if (type !== "count" && type !== "percentage") return;
22626
22687
  }
@@ -22653,7 +22714,10 @@ function aggregateWithColumn(rows, colKey, aggregations, getGroupKey) {
22653
22714
  });
22654
22715
  Object.keys(accs).forEach((groupKey) => {
22655
22716
  if (!seen[groupKey]) seen[groupKey] = {};
22656
- const sumOfDenom = Object.values(accs[groupKey]).reduce((t, a) => t + a.count, 0);
22717
+ const sumOfDenom = Object.values(accs[groupKey]).reduce(
22718
+ (t, a) => t + a.count,
22719
+ 0
22720
+ );
22657
22721
  Object.keys(accs[groupKey]).forEach((colVal) => {
22658
22722
  const acc = accs[groupKey][colVal];
22659
22723
  const finalKey = `${colVal}` + (multiAgg ? `_${type}` : "");
@@ -22675,7 +22739,13 @@ function aggregateWithoutColumn(rows, aggregations, getGroupKey) {
22675
22739
  const seen = {};
22676
22740
  const multiAgg = aggregations.length > 1;
22677
22741
  aggregations.forEach((agg) => {
22678
- const { aggregationType: type, valueField, valueFieldType, valueField2, valueField2Type } = agg;
22742
+ const {
22743
+ aggregationType: type,
22744
+ valueField,
22745
+ valueFieldType,
22746
+ valueField2,
22747
+ valueField2Type
22748
+ } = agg;
22679
22749
  if (!valueField) {
22680
22750
  if (type !== "count" && type !== "percentage") return;
22681
22751
  }
@@ -22706,7 +22776,10 @@ function aggregateWithoutColumn(rows, aggregations, getGroupKey) {
22706
22776
  }
22707
22777
  updateAccumulator(acc, row, agg, false);
22708
22778
  });
22709
- const sumOfDenom = Object.values(accs).reduce((t, a) => t + a.count, 0);
22779
+ const sumOfDenom = Object.values(accs).reduce(
22780
+ (t, a) => t + a.count,
22781
+ 0
22782
+ );
22710
22783
  Object.keys(accs).forEach((k) => {
22711
22784
  const acc = accs[k];
22712
22785
  seen[k][finalKey] = getFinalAggregationValue({
@@ -22734,13 +22807,18 @@ function applyPivotInMemory(rows, pivot, filters) {
22734
22807
  const dateRange = dateBucket ? getDateRangeFromFilters(filters) : void 0;
22735
22808
  const getRowKey = dateBucket ? (row) => {
22736
22809
  const rawValue = row[rowField];
22737
- const rawDateValue = rawValue !== null && typeof rawValue === "object" && rawValue.value ? rawValue.value : rawValue;
22810
+ const rawDateFromQuill = row.__quillRawDate;
22811
+ const rawDateValue = rawDateFromQuill ?? (rawValue !== null && typeof rawValue === "object" && rawValue.value ? rawValue.value : rawValue);
22738
22812
  return getDateKey(new Date(rawDateValue), dateBucket);
22739
22813
  } : (row) => row[rowField];
22740
22814
  const aggregated = columnField ? aggregateWithColumn(rows, columnField, aggregations, getRowKey) : aggregateWithoutColumn(rows, aggregations, getRowKey);
22741
22815
  const aggregatedRows = aggregated || {};
22742
22816
  if (rows.length === 0 && dateBucket && dateRange && !columnField) {
22743
- const bucketKeys = generateBucketKeys(dateRange.start, dateRange.end, dateBucket);
22817
+ const bucketKeys = generateBucketKeys(
22818
+ dateRange.start,
22819
+ dateRange.end,
22820
+ dateBucket
22821
+ );
22744
22822
  const emptyAgg = buildEmptyAggRow(aggregations);
22745
22823
  bucketKeys.forEach((k) => {
22746
22824
  aggregatedRows[k] = { ...emptyAgg };
@@ -22758,6 +22836,61 @@ function applyPivotInMemory(rows, pivot, filters) {
22758
22836
  }
22759
22837
  return sorted;
22760
22838
  }
22839
+ function generatePivotColumnsInMemory({
22840
+ pivot,
22841
+ pivotRows,
22842
+ sourceColumns
22843
+ }) {
22844
+ if (!pivot?.rowField || !Array.isArray(pivotRows) || pivotRows.length === 0) {
22845
+ return void 0;
22846
+ }
22847
+ const columns = Array.isArray(sourceColumns) ? sourceColumns : [];
22848
+ const rowSource = columns.find((col) => col.field === pivot.rowField);
22849
+ const isRowFieldDate = isDateLikeType(pivot.rowFieldType);
22850
+ const rowFieldType = rowSource?.fieldType ?? pivot.rowFieldType ?? "string";
22851
+ const rowColumn = {
22852
+ field: pivot.rowField,
22853
+ label: rowSource?.label ?? pivot.rowField,
22854
+ format: isRowFieldDate ? "string" : rowSource?.format ?? "string",
22855
+ fieldType: rowFieldType,
22856
+ dataTypeID: rowSource?.dataTypeID ?? 1043,
22857
+ jsType: rowSource?.jsType ?? (isRowFieldDate ? "date" : "string")
22858
+ };
22859
+ const valueFieldFormat = (valueField) => columns.find((col) => col.field === valueField)?.format ?? "whole_number";
22860
+ const multiAgg = (pivot.aggregations?.length ?? 0) > 1;
22861
+ const aggregationBySuffix = new Map(
22862
+ (pivot.aggregations ?? []).map((agg) => [
22863
+ multiAgg ? `_${agg.aggregationType}` : "",
22864
+ agg
22865
+ ])
22866
+ );
22867
+ const valueKeys = Array.from(
22868
+ new Set(
22869
+ pivotRows.flatMap(
22870
+ (row) => Object.keys(row).filter(
22871
+ (key) => key !== pivot.rowField && key !== "__quillRawDate"
22872
+ )
22873
+ )
22874
+ )
22875
+ );
22876
+ const valueColumns = valueKeys.map((key) => {
22877
+ const matchingSuffix = Array.from(aggregationBySuffix.keys()).find(
22878
+ (suffix) => suffix && key.endsWith(suffix)
22879
+ );
22880
+ const matchedAgg = matchingSuffix ? aggregationBySuffix.get(matchingSuffix) : pivot.aggregations?.[0];
22881
+ const format9 = matchedAgg?.aggregationType === "percentage" ? "percent" : valueFieldFormat(matchedAgg?.valueField);
22882
+ const valueFieldType = matchedAgg?.valueFieldType ?? "number";
22883
+ return {
22884
+ field: key,
22885
+ label: key,
22886
+ format: format9,
22887
+ fieldType: valueFieldType,
22888
+ jsType: valueFieldType,
22889
+ dataTypeID: columns.find((col) => col.field === matchedAgg?.valueField)?.dataTypeID ?? 20
22890
+ };
22891
+ });
22892
+ return [rowColumn, ...valueColumns];
22893
+ }
22761
22894
 
22762
22895
  // src/utils/cacheCab.ts
22763
22896
  var import_idb = require("idb");
@@ -22875,7 +23008,12 @@ var CacheCab = class {
22875
23008
  }
22876
23009
  const newRows = await this.applyPivotsAndFilters(result, dashboardFilters, customFilters, pivot, tenantPart, false);
22877
23010
  if (pivot) {
22878
- return { ...result, pivotRows: newRows, pivotRowCount: newRows.length };
23011
+ const pivotColumns = generatePivotColumnsInMemory({
23012
+ pivot,
23013
+ pivotRows: newRows,
23014
+ sourceColumns: result.columnInternal ?? result.columns
23015
+ });
23016
+ return { ...result, pivotRows: newRows, pivotColumns: pivotColumns ?? result.pivotColumns, pivotRowCount: newRows.length };
22879
23017
  }
22880
23018
  return { ...result, rows: newRows, rowCount: newRows.length };
22881
23019
  } else {
@@ -22961,7 +23099,12 @@ var CacheCab = class {
22961
23099
  await this.persistMetaToStorage();
22962
23100
  const newRows = await this.applyPivotsAndFilters(merged, dashboardFilters, customFilters, pivot, tenantPart, false);
22963
23101
  if (pivot) {
22964
- return { ...merged, pivotRows: newRows, pivotRowCount: newRows.length };
23102
+ const pivotColumns = generatePivotColumnsInMemory({
23103
+ pivot,
23104
+ pivotRows: newRows,
23105
+ sourceColumns: merged.columnInternal ?? merged.columns
23106
+ });
23107
+ return { ...merged, pivotRows: newRows, pivotColumns: pivotColumns ?? merged.pivotColumns, pivotRowCount: newRows.length };
22965
23108
  }
22966
23109
  return { ...merged, rows: newRows, rowCount: newRows.length };
22967
23110
  }
@@ -22989,7 +23132,12 @@ var CacheCab = class {
22989
23132
  const tenantPart = tenants ? JSON.stringify(tenants) : "";
22990
23133
  const newRows = await this.applyPivotsAndFilters(parsed, dashboardFilters, customFilters, pivot, tenantPart);
22991
23134
  if (pivot) {
22992
- return { ...parsed, pivotRows: newRows, pivotRowCount: newRows.length };
23135
+ const pivotColumns = generatePivotColumnsInMemory({
23136
+ pivot,
23137
+ pivotRows: newRows,
23138
+ sourceColumns: parsed.columnInternal ?? parsed.columns
23139
+ });
23140
+ return { ...parsed, pivotRows: newRows, pivotColumns: pivotColumns ?? parsed.pivotColumns, pivotRowCount: newRows.length };
22993
23141
  }
22994
23142
  return { ...parsed, rows: newRows, rowCount: newRows.length };
22995
23143
  } catch (err) {
@@ -26359,6 +26507,29 @@ var useDashboard = (dashboardName, config) => {
26359
26507
  };
26360
26508
  const usePivotTask = !cacheEnabled && !!reportInfo.pivot;
26361
26509
  const allFilters = dashboardFilters2.concat(customFilters).concat(customReportFiltersArray);
26510
+ const applyInMemoryPivotIfNeeded = (report2) => {
26511
+ const pivotToApply = reportInfo.pivot ?? report2.pivot;
26512
+ if (!pivotToApply || usePivotTask) {
26513
+ return report2;
26514
+ }
26515
+ const pivotRows = applyPivotInMemory(
26516
+ report2.rows ?? [],
26517
+ pivotToApply,
26518
+ allFilters
26519
+ );
26520
+ const pivotColumns = generatePivotColumnsInMemory({
26521
+ pivot: pivotToApply,
26522
+ pivotRows,
26523
+ sourceColumns: report2.columnInternal ?? report2.columns
26524
+ });
26525
+ return {
26526
+ ...report2,
26527
+ pivot: pivotToApply,
26528
+ pivotRows,
26529
+ pivotColumns: pivotColumns ?? report2.pivotColumns,
26530
+ pivotRowCount: pivotRows.length
26531
+ };
26532
+ };
26362
26533
  if (cacheEnabled && cacheCab.isCacheable(reportId)) {
26363
26534
  const report2 = await cacheCab.get(reportId, dashboardFilters2, customFilters.concat(customReportFiltersArray), reportInfo.pivot, client, tenants, flags, pageSize, getToken, eventTracking, forceCacheToRefresh);
26364
26535
  if (reportRequestIds.current[reportId] !== requestId) {
@@ -26416,11 +26587,12 @@ var useDashboard = (dashboardName, config) => {
26416
26587
  if (reportRequestIds.current[reportId] !== requestId) {
26417
26588
  return null;
26418
26589
  }
26590
+ const uncacheableReportWithPivot = applyInMemoryPivotIfNeeded(uncacheableReport);
26419
26591
  reportsDispatch({
26420
26592
  type: "UPDATE_REPORT",
26421
26593
  id: reportId,
26422
26594
  data: {
26423
- ...uncacheableReport,
26595
+ ...uncacheableReportWithPivot,
26424
26596
  pagination,
26425
26597
  triggerReload: false
26426
26598
  }
@@ -26471,7 +26643,7 @@ var useDashboard = (dashboardName, config) => {
26471
26643
  console.error("Failed to fetch background rows", e);
26472
26644
  });
26473
26645
  }
26474
- return uncacheableReport;
26646
+ return uncacheableReportWithPivot;
26475
26647
  } catch (error2) {
26476
26648
  console.error(error2);
26477
26649
  return null;
@@ -33345,24 +33517,24 @@ function DayPicker({
33345
33517
  if (localStartDate && !localEndDate) {
33346
33518
  setLocalEndDate(date);
33347
33519
  updateDateFilter({
33348
- startDate: localStartDate,
33349
- endDate: date
33520
+ startDate: (0, import_date_fns13.startOfDay)(localStartDate),
33521
+ endDate: (0, import_date_fns13.endOfDay)(date)
33350
33522
  });
33351
33523
  setLocalPreset("");
33352
33524
  }
33353
33525
  if (localStartDate && localEndDate && (0, import_date_fns13.isAfter)(date, localStartDate)) {
33354
33526
  setLocalEndDate(date);
33355
33527
  updateDateFilter({
33356
- startDate: localStartDate,
33357
- endDate: date
33528
+ startDate: (0, import_date_fns13.startOfDay)(localStartDate),
33529
+ endDate: (0, import_date_fns13.endOfDay)(date)
33358
33530
  });
33359
33531
  setLocalPreset("");
33360
33532
  }
33361
33533
  if (localStartDate && localEndDate && (0, import_date_fns13.isBefore)(date, localStartDate)) {
33362
33534
  setLocalStartDate(date);
33363
33535
  updateDateFilter({
33364
- startDate: date,
33365
- endDate: localEndDate
33536
+ startDate: (0, import_date_fns13.startOfDay)(date),
33537
+ endDate: (0, import_date_fns13.endOfDay)(localEndDate)
33366
33538
  });
33367
33539
  setLocalPreset("");
33368
33540
  }
@@ -35869,12 +36041,41 @@ var useReportInternal = (reportId) => {
35869
36041
  var import_fast_deep_equal3 = __toESM(require("fast-deep-equal"), 1);
35870
36042
 
35871
36043
  // src/components/Chart/MapChart.tsx
35872
- var import_react_simple_maps = require("react-simple-maps");
35873
- var import_react27 = require("react");
36044
+ var import_react27 = __toESM(require("react"), 1);
35874
36045
  init_valueFormatter();
36046
+ var import_states_10m = __toESM(require("us-atlas/states-10m.json"), 1);
36047
+ var import_countries_50m = __toESM(require("world-atlas/countries-50m.json"), 1);
35875
36048
  var import_jsx_runtime46 = require("react/jsx-runtime");
35876
- var statesUrl = "https://cdn.jsdelivr.net/npm/us-atlas@3/states-10m.json";
35877
- var countriesUrl = "https://cdn.jsdelivr.net/npm/world-atlas@2/countries-50m.json";
36049
+ var statesGeography = import_states_10m.default;
36050
+ var countriesGeography = import_countries_50m.default;
36051
+ var getSimpleMapsImport = () => {
36052
+ const majorVersion = Number.parseInt(import_react27.default.version.split(".")[0] ?? "18", 10);
36053
+ if (majorVersion >= 19) {
36054
+ const react19Maps = "@vnedyalk0v/react19-simple-maps";
36055
+ return import(
36056
+ /* @vite-ignore */
36057
+ react19Maps
36058
+ ).catch(() => {
36059
+ return import("react-simple-maps");
36060
+ });
36061
+ }
36062
+ return import("react-simple-maps");
36063
+ };
36064
+ var useSimpleMapsModule = () => {
36065
+ const [simpleMapsModule, setSimpleMapsModule] = (0, import_react27.useState)();
36066
+ (0, import_react27.useEffect)(() => {
36067
+ let mounted = true;
36068
+ getSimpleMapsImport().then((module2) => {
36069
+ if (mounted) {
36070
+ setSimpleMapsModule(module2);
36071
+ }
36072
+ });
36073
+ return () => {
36074
+ mounted = false;
36075
+ };
36076
+ }, []);
36077
+ return simpleMapsModule;
36078
+ };
35878
36079
  var fipsToNames = {
35879
36080
  "01": { name: "Alabama", abbreviation: "AL" },
35880
36081
  "02": { name: "Alaska", abbreviation: "AK" },
@@ -36197,6 +36398,7 @@ function USMap({
36197
36398
  className,
36198
36399
  containerStyle
36199
36400
  }) {
36401
+ const simpleMaps = useSimpleMapsModule();
36200
36402
  const containerRef = (0, import_react27.useRef)(null);
36201
36403
  const [hoveredState, setHoveredState] = (0, import_react27.useState)(
36202
36404
  void 0
@@ -36265,6 +36467,9 @@ function USMap({
36265
36467
  }
36266
36468
  );
36267
36469
  }
36470
+ if (!simpleMaps) {
36471
+ return null;
36472
+ }
36268
36473
  return /* @__PURE__ */ (0, import_jsx_runtime46.jsxs)(
36269
36474
  "div",
36270
36475
  {
@@ -36279,9 +36484,10 @@ function USMap({
36279
36484
  position: "relative"
36280
36485
  },
36281
36486
  children: [
36282
- /* @__PURE__ */ (0, import_jsx_runtime46.jsx)(import_react_simple_maps.ComposableMap, { projection: "geoAlbersUsa", children: /* @__PURE__ */ (0, import_jsx_runtime46.jsx)(
36487
+ /* @__PURE__ */ (0, import_jsx_runtime46.jsx)(simpleMaps.ComposableMap, { projection: "geoAlbersUsa", children: /* @__PURE__ */ (0, import_jsx_runtime46.jsx)(
36283
36488
  MapLayout,
36284
36489
  {
36490
+ simpleMaps,
36285
36491
  hoveredRegion: hoveredState,
36286
36492
  setHoveredRegion: setHoveredState,
36287
36493
  setHoveredCoords,
@@ -36291,7 +36497,7 @@ function USMap({
36291
36497
  colorScale,
36292
36498
  onClickChartElement,
36293
36499
  regionNames: fipsToNames,
36294
- geographyUrl: statesUrl
36500
+ geographyUrl: statesGeography
36295
36501
  }
36296
36502
  ) }),
36297
36503
  hoveredCoords && hoveredState && /* @__PURE__ */ (0, import_jsx_runtime46.jsx)(
@@ -36388,6 +36594,7 @@ function WorldMap({
36388
36594
  className,
36389
36595
  containerStyle
36390
36596
  }) {
36597
+ const simpleMaps = useSimpleMapsModule();
36391
36598
  const containerRef = (0, import_react27.useRef)(null);
36392
36599
  const [hoveredCountry, setHoveredCountry] = (0, import_react27.useState)(
36393
36600
  void 0
@@ -36456,6 +36663,9 @@ function WorldMap({
36456
36663
  }
36457
36664
  );
36458
36665
  }
36666
+ if (!simpleMaps) {
36667
+ return null;
36668
+ }
36459
36669
  return /* @__PURE__ */ (0, import_jsx_runtime46.jsxs)(
36460
36670
  "div",
36461
36671
  {
@@ -36471,9 +36681,10 @@ function WorldMap({
36471
36681
  position: "relative"
36472
36682
  },
36473
36683
  children: [
36474
- /* @__PURE__ */ (0, import_jsx_runtime46.jsx)(import_react_simple_maps.ComposableMap, { projection: "geoEqualEarth", children: /* @__PURE__ */ (0, import_jsx_runtime46.jsx)(
36684
+ /* @__PURE__ */ (0, import_jsx_runtime46.jsx)(simpleMaps.ComposableMap, { projection: "geoEqualEarth", children: /* @__PURE__ */ (0, import_jsx_runtime46.jsx)(
36475
36685
  MapLayout,
36476
36686
  {
36687
+ simpleMaps,
36477
36688
  hoveredRegion: hoveredCountry,
36478
36689
  setHoveredRegion: setHoveredCountry,
36479
36690
  setHoveredCoords,
@@ -36482,7 +36693,7 @@ function WorldMap({
36482
36693
  measureField,
36483
36694
  colorScale,
36484
36695
  onClickChartElement,
36485
- geographyUrl: countriesUrl,
36696
+ geographyUrl: countriesGeography,
36486
36697
  regionNames: isoToNames
36487
36698
  }
36488
36699
  ) }),
@@ -36569,6 +36780,7 @@ function WorldMap({
36569
36780
  );
36570
36781
  }
36571
36782
  function MapLayout({
36783
+ simpleMaps,
36572
36784
  geographyUrl,
36573
36785
  hoveredRegion,
36574
36786
  setHoveredRegion,
@@ -36580,19 +36792,19 @@ function MapLayout({
36580
36792
  onClickChartElement,
36581
36793
  regionNames
36582
36794
  }) {
36583
- const { projection } = (0, import_react_simple_maps.useMapContext)();
36795
+ const { projection } = simpleMaps.useMapContext();
36584
36796
  const [geoCentroid, setGeoCentroid] = (0, import_react27.useState)(null);
36585
36797
  (0, import_react27.useEffect)(() => {
36586
36798
  import("d3-geo").then((geo) => {
36587
36799
  setGeoCentroid(() => geo.geoCentroid);
36588
36800
  });
36589
36801
  }, []);
36590
- return /* @__PURE__ */ (0, import_jsx_runtime46.jsx)(import_react_simple_maps.Geographies, { geography: geographyUrl, children: ({ geographies }) => geographies.map((geo, index) => {
36802
+ return /* @__PURE__ */ (0, import_jsx_runtime46.jsx)(simpleMaps.Geographies, { geography: geographyUrl, children: ({ geographies }) => geographies.map((geo, index) => {
36591
36803
  const regionData = mappedData[geo.id] ?? mappedData[regionNames[geo.id]?.abbreviation ?? ""] ?? mappedData[regionNames[geo.id]?.name ?? ""] ?? mappedData[regionNames[geo.id]?.abbreviation?.toLowerCase() ?? ""] ?? mappedData[regionNames[geo.id]?.name?.toLowerCase() ?? ""];
36592
36804
  const value = regionData ? parseFloat(regionData[measureField]) : null;
36593
36805
  const fill = value != null ? colorScale(value) : "#D6D6DA";
36594
36806
  return /* @__PURE__ */ (0, import_jsx_runtime46.jsx)(
36595
- import_react_simple_maps.Geography,
36807
+ simpleMaps.Geography,
36596
36808
  {
36597
36809
  geography: geo,
36598
36810
  fill,
@@ -38684,13 +38896,28 @@ function Chart({
38684
38896
  return /* @__PURE__ */ (0, import_jsx_runtime49.jsx)("div", { style: containerStyle, className, children: /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(ChartError, { errorMessage: report?.error ?? error }) });
38685
38897
  }
38686
38898
  if (isMissingDateField) {
38687
- return /* @__PURE__ */ (0, import_jsx_runtime49.jsx)("div", { style: containerStyle, className, children: /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(ChartError, { errorMessage: `The query for this report is missing dashboard date filter field ${report?.dateField?.field}, which is necessary for date filtering on this dashboard when the cache is enabled.` }) });
38899
+ return /* @__PURE__ */ (0, import_jsx_runtime49.jsx)("div", { style: containerStyle, className, children: /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
38900
+ ChartError,
38901
+ {
38902
+ errorMessage: `The query for this report is missing dashboard date filter field ${report?.dateField?.field}, which is necessary for date filtering on this dashboard when the cache is enabled.`
38903
+ }
38904
+ ) });
38688
38905
  }
38689
38906
  if (usesLimitInQuery) {
38690
- return /* @__PURE__ */ (0, import_jsx_runtime49.jsx)("div", { style: containerStyle, className, children: /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(ChartError, { errorMessage: `The query for this report uses the LIMIT keyword, which is not supported when the cache is enabled.` }) });
38907
+ return /* @__PURE__ */ (0, import_jsx_runtime49.jsx)("div", { style: containerStyle, className, children: /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
38908
+ ChartError,
38909
+ {
38910
+ errorMessage: `The query for this report uses the LIMIT keyword, which is not supported when the cache is enabled.`
38911
+ }
38912
+ ) });
38691
38913
  }
38692
38914
  if (missingDashboardFilterFields.length) {
38693
- return /* @__PURE__ */ (0, import_jsx_runtime49.jsx)("div", { style: containerStyle, className, children: /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(ChartError, { errorMessage: `The query for this report is missing dashboard filter fields: ${missingDashboardFilterFields.join(", ")}` }) });
38915
+ return /* @__PURE__ */ (0, import_jsx_runtime49.jsx)("div", { style: containerStyle, className, children: /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
38916
+ ChartError,
38917
+ {
38918
+ errorMessage: `The query for this report is missing dashboard filter fields: ${missingDashboardFilterFields.join(", ")}`
38919
+ }
38920
+ ) });
38694
38921
  }
38695
38922
  return /* @__PURE__ */ (0, import_jsx_runtime49.jsxs)(
38696
38923
  "div",
@@ -41238,9 +41465,12 @@ function Dashboard({
41238
41465
  setFilterListAddFilterPopoverIsOpen
41239
41466
  ] = (0, import_react38.useState)(false);
41240
41467
  const presetOptions = (0, import_react38.useMemo)(() => {
41241
- return populatedDashboardFilters?.[0]?.filterType === "date_range" ? convertPresetOptionsToSelectableList(
41242
- populatedDashboardFilters[0].presetOptions ?? [],
41243
- populatedDashboardFilters[0].defaultPresetRanges ?? []
41468
+ const dashboardDateFilter = populatedDashboardFilters?.find(
41469
+ (filter) => filter.filterType === "date_range"
41470
+ );
41471
+ return dashboardDateFilter ? convertPresetOptionsToSelectableList(
41472
+ dashboardDateFilter.presetOptions ?? [],
41473
+ dashboardDateFilter.defaultPresetRanges ?? []
41244
41474
  ) : defaultOptionsV2;
41245
41475
  }, [populatedDashboardFilters]);
41246
41476
  const [filterValues, setFilterValues] = (0, import_react38.useState)({});
@@ -48679,7 +48909,7 @@ function ChartBuilder({
48679
48909
  )
48680
48910
  }
48681
48911
  ),
48682
- (showTableFormatOptions || isAdmin) && /* @__PURE__ */ (0, import_jsx_runtime66.jsxs)(
48912
+ (showTableFormatOptions || isAdmin || formData.chartType === "table" && !hideTableView) && /* @__PURE__ */ (0, import_jsx_runtime66.jsxs)(
48683
48913
  "div",
48684
48914
  {
48685
48915
  style: {
@@ -56520,10 +56750,29 @@ function StaticChart(props) {
56520
56750
  ...report,
56521
56751
  ...report.pivot ? formattedPivotRowsAndColumns(report) : {}
56522
56752
  } : void 0;
56753
+ const patchedConfig = config && config.pivot ? {
56754
+ ...config,
56755
+ yAxisFields: config.columns?.slice(1).map((col) => ({
56756
+ field: col.field,
56757
+ label: col.label ?? col.field,
56758
+ format: col.format ?? "number"
56759
+ })) ?? config.yAxisFields
56760
+ } : config;
56761
+ if (patchedConfig) {
56762
+ const sample = (patchedConfig.pivotRows ?? patchedConfig.rows ?? []).slice(0, 1).map((row) => {
56763
+ const field = patchedConfig.yAxisFields?.[0]?.field;
56764
+ return {
56765
+ ...row,
56766
+ _firstField: field,
56767
+ _firstFieldType: field ? typeof row[field] : void 0
56768
+ };
56769
+ });
56770
+ }
56523
56771
  return /* @__PURE__ */ (0, import_jsx_runtime84.jsx)(
56524
56772
  ChartDisplay,
56525
56773
  {
56526
- config,
56774
+ reportId,
56775
+ config: patchedConfig,
56527
56776
  onClickChartElement,
56528
56777
  loading,
56529
56778
  className,