@quillsql/react 2.16.78 → 2.16.80

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
@@ -15028,46 +15028,12 @@ function parseQueryDateRangeByDatabaseType(minRange, maxRange, databaseType) {
15028
15028
  }
15029
15029
  }
15030
15030
  function getDateFormatFromBucket(dateBucket) {
15031
- let format9 = "MMM_yyyy";
15032
- switch (dateBucket) {
15033
- case "day":
15034
- format9 = "MMM_dd";
15035
- break;
15036
- case "week":
15037
- format9 = "MMM_dd-MMM_dd";
15038
- break;
15039
- case "month":
15040
- format9 = "MMM_yyyy";
15041
- break;
15042
- case "year":
15043
- format9 = "yyyy";
15044
- break;
15045
- default:
15046
- format9 = "MMM_yyyy";
15047
- break;
15048
- }
15049
- return format9;
15031
+ return DATE_BUCKET_AXIS_FORMATS[dateBucket] ?? "MMM_yyyy";
15050
15032
  }
15051
15033
  function getDateString(value, dateRange, dateBucket, databaseType) {
15052
15034
  let format9;
15053
15035
  if (dateBucket) {
15054
- switch (dateBucket) {
15055
- case "day":
15056
- format9 = "MMM_dd";
15057
- break;
15058
- case "week":
15059
- format9 = "MMM_dd-MMM_dd";
15060
- break;
15061
- case "month":
15062
- format9 = "MMM_yyyy";
15063
- break;
15064
- case "year":
15065
- format9 = "yyyy";
15066
- break;
15067
- default:
15068
- format9 = "MMM_yyyy";
15069
- break;
15070
- }
15036
+ format9 = getDateFormatFromBucket(dateBucket);
15071
15037
  } else {
15072
15038
  if (!dateRange) {
15073
15039
  format9 = "MMM_yyyy";
@@ -15156,7 +15122,7 @@ function getExclusiveDateBucketRange(startInput, bucket) {
15156
15122
  endExclusive: endExclusive.toISOString()
15157
15123
  };
15158
15124
  }
15159
- var import_date_fns5;
15125
+ var import_date_fns5, DATE_BUCKET_AXIS_FORMATS;
15160
15126
  var init_dates = __esm({
15161
15127
  "src/utils/dates.ts"() {
15162
15128
  "use strict";
@@ -15164,6 +15130,12 @@ var init_dates = __esm({
15164
15130
  init_dateRangePickerUtils();
15165
15131
  init_inMemoryPivotEngine();
15166
15132
  init_valueFormatter();
15133
+ DATE_BUCKET_AXIS_FORMATS = {
15134
+ day: "MMM_dd_yyyy",
15135
+ week: "MMM_dd-MMM_dd",
15136
+ month: "MMM_yyyy",
15137
+ year: "yyyy"
15138
+ };
15167
15139
  }
15168
15140
  });
15169
15141
 
@@ -21357,6 +21329,22 @@ init_dates();
21357
21329
  init_pivotConstructor();
21358
21330
  init_columnProcessing();
21359
21331
  init_paginationProcessing();
21332
+
21333
+ // src/utils/dashboardProfiler.ts
21334
+ function profileDashboard(event, data) {
21335
+ if (typeof window === "undefined") return;
21336
+ const profileWindow = window;
21337
+ if (!profileWindow.__QUILL_DASHBOARD_PROFILE__) return;
21338
+ const entry = {
21339
+ at: Math.round(performance.now() * 10) / 10,
21340
+ event,
21341
+ data
21342
+ };
21343
+ profileWindow.__QUILL_DASHBOARD_TRACE__ ??= [];
21344
+ profileWindow.__QUILL_DASHBOARD_TRACE__.push(entry);
21345
+ }
21346
+
21347
+ // src/utils/dashboard.ts
21360
21348
  var defaultDashboardItem = {
21361
21349
  id: "",
21362
21350
  name: "",
@@ -21442,6 +21430,15 @@ async function cleanDashboardItem({
21442
21430
  const pivotChartProcessing = {
21443
21431
  page: DEFAULT_PAGINATION
21444
21432
  };
21433
+ profileDashboard("clean-dashboard-pivot-path", {
21434
+ reportId: item._id ?? item.id ?? null,
21435
+ chartType: item.chartType,
21436
+ skipPivotFetch: !!skipPivotFetch,
21437
+ hasRows: !!item.rows,
21438
+ rowCount: item.rows?.length ?? 0,
21439
+ hasFields: !!item.fields,
21440
+ path: item.pivot && skipPivotFetch && item.rows && item.fields ? "process-locally" : "get-pivot-table"
21441
+ });
21445
21442
  if (item.pivot && skipPivotFetch && item.rows && item.fields) {
21446
21443
  const pivotSourceRows = item.rows.map((row) => ({ ...row }));
21447
21444
  const dateFilter = dashboardFilters?.find(
@@ -21549,6 +21546,7 @@ async function cleanDashboardItem({
21549
21546
  pivotColumns: pivotTable ? pivotTable.columns : void 0,
21550
21547
  compareRows: item.compareRows,
21551
21548
  showLegend: item.showLegend ?? false,
21549
+ chartSort: item.chartSort,
21552
21550
  columns: processedColumns.map((column) => {
21553
21551
  return {
21554
21552
  field: column.field,
@@ -21749,6 +21747,32 @@ init_filterProcessing();
21749
21747
 
21750
21748
  // src/utils/chartBuilder.ts
21751
21749
  init_textProcessing();
21750
+ var MAX_CHART_ROWS = 500;
21751
+ var MAX_CHART_MARKS = 5e3;
21752
+ var UNLIMITED_CHART_TYPES = /* @__PURE__ */ new Set([
21753
+ "metric",
21754
+ "table",
21755
+ "gauge",
21756
+ "us map",
21757
+ "world map"
21758
+ ]);
21759
+ function getChartRenderLimitError(report) {
21760
+ if (!report) return void 0;
21761
+ if (UNLIMITED_CHART_TYPES.has(report.chartType?.toLowerCase() ?? "")) {
21762
+ return void 0;
21763
+ }
21764
+ const rowCount = report.pivot ? report.pivotRowCount ?? report.pivotRows?.length ?? report.rows?.length : report.rowCount ?? report.rows?.length;
21765
+ if (rowCount !== void 0 && rowCount > MAX_CHART_ROWS) {
21766
+ return `Charts can only display ${MAX_CHART_ROWS} rows. Please modify the query.`;
21767
+ }
21768
+ const renderedRows = report.rows?.length ?? 0;
21769
+ const renderedSeries = Math.max(report.yAxisFields?.length ?? 0, 1);
21770
+ const renderedMarks = renderedRows * renderedSeries;
21771
+ if (renderedMarks > MAX_CHART_MARKS) {
21772
+ return `Charts can only render ${MAX_CHART_MARKS.toLocaleString()} data points. This chart would render ${renderedMarks.toLocaleString()}. Please reduce the number of rows or series.`;
21773
+ }
21774
+ return void 0;
21775
+ }
21752
21776
  function isStackedChartType(chartType) {
21753
21777
  const normalized = chartType?.toLowerCase();
21754
21778
  return normalized === "stacked" || normalized === "stacked bar";
@@ -22351,6 +22375,376 @@ async function fetchPivotTemplateReportForUseForm({
22351
22375
  }
22352
22376
  }
22353
22377
 
22378
+ // src/utils/color.ts
22379
+ var DEFAULT_GRADIENT_COLORS = [
22380
+ "#4E80EE",
22381
+ // vivid indigo
22382
+ "#586FF4",
22383
+ "#6464FA",
22384
+ "#715AFE",
22385
+ "#8450FF",
22386
+ "#9B48FF",
22387
+ "#B33FFF",
22388
+ "#CA37F3",
22389
+ "#DE2FE1",
22390
+ "#F028CB",
22391
+ "#FF20B5"
22392
+ ];
22393
+ function generateArrayFromColor(colors, length) {
22394
+ if (length <= 0) {
22395
+ return [];
22396
+ }
22397
+ if (typeof colors === "string") {
22398
+ const trimmedColor = colors.trim();
22399
+ return monochromaticInterpolation(
22400
+ trimmedColor.length > 0 ? trimmedColor : DEFAULT_GRADIENT_COLORS[0],
22401
+ length
22402
+ );
22403
+ }
22404
+ const normalizedColors = colors.filter((color) => typeof color === "string").map((color) => color.trim()).filter((color) => color.length > 0);
22405
+ const baseColors = normalizedColors.length > 0 ? normalizedColors : DEFAULT_GRADIENT_COLORS;
22406
+ if (baseColors.length === 1) {
22407
+ return monochromaticInterpolation(baseColors[0], length);
22408
+ }
22409
+ if (length <= baseColors.length) {
22410
+ return baseColors.slice(0, length);
22411
+ }
22412
+ const pairs = baseColors.length - 1;
22413
+ if (pairs <= 0) {
22414
+ return [baseColors[0]];
22415
+ }
22416
+ const needed = length - baseColors.length;
22417
+ const baseAmount = Math.floor(needed / pairs);
22418
+ const extras = needed % pairs;
22419
+ let result = [];
22420
+ let i = 0;
22421
+ let j = 1;
22422
+ while (j < baseColors.length) {
22423
+ const additional = i < extras ? 1 : 0;
22424
+ const interpLength = 2 + baseAmount + additional;
22425
+ const interp = interpolateBetween(
22426
+ baseColors[i],
22427
+ baseColors[j],
22428
+ interpLength
22429
+ );
22430
+ const lastIndex = j === baseColors.length - 1 ? void 0 : -1;
22431
+ result = result.concat(interp.slice(0, lastIndex));
22432
+ i++;
22433
+ j++;
22434
+ }
22435
+ return result;
22436
+ }
22437
+ function buildSeriesColorMap(keys, colors) {
22438
+ const uniqueKeys = [
22439
+ ...new Set(keys.map((key) => key.replace("comparison_", "")))
22440
+ ].sort();
22441
+ const palette = generateArrayFromColor(colors, uniqueKeys.length);
22442
+ return Object.fromEntries(
22443
+ uniqueKeys.map((key, index) => [key, palette[index]])
22444
+ );
22445
+ }
22446
+ function hexToRgb(hex) {
22447
+ const r = parseInt(hex.substring(1, 3), 16);
22448
+ const g = parseInt(hex.substring(3, 5), 16);
22449
+ const b = parseInt(hex.substring(5, 7), 16);
22450
+ return { r, g, b };
22451
+ }
22452
+ function rgbToHex(rgb) {
22453
+ const rHex = rgb.r.toString(16).padStart(2, "0");
22454
+ const gHex = rgb.g.toString(16).padStart(2, "0");
22455
+ const bHex = rgb.b.toString(16).padStart(2, "0");
22456
+ return `#${rHex}${gHex}${bHex}`;
22457
+ }
22458
+ function colorToHSL(color) {
22459
+ const colorHex = namedColorToHex(color);
22460
+ const { r, g, b } = hexToRgb(colorHex);
22461
+ return rgbToHsl(r, g, b);
22462
+ }
22463
+ function interpolateBetween(leftColor, rightColor, length = 3) {
22464
+ const [h, s, _l] = colorToHSL(leftColor);
22465
+ const [h2, s2, _l2] = colorToHSL(rightColor);
22466
+ const hues = linspace(h, h2, length);
22467
+ const saturations = linspace(s, s2, length);
22468
+ const lightnesses = linspace(_l, _l2, length);
22469
+ return Array.from({ length }).map((_, i) => {
22470
+ const [r, g, b] = HSLtoRGB(hues[i], saturations[i], lightnesses[i]);
22471
+ return rgbToHex({ r: Math.round(r), g: Math.round(g), b: Math.round(b) });
22472
+ });
22473
+ }
22474
+ function monochromaticInterpolation(color, length) {
22475
+ const [h, s] = colorToHSL(color);
22476
+ const hues = linspace(h, h, length);
22477
+ const saturations = linspace(s, s, length);
22478
+ const lightnesses = linspace(0.6, 0.9, length);
22479
+ return Array.from({ length }).map((_, i) => {
22480
+ const [r, g, b] = HSLtoRGB(hues[i], saturations[i], lightnesses[i]);
22481
+ return rgbToHex({ r: Math.round(r), g: Math.round(g), b: Math.round(b) });
22482
+ });
22483
+ }
22484
+ function linspace(start, end, num) {
22485
+ if (num <= 1) return [start];
22486
+ const step = (end - start) / (num - 1);
22487
+ const result = new Array(num);
22488
+ for (let i = 0; i < num; i++) {
22489
+ result[i] = start + step * i;
22490
+ }
22491
+ return result;
22492
+ }
22493
+ function stableColorIndex(field) {
22494
+ let hash = 0;
22495
+ for (const character of field.replace("comparison_", "")) {
22496
+ hash = Math.imul(hash, 31) + character.charCodeAt(0) >>> 0;
22497
+ }
22498
+ return hash;
22499
+ }
22500
+ function selectColor(element, colors, index) {
22501
+ if (!element?.field) return "gray";
22502
+ const isComparison = element.field.includes("comparison_");
22503
+ const color = colors[index % colors.length] ?? "";
22504
+ if (!isComparison) {
22505
+ return color;
22506
+ }
22507
+ if (Object.keys(COLOR_TO_HEX).includes(color)) {
22508
+ const colorHex = COLOR_TO_HEX[color];
22509
+ const rgbArray = hexToRGB(colorHex);
22510
+ return toGrayscale(rgbArray);
22511
+ }
22512
+ if (color?.startsWith("#")) {
22513
+ const rgbArray = hexToRGB(color);
22514
+ return toGrayscale(rgbArray);
22515
+ }
22516
+ return "gray";
22517
+ }
22518
+ function hexToRGB(hex) {
22519
+ const regex = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})?$/i;
22520
+ const result = regex.exec(hex);
22521
+ if (result) {
22522
+ return [
22523
+ parseInt(result[1], 16),
22524
+ // index 0 is whole string, then ()'s
22525
+ parseInt(result[2], 16),
22526
+ parseInt(result[3], 16),
22527
+ ...result[4] ? [parseInt(result[4], 16)] : []
22528
+ // <- alpha channel
22529
+ ];
22530
+ }
22531
+ const rgba = hex.match(/[0-9.]+/g);
22532
+ if (rgba) {
22533
+ return [
22534
+ Number(rgba[0]),
22535
+ Number(rgba[1]),
22536
+ Number(rgba[2]),
22537
+ ...rgba[3] ? [Number(rgba[3])] : []
22538
+ ];
22539
+ }
22540
+ return [128, 128, 128];
22541
+ }
22542
+ function toGrayscale(rgba) {
22543
+ if (rgba.length < 3) return "rbg(128, 128, 128)";
22544
+ let sum = 0;
22545
+ sum += Number(rgba[0] * 0.89);
22546
+ sum += Number(rgba[1] * 1.77);
22547
+ sum += Number(rgba[2] * 0.33);
22548
+ const avg = (sum / 3).toFixed(2);
22549
+ return `rgb(${avg}, ${avg}, ${avg})`;
22550
+ }
22551
+ function namedColorToHex(color) {
22552
+ if (Object.keys(COLOR_TO_HEX).includes(color)) {
22553
+ return COLOR_TO_HEX[color];
22554
+ }
22555
+ return color;
22556
+ }
22557
+ var COLOR_TO_HEX = {
22558
+ aliceblue: "#f0f8ff",
22559
+ antiquewhite: "#faebd7",
22560
+ aqua: "#00ffff",
22561
+ aquamarine: "#7fffd4",
22562
+ azure: "#f0ffff",
22563
+ beige: "#f5f5dc",
22564
+ bisque: "#ffe4c4",
22565
+ black: "#000000",
22566
+ blanchedalmond: "#ffebcd",
22567
+ blue: "#0000ff",
22568
+ blueviolet: "#8a2be2",
22569
+ brown: "#a52a2a",
22570
+ burlywood: "#deb887",
22571
+ cadetblue: "#5f9ea0",
22572
+ chartreuse: "#7fff00",
22573
+ chocolate: "#d2691e",
22574
+ coral: "#ff7f50",
22575
+ cornflowerblue: "#6495ed",
22576
+ cornsilk: "#fff8dc",
22577
+ crimson: "#dc143c",
22578
+ cyan: "#00ffff",
22579
+ darkblue: "#00008b",
22580
+ darkcyan: "#008b8b",
22581
+ darkgoldenrod: "#b8860b",
22582
+ darkgray: "#a9a9a9",
22583
+ darkgreen: "#006400",
22584
+ darkkhaki: "#bdb76b",
22585
+ darkmagenta: "#8b008b",
22586
+ darkolivegreen: "#556b2f",
22587
+ darkorange: "#ff8c00",
22588
+ darkorchid: "#9932cc",
22589
+ darkred: "#8b0000",
22590
+ darksalmon: "#e9967a",
22591
+ darkseagreen: "#8fbc8f",
22592
+ darkslateblue: "#483d8b",
22593
+ darkslategray: "#2f4f4f",
22594
+ darkturquoise: "#00ced1",
22595
+ darkviolet: "#9400d3",
22596
+ deeppink: "#ff1493",
22597
+ deepskyblue: "#00bfff",
22598
+ dimgray: "#696969",
22599
+ dodgerblue: "#1e90ff",
22600
+ firebrick: "#b22222",
22601
+ floralwhite: "#fffaf0",
22602
+ forestgreen: "#228b22",
22603
+ fuchsia: "#ff00ff",
22604
+ gainsboro: "#dcdcdc",
22605
+ ghostwhite: "#f8f8ff",
22606
+ gold: "#ffd700",
22607
+ goldenrod: "#daa520",
22608
+ gray: "#808080",
22609
+ green: "#008000",
22610
+ greenyellow: "#adff2f",
22611
+ honeydew: "#f0fff0",
22612
+ hotpink: "#ff69b4",
22613
+ indianred: "#cd5c5c",
22614
+ indigo: "#4b0082",
22615
+ ivory: "#fffff0",
22616
+ khaki: "#f0e68c",
22617
+ lavender: "#e6e6fa",
22618
+ lavenderblush: "#fff0f5",
22619
+ lawngreen: "#7cfc00",
22620
+ lemonchiffon: "#fffacd",
22621
+ lightblue: "#add8e6",
22622
+ lightcoral: "#f08080",
22623
+ lightcyan: "#e0ffff",
22624
+ lightgoldenrodyellow: "#fafad2",
22625
+ lightgrey: "#d3d3d3",
22626
+ lightgreen: "#90ee90",
22627
+ lightpink: "#ffb6c1",
22628
+ lightsalmon: "#ffa07a",
22629
+ lightseagreen: "#20b2aa",
22630
+ lightskyblue: "#87cefa",
22631
+ lightslategray: "#778899",
22632
+ lightsteelblue: "#b0c4de",
22633
+ lightyellow: "#ffffe0",
22634
+ lime: "#00ff00",
22635
+ limegreen: "#32cd32",
22636
+ linen: "#faf0e6",
22637
+ magenta: "#ff00ff",
22638
+ maroon: "#800000",
22639
+ mediumaquamarine: "#66cdaa",
22640
+ mediumblue: "#0000cd",
22641
+ mediumorchid: "#ba55d3",
22642
+ mediumpurple: "#9370d8",
22643
+ mediumseagreen: "#3cb371",
22644
+ mediumslateblue: "#7b68ee",
22645
+ mediumspringgreen: "#00fa9a",
22646
+ mediumturquoise: "#48d1cc",
22647
+ mediumvioletred: "#c71585",
22648
+ midnightblue: "#191970",
22649
+ mintcream: "#f5fffa",
22650
+ mistyrose: "#ffe4e1",
22651
+ moccasin: "#ffe4b5",
22652
+ navajowhite: "#ffdead",
22653
+ navy: "#000080",
22654
+ oldlace: "#fdf5e6",
22655
+ olive: "#808000",
22656
+ olivedrab: "#6b8e23",
22657
+ orange: "#ffa500",
22658
+ orangered: "#ff4500",
22659
+ orchid: "#da70d6",
22660
+ palegoldenrod: "#eee8aa",
22661
+ palegreen: "#98fb98",
22662
+ paleturquoise: "#afeeee",
22663
+ palevioletred: "#d87093",
22664
+ papayawhip: "#ffefd5",
22665
+ peachpuff: "#ffdab9",
22666
+ peru: "#cd853f",
22667
+ pink: "#ffc0cb",
22668
+ plum: "#dda0dd",
22669
+ powderblue: "#b0e0e6",
22670
+ purple: "#800080",
22671
+ rebeccapurple: "#663399",
22672
+ red: "#ff0000",
22673
+ rosybrown: "#bc8f8f",
22674
+ royalblue: "#4169e1",
22675
+ saddlebrown: "#8b4513",
22676
+ salmon: "#fa8072",
22677
+ sandybrown: "#f4a460",
22678
+ seagreen: "#2e8b57",
22679
+ seashell: "#fff5ee",
22680
+ sienna: "#a0522d",
22681
+ silver: "#c0c0c0",
22682
+ skyblue: "#87ceeb",
22683
+ slateblue: "#6a5acd",
22684
+ slategray: "#708090",
22685
+ snow: "#fffafa",
22686
+ springgreen: "#00ff7f",
22687
+ steelblue: "#4682b4",
22688
+ tan: "#d2b48c",
22689
+ teal: "#008080",
22690
+ thistle: "#d8bfd8",
22691
+ tomato: "#ff6347",
22692
+ turquoise: "#40e0d0",
22693
+ violet: "#ee82ee",
22694
+ wheat: "#f5deb3",
22695
+ white: "#ffffff",
22696
+ whitesmoke: "#f5f5f5",
22697
+ yellow: "#ffff00",
22698
+ yellowgreen: "#9acd32"
22699
+ };
22700
+ function rgbToHsl(r, g, b) {
22701
+ r /= 255, g /= 255, b /= 255;
22702
+ const max2 = Math.max(r, g, b), min2 = Math.min(r, g, b);
22703
+ let h = (max2 + min2) / 2;
22704
+ let s = (max2 + min2) / 2;
22705
+ const l = (max2 + min2) / 2;
22706
+ if (max2 == min2) {
22707
+ h = s = 0;
22708
+ } else {
22709
+ const d = max2 - min2;
22710
+ s = l > 0.5 ? d / (2 - max2 - min2) : d / (max2 + min2);
22711
+ switch (max2) {
22712
+ case r:
22713
+ h = (g - b) / d + (g < b ? 6 : 0);
22714
+ break;
22715
+ case g:
22716
+ h = (b - r) / d + 2;
22717
+ break;
22718
+ case b:
22719
+ h = (r - g) / d + 4;
22720
+ break;
22721
+ }
22722
+ h /= 6;
22723
+ }
22724
+ return [h, s, l];
22725
+ }
22726
+ function HSLtoRGB(h, s, l) {
22727
+ let r, g, b;
22728
+ if (s == 0) {
22729
+ r = g = b = l;
22730
+ } else {
22731
+ const hue2rgb = (p2, q2, t) => {
22732
+ if (t < 0) t += 1;
22733
+ if (t > 1) t -= 1;
22734
+ if (t < 1 / 6) return p2 + (q2 - p2) * 6 * t;
22735
+ if (t < 1 / 2) return q2;
22736
+ if (t < 2 / 3) return p2 + (q2 - p2) * (2 / 3 - t) * 6;
22737
+ return p2;
22738
+ };
22739
+ const q = l < 0.5 ? l * (1 + s) : l + s - l * s;
22740
+ const p = 2 * l - q;
22741
+ r = hue2rgb(p, q, h + 1 / 3);
22742
+ g = hue2rgb(p, q, h);
22743
+ b = hue2rgb(p, q, h - 1 / 3);
22744
+ }
22745
+ return [r * 255, g * 255, b * 255];
22746
+ }
22747
+
22354
22748
  // src/utils/report.ts
22355
22749
  init_columnProcessing();
22356
22750
  init_dataFetcher();
@@ -22364,90 +22758,514 @@ init_valueFormatter();
22364
22758
  init_astFilterProcessing();
22365
22759
  init_reportBuilder();
22366
22760
  init_astProcessing();
22367
- function extractAllReportValuesFromQuillInternalReport(reportInternal) {
22368
- return {
22369
- id: reportInternal.id,
22370
- name: reportInternal.name,
22371
- dashboardName: reportInternal.dashboardName,
22372
- // section: reportInternal.section,
22373
- pagination: reportInternal.pagination,
22374
- sort: reportInternal.sort,
22375
- rows: reportInternal.rows,
22376
- columns: reportInternal.columns,
22377
- chartType: reportInternal.chartType,
22378
- dateField: reportInternal.dateField,
22379
- pivot: reportInternal.pivot,
22380
- xAxisLabel: reportInternal.xAxisLabel,
22381
- xAxisField: reportInternal.xAxisField,
22382
- xAxisFormat: reportInternal.xAxisFormat,
22383
- yAxisFields: reportInternal.yAxisFields,
22384
- order: reportInternal.order,
22385
- compareRows: reportInternal.compareRows,
22386
- filtersApplied: reportInternal.filtersApplied,
22387
- queryString: reportInternal.queryString,
22388
- rowCount: reportInternal.rowCount,
22389
- template: reportInternal.template,
22390
- referenceLineYValues: reportInternal.referenceLineYValues,
22391
- referenceLines: reportInternal.referenceLines,
22392
- includeCustomFields: reportInternal.includeCustomFields,
22393
- columnsWithCustomFields: reportInternal.columnsWithCustomFields,
22394
- pivotRows: reportInternal.pivotRows,
22395
- pivotColumns: reportInternal.pivotColumns,
22396
- pivotRowCount: reportInternal.pivotRowCount,
22397
- filterMap: reportInternal.filterMap,
22398
- showLegend: reportInternal.showLegend
22399
- };
22761
+
22762
+ // src/utils/chartSort.ts
22763
+ init_columnProcessing();
22764
+
22765
+ // src/utils/pivotAggregations.ts
22766
+ function getPivotAggregations(report) {
22767
+ const pivot = report.pivot;
22768
+ if (!pivot) return [];
22769
+ if ("aggregations" in pivot && Array.isArray(pivot.aggregations)) {
22770
+ return pivot.aggregations;
22771
+ }
22772
+ if ("aggregationType" in pivot && pivot.aggregationType) {
22773
+ return [
22774
+ {
22775
+ aggregationType: pivot.aggregationType,
22776
+ valueField: pivot.valueField,
22777
+ valueField2: pivot.valueField2,
22778
+ valueField2Type: pivot.valueField2Type,
22779
+ valueFieldType: pivot.valueFieldType
22780
+ }
22781
+ ];
22782
+ }
22783
+ return [];
22400
22784
  }
22401
- async function fetchReportRows({
22402
- reportId,
22403
- client,
22404
- tenants,
22405
- filters = [],
22406
- getToken,
22407
- abortSignal,
22408
- additionalProcessing,
22409
- overwriteCache = false
22410
- }) {
22411
- const fetchResp = await quillFetch({
22412
- client,
22413
- task: "report",
22414
- metadata: {
22415
- reportId,
22416
- clientId: client.id,
22417
- databaseType: client.databaseType,
22418
- filters: filters.map((filter) => ({ ...filter, options: void 0 })),
22419
- useNewNodeSql: true,
22420
- tenants,
22421
- additionalProcessing,
22422
- overwriteCache
22423
- },
22424
- abortSignal,
22425
- getToken
22426
- });
22427
- const resp = await parseFetchResponse(client, "report", fetchResp, getToken);
22428
- if (client.databaseType?.toLowerCase() === "bigquery") {
22429
- parseValueFromBigQueryDates(resp.rows, resp.fields);
22785
+ function getAggregationFieldKey(aggregation, hasMultipleAggregations) {
22786
+ if (!aggregation.aggregationType) return null;
22787
+ if (!aggregation.valueField && aggregation.aggregationType === "percentage") {
22788
+ return "percentage";
22430
22789
  }
22431
- return {
22432
- rows: resp.rows || [],
22433
- rowCount: resp.rowCount || 0,
22434
- columns: resp.columns || [],
22435
- fields: resp.fields || []
22436
- };
22790
+ if (aggregation.valueField) {
22791
+ return hasMultipleAggregations ? `${aggregation.valueField}_${aggregation.aggregationType}` : aggregation.valueField;
22792
+ }
22793
+ return hasMultipleAggregations ? `${aggregation.aggregationType}_${aggregation.aggregationType}` : aggregation.aggregationType;
22437
22794
  }
22438
- async function fetchReport({
22439
- reportId,
22440
- client,
22441
- tenants,
22442
- flags,
22443
- useReportTask = true,
22444
- filters = [],
22445
- additionalProcessing,
22446
- dateBucket,
22447
- customFields,
22448
- rowsOnly,
22449
- rowCountOnly,
22450
- abortSignal,
22795
+ function getAggregationIdentityKey(aggregation) {
22796
+ if (!aggregation) return "";
22797
+ const aggregationType = String(aggregation.aggregationType ?? "").trim().toLowerCase();
22798
+ const valueField = String(aggregation.valueField ?? "").trim().toLowerCase();
22799
+ return `${aggregationType}::${valueField}`;
22800
+ }
22801
+ function trimFieldSuffix(value, suffix) {
22802
+ const normalizedSuffix = String(suffix ?? "").trim();
22803
+ if (!normalizedSuffix) return value;
22804
+ for (const separator of ["_", ":"]) {
22805
+ const ending = `${separator}${normalizedSuffix}`;
22806
+ if (value.endsWith(ending)) {
22807
+ return value.slice(0, -ending.length);
22808
+ }
22809
+ }
22810
+ return value;
22811
+ }
22812
+ function getPivotColumnValueForSeries(field, aggregation, hasMultipleAggregations) {
22813
+ let value = String(field ?? "").replace(/^comparison_/, "").trim();
22814
+ if (hasMultipleAggregations) {
22815
+ value = trimFieldSuffix(value, aggregation.aggregationType);
22816
+ }
22817
+ return trimFieldSuffix(value, aggregation.valueField);
22818
+ }
22819
+ function trailingPivotMeasureSegmentBeforeAggType(normalizedField, normalizedAggregationType) {
22820
+ const suffix = `_${normalizedAggregationType}`;
22821
+ if (!normalizedField.endsWith(suffix)) return null;
22822
+ const base = normalizedField.slice(0, -suffix.length);
22823
+ const lastUnderscore = base.lastIndexOf("_");
22824
+ if (lastUnderscore < 0) return null;
22825
+ const candidate = base.slice(lastUnderscore + 1).trim();
22826
+ return candidate || null;
22827
+ }
22828
+ var PIVOT_FIELD_AGG_MATCH_TIER = {
22829
+ looseAggSuffix: 1,
22830
+ rawValueField: 2,
22831
+ pivotWideValueAndAggSuffix: 3,
22832
+ canonicalValueAggOrCount: 4
22833
+ };
22834
+ function matchPivotFieldToAggregationTier(normalizedField, aggregation) {
22835
+ const aggregationType = String(aggregation.aggregationType ?? "").trim();
22836
+ if (!aggregationType) return null;
22837
+ const type = aggregationType.toLowerCase();
22838
+ const valueField = String(aggregation.valueField ?? "").trim().toLowerCase();
22839
+ if (!valueField && normalizedField === type) {
22840
+ return PIVOT_FIELD_AGG_MATCH_TIER.canonicalValueAggOrCount;
22841
+ }
22842
+ if (valueField && normalizedField === valueField) {
22843
+ return PIVOT_FIELD_AGG_MATCH_TIER.rawValueField;
22844
+ }
22845
+ if (valueField && normalizedField === `${valueField}_${type}`) {
22846
+ return PIVOT_FIELD_AGG_MATCH_TIER.canonicalValueAggOrCount;
22847
+ }
22848
+ if (valueField && normalizedField.endsWith(`_${valueField}_${type}`)) {
22849
+ return PIVOT_FIELD_AGG_MATCH_TIER.pivotWideValueAndAggSuffix;
22850
+ }
22851
+ if (normalizedField.endsWith(`_${type}`) || normalizedField.endsWith(`:${type}`)) {
22852
+ const embeddedMeasure = trailingPivotMeasureSegmentBeforeAggType(
22853
+ normalizedField,
22854
+ type
22855
+ );
22856
+ if (embeddedMeasure && valueField && embeddedMeasure !== valueField) {
22857
+ return null;
22858
+ }
22859
+ return PIVOT_FIELD_AGG_MATCH_TIER.looseAggSuffix;
22860
+ }
22861
+ return null;
22862
+ }
22863
+ function findAggregationForFieldStrict(field, aggregations) {
22864
+ const normalizedField = String(field ?? "").trim().toLowerCase();
22865
+ let best;
22866
+ for (let index = 0; index < aggregations.length; index++) {
22867
+ const aggregation = aggregations[index];
22868
+ const tier = matchPivotFieldToAggregationTier(normalizedField, aggregation);
22869
+ if (tier == null) continue;
22870
+ if (!best || tier > best.tier || tier === best.tier && index < best.index) {
22871
+ best = { aggregation, tier, index };
22872
+ }
22873
+ }
22874
+ return best?.aggregation;
22875
+ }
22876
+
22877
+ // src/utils/chartSort.ts
22878
+ var ROW_SORT_CHART_TYPES = /* @__PURE__ */ new Set([
22879
+ "column",
22880
+ "stacked",
22881
+ "stacked bar",
22882
+ "line",
22883
+ "radar",
22884
+ "bar",
22885
+ "pie"
22886
+ ]);
22887
+ var TWO_DIMENSIONAL_SORT_CHART_TYPES = /* @__PURE__ */ new Set([
22888
+ "column",
22889
+ "stacked",
22890
+ "stacked bar",
22891
+ "line",
22892
+ "radar"
22893
+ ]);
22894
+ var directionLabel = (direction) => direction === "DESC" ? "descending" : "ascending";
22895
+ function dimensionOrderLabel(report, field, direction) {
22896
+ const fieldType = String(
22897
+ field === report.pivot?.rowField ? report.pivot.rowFieldType : field === report.pivot?.columnField ? report.pivot.columnFieldType : ""
22898
+ ).toLowerCase();
22899
+ const format9 = field === report.xAxisField ? String(report.xAxisFormat ?? "") : "";
22900
+ const isDate = /date|time/.test(fieldType) || /^(date|yyyy|MMM_|hh_)/.test(format9);
22901
+ const isNumber = /int|number|numeric|decimal|float|double/.test(fieldType) || /^(whole_number|one_decimal_place|two_decimal_places|percent|dollar_)/.test(
22902
+ format9
22903
+ );
22904
+ if (isDate) {
22905
+ return direction === "ASC" ? "oldest to newest" : "newest to oldest";
22906
+ }
22907
+ if (isNumber) {
22908
+ return direction === "ASC" ? "low to high" : "high to low";
22909
+ }
22910
+ return direction === "ASC" ? "A to Z" : "Z to A";
22911
+ }
22912
+ function formatChartSortValue(chartSort) {
22913
+ if (!chartSort?.field) return "";
22914
+ return `${chartSort.target}:${chartSort.field} ${directionLabel(
22915
+ chartSort.direction
22916
+ )}`;
22917
+ }
22918
+ function parseChartSortValue(value) {
22919
+ const trimmed = String(value ?? "").trim();
22920
+ if (!trimmed) return void 0;
22921
+ const match = trimmed.match(/^(rows|series):(.*)\s+(ascending|descending)$/i);
22922
+ if (!match) return void 0;
22923
+ const target = String(match[1]).toLowerCase();
22924
+ const field = String(match[2] ?? "").trim();
22925
+ if (!field) return void 0;
22926
+ return {
22927
+ target,
22928
+ field,
22929
+ direction: String(match[3]).toLowerCase() === "descending" ? "DESC" : "ASC"
22930
+ };
22931
+ }
22932
+ function getSupportedChartSortTargets(report) {
22933
+ const chartType = String(report.chartType ?? "").toLowerCase();
22934
+ const rowField = String(report.pivot?.rowField ?? "").trim();
22935
+ const columnField = String(report.pivot?.columnField ?? "").trim();
22936
+ if (report.pivot && !rowField) return [];
22937
+ if (rowField && columnField) {
22938
+ return TWO_DIMENSIONAL_SORT_CHART_TYPES.has(chartType) ? ["rows", "series"] : [];
22939
+ }
22940
+ return ROW_SORT_CHART_TYPES.has(chartType) ? ["rows"] : [];
22941
+ }
22942
+ function getChartSortOptions(report) {
22943
+ if (!report || getSupportedChartSortTargets(report).length === 0) return [];
22944
+ const rowField = String(
22945
+ report.pivot?.rowField || report.xAxisField || ""
22946
+ ).trim();
22947
+ const columnField = String(report.pivot?.columnField ?? "").trim();
22948
+ const isTwoDimensional = Boolean(rowField && columnField);
22949
+ const aggregations = getPivotAggregations(report);
22950
+ const totals = aggregations.flatMap((aggregation) => {
22951
+ const field = getAggregationFieldKey(aggregation, aggregations.length > 1);
22952
+ return field ? [
22953
+ {
22954
+ field,
22955
+ label: `Total ${getPivotAggregationLabel(report, aggregation)}`
22956
+ }
22957
+ ] : [];
22958
+ });
22959
+ const groups = isTwoDimensional ? [
22960
+ {
22961
+ target: "rows",
22962
+ targetField: rowField,
22963
+ targetLabel: getReportFieldLabel(report, rowField),
22964
+ fields: [
22965
+ { field: rowField, label: getReportFieldLabel(report, rowField) },
22966
+ ...totals
22967
+ ]
22968
+ },
22969
+ {
22970
+ target: "series",
22971
+ targetField: columnField,
22972
+ targetLabel: getReportFieldLabel(report, columnField),
22973
+ fields: [
22974
+ {
22975
+ field: columnField,
22976
+ label: getReportFieldLabel(report, columnField)
22977
+ },
22978
+ ...totals
22979
+ ]
22980
+ }
22981
+ ] : [
22982
+ {
22983
+ target: "rows",
22984
+ targetField: rowField,
22985
+ targetLabel: report.pivot?.rowField ? getReportFieldLabel(report, rowField) : String(report.xAxisLabel || rowField).trim(),
22986
+ fields: [
22987
+ {
22988
+ field: rowField,
22989
+ label: report.pivot?.rowField ? getReportFieldLabel(report, rowField) : String(report.xAxisLabel || rowField).trim()
22990
+ },
22991
+ ...(report.yAxisFields ?? []).filter(({ field }) => !String(field).startsWith("comparison_")).map(({ field, label }) => ({
22992
+ field: String(field ?? "").trim(),
22993
+ label: String(label || field || "").trim()
22994
+ }))
22995
+ ]
22996
+ }
22997
+ ];
22998
+ return groups.flatMap(
22999
+ ({ target, targetField, targetLabel, fields }) => Array.from(
23000
+ new Map(
23001
+ fields.filter(({ field }) => Boolean(field)).map((field) => [field.field, field])
23002
+ ).values()
23003
+ ).flatMap(
23004
+ ({ field, label }) => ["ASC", "DESC"].map((direction) => ({
23005
+ label: field === targetField ? `${targetLabel} \u2014 ${dimensionOrderLabel(
23006
+ report,
23007
+ targetField,
23008
+ direction
23009
+ )}` : `${targetLabel} by ${label || field} \u2014 ${direction === "ASC" ? "low to high" : "high to low"}`,
23010
+ value: formatChartSortValue({ target, field, direction })
23011
+ }))
23012
+ )
23013
+ );
23014
+ }
23015
+ function getReportFieldLabel(report, field) {
23016
+ const pivotFilter = field === report.pivot?.rowField ? report.pivot.rowFilter : field === report.pivot?.columnField ? report.pivot.columnFilter : null;
23017
+ if (pivotFilter?.label) return pivotFilter.label;
23018
+ return report.columns.find(
23019
+ (column) => column.field === field || column.field.endsWith(`.${field}`)
23020
+ )?.label ?? field.split(".").pop().replace(/[_-]+/g, " ").replace(/\b\w/g, (character) => character.toUpperCase());
23021
+ }
23022
+ function getPivotAggregationLabel(report, aggregation) {
23023
+ const aggregationLabel = aggregation.aggregationType ? formatAggregationTypeForDisplay(
23024
+ aggregation.aggregationType
23025
+ ) : "Value";
23026
+ const valueField = String(aggregation.valueField ?? "").trim();
23027
+ if (!valueField) return aggregationLabel;
23028
+ const valueLabel = report.columns.find(({ field }) => field === valueField)?.label || valueField.replace(/[_-]+/g, " ").replace(/\b\w/g, (character) => character.toUpperCase());
23029
+ if (aggregation.aggregationType === "sum") return valueLabel;
23030
+ return `${aggregationLabel} ${valueLabel}`;
23031
+ }
23032
+ function isEmpty(value) {
23033
+ return value === null || value === void 0 || value === "";
23034
+ }
23035
+ function getNumericValue(value) {
23036
+ if (typeof value === "number") {
23037
+ return Number.isFinite(value) ? value : void 0;
23038
+ }
23039
+ const normalized = String(value ?? "").trim().replace(/[$£€¥,%\s,]/g, "");
23040
+ if (!normalized) return void 0;
23041
+ const parsed = Number(normalized);
23042
+ return Number.isFinite(parsed) ? parsed : void 0;
23043
+ }
23044
+ function compareValues2(left, right) {
23045
+ const leftNumber = getNumericValue(left);
23046
+ const rightNumber = getNumericValue(right);
23047
+ if (leftNumber !== void 0 && rightNumber !== void 0) {
23048
+ return leftNumber - rightNumber;
23049
+ }
23050
+ return String(left).localeCompare(String(right), void 0, {
23051
+ numeric: true,
23052
+ sensitivity: "base"
23053
+ });
23054
+ }
23055
+ function getPivotSeries(report) {
23056
+ const aggregations = getPivotAggregations(report);
23057
+ const hasMultipleAggregations = aggregations.length > 1;
23058
+ return report.yAxisFields.map((axis, index) => {
23059
+ const normalizedField = axis.field.replace(/^comparison_/, "");
23060
+ const aggregation = aggregations.length === 1 ? aggregations[0] : findAggregationForFieldStrict(normalizedField, aggregations);
23061
+ return {
23062
+ axis,
23063
+ index,
23064
+ aggregationIdentity: getAggregationIdentityKey(aggregation),
23065
+ columnValue: aggregation ? getPivotColumnValueForSeries(
23066
+ normalizedField,
23067
+ aggregation,
23068
+ hasMultipleAggregations
23069
+ ) : normalizedField
23070
+ };
23071
+ });
23072
+ }
23073
+ function compareText(left, right) {
23074
+ return left.localeCompare(right, void 0, {
23075
+ numeric: true,
23076
+ sensitivity: "base"
23077
+ });
23078
+ }
23079
+ function applyTwoDimensionalPivotSeriesSort(report, chartSort) {
23080
+ const columnField = String(report.pivot?.columnField ?? "").trim();
23081
+ if (!columnField) return report;
23082
+ const multiplier = chartSort.direction === "DESC" ? -1 : 1;
23083
+ const series = getPivotSeries(report);
23084
+ const aggregations = getPivotAggregations(report);
23085
+ let compareColumnValues;
23086
+ if (chartSort.field === columnField) {
23087
+ compareColumnValues = (left, right) => compareText(left, right) * multiplier;
23088
+ } else {
23089
+ const selectedAggregation = aggregations.find(
23090
+ (aggregation) => getAggregationFieldKey(aggregation, aggregations.length > 1) === chartSort.field
23091
+ );
23092
+ if (!selectedAggregation) return report;
23093
+ const selectedIdentity = getAggregationIdentityKey(selectedAggregation);
23094
+ const totals = /* @__PURE__ */ new Map();
23095
+ for (const entry of series) {
23096
+ if (entry.axis.field.startsWith("comparison_") || entry.aggregationIdentity !== selectedIdentity) {
23097
+ continue;
23098
+ }
23099
+ const total = report.rows.reduce(
23100
+ (sum, row) => sum + (getNumericValue(row[entry.axis.field]) ?? 0),
23101
+ 0
23102
+ );
23103
+ totals.set(entry.columnValue, total);
23104
+ }
23105
+ compareColumnValues = (left, right) => {
23106
+ const compared = (totals.get(left) ?? 0) - (totals.get(right) ?? 0);
23107
+ return compared === 0 ? compareText(left, right) : compared * multiplier;
23108
+ };
23109
+ }
23110
+ const yAxisFields = [...series].sort((left, right) => {
23111
+ const compared = compareColumnValues(left.columnValue, right.columnValue);
23112
+ return compared === 0 ? left.index - right.index : compared;
23113
+ }).map(({ axis }) => axis);
23114
+ return {
23115
+ ...report,
23116
+ chartSort,
23117
+ yAxisFields
23118
+ };
23119
+ }
23120
+ function applyChartRowSort(report, chartSort) {
23121
+ const { field, direction } = chartSort;
23122
+ const multiplier = direction === "DESC" ? -1 : 1;
23123
+ const rowField = String(
23124
+ report.pivot?.rowField || report.xAxisField || ""
23125
+ ).trim();
23126
+ const aggregations = getPivotAggregations(report);
23127
+ const selectedAggregation = aggregations.find(
23128
+ (aggregation) => getAggregationFieldKey(aggregation, aggregations.length > 1) === field
23129
+ );
23130
+ const selectedIdentity = getAggregationIdentityKey(selectedAggregation);
23131
+ const totalSeries = selectedAggregation ? getPivotSeries(report).filter(
23132
+ (series) => !series.axis.field.startsWith("comparison_") && series.aggregationIdentity === selectedIdentity
23133
+ ) : [];
23134
+ const getSortValue = (row) => {
23135
+ const rawDate = row.__quillRawDate;
23136
+ if (field === rowField && rawDate !== null && rawDate !== void 0 && rawDate !== "") {
23137
+ return rawDate;
23138
+ }
23139
+ if (selectedAggregation && report.pivot?.columnField) {
23140
+ return totalSeries.reduce(
23141
+ (total, series) => total + (getNumericValue(row[series.axis.field]) ?? 0),
23142
+ 0
23143
+ );
23144
+ }
23145
+ return row[field];
23146
+ };
23147
+ const rows = report.rows.map((row, index) => ({ row, index })).sort((left, right) => {
23148
+ const leftValue = getSortValue(left.row);
23149
+ const rightValue = getSortValue(right.row);
23150
+ if (isEmpty(leftValue) && isEmpty(rightValue)) {
23151
+ return left.index - right.index;
23152
+ }
23153
+ if (isEmpty(leftValue)) return 1;
23154
+ if (isEmpty(rightValue)) return -1;
23155
+ const compared = compareValues2(leftValue, rightValue);
23156
+ return compared === 0 ? left.index - right.index : compared * multiplier;
23157
+ }).map(({ row }) => row);
23158
+ return {
23159
+ ...report,
23160
+ chartSort,
23161
+ rows
23162
+ };
23163
+ }
23164
+ function applyChartSort(report, chartSort = report.chartSort) {
23165
+ if (!chartSort?.field || !Array.isArray(report.rows)) return report;
23166
+ const validOption = getChartSortOptions(report).some(
23167
+ ({ value }) => value === formatChartSortValue(chartSort)
23168
+ );
23169
+ if (!validOption) return report;
23170
+ if (chartSort.target === "series") {
23171
+ return applyTwoDimensionalPivotSeriesSort(report, chartSort);
23172
+ }
23173
+ return applyChartRowSort(report, chartSort);
23174
+ }
23175
+
23176
+ // src/utils/report.ts
23177
+ function extractAllReportValuesFromQuillInternalReport(reportInternal) {
23178
+ return {
23179
+ id: reportInternal.id,
23180
+ name: reportInternal.name,
23181
+ dashboardName: reportInternal.dashboardName,
23182
+ // section: reportInternal.section,
23183
+ pagination: reportInternal.pagination,
23184
+ sort: reportInternal.sort,
23185
+ rows: reportInternal.rows,
23186
+ columns: reportInternal.columns,
23187
+ chartType: reportInternal.chartType,
23188
+ dateField: reportInternal.dateField,
23189
+ pivot: reportInternal.pivot,
23190
+ xAxisLabel: reportInternal.xAxisLabel,
23191
+ xAxisField: reportInternal.xAxisField,
23192
+ xAxisFormat: reportInternal.xAxisFormat,
23193
+ yAxisFields: reportInternal.yAxisFields,
23194
+ order: reportInternal.order,
23195
+ compareRows: reportInternal.compareRows,
23196
+ filtersApplied: reportInternal.filtersApplied,
23197
+ queryString: reportInternal.queryString,
23198
+ rowCount: reportInternal.rowCount,
23199
+ template: reportInternal.template,
23200
+ referenceLineYValues: reportInternal.referenceLineYValues,
23201
+ referenceLines: reportInternal.referenceLines,
23202
+ includeCustomFields: reportInternal.includeCustomFields,
23203
+ columnsWithCustomFields: reportInternal.columnsWithCustomFields,
23204
+ pivotRows: reportInternal.pivotRows,
23205
+ pivotColumns: reportInternal.pivotColumns,
23206
+ pivotRowCount: reportInternal.pivotRowCount,
23207
+ filterMap: reportInternal.filterMap,
23208
+ showLegend: reportInternal.showLegend,
23209
+ chartSort: reportInternal.chartSort
23210
+ };
23211
+ }
23212
+ async function fetchReportRows({
23213
+ reportId,
23214
+ client,
23215
+ tenants,
23216
+ filters = [],
23217
+ getToken,
23218
+ abortSignal,
23219
+ additionalProcessing,
23220
+ overwriteCache = false
23221
+ }) {
23222
+ const startedAt = performance.now();
23223
+ profileDashboard("raw-report-rows-fetch-start", { reportId });
23224
+ const fetchResp = await quillFetch({
23225
+ client,
23226
+ task: "report",
23227
+ metadata: {
23228
+ reportId,
23229
+ clientId: client.id,
23230
+ databaseType: client.databaseType,
23231
+ filters: filters.map((filter) => ({ ...filter, options: void 0 })),
23232
+ useNewNodeSql: true,
23233
+ tenants,
23234
+ additionalProcessing,
23235
+ overwriteCache
23236
+ },
23237
+ abortSignal,
23238
+ getToken
23239
+ });
23240
+ const resp = await parseFetchResponse(client, "report", fetchResp, getToken);
23241
+ profileDashboard("raw-report-rows-fetch-finish", {
23242
+ reportId,
23243
+ elapsedMs: Math.round(performance.now() - startedAt),
23244
+ rowCount: resp.rows?.length ?? 0
23245
+ });
23246
+ if (client.databaseType?.toLowerCase() === "bigquery") {
23247
+ parseValueFromBigQueryDates(resp.rows, resp.fields);
23248
+ }
23249
+ return {
23250
+ rows: resp.rows || [],
23251
+ rowCount: resp.rowCount || 0,
23252
+ columns: resp.columns || [],
23253
+ fields: resp.fields || []
23254
+ };
23255
+ }
23256
+ async function fetchReport({
23257
+ reportId,
23258
+ client,
23259
+ tenants,
23260
+ flags,
23261
+ useReportTask = true,
23262
+ filters = [],
23263
+ additionalProcessing,
23264
+ dateBucket,
23265
+ customFields,
23266
+ rowsOnly,
23267
+ rowCountOnly,
23268
+ abortSignal,
22451
23269
  getToken,
22452
23270
  eventTracking,
22453
23271
  usePivotTask = false,
@@ -22460,8 +23278,16 @@ async function fetchReport({
22460
23278
  }) {
22461
23279
  let reportInfo = void 0;
22462
23280
  let errorMessage = void 0;
23281
+ const startedAt = performance.now();
22463
23282
  try {
22464
23283
  const task = usePivotTask ? "pivot-template" : useReportTask ? "report" : "item";
23284
+ profileDashboard("fetch-report-start", {
23285
+ reportId: reportId ?? null,
23286
+ task,
23287
+ usePivotTask,
23288
+ skipPivotFetch: skipPivotFetch ?? null,
23289
+ shareRequest
23290
+ });
22465
23291
  let pivotForRequest = pivot ?? void 0;
22466
23292
  let reportBuilderStateForRequest = reportBuilderState ?? void 0;
22467
23293
  if (usePivotTask && (pivotForRequest != null || reportBuilderStateForRequest?.pivot != null)) {
@@ -22504,6 +23330,16 @@ async function fetchReport({
22504
23330
  getToken
22505
23331
  });
22506
23332
  const resp = await parseFetchResponse(client, task, fetchResp, getToken);
23333
+ profileDashboard("fetch-report-response", {
23334
+ reportId: reportId ?? null,
23335
+ task,
23336
+ elapsedMs: Math.round(performance.now() - startedAt),
23337
+ hasRows: !!resp?.rows,
23338
+ rowCount: resp?.rows?.length ?? 0,
23339
+ hasFields: !!resp?.fields,
23340
+ hasPivotRows: !!resp?.pivotRows,
23341
+ pivotRowCount: resp?.pivotRows?.length ?? 0
23342
+ });
22507
23343
  reportInfo = await processReportResponse({
22508
23344
  resp,
22509
23345
  client,
@@ -22519,6 +23355,13 @@ async function fetchReport({
22519
23355
  skipPivotFetch: skipPivotFetch ?? !usePivotTask,
22520
23356
  overwriteCache
22521
23357
  });
23358
+ profileDashboard("fetch-report-processed", {
23359
+ reportId: reportId ?? null,
23360
+ task,
23361
+ elapsedMs: Math.round(performance.now() - startedAt),
23362
+ rowCount: reportInfo.rows?.length ?? 0,
23363
+ pivotRowCount: reportInfo.pivotRows?.length ?? 0
23364
+ });
22522
23365
  } catch (error) {
22523
23366
  if (error instanceof Error && error.name === "AbortError") {
22524
23367
  throw error;
@@ -22571,6 +23414,15 @@ async function processReportResponse({
22571
23414
  overwriteCache
22572
23415
  }) {
22573
23416
  const shouldSkipPivotFetch = skipPivotFetch || !!resp?.pivotRows && !!resp?.fields;
23417
+ profileDashboard("process-report-pivot-decision", {
23418
+ reportId: resp?._id ?? resp?.id ?? null,
23419
+ requestedSkipPivotFetch: skipPivotFetch,
23420
+ hasPivot: !!resp?.pivot,
23421
+ hasRows: !!resp?.rows,
23422
+ hasFields: !!resp?.fields,
23423
+ hasPivotRows: !!resp?.pivotRows,
23424
+ shouldSkipPivotFetch
23425
+ });
22574
23426
  const dashboardItem = {
22575
23427
  ...resp,
22576
23428
  filtersApplied: filters?.filter(
@@ -22817,6 +23669,51 @@ function formattedPivotRowsAndColumns(report, dashboardFilters = [], options = {
22817
23669
  rowCount: report.chartType === "table" ? report.pivotRowCount ?? report.rowCount : rows ? rows.length : 0
22818
23670
  };
22819
23671
  }
23672
+ function hasPreformattedDateBucketLabels(report) {
23673
+ const pivot = report.pivot;
23674
+ if (!pivot?.dateBucket) return false;
23675
+ if (report.chartType?.toLowerCase() === "table") return false;
23676
+ return report.xAxisField?.trim() === pivot.rowField?.trim();
23677
+ }
23678
+ function prepareStaticChartReport(report, { removePagination }) {
23679
+ const config = report.pivot ? {
23680
+ ...report,
23681
+ ...formattedPivotRowsAndColumns(report, [], { formatRows: false })
23682
+ } : { ...report };
23683
+ if (removePagination) {
23684
+ config.pagination = void 0;
23685
+ }
23686
+ if (hasPreformattedDateBucketLabels(config)) {
23687
+ config.xAxisFormat = "string";
23688
+ }
23689
+ return applyChartSort(config);
23690
+ }
23691
+ function getReportSeriesFields(report) {
23692
+ const drilldownFields = report?.pivot?.columnFilter?.options.map(({ value }) => value) ?? [];
23693
+ if (drilldownFields.length > 0) {
23694
+ return drilldownFields;
23695
+ }
23696
+ if (report?.pivot?.columnValues?.length) {
23697
+ return report.pivot.columnValues;
23698
+ }
23699
+ return report?.yAxisFields?.map(({ field }) => field) ?? [];
23700
+ }
23701
+ function resolveReportColorMap(report, colors, overrides = {}) {
23702
+ const seriesColors = buildSeriesColorMap(
23703
+ getReportSeriesFields(report),
23704
+ colors
23705
+ );
23706
+ const generated = Object.fromEntries(
23707
+ Object.entries(seriesColors).map(([field, color]) => [
23708
+ field,
23709
+ { primary: color, comparison: color }
23710
+ ])
23711
+ );
23712
+ return {
23713
+ ...generated,
23714
+ ...overrides
23715
+ };
23716
+ }
22820
23717
  function convertInternalReportToReport(report, dashboardFilters, eventTracking, initiator) {
22821
23718
  try {
22822
23719
  if (!report) {
@@ -22840,7 +23737,7 @@ function convertInternalReportToReport(report, dashboardFilters, eventTracking,
22840
23737
  ...pivotFormatted
22841
23738
  };
22842
23739
  pivotReport.formattedBaseRows = formattedBaseRows;
22843
- return pivotReport;
23740
+ return applyChartSort(pivotReport);
22844
23741
  }
22845
23742
  let rows = report.rows;
22846
23743
  if (report.chartType === "metric") {
@@ -22852,11 +23749,11 @@ function convertInternalReportToReport(report, dashboardFilters, eventTracking,
22852
23749
  } else if (report.chartType === "table" && initiator !== "useDashboardReport") {
22853
23750
  rows = formatRowsFromReport(report);
22854
23751
  }
22855
- return {
23752
+ return applyChartSort({
22856
23753
  ...extractAllReportValuesFromQuillInternalReport(formattedReport),
22857
23754
  rows,
22858
23755
  yAxisFields: shouldPreserveYAxisFields ? report.yAxisFields : getYAxisFields(report, dashboardFilters)
22859
- };
23756
+ });
22860
23757
  } catch (error) {
22861
23758
  eventTracking?.logError?.({
22862
23759
  type: "bug",
@@ -25829,8 +26726,14 @@ var reportsReducer = (state = {}, action) => {
25829
26726
  };
25830
26727
  var reportsLoadingStateReducer = (state = {}, action) => {
25831
26728
  switch (action.type) {
25832
- case "SET_REPORT_LOADING":
26729
+ case "SET_REPORT_LOADING": {
26730
+ profileDashboard("report-loading-state", {
26731
+ reportId: action.id,
26732
+ previous: state[action.id] ?? false,
26733
+ next: action.data
26734
+ });
25833
26735
  return { ...state, [action.id]: action.data };
26736
+ }
25834
26737
  default:
25835
26738
  return state;
25836
26739
  }
@@ -25846,6 +26749,11 @@ var ReportsContext = (0, import_react.createContext)({
25846
26749
  var customReportFiltersReducer = (state, action) => {
25847
26750
  switch (action.type) {
25848
26751
  case "ADD_CUSTOM_REPORT_FILTERS":
26752
+ profileDashboard("custom-report-filters-add", {
26753
+ reportId: action.reportId,
26754
+ filterCount: action.data?.length ?? 0,
26755
+ removesEntry: !action.data
26756
+ });
25849
26757
  if (!action.data) {
25850
26758
  const newState = { ...state };
25851
26759
  delete newState[action.reportId];
@@ -26121,7 +27029,14 @@ var ContextProvider = ({
26121
27029
  const mappedTenantsRequests = (0, import_react.useRef)(/* @__PURE__ */ new Set());
26122
27030
  const loadDashboardProcessId = (0, import_react.useRef)({});
26123
27031
  (0, import_react.useEffect)(() => {
27032
+ profileDashboard("custom-report-filters-changed", {
27033
+ reportIds: Object.keys(customReportFilters),
27034
+ currentLoadedFlag: customFiltersLoaded
27035
+ });
26124
27036
  if (Object.keys(customReportFilters).length) {
27037
+ profileDashboard("custom-filters-loaded-set", {
27038
+ next: true
27039
+ });
26125
27040
  setCustomFiltersLoaded(true);
26126
27041
  }
26127
27042
  }, [customReportFilters]);
@@ -27700,6 +28615,7 @@ init_dataFetcher();
27700
28615
  init_tableProcessing();
27701
28616
  init_paginationProcessing();
27702
28617
  init_inMemoryPivotEngine();
28618
+ init_pivotConstructor();
27703
28619
 
27704
28620
  // src/utils/dashboardPagination.ts
27705
28621
  function isDashboardPivotTable(report) {
@@ -28414,6 +29330,7 @@ var useDashboard = (dashboardName, config) => {
28414
29330
  const { getCacheCab } = (0, import_react2.useContext)(CacheCabContext);
28415
29331
  const reportRequestIds = (0, import_react2.useRef)({});
28416
29332
  const reportFetchAbortController = (0, import_react2.useRef)(null);
29333
+ const dashboardFetchGeneration = (0, import_react2.useRef)(0);
28417
29334
  const lastDashboardName = (0, import_react2.useRef)(null);
28418
29335
  const pendingNameChangeReload = (0, import_react2.useRef)(false);
28419
29336
  const [loadedDashes, setLoadedDashes] = (0, import_react2.useState)([]);
@@ -28423,12 +29340,6 @@ var useDashboard = (dashboardName, config) => {
28423
29340
  () => getCacheCab(config?.cacheType),
28424
29341
  [getCacheCab, config?.cacheType]
28425
29342
  );
28426
- (0, import_react2.useEffect)(() => {
28427
- return () => {
28428
- reportFetchAbortController.current?.abort();
28429
- reportFetchAbortController.current = null;
28430
- };
28431
- }, [dashboardName]);
28432
29343
  (0, import_react2.useEffect)(() => {
28433
29344
  const nameChanged = dashboardName !== lastDashboardName.current;
28434
29345
  if (nameChanged) {
@@ -28491,15 +29402,42 @@ var useDashboard = (dashboardName, config) => {
28491
29402
  );
28492
29403
  }, [dashboardFilters]);
28493
29404
  (0, import_react2.useEffect)(() => {
29405
+ profileDashboard("initial-fetch-effect", {
29406
+ dashboardName,
29407
+ fetchedInitialReports: fetchedInitialReports.current,
29408
+ hasData: !!data,
29409
+ dashboardFiltersReady: dashboardFilters !== null,
29410
+ customFiltersLoaded,
29411
+ customReportFilterIds: Object.keys(customReportFilters)
29412
+ });
28494
29413
  if (!fetchedInitialReports.current && data && dashboardFilters !== null) {
28495
29414
  fetchedInitialReports.current = true;
28496
- fetchReports([], dashboardFilters ?? [], config?.pageSize);
29415
+ void fetchReports(
29416
+ [],
29417
+ dashboardFilters ?? [],
29418
+ config?.pageSize,
29419
+ false,
29420
+ "initial-effect"
29421
+ );
28497
29422
  }
28498
29423
  }, [fetchedInitialReports, data, dashboardFilters, customFiltersLoaded]);
28499
29424
  (0, import_react2.useEffect)(() => {
29425
+ profileDashboard("custom-filter-fetch-effect", {
29426
+ dashboardName,
29427
+ customFiltersLoaded,
29428
+ hasData: !!data,
29429
+ dashboardFiltersReady: dashboardFilters !== null,
29430
+ customReportFilterIds: Object.keys(customReportFilters)
29431
+ });
28500
29432
  if (customFiltersLoaded && data && dashboardFilters !== null) {
28501
29433
  fetchedInitialReports.current = true;
28502
- fetchReports([], dashboardFilters ?? [], config?.pageSize);
29434
+ void fetchReports(
29435
+ [],
29436
+ dashboardFilters ?? [],
29437
+ config?.pageSize,
29438
+ false,
29439
+ "custom-filters-effect"
29440
+ );
28503
29441
  }
28504
29442
  }, [customFiltersLoaded]);
28505
29443
  const applyDashboardFilters = (filtersToUpdate) => {
@@ -28610,11 +29548,23 @@ var useDashboard = (dashboardName, config) => {
28610
29548
  const customFilters = filters2.filter(isFilter2);
28611
29549
  const newCustomFilters = applyCustomFilters(customFilters);
28612
29550
  const newDashboardFilters = applyDashboardFilters(dashboardFilters2);
28613
- fetchReports(newCustomFilters, newDashboardFilters);
29551
+ void fetchReports(
29552
+ newCustomFilters,
29553
+ newDashboardFilters,
29554
+ void 0,
29555
+ false,
29556
+ "apply-filters"
29557
+ );
28614
29558
  };
28615
29559
  const forceCacheRefresh = () => {
28616
29560
  if (!cacheEnabled) return;
28617
- fetchReports([], dashboardFilters ?? [], config?.pageSize, true);
29561
+ void fetchReports(
29562
+ [],
29563
+ dashboardFilters ?? [],
29564
+ config?.pageSize,
29565
+ true,
29566
+ "force-cache-refresh"
29567
+ );
28618
29568
  };
28619
29569
  const primeReportSource = async (reportId) => {
28620
29570
  const reportInfo = allReportsById[reportId];
@@ -28656,9 +29606,36 @@ var useDashboard = (dashboardName, config) => {
28656
29606
  }
28657
29607
  );
28658
29608
  };
28659
- const fetchReports = async (customFilters, dashboardFilters2, pageSize, forceCacheToRefresh = false) => {
28660
- if (!client || !sections) return;
28661
- reportFetchAbortController.current?.abort();
29609
+ const fetchReports = async (customFilters, dashboardFilters2, pageSize, forceCacheToRefresh = false, reason = "unknown") => {
29610
+ if (!client || !sections) {
29611
+ profileDashboard("dashboard-fetch-skipped", {
29612
+ dashboardName,
29613
+ reason,
29614
+ hasClient: !!client,
29615
+ hasSections: !!sections
29616
+ });
29617
+ return;
29618
+ }
29619
+ const generation = dashboardFetchGeneration.current + 1;
29620
+ dashboardFetchGeneration.current = generation;
29621
+ const previousController = reportFetchAbortController.current;
29622
+ profileDashboard("dashboard-fetch-start", {
29623
+ dashboardName,
29624
+ generation,
29625
+ reason,
29626
+ reportCount: Object.values(sections).flat().length,
29627
+ customFilterCount: customFilters.length,
29628
+ customReportFilterIds: Object.keys(customReportFilters),
29629
+ abortsPreviousGeneration: !!previousController
29630
+ });
29631
+ if (previousController) {
29632
+ profileDashboard("dashboard-fetch-abort-previous", {
29633
+ dashboardName,
29634
+ generation,
29635
+ reason
29636
+ });
29637
+ previousController.abort();
29638
+ }
28662
29639
  const abortController = new AbortController();
28663
29640
  reportFetchAbortController.current = abortController;
28664
29641
  const abortSignal = abortController.signal;
@@ -28670,6 +29647,32 @@ var useDashboard = (dashboardName, config) => {
28670
29647
  const reportId = reportInfo.id;
28671
29648
  const requestId = (reportRequestIds.current[reportId] ?? 0) + 1;
28672
29649
  reportRequestIds.current[reportId] = requestId;
29650
+ const reportStartedAt = performance.now();
29651
+ profileDashboard("report-fetch-start", {
29652
+ dashboardName,
29653
+ generation,
29654
+ reason,
29655
+ reportId,
29656
+ requestId,
29657
+ chartType: reportInfo.chartType,
29658
+ pivot: !!reportInfo.pivot,
29659
+ customFilterCount: customReportFilters[reportId]?.length ?? 0
29660
+ });
29661
+ abortSignal.addEventListener(
29662
+ "abort",
29663
+ () => {
29664
+ profileDashboard("report-fetch-aborted", {
29665
+ dashboardName,
29666
+ generation,
29667
+ reason,
29668
+ reportId,
29669
+ requestId,
29670
+ elapsedMs: Math.round(performance.now() - reportStartedAt),
29671
+ currentRequestId: reportRequestIds.current[reportId]
29672
+ });
29673
+ },
29674
+ { once: true }
29675
+ );
28673
29676
  reportsLoadingStateDispatch({
28674
29677
  type: "SET_REPORT_LOADING",
28675
29678
  id: reportId,
@@ -28896,20 +29899,65 @@ var useDashboard = (dashboardName, config) => {
28896
29899
  additionalProcessing: reportAdditionalProcessing
28897
29900
  }
28898
29901
  ];
28899
- const fetchDashboardReport = () => fetchReport({
28900
- reportId,
28901
- client,
28902
- tenants,
28903
- flags,
28904
- additionalProcessing: reportAdditionalProcessing,
28905
- filters: allFilters,
28906
- getToken,
28907
- eventTracking,
28908
- abortSignal,
28909
- usePivotTask,
28910
- overwriteCache: forceCacheToRefresh,
28911
- shareRequest: !forceCacheToRefresh
28912
- });
29902
+ const fetchDashboardReport = async () => {
29903
+ if (usePivotTask && reportInfo.pivot) {
29904
+ try {
29905
+ const dateFilter = allFilters.find(
29906
+ (filter) => filter.filterType === "date_range" /* Date */ || filter.operator === "BETWEEN"
29907
+ );
29908
+ const pivotData = await generatePivotWithSQL({
29909
+ pivot: reportInfo.pivot,
29910
+ report: reportInfo,
29911
+ client,
29912
+ dateBucket: reportInfo.pivot.dateBucket,
29913
+ dateFilter,
29914
+ dashboardName,
29915
+ dashboardFilters: allFilters,
29916
+ tenants,
29917
+ additionalProcessing: reportAdditionalProcessing,
29918
+ getToken,
29919
+ overwriteCache: forceCacheToRefresh,
29920
+ abortSignal
29921
+ });
29922
+ return {
29923
+ report: {
29924
+ ...reportInfo,
29925
+ rows: [],
29926
+ columnInternal: pivotData.columns,
29927
+ pivotRows: pivotData.rows,
29928
+ pivotColumns: pivotData.columns,
29929
+ pivotRowCount: pivotData.rowCount,
29930
+ pivotQuery: pivotData.pivotQuery,
29931
+ comparisonPivotQuery: pivotData.comparisonPivotQuery
29932
+ },
29933
+ error: void 0
29934
+ };
29935
+ } catch (error2) {
29936
+ if (abortSignal.aborted || error2 instanceof Error && error2.name === "AbortError") {
29937
+ const abortError = new Error("Dashboard report fetch aborted");
29938
+ abortError.name = "AbortError";
29939
+ throw abortError;
29940
+ }
29941
+ return {
29942
+ report: reportInfo,
29943
+ error: error2 instanceof Error ? error2.message : String(error2 ?? "Failed to fetch pivot report")
29944
+ };
29945
+ }
29946
+ }
29947
+ return fetchReport({
29948
+ reportId,
29949
+ client,
29950
+ tenants,
29951
+ flags,
29952
+ additionalProcessing: reportAdditionalProcessing,
29953
+ filters: allFilters,
29954
+ getToken,
29955
+ eventTracking,
29956
+ abortSignal,
29957
+ overwriteCache: forceCacheToRefresh,
29958
+ shareRequest: !forceCacheToRefresh
29959
+ });
29960
+ };
28913
29961
  const result = forceCacheToRefresh ? await fetchDashboardReport() : await queryClient.fetchQuery({
28914
29962
  queryKey,
28915
29963
  queryFn: fetchDashboardReport,
@@ -28988,10 +30036,25 @@ var useDashboard = (dashboardName, config) => {
28988
30036
  return report;
28989
30037
  })
28990
30038
  ).catch((error) => {
30039
+ profileDashboard("dashboard-fetch-rejected", {
30040
+ dashboardName,
30041
+ generation,
30042
+ reason,
30043
+ errorName: error instanceof Error ? error.name : typeof error,
30044
+ errorMessage: error instanceof Error ? error.message : String(error)
30045
+ });
28991
30046
  if (!(error instanceof Error) || error.name !== "AbortError") {
28992
30047
  throw error;
28993
30048
  }
28994
30049
  });
30050
+ profileDashboard("dashboard-fetch-settled", {
30051
+ dashboardName,
30052
+ generation,
30053
+ reason,
30054
+ elapsedMs: Date.now() - fetchStartTime,
30055
+ aborted: abortSignal.aborted,
30056
+ latestGeneration: dashboardFetchGeneration.current
30057
+ });
28995
30058
  if (!loadedDashes.includes(dashboardName) || !cacheEnabled || forceCacheToRefresh) {
28996
30059
  setLoadedDashes(
28997
30060
  (prev) => prev.includes(dashboardName) ? prev : [...prev, dashboardName]
@@ -29674,682 +30737,319 @@ function QuillCustomDocumentComponent({
29674
30737
  overflow: "hidden",
29675
30738
  textOverflow: "ellipsis",
29676
30739
  width: "100%",
29677
- margin: 0
29678
- },
29679
- colSpan: report.columns.length,
29680
- children: report.name
29681
- }
29682
- ) }),
29683
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("tr", { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("td", { colSpan: report.columns.length, children: "\xA0" }) }),
29684
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("tr", { children: report.columns.map((col, colIndex) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
29685
- "th",
29686
- {
29687
- style: { padding: "2px", paddingLeft: "3px", fontSize: 8 },
29688
- children: col.label
29689
- },
29690
- "head" + colIndex
29691
- )) })
29692
- ]
29693
- }
29694
- ),
29695
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("tbody", { children: [
29696
- report.rows.slice(rowStartIndex, rowEndIndex).map((row, rowIndex) => {
29697
- return [
29698
- // Title and header at the top of every page
29699
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("tr", { children: report.columns.map((col, colIndex) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
29700
- "td",
29701
- {
29702
- style: {
29703
- padding: "2px",
29704
- paddingLeft: "3px",
29705
- fontSize: 8,
29706
- whiteSpace: "nowrap",
29707
- overflow: "hidden",
29708
- textOverflow: "ellipsis",
29709
- width: "100%"
29710
- },
29711
- children: quillFormat({
29712
- value: row[col.field],
29713
- format: col.format
29714
- })
29715
- },
29716
- "cell" + col.field + colIndex + rowIndex
29717
- )) }, "row" + rowIndex)
29718
- ];
29719
- }),
29720
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("tr", { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("td", { colSpan: report.columns.length, children: "\xA0" }) }),
29721
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("tr", { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
29722
- "td",
29723
- {
29724
- style: {
29725
- fontSize: "8px",
29726
- textAlign: "left",
29727
- whiteSpace: "nowrap",
29728
- overflow: "hidden",
29729
- textOverflow: "ellipsis",
29730
- width: "100%",
29731
- margin: 0
29732
- },
29733
- colSpan: report.columns.length,
29734
- children: [
29735
- "Page ",
29736
- pageNumber,
29737
- " of ",
29738
- numberOfPages
29739
- ]
29740
- }
29741
- ) })
29742
- ] })
29743
- ]
29744
- }
29745
- )
29746
- }
29747
- ) })
29748
- }
29749
- );
29750
- }
29751
-
29752
- // src/Chart.tsx
29753
- var import_date_fns14 = require("date-fns");
29754
-
29755
- // src/components/Chart/BarList.tsx
29756
- var import_react4 = __toESM(require("react"), 1);
29757
- init_valueFormatter();
29758
- init_chart();
29759
- var import_jsx_runtime3 = require("react/jsx-runtime");
29760
- var getWidthsFromValues = (dataValues) => {
29761
- let maxValue = -Infinity;
29762
- dataValues.forEach((value) => {
29763
- maxValue = Math.max(maxValue, value);
29764
- });
29765
- return dataValues.map((value) => {
29766
- if (value === 0) return 0;
29767
- return Math.max(value / maxValue * 100, 1);
29768
- });
29769
- };
29770
- function getColors(colorMap, xAxisField, colors) {
29771
- if (colorMap && colorMap[xAxisField] && colorMap[xAxisField]["primary"]) {
29772
- return colorMap[xAxisField]["primary"];
29773
- } else if (colors) {
29774
- return hexToRgbaWith10PercentAlpha(colors[0]);
29775
- }
29776
- return hexToRgbaWith10PercentAlpha(void 0);
29777
- }
29778
- var BarList = import_react4.default.forwardRef((props, ref) => {
29779
- const {
29780
- data = [],
29781
- yAxisFields,
29782
- xAxisField,
29783
- xAxisFormat,
29784
- colors,
29785
- colorMap = {},
29786
- // valueFormatter = (value: any) => value,valueFormatter
29787
- showAnimation = true,
29788
- className,
29789
- containerStyle,
29790
- theme,
29791
- onClickChartElement,
29792
- scrollable,
29793
- ...other
29794
- } = props;
29795
- const widths = getWidthsFromValues(
29796
- data.map((item) => {
29797
- if (yAxisFields && yAxisFields[0] && yAxisFields[0].field) {
29798
- return item[yAxisFields[0].field];
29799
- }
29800
- return 0;
29801
- })
29802
- );
29803
- const NUM_TO_SHOW = scrollable ? 500 : 5;
29804
- if (!data || data.length === 0) {
29805
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
29806
- "div",
29807
- {
29808
- style: {
29809
- display: "flex",
29810
- flex: "1 0 auto",
29811
- // height: '100%',
29812
- margin: "auto",
29813
- justifyContent: "center",
29814
- alignItems: "center",
29815
- fontSize: 13,
29816
- fontFamily: theme?.fontFamily,
29817
- color: theme.secondaryTextColor,
29818
- ...containerStyle
29819
- },
29820
- className,
29821
- children: "No results"
29822
- }
29823
- );
29824
- }
29825
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
29826
- "div",
29827
- {
29828
- ref,
29829
- className,
29830
- style: {
29831
- // width: '100%',
29832
- boxSizing: "content-box",
29833
- height: "100%",
29834
- // marginLeft: 25,
29835
- // background: 'red',
29836
- // paddingRight: 25,
29837
- // paddingRight: 25,
29838
- ...containerStyle
29839
- },
29840
- ...other,
29841
- children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
29842
- "div",
29843
- {
29844
- style: {
29845
- display: "flex",
29846
- justifyContent: "space-between",
29847
- boxSizing: "content-box",
29848
- overflow: scrollable ? "scroll" : "hidden",
29849
- width: "100%",
29850
- height: "100%"
29851
- },
29852
- children: [
29853
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
29854
- "div",
29855
- {
29856
- style: {
29857
- width: "100%",
29858
- boxSizing: "content-box",
29859
- height: "100%",
29860
- position: "relative",
29861
- paddingRight: 25
29862
- },
29863
- children: [
29864
- data.slice(0, NUM_TO_SHOW).map((item, idx) => {
29865
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
29866
- "div",
29867
- {
29868
- style: {
29869
- width: `${widths[idx]}%`,
29870
- transition: showAnimation ? "all 2s" : "",
29871
- boxSizing: "content-box",
29872
- backgroundColor: getColors(colorMap, xAxisField, colors),
29873
- display: "flex",
29874
- alignItems: "center",
29875
- height: "36px",
29876
- marginBottom: "8px",
29877
- borderRadius: "4px"
29878
- },
29879
- onClick: () => onClickChartElement?.(item),
29880
- children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
29881
- "div",
29882
- {
29883
- style: {
29884
- boxSizing: "content-box",
29885
- position: "absolute",
29886
- maxWidth: "100%",
29887
- display: "flex",
29888
- marginLeft: "8px"
29889
- },
29890
- children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
29891
- "p",
29892
- {
29893
- style: {
29894
- color: theme?.chartLabelColor,
29895
- boxSizing: "content-box",
29896
- whiteSpace: "nowrap",
29897
- overflow: "hidden",
29898
- textOverflow: "ellipsis",
29899
- fontFamily: theme?.chartLabelFontFamily || theme?.fontFamily,
29900
- fontSize: theme?.fontSizeSmall || "14px"
29901
- },
29902
- children: valueFormatter({
29903
- value: item[xAxisField] ?? item[`comparison_${xAxisField}`],
29904
- field: xAxisField,
29905
- // @ts-ignore
29906
- fields: [{ field: xAxisField, format: xAxisFormat }]
29907
- })
29908
- }
29909
- )
29910
- }
29911
- )
29912
- },
29913
- item[xAxisField] + "label" + idx
29914
- );
29915
- }),
29916
- data.length > NUM_TO_SHOW && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
29917
- "div",
29918
- {
29919
- style: {
29920
- color: theme?.chartLabelColor,
29921
- boxSizing: "content-box",
29922
- fontFamily: theme?.chartLabelFontFamily || theme?.fontFamily,
29923
- fontSize: theme?.fontSizeSmall || "14px"
29924
- },
29925
- children: [
29926
- "...",
29927
- data.length - NUM_TO_SHOW,
29928
- " more"
29929
- ]
29930
- }
29931
- )
29932
- ]
29933
- }
29934
- ),
29935
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
29936
- "div",
29937
- {
29938
- style: {
29939
- boxSizing: "content-box",
29940
- textAlign: "right",
29941
- minWidth: "min-content",
29942
- paddingLeft: 10
29943
- },
29944
- children: data.slice(0, NUM_TO_SHOW).map((item, idx) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
29945
- "div",
29946
- {
29947
- style: {
29948
- boxSizing: "content-box",
29949
- display: "flex",
29950
- alignItems: "center",
29951
- justifyContent: "flex-end",
29952
- marginBottom: idx === data.length - 1 ? 0 : "8px",
29953
- height: "36px"
29954
- },
29955
- children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
29956
- "p",
29957
- {
29958
- style: {
29959
- color: theme?.chartLabelColor,
29960
- boxSizing: "content-box",
29961
- fontFamily: theme?.chartLabelFontFamily || theme?.fontFamily,
29962
- whiteSpace: "nowrap",
29963
- overflow: "hidden",
29964
- textOverflow: "ellipsis",
29965
- fontSize: theme?.fontSizeSmall || "14px"
29966
- },
29967
- children: valueFormatter({
29968
- value: yAxisFields && yAxisFields[0] && item[yAxisFields[0].field] ? item[yAxisFields[0].field] : 0,
29969
- field: yAxisFields && yAxisFields[0] && yAxisFields[0].field,
29970
- fields: yAxisFields
29971
- })
29972
- }
29973
- )
29974
- },
29975
- item[xAxisField] + "value" + idx
29976
- ))
29977
- }
29978
- )
29979
- ]
29980
- }
29981
- )
29982
- }
29983
- );
29984
- });
29985
- var BarList_default = BarList;
29986
-
29987
- // src/components/Chart/PieChart.tsx
29988
- var import_react13 = __toESM(require("react"), 1);
29989
- var import_recharts = require("recharts");
29990
-
29991
- // src/utils/color.ts
29992
- var DEFAULT_GRADIENT_COLORS = [
29993
- "#4E80EE",
29994
- // vivid indigo
29995
- "#586FF4",
29996
- "#6464FA",
29997
- "#715AFE",
29998
- "#8450FF",
29999
- "#9B48FF",
30000
- "#B33FFF",
30001
- "#CA37F3",
30002
- "#DE2FE1",
30003
- "#F028CB",
30004
- "#FF20B5"
30005
- ];
30006
- function generateArrayFromColor(colors, length) {
30007
- if (length <= 0) {
30008
- return [];
30009
- }
30010
- if (typeof colors === "string") {
30011
- const trimmedColor = colors.trim();
30012
- return monochromaticInterpolation(
30013
- trimmedColor.length > 0 ? trimmedColor : DEFAULT_GRADIENT_COLORS[0],
30014
- length
30015
- );
30016
- }
30017
- const normalizedColors = colors.filter((color) => typeof color === "string").map((color) => color.trim()).filter((color) => color.length > 0);
30018
- const baseColors = normalizedColors.length > 0 ? normalizedColors : DEFAULT_GRADIENT_COLORS;
30019
- if (baseColors.length === 1) {
30020
- return monochromaticInterpolation(baseColors[0], length);
30021
- }
30022
- if (length <= baseColors.length) {
30023
- return baseColors.slice(0, length);
30024
- }
30025
- const pairs = baseColors.length - 1;
30026
- if (pairs <= 0) {
30027
- return [baseColors[0]];
30028
- }
30029
- const needed = length - baseColors.length;
30030
- const baseAmount = Math.floor(needed / pairs);
30031
- const extras = needed % pairs;
30032
- let result = [];
30033
- let i = 0;
30034
- let j = 1;
30035
- while (j < baseColors.length) {
30036
- const additional = i < extras ? 1 : 0;
30037
- const interpLength = 2 + baseAmount + additional;
30038
- const interp = interpolateBetween(
30039
- baseColors[i],
30040
- baseColors[j],
30041
- interpLength
30042
- );
30043
- const lastIndex = j === baseColors.length - 1 ? void 0 : -1;
30044
- result = result.concat(interp.slice(0, lastIndex));
30045
- i++;
30046
- j++;
30047
- }
30048
- return result;
30049
- }
30050
- function hexToRgb(hex) {
30051
- const r = parseInt(hex.substring(1, 3), 16);
30052
- const g = parseInt(hex.substring(3, 5), 16);
30053
- const b = parseInt(hex.substring(5, 7), 16);
30054
- return { r, g, b };
30055
- }
30056
- function rgbToHex(rgb) {
30057
- const rHex = rgb.r.toString(16).padStart(2, "0");
30058
- const gHex = rgb.g.toString(16).padStart(2, "0");
30059
- const bHex = rgb.b.toString(16).padStart(2, "0");
30060
- return `#${rHex}${gHex}${bHex}`;
30061
- }
30062
- function colorToHSL(color) {
30063
- const colorHex = namedColorToHex(color);
30064
- const { r, g, b } = hexToRgb(colorHex);
30065
- return rgbToHsl(r, g, b);
30066
- }
30067
- function interpolateBetween(leftColor, rightColor, length = 3) {
30068
- const [h, s, _l] = colorToHSL(leftColor);
30069
- const [h2, s2, _l2] = colorToHSL(rightColor);
30070
- const hues = linspace(h, h2, length);
30071
- const saturations = linspace(s, s2, length);
30072
- const lightnesses = linspace(_l, _l2, length);
30073
- return Array.from({ length }).map((_, i) => {
30074
- const [r, g, b] = HSLtoRGB(hues[i], saturations[i], lightnesses[i]);
30075
- return rgbToHex({ r: Math.round(r), g: Math.round(g), b: Math.round(b) });
30076
- });
30077
- }
30078
- function monochromaticInterpolation(color, length) {
30079
- const [h, s] = colorToHSL(color);
30080
- const hues = linspace(h, h, length);
30081
- const saturations = linspace(s, s, length);
30082
- const lightnesses = linspace(0.6, 0.9, length);
30083
- return Array.from({ length }).map((_, i) => {
30084
- const [r, g, b] = HSLtoRGB(hues[i], saturations[i], lightnesses[i]);
30085
- return rgbToHex({ r: Math.round(r), g: Math.round(g), b: Math.round(b) });
30086
- });
30087
- }
30088
- function linspace(start, end, num) {
30089
- if (num <= 1) return [start];
30090
- const step = (end - start) / (num - 1);
30091
- const result = new Array(num);
30092
- for (let i = 0; i < num; i++) {
30093
- result[i] = start + step * i;
30094
- }
30095
- return result;
30096
- }
30097
- function stableColorIndex(field) {
30098
- let hash = 0;
30099
- for (const character of field.replace("comparison_", "")) {
30100
- hash = Math.imul(hash, 31) + character.charCodeAt(0) >>> 0;
30101
- }
30102
- return hash;
30103
- }
30104
- function selectColor(element, colors, index) {
30105
- if (!element?.field) return "gray";
30106
- const isComparison = element.field.includes("comparison_");
30107
- const color = colors[index % colors.length] ?? "";
30108
- if (!isComparison) {
30109
- return color;
30110
- }
30111
- if (Object.keys(COLOR_TO_HEX).includes(color)) {
30112
- const colorHex = COLOR_TO_HEX[color];
30113
- const rgbArray = hexToRGB(colorHex);
30114
- return toGrayscale(rgbArray);
30115
- }
30116
- if (color?.startsWith("#")) {
30117
- const rgbArray = hexToRGB(color);
30118
- return toGrayscale(rgbArray);
30119
- }
30120
- return "gray";
30121
- }
30122
- function hexToRGB(hex) {
30123
- const regex = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})?$/i;
30124
- const result = regex.exec(hex);
30125
- if (result) {
30126
- return [
30127
- parseInt(result[1], 16),
30128
- // index 0 is whole string, then ()'s
30129
- parseInt(result[2], 16),
30130
- parseInt(result[3], 16),
30131
- ...result[4] ? [parseInt(result[4], 16)] : []
30132
- // <- alpha channel
30133
- ];
30134
- }
30135
- const rgba = hex.match(/[0-9.]+/g);
30136
- if (rgba) {
30137
- return [
30138
- Number(rgba[0]),
30139
- Number(rgba[1]),
30140
- Number(rgba[2]),
30141
- ...rgba[3] ? [Number(rgba[3])] : []
30142
- ];
30143
- }
30144
- return [128, 128, 128];
30145
- }
30146
- function toGrayscale(rgba) {
30147
- if (rgba.length < 3) return "rbg(128, 128, 128)";
30148
- let sum = 0;
30149
- sum += Number(rgba[0] * 0.89);
30150
- sum += Number(rgba[1] * 1.77);
30151
- sum += Number(rgba[2] * 0.33);
30152
- const avg = (sum / 3).toFixed(2);
30153
- return `rgb(${avg}, ${avg}, ${avg})`;
30154
- }
30155
- function namedColorToHex(color) {
30156
- if (Object.keys(COLOR_TO_HEX).includes(color)) {
30157
- return COLOR_TO_HEX[color];
30158
- }
30159
- return color;
30160
- }
30161
- var COLOR_TO_HEX = {
30162
- aliceblue: "#f0f8ff",
30163
- antiquewhite: "#faebd7",
30164
- aqua: "#00ffff",
30165
- aquamarine: "#7fffd4",
30166
- azure: "#f0ffff",
30167
- beige: "#f5f5dc",
30168
- bisque: "#ffe4c4",
30169
- black: "#000000",
30170
- blanchedalmond: "#ffebcd",
30171
- blue: "#0000ff",
30172
- blueviolet: "#8a2be2",
30173
- brown: "#a52a2a",
30174
- burlywood: "#deb887",
30175
- cadetblue: "#5f9ea0",
30176
- chartreuse: "#7fff00",
30177
- chocolate: "#d2691e",
30178
- coral: "#ff7f50",
30179
- cornflowerblue: "#6495ed",
30180
- cornsilk: "#fff8dc",
30181
- crimson: "#dc143c",
30182
- cyan: "#00ffff",
30183
- darkblue: "#00008b",
30184
- darkcyan: "#008b8b",
30185
- darkgoldenrod: "#b8860b",
30186
- darkgray: "#a9a9a9",
30187
- darkgreen: "#006400",
30188
- darkkhaki: "#bdb76b",
30189
- darkmagenta: "#8b008b",
30190
- darkolivegreen: "#556b2f",
30191
- darkorange: "#ff8c00",
30192
- darkorchid: "#9932cc",
30193
- darkred: "#8b0000",
30194
- darksalmon: "#e9967a",
30195
- darkseagreen: "#8fbc8f",
30196
- darkslateblue: "#483d8b",
30197
- darkslategray: "#2f4f4f",
30198
- darkturquoise: "#00ced1",
30199
- darkviolet: "#9400d3",
30200
- deeppink: "#ff1493",
30201
- deepskyblue: "#00bfff",
30202
- dimgray: "#696969",
30203
- dodgerblue: "#1e90ff",
30204
- firebrick: "#b22222",
30205
- floralwhite: "#fffaf0",
30206
- forestgreen: "#228b22",
30207
- fuchsia: "#ff00ff",
30208
- gainsboro: "#dcdcdc",
30209
- ghostwhite: "#f8f8ff",
30210
- gold: "#ffd700",
30211
- goldenrod: "#daa520",
30212
- gray: "#808080",
30213
- green: "#008000",
30214
- greenyellow: "#adff2f",
30215
- honeydew: "#f0fff0",
30216
- hotpink: "#ff69b4",
30217
- indianred: "#cd5c5c",
30218
- indigo: "#4b0082",
30219
- ivory: "#fffff0",
30220
- khaki: "#f0e68c",
30221
- lavender: "#e6e6fa",
30222
- lavenderblush: "#fff0f5",
30223
- lawngreen: "#7cfc00",
30224
- lemonchiffon: "#fffacd",
30225
- lightblue: "#add8e6",
30226
- lightcoral: "#f08080",
30227
- lightcyan: "#e0ffff",
30228
- lightgoldenrodyellow: "#fafad2",
30229
- lightgrey: "#d3d3d3",
30230
- lightgreen: "#90ee90",
30231
- lightpink: "#ffb6c1",
30232
- lightsalmon: "#ffa07a",
30233
- lightseagreen: "#20b2aa",
30234
- lightskyblue: "#87cefa",
30235
- lightslategray: "#778899",
30236
- lightsteelblue: "#b0c4de",
30237
- lightyellow: "#ffffe0",
30238
- lime: "#00ff00",
30239
- limegreen: "#32cd32",
30240
- linen: "#faf0e6",
30241
- magenta: "#ff00ff",
30242
- maroon: "#800000",
30243
- mediumaquamarine: "#66cdaa",
30244
- mediumblue: "#0000cd",
30245
- mediumorchid: "#ba55d3",
30246
- mediumpurple: "#9370d8",
30247
- mediumseagreen: "#3cb371",
30248
- mediumslateblue: "#7b68ee",
30249
- mediumspringgreen: "#00fa9a",
30250
- mediumturquoise: "#48d1cc",
30251
- mediumvioletred: "#c71585",
30252
- midnightblue: "#191970",
30253
- mintcream: "#f5fffa",
30254
- mistyrose: "#ffe4e1",
30255
- moccasin: "#ffe4b5",
30256
- navajowhite: "#ffdead",
30257
- navy: "#000080",
30258
- oldlace: "#fdf5e6",
30259
- olive: "#808000",
30260
- olivedrab: "#6b8e23",
30261
- orange: "#ffa500",
30262
- orangered: "#ff4500",
30263
- orchid: "#da70d6",
30264
- palegoldenrod: "#eee8aa",
30265
- palegreen: "#98fb98",
30266
- paleturquoise: "#afeeee",
30267
- palevioletred: "#d87093",
30268
- papayawhip: "#ffefd5",
30269
- peachpuff: "#ffdab9",
30270
- peru: "#cd853f",
30271
- pink: "#ffc0cb",
30272
- plum: "#dda0dd",
30273
- powderblue: "#b0e0e6",
30274
- purple: "#800080",
30275
- rebeccapurple: "#663399",
30276
- red: "#ff0000",
30277
- rosybrown: "#bc8f8f",
30278
- royalblue: "#4169e1",
30279
- saddlebrown: "#8b4513",
30280
- salmon: "#fa8072",
30281
- sandybrown: "#f4a460",
30282
- seagreen: "#2e8b57",
30283
- seashell: "#fff5ee",
30284
- sienna: "#a0522d",
30285
- silver: "#c0c0c0",
30286
- skyblue: "#87ceeb",
30287
- slateblue: "#6a5acd",
30288
- slategray: "#708090",
30289
- snow: "#fffafa",
30290
- springgreen: "#00ff7f",
30291
- steelblue: "#4682b4",
30292
- tan: "#d2b48c",
30293
- teal: "#008080",
30294
- thistle: "#d8bfd8",
30295
- tomato: "#ff6347",
30296
- turquoise: "#40e0d0",
30297
- violet: "#ee82ee",
30298
- wheat: "#f5deb3",
30299
- white: "#ffffff",
30300
- whitesmoke: "#f5f5f5",
30301
- yellow: "#ffff00",
30302
- yellowgreen: "#9acd32"
30303
- };
30304
- function rgbToHsl(r, g, b) {
30305
- r /= 255, g /= 255, b /= 255;
30306
- const max2 = Math.max(r, g, b), min2 = Math.min(r, g, b);
30307
- let h = (max2 + min2) / 2;
30308
- let s = (max2 + min2) / 2;
30309
- const l = (max2 + min2) / 2;
30310
- if (max2 == min2) {
30311
- h = s = 0;
30312
- } else {
30313
- const d = max2 - min2;
30314
- s = l > 0.5 ? d / (2 - max2 - min2) : d / (max2 + min2);
30315
- switch (max2) {
30316
- case r:
30317
- h = (g - b) / d + (g < b ? 6 : 0);
30318
- break;
30319
- case g:
30320
- h = (b - r) / d + 2;
30321
- break;
30322
- case b:
30323
- h = (r - g) / d + 4;
30324
- break;
30740
+ margin: 0
30741
+ },
30742
+ colSpan: report.columns.length,
30743
+ children: report.name
30744
+ }
30745
+ ) }),
30746
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("tr", { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("td", { colSpan: report.columns.length, children: "\xA0" }) }),
30747
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("tr", { children: report.columns.map((col, colIndex) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
30748
+ "th",
30749
+ {
30750
+ style: { padding: "2px", paddingLeft: "3px", fontSize: 8 },
30751
+ children: col.label
30752
+ },
30753
+ "head" + colIndex
30754
+ )) })
30755
+ ]
30756
+ }
30757
+ ),
30758
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("tbody", { children: [
30759
+ report.rows.slice(rowStartIndex, rowEndIndex).map((row, rowIndex) => {
30760
+ return [
30761
+ // Title and header at the top of every page
30762
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("tr", { children: report.columns.map((col, colIndex) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
30763
+ "td",
30764
+ {
30765
+ style: {
30766
+ padding: "2px",
30767
+ paddingLeft: "3px",
30768
+ fontSize: 8,
30769
+ whiteSpace: "nowrap",
30770
+ overflow: "hidden",
30771
+ textOverflow: "ellipsis",
30772
+ width: "100%"
30773
+ },
30774
+ children: quillFormat({
30775
+ value: row[col.field],
30776
+ format: col.format
30777
+ })
30778
+ },
30779
+ "cell" + col.field + colIndex + rowIndex
30780
+ )) }, "row" + rowIndex)
30781
+ ];
30782
+ }),
30783
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("tr", { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("td", { colSpan: report.columns.length, children: "\xA0" }) }),
30784
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("tr", { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
30785
+ "td",
30786
+ {
30787
+ style: {
30788
+ fontSize: "8px",
30789
+ textAlign: "left",
30790
+ whiteSpace: "nowrap",
30791
+ overflow: "hidden",
30792
+ textOverflow: "ellipsis",
30793
+ width: "100%",
30794
+ margin: 0
30795
+ },
30796
+ colSpan: report.columns.length,
30797
+ children: [
30798
+ "Page ",
30799
+ pageNumber,
30800
+ " of ",
30801
+ numberOfPages
30802
+ ]
30803
+ }
30804
+ ) })
30805
+ ] })
30806
+ ]
30807
+ }
30808
+ )
30809
+ }
30810
+ ) })
30325
30811
  }
30326
- h /= 6;
30327
- }
30328
- return [h, s, l];
30812
+ );
30329
30813
  }
30330
- function HSLtoRGB(h, s, l) {
30331
- let r, g, b;
30332
- if (s == 0) {
30333
- r = g = b = l;
30334
- } else {
30335
- const hue2rgb = (p2, q2, t) => {
30336
- if (t < 0) t += 1;
30337
- if (t > 1) t -= 1;
30338
- if (t < 1 / 6) return p2 + (q2 - p2) * 6 * t;
30339
- if (t < 1 / 2) return q2;
30340
- if (t < 2 / 3) return p2 + (q2 - p2) * (2 / 3 - t) * 6;
30341
- return p2;
30342
- };
30343
- const q = l < 0.5 ? l * (1 + s) : l + s - l * s;
30344
- const p = 2 * l - q;
30345
- r = hue2rgb(p, q, h + 1 / 3);
30346
- g = hue2rgb(p, q, h);
30347
- b = hue2rgb(p, q, h - 1 / 3);
30814
+
30815
+ // src/Chart.tsx
30816
+ var import_date_fns14 = require("date-fns");
30817
+
30818
+ // src/components/Chart/BarList.tsx
30819
+ var import_react4 = __toESM(require("react"), 1);
30820
+ init_valueFormatter();
30821
+ init_chart();
30822
+ var import_jsx_runtime3 = require("react/jsx-runtime");
30823
+ var getWidthsFromValues = (dataValues) => {
30824
+ let maxValue = -Infinity;
30825
+ dataValues.forEach((value) => {
30826
+ maxValue = Math.max(maxValue, value);
30827
+ });
30828
+ return dataValues.map((value) => {
30829
+ if (value === 0) return 0;
30830
+ return Math.max(value / maxValue * 100, 1);
30831
+ });
30832
+ };
30833
+ function getColors(colorMap, xAxisField, colors) {
30834
+ if (colorMap && colorMap[xAxisField] && colorMap[xAxisField]["primary"]) {
30835
+ return colorMap[xAxisField]["primary"];
30836
+ } else if (colors) {
30837
+ return hexToRgbaWith10PercentAlpha(colors[0]);
30348
30838
  }
30349
- return [r * 255, g * 255, b * 255];
30839
+ return hexToRgbaWith10PercentAlpha(void 0);
30350
30840
  }
30841
+ var BarList = import_react4.default.forwardRef((props, ref) => {
30842
+ const {
30843
+ data = [],
30844
+ yAxisFields,
30845
+ xAxisField,
30846
+ xAxisFormat,
30847
+ colors,
30848
+ colorMap = {},
30849
+ // valueFormatter = (value: any) => value,valueFormatter
30850
+ showAnimation = true,
30851
+ className,
30852
+ containerStyle,
30853
+ theme,
30854
+ onClickChartElement,
30855
+ scrollable,
30856
+ ...other
30857
+ } = props;
30858
+ const widths = getWidthsFromValues(
30859
+ data.map((item) => {
30860
+ if (yAxisFields && yAxisFields[0] && yAxisFields[0].field) {
30861
+ return item[yAxisFields[0].field];
30862
+ }
30863
+ return 0;
30864
+ })
30865
+ );
30866
+ const NUM_TO_SHOW = scrollable ? 500 : 5;
30867
+ if (!data || data.length === 0) {
30868
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
30869
+ "div",
30870
+ {
30871
+ style: {
30872
+ display: "flex",
30873
+ flex: "1 0 auto",
30874
+ // height: '100%',
30875
+ margin: "auto",
30876
+ justifyContent: "center",
30877
+ alignItems: "center",
30878
+ fontSize: 13,
30879
+ fontFamily: theme?.fontFamily,
30880
+ color: theme.secondaryTextColor,
30881
+ ...containerStyle
30882
+ },
30883
+ className,
30884
+ children: "No results"
30885
+ }
30886
+ );
30887
+ }
30888
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
30889
+ "div",
30890
+ {
30891
+ ref,
30892
+ className,
30893
+ style: {
30894
+ // width: '100%',
30895
+ boxSizing: "content-box",
30896
+ height: "100%",
30897
+ // marginLeft: 25,
30898
+ // background: 'red',
30899
+ // paddingRight: 25,
30900
+ // paddingRight: 25,
30901
+ ...containerStyle
30902
+ },
30903
+ ...other,
30904
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
30905
+ "div",
30906
+ {
30907
+ style: {
30908
+ display: "flex",
30909
+ justifyContent: "space-between",
30910
+ boxSizing: "content-box",
30911
+ overflow: scrollable ? "scroll" : "hidden",
30912
+ width: "100%",
30913
+ height: "100%"
30914
+ },
30915
+ children: [
30916
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
30917
+ "div",
30918
+ {
30919
+ style: {
30920
+ width: "100%",
30921
+ boxSizing: "content-box",
30922
+ height: "100%",
30923
+ position: "relative",
30924
+ paddingRight: 25
30925
+ },
30926
+ children: [
30927
+ data.slice(0, NUM_TO_SHOW).map((item, idx) => {
30928
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
30929
+ "div",
30930
+ {
30931
+ style: {
30932
+ width: `${widths[idx]}%`,
30933
+ transition: showAnimation ? "all 2s" : "",
30934
+ boxSizing: "content-box",
30935
+ backgroundColor: getColors(colorMap, xAxisField, colors),
30936
+ display: "flex",
30937
+ alignItems: "center",
30938
+ height: "36px",
30939
+ marginBottom: "8px",
30940
+ borderRadius: "4px"
30941
+ },
30942
+ onClick: () => onClickChartElement?.(item),
30943
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
30944
+ "div",
30945
+ {
30946
+ style: {
30947
+ boxSizing: "content-box",
30948
+ position: "absolute",
30949
+ maxWidth: "100%",
30950
+ display: "flex",
30951
+ marginLeft: "8px"
30952
+ },
30953
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
30954
+ "p",
30955
+ {
30956
+ style: {
30957
+ color: theme?.chartLabelColor,
30958
+ boxSizing: "content-box",
30959
+ whiteSpace: "nowrap",
30960
+ overflow: "hidden",
30961
+ textOverflow: "ellipsis",
30962
+ fontFamily: theme?.chartLabelFontFamily || theme?.fontFamily,
30963
+ fontSize: theme?.fontSizeSmall || "14px"
30964
+ },
30965
+ children: valueFormatter({
30966
+ value: item[xAxisField] ?? item[`comparison_${xAxisField}`],
30967
+ field: xAxisField,
30968
+ // @ts-ignore
30969
+ fields: [{ field: xAxisField, format: xAxisFormat }]
30970
+ })
30971
+ }
30972
+ )
30973
+ }
30974
+ )
30975
+ },
30976
+ item[xAxisField] + "label" + idx
30977
+ );
30978
+ }),
30979
+ data.length > NUM_TO_SHOW && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
30980
+ "div",
30981
+ {
30982
+ style: {
30983
+ color: theme?.chartLabelColor,
30984
+ boxSizing: "content-box",
30985
+ fontFamily: theme?.chartLabelFontFamily || theme?.fontFamily,
30986
+ fontSize: theme?.fontSizeSmall || "14px"
30987
+ },
30988
+ children: [
30989
+ "...",
30990
+ data.length - NUM_TO_SHOW,
30991
+ " more"
30992
+ ]
30993
+ }
30994
+ )
30995
+ ]
30996
+ }
30997
+ ),
30998
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
30999
+ "div",
31000
+ {
31001
+ style: {
31002
+ boxSizing: "content-box",
31003
+ textAlign: "right",
31004
+ minWidth: "min-content",
31005
+ paddingLeft: 10
31006
+ },
31007
+ children: data.slice(0, NUM_TO_SHOW).map((item, idx) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
31008
+ "div",
31009
+ {
31010
+ style: {
31011
+ boxSizing: "content-box",
31012
+ display: "flex",
31013
+ alignItems: "center",
31014
+ justifyContent: "flex-end",
31015
+ marginBottom: idx === data.length - 1 ? 0 : "8px",
31016
+ height: "36px"
31017
+ },
31018
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
31019
+ "p",
31020
+ {
31021
+ style: {
31022
+ color: theme?.chartLabelColor,
31023
+ boxSizing: "content-box",
31024
+ fontFamily: theme?.chartLabelFontFamily || theme?.fontFamily,
31025
+ whiteSpace: "nowrap",
31026
+ overflow: "hidden",
31027
+ textOverflow: "ellipsis",
31028
+ fontSize: theme?.fontSizeSmall || "14px"
31029
+ },
31030
+ children: valueFormatter({
31031
+ value: yAxisFields && yAxisFields[0] && item[yAxisFields[0].field] ? item[yAxisFields[0].field] : 0,
31032
+ field: yAxisFields && yAxisFields[0] && yAxisFields[0].field,
31033
+ fields: yAxisFields
31034
+ })
31035
+ }
31036
+ )
31037
+ },
31038
+ item[xAxisField] + "value" + idx
31039
+ ))
31040
+ }
31041
+ )
31042
+ ]
31043
+ }
31044
+ )
31045
+ }
31046
+ );
31047
+ });
31048
+ var BarList_default = BarList;
30351
31049
 
30352
31050
  // src/components/Chart/PieChart.tsx
31051
+ var import_react13 = __toESM(require("react"), 1);
31052
+ var import_recharts = require("recharts");
30353
31053
  init_util();
30354
31054
  init_valueFormatter();
30355
31055
 
@@ -35101,16 +35801,9 @@ function BarChart({
35101
35801
  }
35102
35802
  return colorMap?.[field]?.[key];
35103
35803
  };
35104
- const sortYAxisFields = (fields) => {
35105
- if (data?.length > 0) {
35106
- fields = fields.sort(
35107
- (a, b) => Object.keys(data[0]).indexOf(a.field) - Object.keys(data[0]).indexOf(b.field)
35108
- ).filter(
35109
- (field) => comparison || !field.field.startsWith("comparison_")
35110
- );
35111
- }
35112
- return fields;
35113
- };
35804
+ const getVisibleYAxisFields = (fields) => fields.filter(
35805
+ ({ field }) => comparison || !field.startsWith("comparison_")
35806
+ );
35114
35807
  const valueDomain = (0, import_react18.useMemo)(
35115
35808
  () => stackedMode ? getStackedDomain(data, yAxisFields, comparison) : getDomain(data, yAxisFields, referenceLines),
35116
35809
  [stackedMode, data, yAxisFields, referenceLines, comparison]
@@ -35136,13 +35829,13 @@ function BarChart({
35136
35829
  const customBarShape = (0, import_react18.useMemo)(() => {
35137
35830
  if (!theme?.barChartCornerRadius && !theme?.barChartCornerRadiusRatio)
35138
35831
  return void 0;
35139
- return createCustomBar(sortYAxisFields([...yAxisFields]), theme, layout);
35832
+ return createCustomBar(getVisibleYAxisFields(yAxisFields), theme, layout);
35140
35833
  }, [isStacked, yAxisFields, theme, layout]);
35141
35834
  const customActiveBarShape = (0, import_react18.useMemo)(() => {
35142
35835
  if (!theme?.barChartCornerRadius && !theme?.barChartCornerRadiusRatio)
35143
35836
  return void 0;
35144
35837
  return createCustomBar(
35145
- sortYAxisFields([...yAxisFields]),
35838
+ getVisibleYAxisFields(yAxisFields),
35146
35839
  theme,
35147
35840
  layout,
35148
35841
  true
@@ -35316,9 +36009,9 @@ function BarChart({
35316
36009
  }
35317
36010
  const row = payload[0]?.payload ?? {};
35318
36011
  const activeLabel = label ?? row[xAxisField] ?? "";
35319
- const payloadItems = sortYAxisFields([
35320
- ...yAxisFields
35321
- ]).map((field) => {
36012
+ const payloadItems = getVisibleYAxisFields(
36013
+ yAxisFields
36014
+ ).map((field) => {
35322
36015
  const rawName = field.label;
35323
36016
  const name2 = rawName ? humanizeChartSeriesTooltipLabel(rawName) : "";
35324
36017
  return {
@@ -35371,7 +36064,7 @@ function BarChart({
35371
36064
  position: isHorizontalBars ? void 0 : { y: 0 }
35372
36065
  }
35373
36066
  ),
35374
- sortYAxisFields([...yAxisFields]).map((elem) => {
36067
+ getVisibleYAxisFields(yAxisFields).map((elem, index) => {
35375
36068
  return /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
35376
36069
  import_recharts4.Bar,
35377
36070
  {
@@ -35388,9 +36081,9 @@ function BarChart({
35388
36081
  style: {
35389
36082
  cursor: onClickChartElement ? "pointer" : void 0
35390
36083
  },
35391
- onClick: (bar, index, event) => {
36084
+ onClick: (bar, index2, event) => {
35392
36085
  event?.stopPropagation();
35393
- const payload = bar.payload ?? data[index] ?? {};
36086
+ const payload = bar.payload ?? data[index2] ?? {};
35394
36087
  onClickChartElement?.({
35395
36088
  ...payload,
35396
36089
  interactionType: "bar",
@@ -35411,11 +36104,11 @@ function BarChart({
35411
36104
  series: elem.field,
35412
36105
  value: payload[elem.field] ?? bar.value,
35413
36106
  row: payload,
35414
- index
36107
+ index: index2
35415
36108
  });
35416
36109
  }
35417
36110
  },
35418
- elem.field
36111
+ `${index}:${elem.field}`
35419
36112
  );
35420
36113
  }),
35421
36114
  referenceLines && referenceLines.map(({ label, query }) => /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
@@ -38499,13 +39192,23 @@ var ChartDataLoader = ({
38499
39192
  reportFilters,
38500
39193
  dashboardFilters
38501
39194
  ]);
38502
- const fetchReportHelper = async (useReportTask = true) => {
39195
+ const fetchReportHelper = async (useReportTask = true, reason = "unknown") => {
38503
39196
  if (!client || !filters) {
38504
39197
  if (!fetchReportAbortController.current) setLoading(false);
38505
39198
  return;
38506
39199
  }
38507
39200
  const fetchRowsRequestId = rowsRequestId.current + 1;
38508
39201
  rowsRequestId.current = fetchRowsRequestId;
39202
+ const startedAt = performance.now();
39203
+ profileDashboard("chart-data-loader-fetch-start", {
39204
+ reportId: item.id,
39205
+ requestId: fetchRowsRequestId,
39206
+ reason,
39207
+ useReportTask,
39208
+ triggerReload: (dashboardName ? dashboard : reports)[item.id]?.triggerReload,
39209
+ abortsPrevious: !!fetchReportAbortController.current,
39210
+ pivot: !!item.pivot
39211
+ });
38509
39212
  previousUserFilters.current = userFilters;
38510
39213
  previousDateBucket.current = dateBucket;
38511
39214
  setLoading(true);
@@ -38638,6 +39341,14 @@ var ChartDataLoader = ({
38638
39341
  });
38639
39342
  setError(e.message ?? "Error fetching report");
38640
39343
  } finally {
39344
+ profileDashboard("chart-data-loader-fetch-finish", {
39345
+ reportId: item.id,
39346
+ requestId: fetchRowsRequestId,
39347
+ reason,
39348
+ elapsedMs: Math.round(performance.now() - startedAt),
39349
+ isLatestRequest: fetchRowsRequestId === rowsRequestId.current,
39350
+ startsBackgroundFetch: !!backgroundFetch
39351
+ });
38641
39352
  if (fetchRowsRequestId === rowsRequestId.current) {
38642
39353
  fetchReportAbortController.current = null;
38643
39354
  setLoading(false);
@@ -38672,7 +39383,7 @@ var ChartDataLoader = ({
38672
39383
  previousTenants.current = tenants;
38673
39384
  previousFilters.current = filters;
38674
39385
  previousCustomFields.current = schemaData.customFields;
38675
- fetchReportHelper();
39386
+ fetchReportHelper(true, "inputs-effect");
38676
39387
  }, [
38677
39388
  filters,
38678
39389
  userFilters,
@@ -38684,8 +39395,13 @@ var ChartDataLoader = ({
38684
39395
  ]);
38685
39396
  (0, import_react26.useEffect)(() => {
38686
39397
  const tempReport = (dashboardName ? dashboard : reports)[item.id];
39398
+ profileDashboard("chart-data-loader-trigger-effect", {
39399
+ reportId: item.id,
39400
+ triggerReload: tempReport?.triggerReload ?? null,
39401
+ hasError: !!tempReport?.error
39402
+ });
38687
39403
  if (tempReport && tempReport.triggerReload) {
38688
- fetchReportHelper();
39404
+ fetchReportHelper(true, "trigger-reload-effect");
38689
39405
  } else if (tempReport?.error) {
38690
39406
  setError(tempReport.error);
38691
39407
  }
@@ -40324,7 +41040,6 @@ function QuillTableDashboardComponent({
40324
41040
  // src/Chart.tsx
40325
41041
  init_valueFormatter();
40326
41042
  var import_jsx_runtime50 = require("react/jsx-runtime");
40327
- var MAX_ROWS_FOR_GENERIC_TABLE = 500;
40328
41043
  function Chart({
40329
41044
  colors,
40330
41045
  reportId,
@@ -40606,6 +41321,14 @@ function Chart({
40606
41321
  }
40607
41322
  };
40608
41323
  (0, import_react32.useEffect)(() => {
41324
+ profileDashboard("chart-fetch-decision", {
41325
+ reportId,
41326
+ clientLoading,
41327
+ isDashboardsLoading,
41328
+ hasDashboardReport: !!dashboardReport,
41329
+ hasReport: !!reports[reportId],
41330
+ dashboardFiltersReady: dashboardFilters !== null
41331
+ });
40609
41332
  if (reportId === void 0 || reportId === "" || clientLoading || isDashboardsLoading) {
40610
41333
  return;
40611
41334
  }
@@ -40627,6 +41350,7 @@ function Chart({
40627
41350
  });
40628
41351
  setLoading(false);
40629
41352
  } else if (!reports[reportId]) {
41353
+ profileDashboard("chart-fetch-individual", { reportId });
40630
41354
  fetchReportHelper();
40631
41355
  return;
40632
41356
  }
@@ -40847,8 +41571,9 @@ var ChartDisplay = ({
40847
41571
  return void 0;
40848
41572
  }, [config, specificReportFilters, specificDashboardFilters]);
40849
41573
  const resolvedShowLegend = showLegend !== void 0 ? showLegend : config?.showLegend ?? false;
41574
+ const resolvedColorMap = resolveReportColorMap(config, chartColors, colorMap);
40850
41575
  const [page, setPage] = (0, import_react32.useState)(0);
40851
- const rowCountForLimit = config?.pivot ? config.pivotRowCount ?? config.pivotRows?.length ?? config.rows?.length : config?.rowCount ?? config?.rows?.length;
41576
+ const chartRenderLimitError = getChartRenderLimitError(config);
40852
41577
  const tableDisplay = (0, import_react32.useMemo)(() => {
40853
41578
  if (!config || config.chartType?.toLowerCase() !== "table") {
40854
41579
  return void 0;
@@ -40881,15 +41606,8 @@ var ChartDisplay = ({
40881
41606
  }, [config]);
40882
41607
  if (loading) {
40883
41608
  return /* @__PURE__ */ (0, import_jsx_runtime50.jsx)("div", { className, style: containerStyle, children: /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(LoadingComponent, {}) });
40884
- } else if (config && !["metric", "table", "gauge", "US map", "World map"].includes(
40885
- config.chartType
40886
- ) && rowCountForLimit !== void 0 && rowCountForLimit > MAX_ROWS_FOR_GENERIC_TABLE) {
40887
- return /* @__PURE__ */ (0, import_jsx_runtime50.jsx)("div", { style: containerStyle, className, children: /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
40888
- ErrorComponent,
40889
- {
40890
- errorMessage: `Charts can only display ${MAX_ROWS_FOR_GENERIC_TABLE} rows. Please modify the query.`
40891
- }
40892
- ) });
41609
+ } else if (chartRenderLimitError) {
41610
+ return /* @__PURE__ */ (0, import_jsx_runtime50.jsx)("div", { style: containerStyle, className, children: /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(ErrorComponent, { errorMessage: chartRenderLimitError }) });
40893
41611
  }
40894
41612
  if (config?.chartType?.toLowerCase() === "pie") {
40895
41613
  return /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
@@ -40955,7 +41673,7 @@ var ChartDisplay = ({
40955
41673
  xAxisFormat: config?.xAxisFormat ?? "string",
40956
41674
  containerStyle,
40957
41675
  className,
40958
- colorMap,
41676
+ colorMap: resolvedColorMap,
40959
41677
  onClickChartElement,
40960
41678
  scrollable,
40961
41679
  showAnimation: isAnimationActive
@@ -40981,7 +41699,7 @@ var ChartDisplay = ({
40981
41699
  hideXAxis,
40982
41700
  hideYAxis,
40983
41701
  hideCartesianGrid,
40984
- colorMap,
41702
+ colorMap: resolvedColorMap,
40985
41703
  onClickChartElement,
40986
41704
  onClickLegendElement,
40987
41705
  dateFilter: !hideDateRangeFilter ? dateFilter : void 0,
@@ -41009,7 +41727,7 @@ var ChartDisplay = ({
41009
41727
  hideXAxis,
41010
41728
  hideYAxis,
41011
41729
  hideCartesianGrid,
41012
- colorMap,
41730
+ colorMap: resolvedColorMap,
41013
41731
  onClickChartElement,
41014
41732
  onClickLegendElement,
41015
41733
  dateFilter: !hideDateRangeFilter ? dateFilter : void 0,
@@ -41131,7 +41849,7 @@ var ChartDisplay = ({
41131
41849
  xAxisFormat: config?.xAxisFormat ?? "string",
41132
41850
  containerStyle,
41133
41851
  className,
41134
- colorMap,
41852
+ colorMap: resolvedColorMap,
41135
41853
  onClickChartElement
41136
41854
  }
41137
41855
  );
@@ -41148,7 +41866,7 @@ var ChartDisplay = ({
41148
41866
  xAxisFormat: config?.xAxisFormat ?? "string",
41149
41867
  containerStyle,
41150
41868
  className,
41151
- colorMap,
41869
+ colorMap: resolvedColorMap,
41152
41870
  onClickChartElement
41153
41871
  }
41154
41872
  );
@@ -41158,7 +41876,7 @@ var ChartDisplay = ({
41158
41876
  RadarChart,
41159
41877
  {
41160
41878
  colors: chartColors,
41161
- colorMap,
41879
+ colorMap: resolvedColorMap,
41162
41880
  yAxisFields: config?.yAxisFields.sort(sortComparisonFirst) ?? [],
41163
41881
  data: config?.rows ?? [],
41164
41882
  xAxisField: config?.xAxisField ?? "",
@@ -41179,7 +41897,7 @@ var ChartDisplay = ({
41179
41897
  LineChart,
41180
41898
  {
41181
41899
  colors: chartColors,
41182
- colorMap,
41900
+ colorMap: resolvedColorMap,
41183
41901
  yAxisFields: config?.yAxisFields.sort(sortComparisonFirst) || [],
41184
41902
  data: config?.rows || [],
41185
41903
  xAxisField: config?.xAxisField || "",
@@ -44335,6 +45053,22 @@ function StaticChart(props) {
44335
45053
  prevPage,
44336
45054
  sortRows: sortRows3
44337
45055
  } = useDashboardReportInternal(reportId);
45056
+ (0, import_react41.useEffect)(() => {
45057
+ profileDashboard("static-chart-state", {
45058
+ reportId,
45059
+ loading,
45060
+ hasReport: !!report,
45061
+ error: error ?? null,
45062
+ rowCount: report?.rows?.length ?? 0,
45063
+ pivotRowCount: report?.pivotRows?.length ?? 0
45064
+ });
45065
+ }, [reportId, loading, report, error]);
45066
+ (0, import_react41.useEffect)(() => {
45067
+ profileDashboard("static-chart-mounted", { reportId });
45068
+ return () => {
45069
+ profileDashboard("static-chart-unmounted", { reportId });
45070
+ };
45071
+ }, [reportId]);
44338
45072
  const baseStyle = report?.chartType && CHART_TYPE_STYLES[report.chartType] ? CHART_TYPE_STYLES[report.chartType] : DEFAULT_STYLE;
44339
45073
  const mergedStyle = className ? { ...containerStyle ?? {} } : { ...baseStyle, ...containerStyle ?? {} };
44340
45074
  const safeContainerStyle = {
@@ -44359,13 +45093,12 @@ function StaticChart(props) {
44359
45093
  });
44360
45094
  };
44361
45095
  const useLocalPivotTablePagination = isDashboardPivotTable(report);
44362
- const config = (0, import_react41.useMemo)(() => {
44363
- return report ? {
44364
- ...report,
44365
- ...useLocalPivotTablePagination ? { pagination: void 0 } : {},
44366
- ...report.pivot ? formattedPivotRowsAndColumns(report, [], { formatRows: false }) : {}
44367
- } : void 0;
44368
- }, [report, useLocalPivotTablePagination]);
45096
+ const config = (0, import_react41.useMemo)(
45097
+ () => report ? prepareStaticChartReport(report, {
45098
+ removePagination: useLocalPivotTablePagination
45099
+ }) : void 0,
45100
+ [report, useLocalPivotTablePagination]
45101
+ );
44369
45102
  if (error) {
44370
45103
  return /* @__PURE__ */ (0, import_jsx_runtime60.jsx)(ChartError, { errorMessage: error, containerStyle: safeContainerStyle });
44371
45104
  }
@@ -59375,13 +60108,13 @@ function ChartEditor({
59375
60108
  }
59376
60109
 
59377
60110
  // src/Chat.tsx
59378
- var import_react64 = require("react");
60111
+ var import_react63 = require("react");
59379
60112
 
59380
60113
  // src/ChatChartCard.tsx
59381
- var import_react63 = require("react");
60114
+ var import_react62 = require("react");
59382
60115
 
59383
60116
  // src/hooks/useForm.tsx
59384
- var import_react62 = require("react");
60117
+ var import_react61 = require("react");
59385
60118
  var import_react_query3 = require("@tanstack/react-query");
59386
60119
  init_Filter();
59387
60120
  init_ReportBuilder();
@@ -60568,20 +61301,6 @@ function useFormReducer(state, action) {
60568
61301
  }
60569
61302
  }
60570
61303
 
60571
- // src/hooks/useForm.refreshDebounce.ts
60572
- var import_react61 = require("react");
60573
- var REPORT_REFRESH_DEBOUNCE_MS = 200;
60574
- function useDebouncedRefreshInput(value, delayMs = REPORT_REFRESH_DEBOUNCE_MS) {
60575
- const [debouncedValue, setDebouncedValue] = (0, import_react61.useState)(value);
60576
- (0, import_react61.useEffect)(() => {
60577
- const timeout = setTimeout(() => {
60578
- setDebouncedValue(value);
60579
- }, delayMs);
60580
- return () => clearTimeout(timeout);
60581
- }, [delayMs, value]);
60582
- return debouncedValue;
60583
- }
60584
-
60585
61304
  // src/utils/pivotDateBuckets.ts
60586
61305
  var import_date_fns18 = require("date-fns");
60587
61306
  function buildPivotDateBucketStarts(range, bucket) {
@@ -61710,22 +62429,6 @@ var buildQueryBuilderFieldConfigByName = (schemaTables) => {
61710
62429
  function getReportBuilderTableNames(report) {
61711
62430
  return (report?.reportBuilderState?.tables ?? []).map((table) => String(table.name ?? "").trim()).filter(Boolean);
61712
62431
  }
61713
- function getPivotAggregations(report) {
61714
- const pivot = report.pivot;
61715
- if (!pivot) return [];
61716
- if ("aggregations" in pivot && Array.isArray(pivot.aggregations)) {
61717
- return pivot.aggregations;
61718
- }
61719
- if ("aggregationType" in pivot && pivot.aggregationType) {
61720
- return [
61721
- {
61722
- aggregationType: pivot.aggregationType,
61723
- valueField: pivot.valueField
61724
- }
61725
- ];
61726
- }
61727
- return [];
61728
- }
61729
62432
  function trimAggregationSuffix(value, aggregationType) {
61730
62433
  if (!aggregationType) return value;
61731
62434
  const suffixes = [`_${aggregationType}`, `:${aggregationType}`];
@@ -61733,16 +62436,6 @@ function trimAggregationSuffix(value, aggregationType) {
61733
62436
  if (!matchedSuffix) return value;
61734
62437
  return value.slice(0, -matchedSuffix.length);
61735
62438
  }
61736
- function getAggregationFieldKey(aggregation, hasMultipleAggregations) {
61737
- if (!aggregation.aggregationType) return null;
61738
- if (!aggregation.valueField && aggregation.aggregationType === "percentage") {
61739
- return "percentage";
61740
- }
61741
- if (aggregation.valueField) {
61742
- return hasMultipleAggregations ? `${aggregation.valueField}_${aggregation.aggregationType}` : aggregation.valueField;
61743
- }
61744
- return hasMultipleAggregations ? `${aggregation.aggregationType}_${aggregation.aggregationType}` : String(aggregation.aggregationType);
61745
- }
61746
62439
  function buildSyntheticAggregationOnlyDisplayRows(chart) {
61747
62440
  const pivot = chart.pivot;
61748
62441
  if (!pivot) return null;
@@ -61782,69 +62475,6 @@ function buildSyntheticAggregationOnlyDisplayRows(chart) {
61782
62475
  }
61783
62476
  return null;
61784
62477
  }
61785
- function trailingPivotMeasureSegmentBeforeAggType(normalizedField, normalizedAggregationType) {
61786
- const suf = `_${normalizedAggregationType}`;
61787
- if (!normalizedField.endsWith(suf)) return null;
61788
- const base = normalizedField.slice(0, -suf.length);
61789
- const lastUnderscore = base.lastIndexOf("_");
61790
- if (lastUnderscore < 0) return null;
61791
- const candidate = base.slice(lastUnderscore + 1).trim();
61792
- return candidate || null;
61793
- }
61794
- var PIVOT_FIELD_AGG_MATCH_TIER = {
61795
- looseAggSuffix: 1,
61796
- rawValueField: 2,
61797
- pivotWideValueAndAggSuffix: 3,
61798
- canonicalValueAggOrCount: 4
61799
- };
61800
- function matchPivotFieldToAggregationTier(normalizedField, aggregation) {
61801
- const aggregationType = String(aggregation.aggregationType ?? "").trim();
61802
- if (!aggregationType) return null;
61803
- const t = aggregationType.toLowerCase();
61804
- const vf = String(aggregation.valueField ?? "").trim().toLowerCase();
61805
- if (!vf && normalizedField === t) {
61806
- return PIVOT_FIELD_AGG_MATCH_TIER.canonicalValueAggOrCount;
61807
- }
61808
- if (vf && normalizedField === vf) {
61809
- return PIVOT_FIELD_AGG_MATCH_TIER.rawValueField;
61810
- }
61811
- if (vf && normalizedField === `${vf}_${t}`) {
61812
- return PIVOT_FIELD_AGG_MATCH_TIER.canonicalValueAggOrCount;
61813
- }
61814
- if (vf && normalizedField.endsWith(`_${vf}_${t}`)) {
61815
- return PIVOT_FIELD_AGG_MATCH_TIER.pivotWideValueAndAggSuffix;
61816
- }
61817
- if (normalizedField.endsWith(`_${t}`) || normalizedField.endsWith(`:${t}`)) {
61818
- const embeddedMeasure = trailingPivotMeasureSegmentBeforeAggType(
61819
- normalizedField,
61820
- t
61821
- );
61822
- if (embeddedMeasure && vf && embeddedMeasure !== vf) {
61823
- return null;
61824
- }
61825
- return PIVOT_FIELD_AGG_MATCH_TIER.looseAggSuffix;
61826
- }
61827
- return null;
61828
- }
61829
- function findAggregationForFieldStrict(field, aggregations) {
61830
- const normalizedField = String(field ?? "").trim().toLowerCase();
61831
- let best = null;
61832
- for (let index = 0; index < aggregations.length; index++) {
61833
- const aggregation = aggregations[index];
61834
- const tier = matchPivotFieldToAggregationTier(normalizedField, aggregation);
61835
- if (tier == null) continue;
61836
- if (!best || tier > best.tier || tier === best.tier && index < best.index) {
61837
- best = { aggregation, tier, index };
61838
- }
61839
- }
61840
- return best?.aggregation;
61841
- }
61842
- function getAggregationIdentityKey(aggregation) {
61843
- if (!aggregation) return "";
61844
- const aggregationType = String(aggregation.aggregationType ?? "").trim().toLowerCase();
61845
- const valueField = String(aggregation.valueField ?? "").trim().toLowerCase();
61846
- return `${aggregationType}::${valueField}`;
61847
- }
61848
62478
  function buildAggregationLabel(aggregation, report) {
61849
62479
  const aggregationType = aggregation.aggregationType ?? "value";
61850
62480
  const reportBuilderTableNames = report?.reportBuilderState?.tables?.map((table) => table.name).filter(Boolean) ?? [];
@@ -64394,10 +65024,10 @@ function generateDraftSessionId() {
64394
65024
  }
64395
65025
  function useReport(reportIdArg, options = {}) {
64396
65026
  const propReportId = String(reportIdArg ?? "").trim();
64397
- const [createdReportBootstrap, setCreatedReportBootstrap] = (0, import_react62.useState)(null);
65027
+ const [createdReportBootstrap, setCreatedReportBootstrap] = (0, import_react61.useState)(null);
64398
65028
  const effectiveReportId = propReportId || createdReportBootstrap?.reportId || "";
64399
- const { eventTracking } = (0, import_react62.useContext)(EventTrackingContext);
64400
- const [draftSessionId, setDraftSessionId] = (0, import_react62.useState)(generateDraftSessionId);
65029
+ const { eventTracking } = (0, import_react61.useContext)(EventTrackingContext);
65030
+ const [draftSessionId, setDraftSessionId] = (0, import_react61.useState)(generateDraftSessionId);
64401
65031
  const useInMemoryEngines = options.useInMemoryEngines ?? false;
64402
65032
  const dateBucketMode = options.dateBucketMode ?? "dynamic";
64403
65033
  const restrictFieldOptionsToSelectedDatasources = options.restrictFieldOptionsToSelectedDatasources ?? true;
@@ -64407,24 +65037,24 @@ function useReport(reportIdArg, options = {}) {
64407
65037
  options.destinationDashboardName ?? ""
64408
65038
  ).trim();
64409
65039
  const controlledPagination = options.state?.pagination;
64410
- const initialPaginationRef = (0, import_react62.useRef)({
65040
+ const initialPaginationRef = (0, import_react61.useRef)({
64411
65041
  ...getDefaultPaginationState(),
64412
65042
  ...options.initialState?.pagination ?? {}
64413
65043
  });
64414
- const [internalPagination, setInternalPagination] = (0, import_react62.useState)(
65044
+ const [internalPagination, setInternalPagination] = (0, import_react61.useState)(
64415
65045
  initialPaginationRef.current
64416
65046
  );
64417
65047
  const pagination = controlledPagination ?? internalPagination;
64418
- const paginationRef = (0, import_react62.useRef)(pagination);
65048
+ const paginationRef = (0, import_react61.useRef)(pagination);
64419
65049
  paginationRef.current = pagination;
64420
- const onPaginationChangeRef = (0, import_react62.useRef)(options.onPaginationChange);
65050
+ const onPaginationChangeRef = (0, import_react61.useRef)(options.onPaginationChange);
64421
65051
  onPaginationChangeRef.current = options.onPaginationChange;
64422
- const controlledPaginationRef = (0, import_react62.useRef)(Boolean(controlledPagination));
65052
+ const controlledPaginationRef = (0, import_react61.useRef)(Boolean(controlledPagination));
64423
65053
  controlledPaginationRef.current = Boolean(controlledPagination);
64424
- const autoResetPageIndexRef = (0, import_react62.useRef)(true);
65054
+ const autoResetPageIndexRef = (0, import_react61.useRef)(true);
64425
65055
  autoResetPageIndexRef.current = options.autoResetPageIndex ?? true;
64426
- const paginationPageCountRef = (0, import_react62.useRef)(-1);
64427
- const applyPaginationUpdate = (0, import_react62.useCallback)(
65056
+ const paginationPageCountRef = (0, import_react61.useRef)(-1);
65057
+ const applyPaginationUpdate = (0, import_react61.useCallback)(
64428
65058
  (updater) => {
64429
65059
  onPaginationChangeRef.current?.(updater);
64430
65060
  if (!controlledPaginationRef.current) {
@@ -64433,11 +65063,11 @@ function useReport(reportIdArg, options = {}) {
64433
65063
  },
64434
65064
  []
64435
65065
  );
64436
- const setPagination = (0, import_react62.useCallback)(
65066
+ const setPagination = (0, import_react61.useCallback)(
64437
65067
  (updater) => applyPaginationUpdate(updater),
64438
65068
  [applyPaginationUpdate]
64439
65069
  );
64440
- const setPageIndex = (0, import_react62.useCallback)(
65070
+ const setPageIndex = (0, import_react61.useCallback)(
64441
65071
  (updater) => applyPaginationUpdate((old) => ({
64442
65072
  ...old,
64443
65073
  pageIndex: clampPageIndex(
@@ -64447,7 +65077,7 @@ function useReport(reportIdArg, options = {}) {
64447
65077
  })),
64448
65078
  [applyPaginationUpdate]
64449
65079
  );
64450
- const setPageSize = (0, import_react62.useCallback)(
65080
+ const setPageSize = (0, import_react61.useCallback)(
64451
65081
  (updater) => applyPaginationUpdate(
64452
65082
  (old) => paginationStateAfterPageSizeChange(
64453
65083
  old,
@@ -64456,46 +65086,46 @@ function useReport(reportIdArg, options = {}) {
64456
65086
  ),
64457
65087
  [applyPaginationUpdate]
64458
65088
  );
64459
- const resetPagination = (0, import_react62.useCallback)(
65089
+ const resetPagination = (0, import_react61.useCallback)(
64460
65090
  (defaultState) => applyPaginationUpdate(
64461
65091
  defaultState ? getDefaultPaginationState() : initialPaginationRef.current
64462
65092
  ),
64463
65093
  [applyPaginationUpdate]
64464
65094
  );
64465
- const resetPageIndex = (0, import_react62.useCallback)(
65095
+ const resetPageIndex = (0, import_react61.useCallback)(
64466
65096
  (defaultState) => {
64467
65097
  const target = defaultState ? 0 : initialPaginationRef.current.pageIndex;
64468
65098
  setPageIndex(target);
64469
65099
  },
64470
65100
  [setPageIndex]
64471
65101
  );
64472
- const resetPageSize = (0, import_react62.useCallback)(
65102
+ const resetPageSize = (0, import_react61.useCallback)(
64473
65103
  (defaultState) => {
64474
65104
  const target = defaultState ? getDefaultPaginationState().pageSize : initialPaginationRef.current.pageSize;
64475
65105
  setPageSize(target);
64476
65106
  },
64477
65107
  [setPageSize]
64478
65108
  );
64479
- const nextPage = (0, import_react62.useCallback)(
65109
+ const nextPage = (0, import_react61.useCallback)(
64480
65110
  () => setPageIndex((old) => old + 1),
64481
65111
  [setPageIndex]
64482
65112
  );
64483
- const previousPage = (0, import_react62.useCallback)(
65113
+ const previousPage = (0, import_react61.useCallback)(
64484
65114
  () => setPageIndex((old) => old - 1),
64485
65115
  [setPageIndex]
64486
65116
  );
64487
- const firstPage = (0, import_react62.useCallback)(() => setPageIndex(0), [setPageIndex]);
64488
- const lastPage = (0, import_react62.useCallback)(
65117
+ const firstPage = (0, import_react61.useCallback)(() => setPageIndex(0), [setPageIndex]);
65118
+ const lastPage = (0, import_react61.useCallback)(
64489
65119
  () => setPageIndex(paginationPageCountRef.current - 1),
64490
65120
  [setPageIndex]
64491
65121
  );
64492
- const chartPivotHydratedFromSourceRef = (0, import_react62.useRef)(false);
64493
- const lastPivotHydrateCompletedSourceIdRef = (0, import_react62.useRef)(null);
64494
- const groupRowsBySetViaSetReportRef = (0, import_react62.useRef)(false);
64495
- const groupColumnsBySetViaSetReportRef = (0, import_react62.useRef)(false);
64496
- const dateBucketSetViaSetReportRef = (0, import_react62.useRef)(false);
64497
- const aggregationStateSetViaSetReportRef = (0, import_react62.useRef)(false);
64498
- const prevReportIdForChartPivotHydrationRef = (0, import_react62.useRef)(effectiveReportId);
65122
+ const chartPivotHydratedFromSourceRef = (0, import_react61.useRef)(false);
65123
+ const lastPivotHydrateCompletedSourceIdRef = (0, import_react61.useRef)(null);
65124
+ const groupRowsBySetViaSetReportRef = (0, import_react61.useRef)(false);
65125
+ const groupColumnsBySetViaSetReportRef = (0, import_react61.useRef)(false);
65126
+ const dateBucketSetViaSetReportRef = (0, import_react61.useRef)(false);
65127
+ const aggregationStateSetViaSetReportRef = (0, import_react61.useRef)(false);
65128
+ const prevReportIdForChartPivotHydrationRef = (0, import_react61.useRef)(effectiveReportId);
64499
65129
  if (prevReportIdForChartPivotHydrationRef.current !== effectiveReportId) {
64500
65130
  prevReportIdForChartPivotHydrationRef.current = effectiveReportId;
64501
65131
  chartPivotHydratedFromSourceRef.current = false;
@@ -64504,16 +65134,16 @@ function useReport(reportIdArg, options = {}) {
64504
65134
  dateBucketSetViaSetReportRef.current = false;
64505
65135
  aggregationStateSetViaSetReportRef.current = false;
64506
65136
  }
64507
- const [chartPivotHydrationEpoch, setChartPivotHydrationEpoch] = (0, import_react62.useState)(0);
65137
+ const [chartPivotHydrationEpoch, setChartPivotHydrationEpoch] = (0, import_react61.useState)(0);
64508
65138
  const [
64509
65139
  expandReportBuilderColumnsForFlatTable,
64510
65140
  setExpandReportBuilderColumnsForFlatTable
64511
- ] = (0, import_react62.useState)(false);
64512
- const prevPivotStateForColumnExpansionRef = (0, import_react62.useRef)(null);
64513
- const [sourceReport, setSourceReport] = (0, import_react62.useState)(
65141
+ ] = (0, import_react61.useState)(false);
65142
+ const prevPivotStateForColumnExpansionRef = (0, import_react61.useRef)(null);
65143
+ const [sourceReport, setSourceReport] = (0, import_react61.useState)(
64514
65144
  null
64515
65145
  );
64516
- const prevSourceReportIdForPivotHydrationRef = (0, import_react62.useRef)(null);
65146
+ const prevSourceReportIdForPivotHydrationRef = (0, import_react61.useRef)(null);
64517
65147
  {
64518
65148
  const currentSourceId = sourceReport ? String(
64519
65149
  sourceReport.id ?? sourceReport._id ?? ""
@@ -64525,21 +65155,23 @@ function useReport(reportIdArg, options = {}) {
64525
65155
  lastPivotHydrateCompletedSourceIdRef.current = null;
64526
65156
  }
64527
65157
  }
64528
- const [preserveSchemaWideOptions, setPreserveSchemaWideOptions] = (0, import_react62.useState)(false);
64529
- const [initialSchemaScopedTableNames, setInitialSchemaScopedTableNames] = (0, import_react62.useState)(null);
64530
- const [tableColumnsEditedSignature, setTableColumnsEditedSignature] = (0, import_react62.useState)(null);
64531
- (0, import_react62.useEffect)(() => {
65158
+ const [preserveSchemaWideOptions, setPreserveSchemaWideOptions] = (0, import_react61.useState)(false);
65159
+ const [initialSchemaScopedTableNames, setInitialSchemaScopedTableNames] = (0, import_react61.useState)(null);
65160
+ const [tableColumnsEditedSignature, setTableColumnsEditedSignature] = (0, import_react61.useState)(null);
65161
+ (0, import_react61.useEffect)(() => {
64532
65162
  setTableColumnsEditedSignature(null);
64533
65163
  }, [effectiveReportId]);
64534
- const [chartAxisEdits, setChartAxisEdits] = (0, import_react62.useState)({});
64535
- const [chartVisibilityOverrides, setChartVisibilityOverrides] = (0, import_react62.useState)({});
64536
- const [client] = (0, import_react62.useContext)(ClientContext);
65164
+ const [chartAxisEdits, setChartAxisEdits] = (0, import_react61.useState)({});
65165
+ const [chartVisibilityOverrides, setChartVisibilityOverrides] = (0, import_react61.useState)({});
65166
+ const [chartSortOverride, setChartSortOverride] = (0, import_react61.useState)(void 0);
65167
+ const [client] = (0, import_react61.useContext)(ClientContext);
65168
+ const { loadDashboard } = (0, import_react61.useContext)(DashboardConfigContext);
64537
65169
  const queryClient = (0, import_react_query3.useQueryClient)();
64538
- const [schemaData] = (0, import_react62.useContext)(SchemaDataContext);
64539
- const { tenants, flags } = (0, import_react62.useContext)(TenantContext);
64540
- const { getToken } = (0, import_react62.useContext)(FetchContext);
64541
- const { getCacheCab } = (0, import_react62.useContext)(CacheCabContext);
64542
- const cacheCab = (0, import_react62.useMemo)(() => getCacheCab(), [getCacheCab]);
65170
+ const [schemaData] = (0, import_react61.useContext)(SchemaDataContext);
65171
+ const { tenants, flags } = (0, import_react61.useContext)(TenantContext);
65172
+ const { getToken } = (0, import_react61.useContext)(FetchContext);
65173
+ const { getCacheCab } = (0, import_react61.useContext)(CacheCabContext);
65174
+ const cacheCab = (0, import_react61.useMemo)(() => getCacheCab(), [getCacheCab]);
64543
65175
  const clientDefaultDashboardName = String(
64544
65176
  client?.defaultDashboard?.name ?? ""
64545
65177
  ).trim();
@@ -64548,7 +65180,7 @@ function useReport(reportIdArg, options = {}) {
64548
65180
  clientDefaultDashboardName,
64549
65181
  destinationDashboardName
64550
65182
  ].map((entry) => String(entry ?? "").trim()).find((entry) => entry.length > 0) ?? "";
64551
- const initialFormState = (0, import_react62.useMemo)(
65183
+ const initialFormState = (0, import_react61.useMemo)(
64552
65184
  () => ({
64553
65185
  reportName: void 0,
64554
65186
  columns: [],
@@ -64568,7 +65200,7 @@ function useReport(reportIdArg, options = {}) {
64568
65200
  }),
64569
65201
  []
64570
65202
  );
64571
- const [formRuntimeState, dispatchFormRuntime] = (0, import_react62.useReducer)(
65203
+ const [formRuntimeState, dispatchFormRuntime] = (0, import_react61.useReducer)(
64572
65204
  useFormReducer,
64573
65205
  initialFormState,
64574
65206
  createInitialUseFormReducerState
@@ -64598,13 +65230,13 @@ function useReport(reportIdArg, options = {}) {
64598
65230
  schemaDatasourceIds
64599
65231
  } = formState;
64600
65232
  const schemaDatasourceIdsKey = schemaDatasourceIds?.map((id) => String(id ?? "").trim()).join("\0") ?? "";
64601
- const queryColumnsBootstrapKey = (0, import_react62.useMemo)(
65233
+ const queryColumnsBootstrapKey = (0, import_react61.useMemo)(
64602
65234
  () => queryColumns.map(
64603
65235
  (c) => `${String(c.table ?? "").trim()}\0${String(c.field ?? "").trim()}`
64604
65236
  ).join("\n"),
64605
65237
  [queryColumns]
64606
65238
  );
64607
- const dashboardNameForNewReport = (0, import_react62.useMemo)(() => {
65239
+ const dashboardNameForNewReport = (0, import_react61.useMemo)(() => {
64608
65240
  return [clientDefaultDashboardName, destinationDashboardName].map((entry) => String(entry ?? "").trim()).find((entry) => entry.length > 0) ?? "";
64609
65241
  }, [clientDefaultDashboardName, destinationDashboardName]);
64610
65242
  const { mutate: createReport } = (0, import_react_query3.useMutation)({
@@ -64651,22 +65283,23 @@ function useReport(reportIdArg, options = {}) {
64651
65283
  };
64652
65284
  }
64653
65285
  });
64654
- const filterStackRef = (0, import_react62.useRef)(filterStack);
65286
+ const filterStackRef = (0, import_react61.useRef)(filterStack);
64655
65287
  filterStackRef.current = filterStack;
64656
65288
  const resolvedGroupRowsBy = decodePivotGroupOptionValue(groupRowsBy);
64657
65289
  const resolvedGroupColumnsBy = decodePivotGroupOptionValue(groupColumnsBy);
64658
- (0, import_react62.useEffect)(() => {
65290
+ (0, import_react61.useEffect)(() => {
64659
65291
  if (propReportId) {
64660
65292
  setCreatedReportBootstrap(null);
64661
65293
  }
64662
65294
  }, [propReportId]);
64663
- (0, import_react62.useEffect)(() => {
65295
+ (0, import_react61.useEffect)(() => {
64664
65296
  setChartAxisEdits({});
64665
65297
  setChartVisibilityOverrides({});
65298
+ setChartSortOverride(void 0);
64666
65299
  }, [effectiveReportId]);
64667
- const bootstrapReportTaskUsedForReportIdRef = (0, import_react62.useRef)(null);
64668
- const sharedInitialRequestUsedForReportIdRef = (0, import_react62.useRef)(null);
64669
- const schemaScopeInitializedForReportIdRef = (0, import_react62.useRef)(null);
65300
+ const bootstrapReportTaskUsedForReportIdRef = (0, import_react61.useRef)(null);
65301
+ const sharedInitialRequestUsedForReportIdRef = (0, import_react61.useRef)(null);
65302
+ const schemaScopeInitializedForReportIdRef = (0, import_react61.useRef)(null);
64670
65303
  const initializeSchemaScopeForReport = (report) => {
64671
65304
  if (!report) return;
64672
65305
  if (schemaScopeInitializedForReportIdRef.current === effectiveReportId)
@@ -64679,16 +65312,16 @@ function useReport(reportIdArg, options = {}) {
64679
65312
  );
64680
65313
  schemaScopeInitializedForReportIdRef.current = effectiveReportId;
64681
65314
  };
64682
- const internalFilters = (0, import_react62.useMemo)(
65315
+ const internalFilters = (0, import_react61.useMemo)(
64683
65316
  () => internalFiltersFromFilterStack(filterStack),
64684
65317
  [filterStack]
64685
65318
  );
64686
- const customFilters = (0, import_react62.useMemo)(
65319
+ const customFilters = (0, import_react61.useMemo)(
64687
65320
  () => customFiltersFromFilterStack(filterStack),
64688
65321
  [filterStack]
64689
65322
  );
64690
65323
  const forceIncompleteCacheCabForParity = process.env.NODE_ENV === "test" && process.env.QUILL_FORCE_INCOMPLETE_CACHECAB_FOR_PARITY === "true";
64691
- const resolveCachedReport = (0, import_react62.useCallback)(
65324
+ const resolveCachedReport = (0, import_react61.useCallback)(
64692
65325
  async ({
64693
65326
  reportBuilderState,
64694
65327
  filters,
@@ -64736,18 +65369,18 @@ function useReport(reportIdArg, options = {}) {
64736
65369
  tenants
64737
65370
  ]
64738
65371
  );
64739
- const reloadKey = (0, import_react62.useMemo)(() => 0, []);
64740
- const schemaForReportBuilderState = (0, import_react62.useMemo)(() => {
65372
+ const reloadKey = (0, import_react61.useMemo)(() => 0, []);
65373
+ const schemaForReportBuilderState = (0, import_react61.useMemo)(() => {
64741
65374
  if (schemaData.schemaWithCustomFields?.length) {
64742
65375
  return schemaData.schemaWithCustomFields;
64743
65376
  }
64744
65377
  return schemaData.schema ?? [];
64745
65378
  }, [schemaData.schema, schemaData.schemaWithCustomFields]);
64746
- const schemaForReportBuilderStateRef = (0, import_react62.useRef)(schemaForReportBuilderState);
64747
- const customFieldsRef = (0, import_react62.useRef)(schemaData.customFields);
65379
+ const schemaForReportBuilderStateRef = (0, import_react61.useRef)(schemaForReportBuilderState);
65380
+ const customFieldsRef = (0, import_react61.useRef)(schemaData.customFields);
64748
65381
  schemaForReportBuilderStateRef.current = schemaForReportBuilderState;
64749
65382
  customFieldsRef.current = schemaData.customFields;
64750
- const isBoolAggregationField = (0, import_react62.useCallback)(
65383
+ const isBoolAggregationField = (0, import_react61.useCallback)(
64751
65384
  (field, table2) => {
64752
65385
  const fieldType = resolveFieldType({
64753
65386
  field,
@@ -64760,11 +65393,11 @@ function useReport(reportIdArg, options = {}) {
64760
65393
  },
64761
65394
  []
64762
65395
  );
64763
- const schemaForeignKeyMap = (0, import_react62.useMemo)(
65396
+ const schemaForeignKeyMap = (0, import_react61.useMemo)(
64764
65397
  () => getSchemaForeignKeyMapping(schemaForReportBuilderState),
64765
65398
  [schemaForReportBuilderState]
64766
65399
  );
64767
- const datasourceJoinOptionsByTable = (0, import_react62.useMemo)(() => {
65400
+ const datasourceJoinOptionsByTable = (0, import_react61.useMemo)(() => {
64768
65401
  const tableNames = new Set(
64769
65402
  schemaForReportBuilderState.map((table2) => String(table2.name ?? "").trim()).filter(Boolean)
64770
65403
  );
@@ -64790,14 +65423,14 @@ function useReport(reportIdArg, options = {}) {
64790
65423
  );
64791
65424
  }, [schemaForReportBuilderState, schemaForeignKeyMap]);
64792
65425
  const reportBuilderBaseTableNamesKey = (sourceReport?.reportBuilderState?.tables ?? []).map((t) => String(t?.name ?? "").trim()).filter(Boolean).join("\0") ?? "";
64793
- const selectedBaseTableNamesForFieldOptions = (0, import_react62.useMemo)(() => {
65426
+ const selectedBaseTableNamesForFieldOptions = (0, import_react61.useMemo)(() => {
64794
65427
  const fromPicker = schemaDatasourceIds?.map((id) => String(id ?? "").trim()).filter(Boolean) ?? [];
64795
65428
  if (fromPicker.length > 0) {
64796
65429
  return fromPicker;
64797
65430
  }
64798
65431
  return (sourceReport?.reportBuilderState?.tables ?? []).map((t) => String(t?.name ?? "").trim()).filter(Boolean);
64799
65432
  }, [schemaDatasourceIdsKey, reportBuilderBaseTableNamesKey]);
64800
- const fieldOptionsAllowedTableNames = (0, import_react62.useMemo)(() => {
65433
+ const fieldOptionsAllowedTableNames = (0, import_react61.useMemo)(() => {
64801
65434
  if (!restrictFieldOptionsToSelectedDatasources) {
64802
65435
  return null;
64803
65436
  }
@@ -64809,7 +65442,7 @@ function useReport(reportIdArg, options = {}) {
64809
65442
  restrictFieldOptionsToSelectedDatasources,
64810
65443
  selectedBaseTableNamesForFieldOptions
64811
65444
  ]);
64812
- (0, import_react62.useEffect)(() => {
65445
+ (0, import_react61.useEffect)(() => {
64813
65446
  if (reportOverride) return;
64814
65447
  if (propReportId) return;
64815
65448
  if (createdReportBootstrap) return;
@@ -64874,7 +65507,7 @@ function useReport(reportIdArg, options = {}) {
64874
65507
  schemaForReportBuilderState,
64875
65508
  queryColumnsBootstrapKey
64876
65509
  ]);
64877
- const datasourceOptions = (0, import_react62.useMemo)(() => {
65510
+ const datasourceOptions = (0, import_react61.useMemo)(() => {
64878
65511
  const seen = /* @__PURE__ */ new Set();
64879
65512
  const result = [];
64880
65513
  for (const table2 of schemaForReportBuilderState) {
@@ -64889,7 +65522,7 @@ function useReport(reportIdArg, options = {}) {
64889
65522
  }
64890
65523
  return result;
64891
65524
  }, [schemaForReportBuilderState, datasourceJoinOptionsByTable]);
64892
- const queryBuilderFieldConfigByName = (0, import_react62.useMemo)(() => {
65525
+ const queryBuilderFieldConfigByName = (0, import_react61.useMemo)(() => {
64893
65526
  const configByName = buildQueryBuilderFieldConfigByName(
64894
65527
  schemaForReportBuilderState
64895
65528
  );
@@ -65023,7 +65656,7 @@ function useReport(reportIdArg, options = {}) {
65023
65656
  sourceReport?.columns,
65024
65657
  sourceReport?.reportBuilderState?.columns
65025
65658
  ]);
65026
- const filterUniqueValuesRequest = (0, import_react62.useMemo)(() => {
65659
+ const filterUniqueValuesRequest = (0, import_react61.useMemo)(() => {
65027
65660
  const dashboardName = resolvedSourceDashboardName;
65028
65661
  const reportBuilderStateFromSource = sourceReport?.reportBuilderState;
65029
65662
  const isStringReportBuilderColumn = (column) => {
@@ -65240,13 +65873,13 @@ function useReport(reportIdArg, options = {}) {
65240
65873
  sourceReport?.reportBuilderState,
65241
65874
  resolvedSourceDashboardName
65242
65875
  ]);
65243
- const filterUniqueValuesRequestHash = (0, import_react62.useMemo)(
65876
+ const filterUniqueValuesRequestHash = (0, import_react61.useMemo)(
65244
65877
  () => stableSerializeForQueryKey(
65245
65878
  filterUniqueValuesRequestForQueryKey(filterUniqueValuesRequest)
65246
65879
  ),
65247
65880
  [filterUniqueValuesRequest]
65248
65881
  );
65249
- const customFiltersHashForUniqueValues = (0, import_react62.useMemo)(
65882
+ const customFiltersHashForUniqueValues = (0, import_react61.useMemo)(
65250
65883
  () => stableSerializeForQueryKey(customFilters),
65251
65884
  [customFilters]
65252
65885
  );
@@ -65355,7 +65988,7 @@ function useReport(reportIdArg, options = {}) {
65355
65988
  gcTime: 15 * 6e4,
65356
65989
  placeholderData: import_react_query3.keepPreviousData
65357
65990
  });
65358
- const backendUniqueValuesByFieldName = (0, import_react62.useMemo)(() => {
65991
+ const backendUniqueValuesByFieldName = (0, import_react61.useMemo)(() => {
65359
65992
  const valuesByField = /* @__PURE__ */ new Map();
65360
65993
  const uniqueValuesByColumn = filterUniqueValuesQuery.data?.uniqueValuesByColumn;
65361
65994
  if (!uniqueValuesByColumn || typeof uniqueValuesByColumn !== "object") {
@@ -65388,7 +66021,7 @@ function useReport(reportIdArg, options = {}) {
65388
66021
  filterUniqueValuesQuery.data?.uniqueValuesByColumn,
65389
66022
  filterUniqueValuesRequest?.stringColumnsByTable
65390
66023
  ]);
65391
- const filterValueOptionsByFieldName = (0, import_react62.useMemo)(() => {
66024
+ const filterValueOptionsByFieldName = (0, import_react61.useMemo)(() => {
65392
66025
  const optionsByField = /* @__PURE__ */ new Map();
65393
66026
  const selectedMultiselectByField = collectSelectedStringMultiselectValuesByField(queryFilters);
65394
66027
  const collectValuesForField = (fieldName) => {
@@ -65454,7 +66087,7 @@ function useReport(reportIdArg, options = {}) {
65454
66087
  queryBuilderFieldConfigByName,
65455
66088
  queryFilters
65456
66089
  ]);
65457
- const filterFieldsComputed = (0, import_react62.useMemo)(() => {
66090
+ const filterFieldsComputed = (0, import_react61.useMemo)(() => {
65458
66091
  const fields = [];
65459
66092
  const seen = /* @__PURE__ */ new Set();
65460
66093
  const addField = (fieldName, fieldType, tableName, rawFieldName) => {
@@ -65555,9 +66188,9 @@ function useReport(reportIdArg, options = {}) {
65555
66188
  queryBuilderFieldConfigByName,
65556
66189
  queryFilters
65557
66190
  ]);
65558
- const filterFieldsStableReportIdRef = (0, import_react62.useRef)("");
65559
- const filterFieldsStableCacheRef = (0, import_react62.useRef)([]);
65560
- const filterFields = (0, import_react62.useMemo)(() => {
66191
+ const filterFieldsStableReportIdRef = (0, import_react61.useRef)("");
66192
+ const filterFieldsStableCacheRef = (0, import_react61.useRef)([]);
66193
+ const filterFields = (0, import_react61.useMemo)(() => {
65561
66194
  const rid = String(effectiveReportId ?? "");
65562
66195
  if (filterFieldsStableReportIdRef.current !== rid) {
65563
66196
  filterFieldsStableReportIdRef.current = rid;
@@ -65572,14 +66205,14 @@ function useReport(reportIdArg, options = {}) {
65572
66205
  }
65573
66206
  return filterFieldsComputed;
65574
66207
  }, [effectiveReportId, filterFieldsComputed]);
65575
- const getFilterOperators = (0, import_react62.useMemo)(
66208
+ const getFilterOperators = (0, import_react61.useMemo)(
65576
66209
  () => (_field, misc) => {
65577
66210
  const fieldType = misc?.fieldData?.quillFieldType ?? queryBuilderFieldConfigByName[String(_field ?? "").trim()]?.fieldType ?? "string";
65578
66211
  return QUERY_BUILDER_OPERATORS_BY_FIELD_TYPE[fieldType] ?? QUERY_BUILDER_OPERATORS_BY_FIELD_TYPE.string;
65579
66212
  },
65580
66213
  [queryBuilderFieldConfigByName]
65581
66214
  );
65582
- const getFilterInputType = (0, import_react62.useMemo)(
66215
+ const getFilterInputType = (0, import_react61.useMemo)(
65583
66216
  () => (_field, operator, misc) => {
65584
66217
  const fieldType = misc?.fieldData?.quillFieldType ?? queryBuilderFieldConfigByName[String(_field ?? "").trim()]?.fieldType ?? "string";
65585
66218
  if (fieldType === "date" && isRelativeDateQueryBuilderOperator(operator)) {
@@ -65589,7 +66222,7 @@ function useReport(reportIdArg, options = {}) {
65589
66222
  },
65590
66223
  [queryBuilderFieldConfigByName]
65591
66224
  );
65592
- const getFilterValueEditorType = (0, import_react62.useMemo)(
66225
+ const getFilterValueEditorType = (0, import_react61.useMemo)(
65593
66226
  () => (_field, operator, misc) => {
65594
66227
  const fieldType = misc?.fieldData?.quillFieldType ?? queryBuilderFieldConfigByName[String(_field ?? "").trim()]?.fieldType;
65595
66228
  if (fieldType === "string" && isMultiValueOperator(operator)) {
@@ -65602,7 +66235,7 @@ function useReport(reportIdArg, options = {}) {
65602
66235
  },
65603
66236
  [queryBuilderFieldConfigByName]
65604
66237
  );
65605
- const getFilterValues = (0, import_react62.useMemo)(
66238
+ const getFilterValues = (0, import_react61.useMemo)(
65606
66239
  () => (_field, operator, misc) => {
65607
66240
  const fieldName = String(_field ?? "").trim();
65608
66241
  if (!fieldName) {
@@ -65632,7 +66265,7 @@ function useReport(reportIdArg, options = {}) {
65632
66265
  },
65633
66266
  [filterValueOptionsByFieldName, queryBuilderFieldConfigByName]
65634
66267
  );
65635
- const filterQueryBuilderProps = (0, import_react62.useMemo)(
66268
+ const filterQueryBuilderProps = (0, import_react61.useMemo)(
65636
66269
  () => ({
65637
66270
  fields: filterFields,
65638
66271
  listsAsArrays: true,
@@ -65649,7 +66282,7 @@ function useReport(reportIdArg, options = {}) {
65649
66282
  getFilterValues
65650
66283
  ]
65651
66284
  );
65652
- const filtersForQueryBuilder = (0, import_react62.useMemo)(
66285
+ const filtersForQueryBuilder = (0, import_react61.useMemo)(
65653
66286
  () => canonicalizeMultiselectStringRulesToOptionValues(
65654
66287
  queryFilters,
65655
66288
  filterValueOptionsByFieldName,
@@ -65716,12 +66349,12 @@ function useReport(reportIdArg, options = {}) {
65716
66349
  ...table2 ? { table: table2 } : {}
65717
66350
  };
65718
66351
  };
65719
- const tenantHash = (0, import_react62.useMemo)(
66352
+ const tenantHash = (0, import_react61.useMemo)(
65720
66353
  () => stableSerializeForQueryKey(tenants),
65721
66354
  [tenants]
65722
66355
  );
65723
- const flagHash = (0, import_react62.useMemo)(() => stableSerializeForQueryKey(flags), [flags]);
65724
- const clientHash = (0, import_react62.useMemo)(
66356
+ const flagHash = (0, import_react61.useMemo)(() => stableSerializeForQueryKey(flags), [flags]);
66357
+ const clientHash = (0, import_react61.useMemo)(
65725
66358
  () => stableSerializeForQueryKey({
65726
66359
  publicKey: client?.publicKey,
65727
66360
  clientId: client?.clientId,
@@ -65729,16 +66362,16 @@ function useReport(reportIdArg, options = {}) {
65729
66362
  }),
65730
66363
  [client]
65731
66364
  );
65732
- const reloadKeyHash = (0, import_react62.useMemo)(
66365
+ const reloadKeyHash = (0, import_react61.useMemo)(
65733
66366
  () => stableSerializeForQueryKey(reloadKey),
65734
66367
  [reloadKey]
65735
66368
  );
65736
- (0, import_react62.useEffect)(() => {
66369
+ (0, import_react61.useEffect)(() => {
65737
66370
  if (!reportOverride) return;
65738
66371
  initializeSchemaScopeForReport(reportOverride);
65739
66372
  setSourceReport(reportOverride);
65740
66373
  }, [reportOverride, propReportId]);
65741
- (0, import_react62.useEffect)(() => {
66374
+ (0, import_react61.useEffect)(() => {
65742
66375
  schemaScopeInitializedForReportIdRef.current = null;
65743
66376
  bootstrapReportTaskUsedForReportIdRef.current = null;
65744
66377
  sharedInitialRequestUsedForReportIdRef.current = null;
@@ -65890,13 +66523,13 @@ function useReport(reportIdArg, options = {}) {
65890
66523
  const reportTitleFromTask = String(reportNameQuery.data?.name ?? "").trim();
65891
66524
  const resolvedReportName = reportNameQueryReportId && sourceReportIdForTitle === reportNameQueryReportId && sourceReportNameForTitle ? sourceReportNameForTitle : reportTitleFromTask || sourceReportNameForTitle || "";
65892
66525
  const displayReportName = formReportName !== void 0 ? formReportName : resolvedReportName;
65893
- (0, import_react62.useEffect)(() => {
66526
+ (0, import_react61.useEffect)(() => {
65894
66527
  if (reportOverride) return;
65895
66528
  const report = initialLoadQuery.data?.report ?? null;
65896
66529
  initializeSchemaScopeForReport(report);
65897
66530
  setSourceReport(report);
65898
66531
  }, [initialLoadQuery.data, reportOverride, effectiveReportId]);
65899
- (0, import_react62.useEffect)(() => {
66532
+ (0, import_react61.useEffect)(() => {
65900
66533
  if (!sourceReport) {
65901
66534
  return;
65902
66535
  }
@@ -66041,11 +66674,11 @@ function useReport(reportIdArg, options = {}) {
66041
66674
  schemaForReportBuilderState,
66042
66675
  sourceReport
66043
66676
  ]);
66044
- const appliedAggregationState = (0, import_react62.useMemo)(
66677
+ const appliedAggregationState = (0, import_react61.useMemo)(
66045
66678
  () => aggregationState.filter(isAppliedAggregation),
66046
66679
  [aggregationState]
66047
66680
  );
66048
- const pivotState = (0, import_react62.useMemo)(() => {
66681
+ const pivotState = (0, import_react61.useMemo)(() => {
66049
66682
  if (!resolvedGroupRowsBy && !resolvedGroupColumnsBy && appliedAggregationState.length === 0) {
66050
66683
  return null;
66051
66684
  }
@@ -66122,7 +66755,7 @@ function useReport(reportIdArg, options = {}) {
66122
66755
  chartPivotHydrationEpoch
66123
66756
  ]);
66124
66757
  const hasDatePivotRow = Boolean(String(pivotState?.rowField ?? "").trim()) && isDateType(String(pivotState?.rowFieldType ?? ""));
66125
- (0, import_react62.useEffect)(() => {
66758
+ (0, import_react61.useEffect)(() => {
66126
66759
  const previous = prevPivotStateForColumnExpansionRef.current;
66127
66760
  if (previous && !pivotState) {
66128
66761
  setExpandReportBuilderColumnsForFlatTable(true);
@@ -66132,7 +66765,7 @@ function useReport(reportIdArg, options = {}) {
66132
66765
  }
66133
66766
  prevPivotStateForColumnExpansionRef.current = pivotState;
66134
66767
  }, [pivotState]);
66135
- const effectiveReportBuilderTables = (0, import_react62.useMemo)(() => {
66768
+ const effectiveReportBuilderTables = (0, import_react61.useMemo)(() => {
66136
66769
  const explicitBaseFromSchemaPicker = Array.isArray(schemaDatasourceIds) && schemaDatasourceIds.length > 0 ? schemaDatasourceIds.map((tableName) => String(tableName ?? "").trim()).filter(Boolean).map((name2) => ({ name: name2 })) : null;
66137
66770
  const baseTablesForMerge = explicitBaseFromSchemaPicker ?? baseReportBuilderTables;
66138
66771
  return mergeReportBuilderTables(
@@ -66156,18 +66789,18 @@ function useReport(reportIdArg, options = {}) {
66156
66789
  queryColumns,
66157
66790
  schemaDatasourceIds
66158
66791
  ]);
66159
- const datasources = (0, import_react62.useMemo)(() => {
66792
+ const datasources = (0, import_react61.useMemo)(() => {
66160
66793
  return effectiveReportBuilderTables.map((table2) => String(table2.name ?? "").trim()).filter((name2) => Boolean(name2));
66161
66794
  }, [effectiveReportBuilderTables]);
66162
- const effectiveReportBuilderTableNames = (0, import_react62.useMemo)(
66795
+ const effectiveReportBuilderTableNames = (0, import_react61.useMemo)(
66163
66796
  () => effectiveReportBuilderTables.map((table2) => String(table2.name ?? "").trim()).filter((name2) => Boolean(name2)),
66164
66797
  [effectiveReportBuilderTables]
66165
66798
  );
66166
- const baseReportBuilderTableNames = (0, import_react62.useMemo)(
66799
+ const baseReportBuilderTableNames = (0, import_react61.useMemo)(
66167
66800
  () => baseReportBuilderTables.map((table2) => String(table2.name ?? "").trim()).filter((name2) => Boolean(name2)),
66168
66801
  [baseReportBuilderTables]
66169
66802
  );
66170
- const normalizeQueryBuilderFieldNameForConfig = (0, import_react62.useMemo)(() => {
66803
+ const normalizeQueryBuilderFieldNameForConfig = (0, import_react61.useMemo)(() => {
66171
66804
  const configEntries = Object.entries(queryBuilderFieldConfigByName);
66172
66805
  const preferredTableNames = /* @__PURE__ */ new Set([
66173
66806
  ...effectiveReportBuilderTableNames,
@@ -66216,7 +66849,7 @@ function useReport(reportIdArg, options = {}) {
66216
66849
  effectiveReportBuilderTableNames,
66217
66850
  queryBuilderFieldConfigByName
66218
66851
  ]);
66219
- const normalizeQueryBuilderFiltersForConfig = (0, import_react62.useMemo)(() => {
66852
+ const normalizeQueryBuilderFiltersForConfig = (0, import_react61.useMemo)(() => {
66220
66853
  const normalizeGroup = (group) => {
66221
66854
  const groupRules = Array.isArray(group.rules) ? group.rules : [];
66222
66855
  const nextRules = groupRules.map((entry) => {
@@ -66253,14 +66886,14 @@ function useReport(reportIdArg, options = {}) {
66253
66886
  return normalizeGroup(group);
66254
66887
  };
66255
66888
  }, [normalizeQueryBuilderFieldNameForConfig, queryBuilderFieldConfigByName]);
66256
- const refreshSelectionTables = (0, import_react62.useMemo)(() => {
66889
+ const refreshSelectionTables = (0, import_react61.useMemo)(() => {
66257
66890
  return [
66258
66891
  getPivotGroupOptionTable(groupRowsBy),
66259
66892
  getPivotGroupOptionTable(groupColumnsBy),
66260
66893
  ...aggregationTablesByIndex
66261
66894
  ].map((tableName) => String(tableName ?? "").trim()).filter((tableName) => Boolean(tableName));
66262
66895
  }, [aggregationTablesByIndex, groupColumnsBy, groupRowsBy]);
66263
- const refreshSelectionFields = (0, import_react62.useMemo)(() => {
66896
+ const refreshSelectionFields = (0, import_react61.useMemo)(() => {
66264
66897
  const resolveFieldTableForSelection = (field, tableHint) => {
66265
66898
  const fieldName = String(field ?? "").trim();
66266
66899
  if (!fieldName) return "";
@@ -66310,7 +66943,7 @@ function useReport(reportIdArg, options = {}) {
66310
66943
  schemaForReportBuilderState,
66311
66944
  sourceReport
66312
66945
  ]);
66313
- const refreshDecision = (0, import_react62.useMemo)(
66946
+ const refreshDecision = (0, import_react61.useMemo)(
66314
66947
  () => decideReportBuilderRefresh({
66315
66948
  baseTables: baseReportBuilderTables,
66316
66949
  baseColumns: baseReportBuilderColumns,
@@ -66324,7 +66957,7 @@ function useReport(reportIdArg, options = {}) {
66324
66957
  refreshSelectionTables
66325
66958
  ]
66326
66959
  );
66327
- const effectiveReportBuilderColumns = (0, import_react62.useMemo)(() => {
66960
+ const effectiveReportBuilderColumns = (0, import_react61.useMemo)(() => {
66328
66961
  const columnsFromPivot = [];
66329
66962
  const appendPivotColumn = (field, tableHint) => {
66330
66963
  const normalizedField = String(field ?? "").trim();
@@ -66387,7 +67020,7 @@ function useReport(reportIdArg, options = {}) {
66387
67020
  queryColumns,
66388
67021
  sourceReport
66389
67022
  ]);
66390
- (0, import_react62.useEffect)(() => {
67023
+ (0, import_react61.useEffect)(() => {
66391
67024
  if (!Array.isArray(filterStack) || filterStack.length === 0) {
66392
67025
  return;
66393
67026
  }
@@ -66422,7 +67055,7 @@ function useReport(reportIdArg, options = {}) {
66422
67055
  queryBuilderFieldConfigByName,
66423
67056
  queryFilters
66424
67057
  ]);
66425
- const resolvedSortFieldType = (0, import_react62.useMemo)(() => {
67058
+ const resolvedSortFieldType = (0, import_react61.useMemo)(() => {
66426
67059
  const sortField = pivotSort?.sortField;
66427
67060
  if (!sortField || !pivotState) return void 0;
66428
67061
  if (sortField === resolvedGroupRowsBy) {
@@ -66443,7 +67076,7 @@ function useReport(reportIdArg, options = {}) {
66443
67076
  resolvedGroupColumnsBy,
66444
67077
  resolvedGroupRowsBy
66445
67078
  ]);
66446
- const effectiveReportBuilderState = (0, import_react62.useMemo)(() => {
67079
+ const effectiveReportBuilderState = (0, import_react61.useMemo)(() => {
66447
67080
  if (!sourceReport && effectiveReportBuilderTables.length === 0) {
66448
67081
  return void 0;
66449
67082
  }
@@ -66486,12 +67119,12 @@ function useReport(reportIdArg, options = {}) {
66486
67119
  resolvedSortFieldType,
66487
67120
  sourceReport
66488
67121
  ]);
66489
- const effectiveReportBuilderStateHash = (0, import_react62.useMemo)(
67122
+ const effectiveReportBuilderStateHash = (0, import_react61.useMemo)(
66490
67123
  () => stableSerializeForQueryKey(effectiveReportBuilderState),
66491
67124
  [effectiveReportBuilderState]
66492
67125
  );
66493
- const prevPaginationResetStateHashRef = (0, import_react62.useRef)(null);
66494
- (0, import_react62.useEffect)(() => {
67126
+ const prevPaginationResetStateHashRef = (0, import_react61.useRef)(null);
67127
+ (0, import_react61.useEffect)(() => {
66495
67128
  const prevHash = prevPaginationResetStateHashRef.current;
66496
67129
  prevPaginationResetStateHashRef.current = effectiveReportBuilderStateHash;
66497
67130
  if (prevHash === null || prevHash === effectiveReportBuilderStateHash) {
@@ -66505,7 +67138,7 @@ function useReport(reportIdArg, options = {}) {
66505
67138
  }
66506
67139
  applyPaginationUpdate((old) => ({ ...old, pageIndex: 0 }));
66507
67140
  }, [applyPaginationUpdate, effectiveReportBuilderStateHash]);
66508
- const pivotTableDataReportBuilderState = (0, import_react62.useMemo)(() => {
67141
+ const pivotTableDataReportBuilderState = (0, import_react61.useMemo)(() => {
66509
67142
  if (!effectiveReportBuilderState?.pivot) {
66510
67143
  return void 0;
66511
67144
  }
@@ -66525,11 +67158,11 @@ function useReport(reportIdArg, options = {}) {
66525
67158
  limit: null
66526
67159
  };
66527
67160
  }, [effectiveReportBuilderState, schemaForReportBuilderState]);
66528
- const pivotTableDataReportBuilderStateHash = (0, import_react62.useMemo)(
67161
+ const pivotTableDataReportBuilderStateHash = (0, import_react61.useMemo)(
66529
67162
  () => stableSerializeForQueryKey(pivotTableDataReportBuilderState),
66530
67163
  [pivotTableDataReportBuilderState]
66531
67164
  );
66532
- const sourceReportMatchesEffectiveReportId = (0, import_react62.useMemo)(() => {
67165
+ const sourceReportMatchesEffectiveReportId = (0, import_react61.useMemo)(() => {
66533
67166
  const loadTarget = String(effectiveReportId ?? "").trim();
66534
67167
  if (!loadTarget || !sourceReport) {
66535
67168
  return true;
@@ -66539,7 +67172,7 @@ function useReport(reportIdArg, options = {}) {
66539
67172
  ).trim();
66540
67173
  return sid === loadTarget;
66541
67174
  }, [effectiveReportId, sourceReport]);
66542
- const shouldSkipRedundantFlatTableReportBuilderQuery = (0, import_react62.useMemo)(() => {
67175
+ const shouldSkipRedundantFlatTableReportBuilderQuery = (0, import_react61.useMemo)(() => {
66543
67176
  if (!sourceReport || pivotState) {
66544
67177
  return false;
66545
67178
  }
@@ -66565,7 +67198,7 @@ function useReport(reportIdArg, options = {}) {
66565
67198
  filterStack
66566
67199
  ]);
66567
67200
  const shouldForceTableRefreshFromFilters = !useInMemoryEngines && !pivotState;
66568
- const immediateTableRefreshInput = (0, import_react62.useMemo)(
67201
+ const tableRefreshInput = (0, import_react61.useMemo)(
66569
67202
  () => ({
66570
67203
  version: tableRefreshVersion,
66571
67204
  reportBuilderStateHash: effectiveReportBuilderStateHash,
@@ -66581,18 +67214,12 @@ function useReport(reportIdArg, options = {}) {
66581
67214
  tableRefreshVersion
66582
67215
  ]
66583
67216
  );
66584
- const debouncedTableRefreshInput = useDebouncedRefreshInput(
66585
- immediateTableRefreshInput
66586
- );
66587
- const disableTableRefreshDebounceForDiagnostics = process.env.NODE_ENV === "test" && process.env.QUILL_DISABLE_REPORT_REFRESH_DEBOUNCE === "true";
66588
- const tableRefreshInput = disableTableRefreshDebounceForDiagnostics ? immediateTableRefreshInput : debouncedTableRefreshInput;
66589
- const tableRefreshInputIsCurrent = tableRefreshInput.version === tableRefreshVersion && tableRefreshInput.reportBuilderStateHash === effectiveReportBuilderStateHash;
66590
- const completedTableRefreshRef = (0, import_react62.useRef)(null);
67217
+ const completedTableRefreshRef = (0, import_react61.useRef)(null);
66591
67218
  if (completedTableRefreshRef.current?.reportId !== effectiveReportId) {
66592
67219
  completedTableRefreshRef.current = null;
66593
67220
  }
66594
- const tableRefreshInputAlreadyCompleted = !disableTableRefreshDebounceForDiagnostics && completedTableRefreshRef.current?.reportId === effectiveReportId && completedTableRefreshRef.current.version >= tableRefreshInput.version;
66595
- const tableRefreshQueryEnabled = !reportOverride && tableRefreshInputIsCurrent && !tableRefreshInputAlreadyCompleted && tableRefreshInput.version > 0 && Boolean(sourceReport) && Boolean(client) && Boolean(tableRefreshInput.reportBuilderState) && !pendingPivotRefresh && sourceReportMatchesEffectiveReportId && tableRefreshInput.shouldRefresh;
67221
+ const tableRefreshInputAlreadyCompleted = completedTableRefreshRef.current?.reportId === effectiveReportId && completedTableRefreshRef.current.version >= tableRefreshInput.version;
67222
+ const tableRefreshQueryEnabled = !reportOverride && !tableRefreshInputAlreadyCompleted && tableRefreshInput.version > 0 && Boolean(sourceReport) && Boolean(client) && Boolean(tableRefreshInput.reportBuilderState) && !pendingPivotRefresh && sourceReportMatchesEffectiveReportId && tableRefreshInput.shouldRefresh;
66596
67223
  const tableRefreshQuery = (0, import_react_query3.useQuery)({
66597
67224
  queryKey: createUseFormTableRefreshQueryKey({
66598
67225
  reportId: effectiveReportId,
@@ -66664,7 +67291,7 @@ function useReport(reportIdArg, options = {}) {
66664
67291
  enabled: isCreatedReportBootstrapLoad && Boolean(client) && !reportOverride,
66665
67292
  retry: false
66666
67293
  });
66667
- (0, import_react62.useEffect)(() => {
67294
+ (0, import_react61.useEffect)(() => {
66668
67295
  if (!tableRefreshQueryEnabled) return;
66669
67296
  const report = tableRefreshQuery.data?.report;
66670
67297
  if (tableRefreshQuery.data?.error || !report) return;
@@ -66679,7 +67306,7 @@ function useReport(reportIdArg, options = {}) {
66679
67306
  tableRefreshQuery.data,
66680
67307
  tableRefreshQueryEnabled
66681
67308
  ]);
66682
- (0, import_react62.useEffect)(() => {
67309
+ (0, import_react61.useEffect)(() => {
66683
67310
  const countReport = createdBootstrapRowCountQuery.data?.report;
66684
67311
  if (createdBootstrapRowCountQuery.data?.error || !countReport) return;
66685
67312
  setSourceReport((currentReport) => {
@@ -66695,11 +67322,11 @@ function useReport(reportIdArg, options = {}) {
66695
67322
  return { ...currentReport, rowCount: countReport.rowCount };
66696
67323
  });
66697
67324
  }, [createdBootstrapRowCountQuery.data, effectiveReportId, sourceReport?.id]);
66698
- const chartTypes = (0, import_react62.useMemo)(() => {
67325
+ const chartTypes = (0, import_react61.useMemo)(() => {
66699
67326
  return getChartTypeOptions2({ pivot: pivotState });
66700
67327
  }, [pivotState]);
66701
67328
  const resolvedChartType = chartTypes.find((option) => option.value === chartType)?.value ?? chartTypes.find((option) => option.value === sourceReport?.chartType)?.value ?? chartTypes.find((option) => option.value === DEFAULT_CHART_TYPE)?.value ?? chartTypes[0]?.value ?? DEFAULT_CHART_TYPE;
66702
- (0, import_react62.useEffect)(() => {
67329
+ (0, import_react61.useEffect)(() => {
66703
67330
  if (!sourceReport) {
66704
67331
  return;
66705
67332
  }
@@ -66734,7 +67361,7 @@ function useReport(reportIdArg, options = {}) {
66734
67361
  });
66735
67362
  }
66736
67363
  }, [chartType, chartTypes, sourceReport]);
66737
- const schemaScopedTableNames = (0, import_react62.useMemo)(() => {
67364
+ const schemaScopedTableNames = (0, import_react61.useMemo)(() => {
66738
67365
  if (preserveSchemaWideOptions) {
66739
67366
  return [];
66740
67367
  }
@@ -66749,7 +67376,7 @@ function useReport(reportIdArg, options = {}) {
66749
67376
  preserveSchemaWideOptions,
66750
67377
  sourceReport?.reportBuilderState?.tables
66751
67378
  ]);
66752
- const joinCompatibleSchemaTableNames = (0, import_react62.useMemo)(() => {
67379
+ const joinCompatibleSchemaTableNames = (0, import_react61.useMemo)(() => {
66753
67380
  if (schemaScopedTableNames.length === 0) {
66754
67381
  return [];
66755
67382
  }
@@ -66758,7 +67385,7 @@ function useReport(reportIdArg, options = {}) {
66758
67385
  schemaForeignKeyMap
66759
67386
  );
66760
67387
  }, [schemaForeignKeyMap, schemaScopedTableNames]);
66761
- const aggregationFallbackTarget = (0, import_react62.useMemo)(() => {
67388
+ const aggregationFallbackTarget = (0, import_react61.useMemo)(() => {
66762
67389
  const tableNames = effectiveReportBuilderTables.map((table2) => table2.name).filter((name2) => Boolean(name2));
66763
67390
  const referencedTableNames = (sourceReport?.referencedTables ?? []).filter(
66764
67391
  (name2) => typeof name2 === "string" && name2.length > 0
@@ -66766,7 +67393,7 @@ function useReport(reportIdArg, options = {}) {
66766
67393
  const tableNamesToUse = tableNames.length ? tableNames : referencedTableNames;
66767
67394
  return tableNamesToUse.length > 0 ? tableNamesToUse.join(", ") : "table";
66768
67395
  }, [effectiveReportBuilderTables, sourceReport?.referencedTables]);
66769
- const aggregationFallbackTableName = (0, import_react62.useMemo)(() => {
67396
+ const aggregationFallbackTableName = (0, import_react61.useMemo)(() => {
66770
67397
  const tableNames = effectiveReportBuilderTables.map((table2) => table2.name).filter((name2) => Boolean(name2));
66771
67398
  const referencedTableNames = (sourceReport?.referencedTables ?? []).filter(
66772
67399
  (name2) => typeof name2 === "string" && name2.length > 0
@@ -66774,7 +67401,7 @@ function useReport(reportIdArg, options = {}) {
66774
67401
  const tableNamesToUse = tableNames.length ? tableNames : referencedTableNames;
66775
67402
  return tableNamesToUse[0] ?? "table";
66776
67403
  }, [effectiveReportBuilderTables, sourceReport?.referencedTables]);
66777
- const cleanedAggregations = (0, import_react62.useMemo)(() => {
67404
+ const cleanedAggregations = (0, import_react61.useMemo)(() => {
66778
67405
  return aggregationState.filter((aggregation) => Boolean(aggregation?.aggregationType)).map((aggregation, index) => {
66779
67406
  const aggregationType = String(aggregation.aggregationType);
66780
67407
  const normalizedAggregationType = aggregationType.toLowerCase();
@@ -66796,7 +67423,7 @@ function useReport(reportIdArg, options = {}) {
66796
67423
  aggregationTablesByIndex,
66797
67424
  isBoolAggregationField
66798
67425
  ]);
66799
- const { aggregationBaseOptions, aggregationOptionTableLookup } = (0, import_react62.useMemo)(() => {
67426
+ const { aggregationBaseOptions, aggregationOptionTableLookup } = (0, import_react61.useMemo)(() => {
66800
67427
  const joinScoped = fieldOptionsAllowedTableNames ? joinCompatibleSchemaTableNames.filter(
66801
67428
  (name2) => fieldOptionsAllowedTableNames.has(name2)
66802
67429
  ) : joinCompatibleSchemaTableNames;
@@ -66879,7 +67506,7 @@ function useReport(reportIdArg, options = {}) {
66879
67506
  resolvedGroupRowsBy,
66880
67507
  schemaForReportBuilderState
66881
67508
  ]);
66882
- const { schemaColumnOptions, columnIdentifierLookup } = (0, import_react62.useMemo)(() => {
67509
+ const { schemaColumnOptions, columnIdentifierLookup } = (0, import_react61.useMemo)(() => {
66883
67510
  const lookup = /* @__PURE__ */ new Map();
66884
67511
  const options2 = [];
66885
67512
  for (const table2 of schemaData.schemaWithCustomFields) {
@@ -66906,7 +67533,7 @@ function useReport(reportIdArg, options = {}) {
66906
67533
  columnIdentifierLookup: lookup
66907
67534
  };
66908
67535
  }, [schemaData.schemaWithCustomFields]);
66909
- const tableColumnPickerPoolOptions = (0, import_react62.useMemo)(() => {
67536
+ const tableColumnPickerPoolOptions = (0, import_react61.useMemo)(() => {
66910
67537
  const allowed = new Set(
66911
67538
  effectiveReportBuilderTableNames.map((name2) => String(name2 ?? "").trim()).filter(Boolean)
66912
67539
  );
@@ -66917,16 +67544,16 @@ function useReport(reportIdArg, options = {}) {
66917
67544
  (option) => allowed.has(String(option.tableName ?? "").trim())
66918
67545
  );
66919
67546
  }, [effectiveReportBuilderTableNames, schemaColumnOptions]);
66920
- const columns = (0, import_react62.useMemo)(() => {
67547
+ const columns = (0, import_react61.useMemo)(() => {
66921
67548
  return displayColumns.filter((column) => Boolean(column.field)).map((column) => encodeColumnOptionValue(column.table, column.field));
66922
67549
  }, [displayColumns]);
66923
- const selectedColumnOptions = (0, import_react62.useMemo)(() => {
67550
+ const selectedColumnOptions = (0, import_react61.useMemo)(() => {
66924
67551
  return displayColumns.map((column) => {
66925
67552
  const value = column.alias || column.field;
66926
67553
  return value ? { label: value, value } : null;
66927
67554
  }).filter((option) => option !== null);
66928
67555
  }, [displayColumns]);
66929
- const scopedSchemaColumns = (0, import_react62.useMemo)(() => {
67556
+ const scopedSchemaColumns = (0, import_react61.useMemo)(() => {
66930
67557
  const tableNames = fieldOptionsAllowedTableNames ? Array.from(fieldOptionsAllowedTableNames) : joinCompatibleSchemaTableNames;
66931
67558
  const schemaTables = schemaForReportBuilderState;
66932
67559
  const tablesToUse = tableNames.length ? schemaTables.filter((table2) => tableNames.includes(table2.name ?? "")) : schemaTables;
@@ -66947,7 +67574,7 @@ function useReport(reportIdArg, options = {}) {
66947
67574
  joinCompatibleSchemaTableNames,
66948
67575
  schemaForReportBuilderState
66949
67576
  ]);
66950
- const pivotUniqueValuesByColumn = (0, import_react62.useMemo)(() => {
67577
+ const pivotUniqueValuesByColumn = (0, import_react61.useMemo)(() => {
66951
67578
  const explicitUniqueValues = sourceReport?.uniqueStringsByColumn ?? sourceReport?.columnUniqueValues ?? sourceReport?.uniqueValues;
66952
67579
  if (explicitUniqueValues && typeof explicitUniqueValues === "object" && !Array.isArray(explicitUniqueValues)) {
66953
67580
  return explicitUniqueValues;
@@ -66973,7 +67600,7 @@ function useReport(reportIdArg, options = {}) {
66973
67600
  }
66974
67601
  return result;
66975
67602
  }, [sourceReport]);
66976
- const possiblePivotFields = (0, import_react62.useMemo)(() => {
67603
+ const possiblePivotFields = (0, import_react61.useMemo)(() => {
66977
67604
  const options2 = getPossiblePivotFieldOptions(
66978
67605
  scopedSchemaColumns,
66979
67606
  pivotUniqueValuesByColumn
@@ -66984,7 +67611,7 @@ function useReport(reportIdArg, options = {}) {
66984
67611
  columnFields: options2.columnFields.filter((field) => !isIdColumn(field))
66985
67612
  };
66986
67613
  }, [scopedSchemaColumns, pivotUniqueValuesByColumn]);
66987
- const groupRowsByOptions = (0, import_react62.useMemo)(() => {
67614
+ const groupRowsByOptions = (0, import_react61.useMemo)(() => {
66988
67615
  const allowedFields = new Set(possiblePivotFields.rowFields);
66989
67616
  const seenValues = /* @__PURE__ */ new Set();
66990
67617
  const options2 = [];
@@ -67011,7 +67638,7 @@ function useReport(reportIdArg, options = {}) {
67011
67638
  }
67012
67639
  return options2;
67013
67640
  }, [groupRowsBy, possiblePivotFields.rowFields, scopedSchemaColumns]);
67014
- const groupColumnsByOptions = (0, import_react62.useMemo)(() => {
67641
+ const groupColumnsByOptions = (0, import_react61.useMemo)(() => {
67015
67642
  const allowedFields = new Set(possiblePivotFields.columnFields);
67016
67643
  const seenValues = /* @__PURE__ */ new Set();
67017
67644
  const options2 = [];
@@ -67038,19 +67665,19 @@ function useReport(reportIdArg, options = {}) {
67038
67665
  }
67039
67666
  return options2;
67040
67667
  }, [groupColumnsBy, possiblePivotFields.columnFields, scopedSchemaColumns]);
67041
- const cleanedSort = (0, import_react62.useMemo)(() => {
67668
+ const cleanedSort = (0, import_react61.useMemo)(() => {
67042
67669
  const activeSort = resolvedGroupRowsBy ? pivotSort : regularSort;
67043
67670
  if (!activeSort?.sortField || !activeSort?.sortDirection) {
67044
67671
  return "";
67045
67672
  }
67046
67673
  return toFlatSortValue(activeSort.sortField, activeSort.sortDirection);
67047
67674
  }, [pivotSort, regularSort, resolvedGroupRowsBy]);
67048
- const aggregationSortLabelFallbackTable = (0, import_react62.useMemo)(() => {
67675
+ const aggregationSortLabelFallbackTable = (0, import_react61.useMemo)(() => {
67049
67676
  const reportBuilderTableName = effectiveReportBuilderTables.map((table2) => String(table2.name ?? "").trim()).find((tableName) => Boolean(tableName));
67050
67677
  if (reportBuilderTableName) return reportBuilderTableName;
67051
67678
  return (sourceReport?.referencedTables ?? []).map((tableName) => String(tableName ?? "").trim()).find((tableName) => Boolean(tableName));
67052
67679
  }, [effectiveReportBuilderTables, sourceReport?.referencedTables]);
67053
- const sortOptions = (0, import_react62.useMemo)(() => {
67680
+ const sortOptions = (0, import_react61.useMemo)(() => {
67054
67681
  if (resolvedGroupRowsBy) {
67055
67682
  const aggregationSortFields = getPivotAggregationSortFields(
67056
67683
  aggregationState,
@@ -67086,9 +67713,9 @@ function useReport(reportIdArg, options = {}) {
67086
67713
  (option) => ["ASC", "DESC"].map((direction) => {
67087
67714
  const field = String(option.value ?? "").trim();
67088
67715
  const labelField = String(option.label ?? field).trim();
67089
- const directionLabel = toFlatSortDirectionLabel(direction);
67716
+ const directionLabel2 = toFlatSortDirectionLabel(direction);
67090
67717
  return {
67091
- label: `${toTitleCaseLabel(labelField)} ${directionLabel}`,
67718
+ label: `${toTitleCaseLabel(labelField)} ${directionLabel2}`,
67092
67719
  value: toFlatSortValue(field, direction)
67093
67720
  };
67094
67721
  })
@@ -67109,7 +67736,7 @@ function useReport(reportIdArg, options = {}) {
67109
67736
  resolvedGroupRowsBy,
67110
67737
  selectedColumnOptions
67111
67738
  ]);
67112
- const { aggregationValues, aggregationOptions } = (0, import_react62.useMemo)(() => {
67739
+ const { aggregationValues, aggregationOptions } = (0, import_react61.useMemo)(() => {
67113
67740
  const baseOptions = aggregationBaseOptions.map((option) => ({
67114
67741
  value: option.value,
67115
67742
  label: option.label
@@ -67153,7 +67780,7 @@ function useReport(reportIdArg, options = {}) {
67153
67780
  aggregationTablesByIndex,
67154
67781
  isBoolAggregationField
67155
67782
  ]);
67156
- const nextPivot = (0, import_react62.useMemo)(() => {
67783
+ const nextPivot = (0, import_react61.useMemo)(() => {
67157
67784
  if (!sourceReport) return null;
67158
67785
  return pivotState ? {
67159
67786
  ...pivotState,
@@ -67168,15 +67795,15 @@ function useReport(reportIdArg, options = {}) {
67168
67795
  rowLimit: limit?.value
67169
67796
  } : null;
67170
67797
  }, [sourceReport, pivotState, pivotSort, limit, resolvedSortFieldType]);
67171
- const nextPivotHash = (0, import_react62.useMemo)(
67798
+ const nextPivotHash = (0, import_react61.useMemo)(
67172
67799
  () => stableSerializeForQueryKey(nextPivot),
67173
67800
  [nextPivot]
67174
67801
  );
67175
- const filterStackHash = (0, import_react62.useMemo)(
67802
+ const filterStackHash = (0, import_react61.useMemo)(
67176
67803
  () => stableSerializeForQueryKey(filterStack),
67177
67804
  [filterStack]
67178
67805
  );
67179
- const shouldSkipPivotRefreshForUnchangedPivot = (0, import_react62.useMemo)(() => {
67806
+ const shouldSkipPivotRefreshForUnchangedPivot = (0, import_react61.useMemo)(() => {
67180
67807
  if (!sourceReport || !nextPivot) return false;
67181
67808
  if (!Array.isArray(sourceReport.rows) || sourceReport.rows.length === 0) {
67182
67809
  return false;
@@ -67194,7 +67821,7 @@ function useReport(reportIdArg, options = {}) {
67194
67821
  );
67195
67822
  return hasSamePivot && sourceFilterStackHash === filterStackHash;
67196
67823
  }, [filterStackHash, nextPivot, sourceReport]);
67197
- (0, import_react62.useEffect)(() => {
67824
+ (0, import_react61.useEffect)(() => {
67198
67825
  if (!pendingPivotRefresh) return;
67199
67826
  if (!nextPivot) {
67200
67827
  if (!sourceReport) {
@@ -67214,7 +67841,7 @@ function useReport(reportIdArg, options = {}) {
67214
67841
  shouldSkipPivotRefreshForUnchangedPivot,
67215
67842
  sourceReport
67216
67843
  ]);
67217
- const shouldSkipRedundantPivotTableDataReportBuilderQuery = (0, import_react62.useMemo)(() => {
67844
+ const shouldSkipRedundantPivotTableDataReportBuilderQuery = (0, import_react61.useMemo)(() => {
67218
67845
  if (!sourceReport || !nextPivot) {
67219
67846
  return false;
67220
67847
  }
@@ -67343,7 +67970,7 @@ function useReport(reportIdArg, options = {}) {
67343
67970
  });
67344
67971
  const tablePageReportBuilderState = pivotTableDataReportBuilderState ?? effectiveReportBuilderState;
67345
67972
  const tablePageReportBuilderStateHash = pivotTableDataReportBuilderState ? pivotTableDataReportBuilderStateHash : effectiveReportBuilderStateHash;
67346
- const tablePaginationSort = (0, import_react62.useMemo)(
67973
+ const tablePaginationSort = (0, import_react61.useMemo)(
67347
67974
  () => getStablePaginationSort({
67348
67975
  columns: tablePageReportBuilderState?.columns,
67349
67976
  sort: tablePageReportBuilderState?.sort
@@ -67399,7 +68026,7 @@ function useReport(reportIdArg, options = {}) {
67399
68026
  const tablePageRows = tablePageQueryEnabled && !tablePageQuery.data?.error && Array.isArray(tablePageQuery.data?.report?.rows) ? tablePageQuery.data.report.rows : void 0;
67400
68027
  const tablePageRowCount = tablePageQueryEnabled && typeof tablePageQuery.data?.report?.rowCount === "number" && tablePageQuery.data.report.rowCount > 0 ? tablePageQuery.data.report.rowCount : void 0;
67401
68028
  const tablePageFetching = tablePageQueryEnabled && tablePageQuery.isFetching;
67402
- const paginationTotalRowCount = (0, import_react62.useMemo)(() => {
68029
+ const paginationTotalRowCount = (0, import_react61.useMemo)(() => {
67403
68030
  if (tablePageRowCount !== void 0) {
67404
68031
  return Math.max(tablePageRowCount, baseWindowRowsLength);
67405
68032
  }
@@ -67422,7 +68049,7 @@ function useReport(reportIdArg, options = {}) {
67422
68049
  pagination.pageSize
67423
68050
  );
67424
68051
  paginationPageCountRef.current = paginationPageCount;
67425
- (0, import_react62.useEffect)(() => {
68052
+ (0, import_react61.useEffect)(() => {
67426
68053
  if (!pivotTableDataRefreshQueryEnabled) return;
67427
68054
  if (pivotTableDataRefreshQuery.status !== "success" && pivotTableDataRefreshQuery.status !== "error") {
67428
68055
  return;
@@ -67463,7 +68090,7 @@ function useReport(reportIdArg, options = {}) {
67463
68090
  pivotTableDataRefreshQueryEnabled,
67464
68091
  effectiveReportId
67465
68092
  ]);
67466
- (0, import_react62.useEffect)(() => {
68093
+ (0, import_react61.useEffect)(() => {
67467
68094
  if (!pivotRefreshQueryEnabled) return;
67468
68095
  if (pivotRefreshQuery.status !== "success" && pivotRefreshQuery.status !== "error") {
67469
68096
  return;
@@ -67524,7 +68151,7 @@ function useReport(reportIdArg, options = {}) {
67524
68151
  const pendingPivotChangesDimensions = Boolean(
67525
68152
  sourceReport && pendingPivotRefresh && nextPivot && (settledSourceRowFieldForChart !== String(nextPivot.rowField ?? "").trim() || String(settledPivotForChart?.rowFieldTable ?? "").trim() !== String(nextPivot.rowFieldTable ?? "").trim() || String(settledPivotForChart?.columnField ?? "").trim() !== String(nextPivot.columnField ?? "").trim() || String(settledPivotForChart?.columnFieldTable ?? "").trim() !== String(nextPivot.columnFieldTable ?? "").trim())
67526
68153
  );
67527
- const chartData = (0, import_react62.useMemo)(() => {
68154
+ const chartData = (0, import_react61.useMemo)(() => {
67528
68155
  if (!sourceReport) return void 0;
67529
68156
  const rowsForChart = Array.isArray(sourceReport.rows) ? sourceReport.rows : [];
67530
68157
  const chartPivot = pendingPivotChangesDimensions ? sourceReport.pivot ?? null : nextPivot ?? (!chartPivotHydratedFromSourceRef.current ? sourceReport.pivot ?? null : null);
@@ -67558,18 +68185,18 @@ function useReport(reportIdArg, options = {}) {
67558
68185
  useInMemoryEngines,
67559
68186
  chartPivotHydrationEpoch
67560
68187
  ]);
67561
- const baseChart = (0, import_react62.useMemo)(
68188
+ const baseChart = (0, import_react61.useMemo)(
67562
68189
  () => normalizePivotChartForDisplay(chartData),
67563
68190
  [chartData]
67564
68191
  );
67565
- const chartAxesBaseChart = (0, import_react62.useMemo)(() => {
68192
+ const chartAxesBaseChart = (0, import_react61.useMemo)(() => {
67566
68193
  if (!chartData) return void 0;
67567
68194
  if (chartData.pivot?.columnField) {
67568
68195
  return normalizePivotChartForAxisControls(chartData, effectiveReportId);
67569
68196
  }
67570
68197
  return baseChart;
67571
68198
  }, [baseChart, chartData, effectiveReportId]);
67572
- const chartAxisOptions = (0, import_react62.useMemo)(() => {
68199
+ const chartAxisOptions = (0, import_react61.useMemo)(() => {
67573
68200
  if (!chartAxesBaseChart) return [];
67574
68201
  const optionsByField = /* @__PURE__ */ new Map();
67575
68202
  const registerOption = (fieldRaw, labelRaw, formatRaw) => {
@@ -67608,14 +68235,14 @@ function useReport(reportIdArg, options = {}) {
67608
68235
  );
67609
68236
  return Array.from(optionsByField.values());
67610
68237
  }, [chartAxesBaseChart]);
67611
- const chartAxisOptionByField = (0, import_react62.useMemo)(() => {
68238
+ const chartAxisOptionByField = (0, import_react61.useMemo)(() => {
67612
68239
  const optionsByField = /* @__PURE__ */ new Map();
67613
68240
  for (const option of chartAxisOptions) {
67614
68241
  optionsByField.set(option.value, option);
67615
68242
  }
67616
68243
  return optionsByField;
67617
68244
  }, [chartAxisOptions]);
67618
- const xAxisOptions = (0, import_react62.useMemo)(() => {
68245
+ const xAxisOptions = (0, import_react61.useMemo)(() => {
67619
68246
  if (!chartAxesBaseChart) return chartAxisOptions;
67620
68247
  const pivot = chartAxesBaseChart.pivot;
67621
68248
  const pivotRowField = String(pivot?.rowField ?? "").trim();
@@ -67638,7 +68265,7 @@ function useReport(reportIdArg, options = {}) {
67638
68265
  }
67639
68266
  return chartAxisOptions;
67640
68267
  }, [chartAxesBaseChart, chartAxisOptions, chartAxisOptionByField]);
67641
- const yAxisOptions = (0, import_react62.useMemo)(() => {
68268
+ const yAxisOptions = (0, import_react61.useMemo)(() => {
67642
68269
  if (!chartAxesBaseChart) return [];
67643
68270
  const keepOption = (option) => {
67644
68271
  const col = findSchemaColumnForChartAxisField(
@@ -67674,21 +68301,21 @@ function useReport(reportIdArg, options = {}) {
67674
68301
  chartAxisOptions,
67675
68302
  schemaColumnOptions
67676
68303
  ]);
67677
- const normalizedChartXAxisOptions = (0, import_react62.useMemo)(() => {
68304
+ const normalizedChartXAxisOptions = (0, import_react61.useMemo)(() => {
67678
68305
  return xAxisOptions.map((option) => ({
67679
68306
  value: String(option.value ?? "").trim(),
67680
68307
  label: String(option.label ?? option.value ?? "").trim(),
67681
68308
  format: String(option.format ?? "").trim()
67682
68309
  }));
67683
68310
  }, [xAxisOptions]);
67684
- const normalizedChartYAxisOptions = (0, import_react62.useMemo)(() => {
68311
+ const normalizedChartYAxisOptions = (0, import_react61.useMemo)(() => {
67685
68312
  return yAxisOptions.map((option) => ({
67686
68313
  value: String(option.value ?? "").trim(),
67687
68314
  label: String(option.label ?? option.value ?? "").trim(),
67688
68315
  format: String(option.format ?? "").trim()
67689
68316
  }));
67690
68317
  }, [yAxisOptions]);
67691
- const resolvedYAxisFields = (0, import_react62.useMemo)(() => {
68318
+ const resolvedYAxisFields = (0, import_react61.useMemo)(() => {
67692
68319
  if (!chartAxesBaseChart) return [];
67693
68320
  const normalizeYAxisField = (yAxisFieldRaw) => {
67694
68321
  const field = String(yAxisFieldRaw?.field ?? "").trim();
@@ -67732,7 +68359,7 @@ function useReport(reportIdArg, options = {}) {
67732
68359
  chartAxisOptionByField,
67733
68360
  chartAxisOptions
67734
68361
  ]);
67735
- const resolvedXAxisField = (0, import_react62.useMemo)(() => {
68362
+ const resolvedXAxisField = (0, import_react61.useMemo)(() => {
67736
68363
  if (!chartAxesBaseChart) return "";
67737
68364
  const chartType2 = String(chartAxesBaseChart.chartType ?? "").toLowerCase();
67738
68365
  const pivotRowField = String(
@@ -67764,7 +68391,7 @@ function useReport(reportIdArg, options = {}) {
67764
68391
  chartAxisOptions,
67765
68392
  resolvedYAxisFields
67766
68393
  ]);
67767
- const resolvedXAxisFormat = (0, import_react62.useMemo)(() => {
68394
+ const resolvedXAxisFormat = (0, import_react61.useMemo)(() => {
67768
68395
  if (!chartAxesBaseChart) {
67769
68396
  return "string";
67770
68397
  }
@@ -67776,9 +68403,7 @@ function useReport(reportIdArg, options = {}) {
67776
68403
  chartAxesBaseChart,
67777
68404
  resolvedXAxisField
67778
68405
  );
67779
- if (bucketFormat && (defaultFormat === "string" || chartAxesBaseChart.pivot?.dateBucket === "week")) {
67780
- defaultFormat = bucketFormat;
67781
- }
68406
+ if (bucketFormat) return bucketFormat;
67782
68407
  if (isPivotTableDateBucketRowAxis(chartAxesBaseChart, resolvedXAxisField) && chartAxisEdits.xAxisFormat === void 0) {
67783
68408
  defaultFormat = "string";
67784
68409
  }
@@ -67790,7 +68415,7 @@ function useReport(reportIdArg, options = {}) {
67790
68415
  resolvedXAxisField,
67791
68416
  resolvedYAxisFields
67792
68417
  ]);
67793
- const resolvedXAxisLabel = (0, import_react62.useMemo)(() => {
68418
+ const resolvedXAxisLabel = (0, import_react61.useMemo)(() => {
67794
68419
  const defaultXLabel = String(
67795
68420
  chartAxesBaseChart?.xAxisLabel ?? chartAxisOptionByField.get(resolvedXAxisField)?.label ?? ""
67796
68421
  ).trim();
@@ -67804,13 +68429,13 @@ function useReport(reportIdArg, options = {}) {
67804
68429
  chartAxisOptionByField,
67805
68430
  resolvedXAxisField
67806
68431
  ]);
67807
- const chartVisibility = (0, import_react62.useMemo)(
68432
+ const chartVisibility = (0, import_react61.useMemo)(
67808
68433
  () => ({
67809
68434
  showLegend: chartVisibilityOverrides.showLegend ?? Boolean(baseChart?.showLegend ?? false)
67810
68435
  }),
67811
68436
  [baseChart?.showLegend, chartVisibilityOverrides]
67812
68437
  );
67813
- const xAxis = (0, import_react62.useMemo)(() => {
68438
+ const xAxis = (0, import_react61.useMemo)(() => {
67814
68439
  const pivotBucketXAxis = isPivotTableDateBucketRowAxis(
67815
68440
  chartAxesBaseChart,
67816
68441
  resolvedXAxisField
@@ -67827,7 +68452,7 @@ function useReport(reportIdArg, options = {}) {
67827
68452
  resolvedXAxisField,
67828
68453
  resolvedXAxisFormat
67829
68454
  ]);
67830
- const yAxis = (0, import_react62.useMemo)(
68455
+ const yAxis = (0, import_react61.useMemo)(
67831
68456
  () => ({
67832
68457
  fields: resolvedYAxisFields.map((yAxisField) => ({
67833
68458
  field: yAxisField.field,
@@ -67839,14 +68464,14 @@ function useReport(reportIdArg, options = {}) {
67839
68464
  }),
67840
68465
  [resolvedYAxisFields]
67841
68466
  );
67842
- const resolvedYAxisFieldsForDisplay = (0, import_react62.useMemo)(() => {
68467
+ const resolvedYAxisFieldsForDisplay = (0, import_react61.useMemo)(() => {
67843
68468
  if (!baseChart) return resolvedYAxisFields;
67844
68469
  return mapResolvedPivotYAxisFieldsForDisplay({
67845
68470
  chart: baseChart,
67846
68471
  resolvedYAxisFields
67847
68472
  });
67848
68473
  }, [baseChart, resolvedYAxisFields]);
67849
- const chart = (0, import_react62.useMemo)(() => {
68474
+ const chart = (0, import_react61.useMemo)(() => {
67850
68475
  if (!baseChart) return void 0;
67851
68476
  let columns2 = mergeChartColumnFormatsFromYAxisFields(
67852
68477
  baseChart.columns,
@@ -67905,8 +68530,8 @@ function useReport(reportIdArg, options = {}) {
67905
68530
  resolvedYAxisFields,
67906
68531
  resolvedYAxisFieldsForDisplay
67907
68532
  ]);
67908
- const pivotDateFilterRangeCacheRef = (0, import_react62.useRef)({ key: "", min: null, max: null });
67909
- const filterOptions = (0, import_react62.useMemo)(() => {
68533
+ const pivotDateFilterRangeCacheRef = (0, import_react61.useRef)({ key: "", min: null, max: null });
68534
+ const filterOptions = (0, import_react61.useMemo)(() => {
67910
68535
  const out = [];
67911
68536
  for (const [field, values] of filterValueOptionsByFieldName) {
67912
68537
  out.push({
@@ -67968,7 +68593,7 @@ function useReport(reportIdArg, options = {}) {
67968
68593
  effectiveReportId,
67969
68594
  filterValueOptionsByFieldName
67970
68595
  ]);
67971
- const chartForUi = (0, import_react62.useMemo)(() => {
68596
+ const chartForUi = (0, import_react61.useMemo)(() => {
67972
68597
  if (!chart?.pivot) return chart;
67973
68598
  const pivot = chart.pivot;
67974
68599
  const qualify = (field, table2) => table2 ? `${table2}.${field}` : field;
@@ -68043,12 +68668,22 @@ function useReport(reportIdArg, options = {}) {
68043
68668
  }
68044
68669
  };
68045
68670
  }, [chart, filterOptions, filtersForQueryBuilder]);
68671
+ const resolvedChartSort = chartSortOverride === void 0 ? sourceReport?.chartSort : chartSortOverride ?? void 0;
68672
+ const chartSort = formatChartSortValue(resolvedChartSort);
68673
+ const chartSortOptions = (0, import_react61.useMemo)(
68674
+ () => getChartSortOptions(chartForUi),
68675
+ [chartForUi]
68676
+ );
68677
+ const chartWithSort = (0, import_react61.useMemo)(
68678
+ () => chartForUi ? applyChartSort(chartForUi, resolvedChartSort) : chartForUi,
68679
+ [chartForUi, resolvedChartSort]
68680
+ );
68046
68681
  const isPivotTableChart = String(chartType ?? "").toLowerCase() === "table" && Boolean(pivotState);
68047
- const pivotTableColumnControls = (0, import_react62.useMemo)(
68682
+ const pivotTableColumnControls = (0, import_react61.useMemo)(
68048
68683
  () => isPivotTableChart ? buildPivotColumnPivotTableFormattingColumns(pivotState, chart) : null,
68049
68684
  [chart, isPivotTableChart, pivotState]
68050
68685
  );
68051
- const chartAxes = (0, import_react62.useMemo)(() => {
68686
+ const chartAxes = (0, import_react61.useMemo)(() => {
68052
68687
  const yAxisItems = resolvedYAxisFields.map(
68053
68688
  (yAxisField, index) => ({
68054
68689
  id: String(index),
@@ -68197,8 +68832,8 @@ function useReport(reportIdArg, options = {}) {
68197
68832
  xAxisOptions,
68198
68833
  yAxisOptions
68199
68834
  ]);
68200
- const tableFormatCacheRef = (0, import_react62.useRef)(/* @__PURE__ */ new Map());
68201
- const tableFormatMerge = (0, import_react62.useMemo)(
68835
+ const tableFormatCacheRef = (0, import_react61.useRef)(/* @__PURE__ */ new Map());
68836
+ const tableFormatMerge = (0, import_react61.useMemo)(
68202
68837
  () => mergeDisplayAndSourceForTableFormats({
68203
68838
  effectiveReportBuilderTableNames,
68204
68839
  scopedSchemaColumns,
@@ -68214,7 +68849,7 @@ function useReport(reportIdArg, options = {}) {
68214
68849
  tableColumnsEditedSignature
68215
68850
  ]
68216
68851
  );
68217
- const table = (0, import_react62.useMemo)(() => {
68852
+ const table = (0, import_react61.useMemo)(() => {
68218
68853
  const baseWindowRows = Array.isArray(sourceReport?.rows) ? sourceReport.rows : [];
68219
68854
  const rawRows = tablePageRows ?? baseWindowRows.slice(paginationRangeStart, paginationRangeEnd);
68220
68855
  const { columns: mergedFromReport } = mergeDisplayAndSourceForTableFormats({
@@ -68344,7 +68979,7 @@ function useReport(reportIdArg, options = {}) {
68344
68979
  const {
68345
68980
  columnsOptions: tableFormattingColumnOptions,
68346
68981
  hasTableDrivenColumnOrder
68347
- } = (0, import_react62.useMemo)(() => {
68982
+ } = (0, import_react61.useMemo)(() => {
68348
68983
  if (pivotTableColumnControls) {
68349
68984
  return getAllColumnOptions({
68350
68985
  schemaColumnOptions,
@@ -68374,24 +69009,24 @@ function useReport(reportIdArg, options = {}) {
68374
69009
  schemaColumnOptions,
68375
69010
  table.columns
68376
69011
  ]);
68377
- const axisSelectFormatLabels = (0, import_react62.useMemo)(
69012
+ const axisSelectFormatLabels = (0, import_react61.useMemo)(
68378
69013
  () => AXIS_FORMAT_OPTIONS.map((option) => option.label),
68379
69014
  []
68380
69015
  );
68381
- const xAxisFormatOptionLabels = (0, import_react62.useMemo)(() => {
69016
+ const xAxisFormatOptionLabels = (0, import_react61.useMemo)(() => {
68382
69017
  if (isPivotTableDateBucketRowAxis(chartAxesBaseChart, resolvedXAxisField)) {
68383
69018
  return ["date", ...axisSelectFormatLabels];
68384
69019
  }
68385
69020
  return axisSelectFormatLabels;
68386
69021
  }, [chartAxesBaseChart, resolvedXAxisField, axisSelectFormatLabels]);
68387
- const tableDerivedColumnOrder = (0, import_react62.useMemo)(() => {
69022
+ const tableDerivedColumnOrder = (0, import_react61.useMemo)(() => {
68388
69023
  return tableFormattingColumnOptions.map((option) => option.value);
68389
69024
  }, [tableFormattingColumnOptions]);
68390
- const tableDerivedColumnOrderSignature = (0, import_react62.useMemo)(
69025
+ const tableDerivedColumnOrderSignature = (0, import_react61.useMemo)(
68391
69026
  () => tableDerivedColumnOrder.join("|"),
68392
69027
  [tableDerivedColumnOrder]
68393
69028
  );
68394
- const activeTableColumnIds = (0, import_react62.useMemo)(() => {
69029
+ const activeTableColumnIds = (0, import_react61.useMemo)(() => {
68395
69030
  if (pivotTableColumnControls) {
68396
69031
  return pivotTableColumnControls.selectedColumnIds;
68397
69032
  }
@@ -68425,7 +69060,7 @@ function useReport(reportIdArg, options = {}) {
68425
69060
  tableDerivedColumnOrder,
68426
69061
  tableFormattingColumnOptions
68427
69062
  ]);
68428
- const columnOptionById = (0, import_react62.useMemo)(() => {
69063
+ const columnOptionById = (0, import_react61.useMemo)(() => {
68429
69064
  const map = /* @__PURE__ */ new Map();
68430
69065
  for (const option of tableColumnPickerPoolOptions) {
68431
69066
  map.set(option.value, option);
@@ -68437,7 +69072,7 @@ function useReport(reportIdArg, options = {}) {
68437
69072
  }
68438
69073
  return map;
68439
69074
  }, [tableColumnPickerPoolOptions, tableFormattingColumnOptions]);
68440
- const displayColumnById = (0, import_react62.useMemo)(() => {
69075
+ const displayColumnById = (0, import_react61.useMemo)(() => {
68441
69076
  const map = /* @__PURE__ */ new Map();
68442
69077
  for (const column of displayColumns) {
68443
69078
  const field = String(column.field ?? "").trim();
@@ -68448,7 +69083,7 @@ function useReport(reportIdArg, options = {}) {
68448
69083
  }
68449
69084
  return map;
68450
69085
  }, [displayColumns]);
68451
- const tableColumnSettingsById = (0, import_react62.useMemo)(() => {
69086
+ const tableColumnSettingsById = (0, import_react61.useMemo)(() => {
68452
69087
  const map = /* @__PURE__ */ new Map();
68453
69088
  const effectiveById = tableFormatMerge.formatByColumnOptionId;
68454
69089
  const mergedColumnByField = /* @__PURE__ */ new Map();
@@ -68578,13 +69213,13 @@ function useReport(reportIdArg, options = {}) {
68578
69213
  sourceReport?.columns,
68579
69214
  tableFormatMerge
68580
69215
  ]);
68581
- const tableColumnSettingsCoalesceRef = (0, import_react62.useRef)(
69216
+ const tableColumnSettingsCoalesceRef = (0, import_react61.useRef)(
68582
69217
  /* @__PURE__ */ new Map()
68583
69218
  );
68584
- (0, import_react62.useLayoutEffect)(() => {
69219
+ (0, import_react61.useLayoutEffect)(() => {
68585
69220
  tableColumnSettingsCoalesceRef.current = new Map(tableColumnSettingsById);
68586
69221
  }, [tableColumnSettingsById]);
68587
- const tableColumnItems = (0, import_react62.useMemo)(() => {
69222
+ const tableColumnItems = (0, import_react61.useMemo)(() => {
68588
69223
  const pivotRowFieldForFormat = String(chart?.pivot?.rowField ?? "").trim();
68589
69224
  const pivotRowFieldType = String(chart?.pivot?.rowFieldType ?? "").trim();
68590
69225
  const items = activeTableColumnIds.map((columnId) => {
@@ -68620,10 +69255,10 @@ function useReport(reportIdArg, options = {}) {
68620
69255
  isPivotTableChart,
68621
69256
  tableColumnSettingsById
68622
69257
  ]);
68623
- const tableColumnById = (0, import_react62.useMemo)(() => {
69258
+ const tableColumnById = (0, import_react61.useMemo)(() => {
68624
69259
  return new Map(tableColumnItems.map((item) => [item.id, item]));
68625
69260
  }, [tableColumnItems]);
68626
- const tableColumnValues = (0, import_react62.useMemo)(() => {
69261
+ const tableColumnValues = (0, import_react61.useMemo)(() => {
68627
69262
  const pivotRowFieldForFormat = String(chart?.pivot?.rowField ?? "").trim();
68628
69263
  const pivotRowFieldType = String(chart?.pivot?.rowFieldType ?? "").trim();
68629
69264
  return tableColumnItems.map((item) => {
@@ -68837,6 +69472,11 @@ function useReport(reportIdArg, options = {}) {
68837
69472
  showLegend: Boolean(effectiveNextState.showLegend)
68838
69473
  }));
68839
69474
  }
69475
+ if (effectiveNextState.chartSort !== void 0) {
69476
+ setChartSortOverride(
69477
+ parseChartSortValue(effectiveNextState.chartSort) ?? null
69478
+ );
69479
+ }
68840
69480
  if (effectiveNextState.xAxis !== void 0 || effectiveNextState.yAxis !== void 0 || effectiveNextState.chartAxes !== void 0) {
68841
69481
  const cx = {
68842
69482
  ...effectiveNextState.chartAxes,
@@ -69409,60 +70049,10 @@ function useReport(reportIdArg, options = {}) {
69409
70049
  })
69410
70050
  });
69411
70051
  }
69412
- } catch (error) {
69413
- const requestedFieldNames = (resolved?.rules ?? []).map((rule) => String(rule?.field ?? "").trim()).filter(Boolean);
69414
- const relevantFieldConfigs = Object.fromEntries(
69415
- Object.entries(queryBuilderFieldConfigByName ?? {}).filter(
69416
- ([key, config]) => {
69417
- const configuredField = String(config?.field ?? "").trim();
69418
- return requestedFieldNames.some((requestedField) => {
69419
- const bareRequestedField = requestedField.split(".").pop() ?? "";
69420
- return key === requestedField || configuredField === requestedField || configuredField === bareRequestedField;
69421
- });
69422
- }
69423
- )
69424
- );
69425
- console.error("[useForm] setFilters swallowed error", {
69426
- error: error instanceof Error ? error.message : String(error),
69427
- stack: error instanceof Error ? error.stack : void 0,
69428
- reportId: effectiveReportId,
69429
- requestedRules: (resolved?.rules ?? []).map((rule) => ({
69430
- table: rule?.table,
69431
- field: rule?.field,
69432
- operator: rule?.operator,
69433
- value: rule?.value
69434
- })),
69435
- normalizedRules: (nextFiltersNormalizedForConfig?.rules ?? []).map((rule) => ({
69436
- table: rule?.table,
69437
- field: rule?.field,
69438
- operator: rule?.operator,
69439
- value: rule?.value
69440
- })),
69441
- relevantFieldConfigs,
69442
- pivot: nextPivot,
69443
- reportBuilderTables: effectiveReportBuilderState?.tables,
69444
- reportBuilderColumns: effectiveReportBuilderColumns.filter(
69445
- (column) => requestedFieldNames.some((requestedField) => {
69446
- const bareRequestedField = requestedField.split(".").pop() ?? "";
69447
- return String(column.field ?? "").trim() === bareRequestedField;
69448
- })
69449
- ).map((column) => ({
69450
- table: column.table,
69451
- field: column.field,
69452
- alias: column.alias
69453
- })),
69454
- schemaTablesWithRequestedFields: schemaForReportBuilderState.filter(
69455
- (table2) => table2.columns?.some(
69456
- (column) => requestedFieldNames.some(
69457
- (requestedField) => String(column.field ?? "").trim() === (requestedField.split(".").pop() ?? "")
69458
- )
69459
- )
69460
- ).map((table2) => table2.name),
69461
- fieldConfigKeys: Object.keys(queryBuilderFieldConfigByName ?? {})
69462
- });
70052
+ } catch {
69463
70053
  }
69464
70054
  };
69465
- const saveChanges = (0, import_react62.useCallback)(async () => {
70055
+ const saveChanges = (0, import_react61.useCallback)(async () => {
69466
70056
  if (!client) return;
69467
70057
  if (!String(dashboardNameForNewReport ?? "").trim()) return;
69468
70058
  if (!sourceReport) return;
@@ -69498,7 +70088,8 @@ function useReport(reportIdArg, options = {}) {
69498
70088
  xAxisFormat: resolvedXAxisFormat,
69499
70089
  xAxisLabel: resolvedXAxisLabel,
69500
70090
  yAxisFields: resolvedYAxisFields,
69501
- showLegend: chartVisibility.showLegend
70091
+ showLegend: chartVisibility.showLegend,
70092
+ chartSort: resolvedChartSort ?? null
69502
70093
  },
69503
70094
  dashboardItemId: effectiveReportId || void 0,
69504
70095
  client,
@@ -69516,6 +70107,7 @@ function useReport(reportIdArg, options = {}) {
69516
70107
  queryKey: ["quill", "dashboard-report", savedReportId],
69517
70108
  refetchType: "none"
69518
70109
  });
70110
+ await loadDashboard(dashboardNameForNewReport, true);
69519
70111
  }
69520
70112
  return resp;
69521
70113
  }, [
@@ -69528,11 +70120,13 @@ function useReport(reportIdArg, options = {}) {
69528
70120
  eventTracking,
69529
70121
  formReportName,
69530
70122
  getToken,
70123
+ loadDashboard,
69531
70124
  queryClient,
69532
70125
  resolvedXAxisField,
69533
70126
  resolvedXAxisFormat,
69534
70127
  resolvedXAxisLabel,
69535
70128
  resolvedChartType,
70129
+ resolvedChartSort,
69536
70130
  resolvedYAxisFields,
69537
70131
  sourceReport,
69538
70132
  setDraftSessionId,
@@ -69541,7 +70135,7 @@ function useReport(reportIdArg, options = {}) {
69541
70135
  ]);
69542
70136
  return {
69543
70137
  /* ── Chart & table (exceptions: not value/options pairs) ── */
69544
- chart: chartForUi,
70138
+ chart: chartWithSort,
69545
70139
  chartLoading,
69546
70140
  table,
69547
70141
  tableLoading,
@@ -69569,6 +70163,9 @@ function useReport(reportIdArg, options = {}) {
69569
70163
  aggregationDescriptionOptions: cleanedAggregations,
69570
70164
  sort: cleanedSort,
69571
70165
  sortOptions,
70166
+ /** Display-only chart ordering; update with a value from `chartSortOptions`. */
70167
+ chartSort,
70168
+ chartSortOptions,
69572
70169
  chartType: resolvedChartType,
69573
70170
  chartTypeOptions: chartTypes,
69574
70171
  /** Selected tabular columns in display order. */
@@ -69645,7 +70242,7 @@ function ChatChartCard({
69645
70242
  loading,
69646
70243
  setReport
69647
70244
  } = useReport(reportId);
69648
- const selectedColumnValues = (0, import_react63.useMemo)(
70245
+ const selectedColumnValues = (0, import_react62.useMemo)(
69649
70246
  () => columns.map((column) => column.value),
69650
70247
  [columns]
69651
70248
  );
@@ -69912,7 +70509,7 @@ function ToolCallBlock({ toolCall }) {
69912
70509
  );
69913
70510
  }
69914
70511
  function ToolCallResult({ content }) {
69915
- const [expanded, setExpanded] = (0, import_react64.useState)(false);
70512
+ const [expanded, setExpanded] = (0, import_react63.useState)(false);
69916
70513
  if (!content) return null;
69917
70514
  const isLong = content.length > 300;
69918
70515
  const displayed = isLong && !expanded ? content.slice(0, 300) + "..." : content;
@@ -69964,18 +70561,18 @@ function Chat({
69964
70561
  agentEndpoint,
69965
70562
  suggestions
69966
70563
  }) {
69967
- const [client] = (0, import_react64.useContext)(ClientContext);
69968
- const { getToken } = (0, import_react64.useContext)(FetchContext);
69969
- const { tenants } = (0, import_react64.useContext)(TenantContext);
69970
- const [messages, setMessages] = (0, import_react64.useState)([]);
69971
- const [input, setInput] = (0, import_react64.useState)("");
69972
- const [inputError, setInputError] = (0, import_react64.useState)("");
69973
- const [isLoading, setIsLoading] = (0, import_react64.useState)(false);
69974
- const [model, setModel] = (0, import_react64.useState)("gemini-3-flash-preview");
69975
- const containerRef = (0, import_react64.useRef)(null);
69976
- const textareaRef = (0, import_react64.useRef)(null);
69977
- const abortControllerRef = (0, import_react64.useRef)(null);
69978
- (0, import_react64.useEffect)(() => {
70564
+ const [client] = (0, import_react63.useContext)(ClientContext);
70565
+ const { getToken } = (0, import_react63.useContext)(FetchContext);
70566
+ const { tenants } = (0, import_react63.useContext)(TenantContext);
70567
+ const [messages, setMessages] = (0, import_react63.useState)([]);
70568
+ const [input, setInput] = (0, import_react63.useState)("");
70569
+ const [inputError, setInputError] = (0, import_react63.useState)("");
70570
+ const [isLoading, setIsLoading] = (0, import_react63.useState)(false);
70571
+ const [model, setModel] = (0, import_react63.useState)("gemini-3-flash-preview");
70572
+ const containerRef = (0, import_react63.useRef)(null);
70573
+ const textareaRef = (0, import_react63.useRef)(null);
70574
+ const abortControllerRef = (0, import_react63.useRef)(null);
70575
+ (0, import_react63.useEffect)(() => {
69979
70576
  if (!containerRef.current) {
69980
70577
  return;
69981
70578
  }
@@ -70409,7 +71006,7 @@ function Chat({
70409
71006
  }
70410
71007
 
70411
71008
  // src/hooks/useReportFilterDraft.ts
70412
- var import_react65 = require("react");
71009
+ var import_react64 = require("react");
70413
71010
  var normalizeOperatorKey = (operator) => String(operator ?? "").trim().toLowerCase().replace(/[_\s]+/g, "");
70414
71011
  var defaultFilterRuleValueForOperator = (operator) => {
70415
71012
  const key = normalizeOperatorKey(operator);
@@ -70448,12 +71045,12 @@ function useReportFilterDraft(args) {
70448
71045
  const committed = queryBuilderFiltersForEditor(
70449
71046
  isQueryBuilderDisplayGroup(committedFilters) ? committedFilters : EMPTY_COMMITTED_FILTERS
70450
71047
  );
70451
- const committedRef = (0, import_react65.useRef)(committed);
71048
+ const committedRef = (0, import_react64.useRef)(committed);
70452
71049
  committedRef.current = committed;
70453
- const setFiltersRef = (0, import_react65.useRef)(setFilters);
71050
+ const setFiltersRef = (0, import_react64.useRef)(setFilters);
70454
71051
  setFiltersRef.current = setFilters;
70455
- const lastNonEmptyFieldsRef = (0, import_react65.useRef)([]);
70456
- const prevReportIdForFieldsRef = (0, import_react65.useRef)(reportId);
71052
+ const lastNonEmptyFieldsRef = (0, import_react64.useRef)([]);
71053
+ const prevReportIdForFieldsRef = (0, import_react64.useRef)(reportId);
70457
71054
  if (prevReportIdForFieldsRef.current !== reportId) {
70458
71055
  prevReportIdForFieldsRef.current = reportId;
70459
71056
  lastNonEmptyFieldsRef.current = [];
@@ -70462,25 +71059,25 @@ function useReportFilterDraft(args) {
70462
71059
  lastNonEmptyFieldsRef.current = queryBuilderProps.fields;
70463
71060
  }
70464
71061
  const effectiveFields = queryBuilderProps.fields.length > 0 ? queryBuilderProps.fields : lastNonEmptyFieldsRef.current;
70465
- const committedSignature = (0, import_react65.useMemo)(
71062
+ const committedSignature = (0, import_react64.useMemo)(
70466
71063
  () => committedFiltersSignature(committed),
70467
71064
  // eslint-disable-next-line react-hooks/exhaustive-deps -- `committed` normalizes null to a stable constant
70468
71065
  [committedFilters]
70469
71066
  );
70470
- const fieldsSignature = (0, import_react65.useMemo)(
71067
+ const fieldsSignature = (0, import_react64.useMemo)(
70471
71068
  () => fieldCatalogSignature(effectiveFields),
70472
71069
  [effectiveFields]
70473
71070
  );
70474
- const [resetEpoch, setResetEpoch] = (0, import_react65.useState)(0);
70475
- const [draftQuery, setDraftQuery] = (0, import_react65.useState)(committed);
70476
- const [hasUnappliedFilterChanges, setHasUnappliedFilterChanges] = (0, import_react65.useState)(false);
71071
+ const [resetEpoch, setResetEpoch] = (0, import_react64.useState)(0);
71072
+ const [draftQuery, setDraftQuery] = (0, import_react64.useState)(committed);
71073
+ const [hasUnappliedFilterChanges, setHasUnappliedFilterChanges] = (0, import_react64.useState)(false);
70477
71074
  const draftResetKey = `${reportId}|${committedSignature}|${resetEpoch}`;
70478
- (0, import_react65.useEffect)(() => {
71075
+ (0, import_react64.useEffect)(() => {
70479
71076
  setDraftQuery(committedRef.current);
70480
71077
  setHasUnappliedFilterChanges(false);
70481
71078
  }, [draftResetKey]);
70482
71079
  const filterDraftKey = `${draftResetKey}|${fieldsSignature}`;
70483
- const handleQueryChange = (0, import_react65.useCallback)((next) => {
71080
+ const handleQueryChange = (0, import_react64.useCallback)((next) => {
70484
71081
  if (!isQueryBuilderDisplayGroup(next)) return;
70485
71082
  const nextGroup = next;
70486
71083
  setDraftQuery(nextGroup);
@@ -70492,25 +71089,25 @@ function useReportFilterDraft(args) {
70492
71089
  (prev) => prev === nextDirty ? prev : nextDirty
70493
71090
  );
70494
71091
  }, []);
70495
- const applyFilterDraft = (0, import_react65.useCallback)(() => {
71092
+ const applyFilterDraft = (0, import_react64.useCallback)(() => {
70496
71093
  setFiltersRef.current(draftQuery);
70497
71094
  }, [draftQuery]);
70498
- const resetFilterDraft = (0, import_react65.useCallback)(() => {
71095
+ const resetFilterDraft = (0, import_react64.useCallback)(() => {
70499
71096
  setDraftQuery(committedRef.current);
70500
71097
  setHasUnappliedFilterChanges(false);
70501
71098
  setResetEpoch((epoch) => epoch + 1);
70502
71099
  }, []);
70503
- const getDefaultField = (0, import_react65.useCallback)((fields) => {
71100
+ const getDefaultField = (0, import_react64.useCallback)((fields) => {
70504
71101
  const stringField = fields.find(
70505
71102
  (field) => field.quillFieldType === "string" && String(field.name ?? "").trim()
70506
71103
  );
70507
71104
  return stringField?.name ?? fields[0]?.name ?? "";
70508
71105
  }, []);
70509
- const getDefaultValue = (0, import_react65.useCallback)(
71106
+ const getDefaultValue = (0, import_react64.useCallback)(
70510
71107
  (rule) => defaultFilterRuleValueForOperator(rule?.operator),
70511
71108
  []
70512
71109
  );
70513
- const filterDraftQueryBuilderProps = (0, import_react65.useMemo)(
71110
+ const filterDraftQueryBuilderProps = (0, import_react64.useMemo)(
70514
71111
  () => ({
70515
71112
  ...queryBuilderProps,
70516
71113
  fields: effectiveFields,
@@ -70563,7 +71160,7 @@ function useReportQueryBuilder(args) {
70563
71160
  }
70564
71161
 
70565
71162
  // src/ReportDetail.tsx
70566
- var import_react66 = require("react");
71163
+ var import_react65 = require("react");
70567
71164
  var import_jsx_runtime89 = require("react/jsx-runtime");
70568
71165
  var CHART_MIN_PX = 220;
70569
71166
  var TABLE_SLOT_HEIGHT_PX = 360;
@@ -70654,7 +71251,7 @@ function ReportDetail({
70654
71251
  hideTableChartOuterBorder = false,
70655
71252
  onClickChartElement
70656
71253
  }) {
70657
- const [theme] = (0, import_react66.useContext)(ThemeContext);
71254
+ const [theme] = (0, import_react65.useContext)(ThemeContext);
70658
71255
  const surfaceBackground = theme?.backgroundColor ?? "#fff";
70659
71256
  const titleColor = theme?.primaryTextColor ?? "var(--foreground, #0f172a)";
70660
71257
  const mutedTextColor = theme?.secondaryTextColor ?? "#64748B";
@@ -70663,9 +71260,9 @@ function ReportDetail({
70663
71260
  const isTableChart = type === "table";
70664
71261
  const useDetailTableFromUseForm = isTableChart && !isPivotTableChartConfig(chart);
70665
71262
  const showBottomRawTable = !isTableChart;
70666
- const chartSlotRef = (0, import_react66.useRef)(null);
70667
- const [chartHeightPx, setChartHeightPx] = (0, import_react66.useState)(360);
70668
- (0, import_react66.useLayoutEffect)(() => {
71263
+ const chartSlotRef = (0, import_react65.useRef)(null);
71264
+ const [chartHeightPx, setChartHeightPx] = (0, import_react65.useState)(360);
71265
+ (0, import_react65.useLayoutEffect)(() => {
70669
71266
  const el = chartSlotRef.current;
70670
71267
  if (!el) {
70671
71268
  return;
@@ -70790,7 +71387,7 @@ function ReportDetail({
70790
71387
  init_valueFormatter();
70791
71388
 
70792
71389
  // src/hooks/useTenants.ts
70793
- var import_react67 = require("react");
71390
+ var import_react66 = require("react");
70794
71391
  var useTenants = (dashboardName) => {
70795
71392
  const {
70796
71393
  tenants,
@@ -70803,13 +71400,13 @@ var useTenants = (dashboardName) => {
70803
71400
  fetchMappedTenantsForDashboard,
70804
71401
  getMappedTenantsForDashboard,
70805
71402
  getViewerTenantsByOwner
70806
- } = (0, import_react67.useContext)(TenantContext);
70807
- (0, import_react67.useEffect)(() => {
71403
+ } = (0, import_react66.useContext)(TenantContext);
71404
+ (0, import_react66.useEffect)(() => {
70808
71405
  if (dashboardName) {
70809
71406
  fetchViewerTenantsForDashboard(dashboardName);
70810
71407
  }
70811
71408
  }, [dashboardName, fetchViewerTenantsForDashboard]);
70812
- (0, import_react67.useEffect)(() => {
71409
+ (0, import_react66.useEffect)(() => {
70813
71410
  if (dashboardName) {
70814
71411
  fetchMappedTenantsForDashboard(dashboardName);
70815
71412
  }
@@ -70828,33 +71425,33 @@ var useTenants = (dashboardName) => {
70828
71425
  };
70829
71426
 
70830
71427
  // src/hooks/useQuill.ts
70831
- var import_react68 = require("react");
71428
+ var import_react67 = require("react");
70832
71429
  init_paginationProcessing();
70833
71430
  init_tableProcessing();
70834
71431
  init_dataProcessing();
70835
71432
  var useQuill = (reportId, pagination) => {
70836
- const { reports, reportsDispatch, fetchIndividualReport } = (0, import_react68.useContext)(ReportsContext);
71433
+ const { reports, reportsDispatch, fetchIndividualReport } = (0, import_react67.useContext)(ReportsContext);
70837
71434
  const { allReportsById } = useAllReports();
70838
- const { getToken } = (0, import_react68.useContext)(FetchContext);
70839
- const dashboardReport = (0, import_react68.useMemo)(() => {
71435
+ const { getToken } = (0, import_react67.useContext)(FetchContext);
71436
+ const dashboardReport = (0, import_react67.useMemo)(() => {
70840
71437
  return allReportsById[reportId ?? ""];
70841
71438
  }, [allReportsById[reportId ?? ""]]);
70842
- const { dashboardFilters, dashboardCustomFilters } = (0, import_react68.useContext)(
71439
+ const { dashboardFilters, dashboardCustomFilters } = (0, import_react67.useContext)(
70843
71440
  DashboardFiltersContext
70844
71441
  );
70845
- const { reportFilters, customReportFilters, reportFiltersDispatch } = (0, import_react68.useContext)(ReportFiltersContext);
70846
- const specificReportFilters = (0, import_react68.useMemo)(() => {
71442
+ const { reportFilters, customReportFilters, reportFiltersDispatch } = (0, import_react67.useContext)(ReportFiltersContext);
71443
+ const specificReportFilters = (0, import_react67.useMemo)(() => {
70847
71444
  if (!reportId) return null;
70848
71445
  return Object.values(reportFilters[reportId] ?? []).map((f) => f.filter);
70849
71446
  }, [reportFilters, reportId]);
70850
- const [schemaData] = (0, import_react68.useContext)(SchemaDataContext);
70851
- const [client, isClientLoading] = (0, import_react68.useContext)(ClientContext);
70852
- const { tenants } = (0, import_react68.useContext)(TenantContext);
70853
- const { eventTracking } = (0, import_react68.useContext)(EventTrackingContext);
70854
- const [loading, setLoading] = (0, import_react68.useState)(true);
70855
- const [error, setError] = (0, import_react68.useState)(void 0);
70856
- const [previousPage, setPreviousPage] = (0, import_react68.useState)(0);
70857
- const processedReport = (0, import_react68.useMemo)(() => {
71447
+ const [schemaData] = (0, import_react67.useContext)(SchemaDataContext);
71448
+ const [client, isClientLoading] = (0, import_react67.useContext)(ClientContext);
71449
+ const { tenants } = (0, import_react67.useContext)(TenantContext);
71450
+ const { eventTracking } = (0, import_react67.useContext)(EventTrackingContext);
71451
+ const [loading, setLoading] = (0, import_react67.useState)(true);
71452
+ const [error, setError] = (0, import_react67.useState)(void 0);
71453
+ const [previousPage, setPreviousPage] = (0, import_react67.useState)(0);
71454
+ const processedReport = (0, import_react67.useMemo)(() => {
70858
71455
  return reportId && allReportsById[reportId] ? convertInternalReportToReport(
70859
71456
  mergeComparisonRange(allReportsById[reportId]),
70860
71457
  specificReportFilters ?? [],
@@ -70862,7 +71459,7 @@ var useQuill = (reportId, pagination) => {
70862
71459
  "useQuill"
70863
71460
  ) : void 0;
70864
71461
  }, [reportId, reportId && allReportsById[reportId], specificReportFilters]);
70865
- const [additionalProcessing, setAdditionProcessing] = (0, import_react68.useState)(
71462
+ const [additionalProcessing, setAdditionProcessing] = (0, import_react67.useState)(
70866
71463
  pagination ? {
70867
71464
  page: pagination
70868
71465
  } : void 0
@@ -71011,7 +71608,7 @@ var useQuill = (reportId, pagination) => {
71011
71608
  setLoading(false);
71012
71609
  }
71013
71610
  };
71014
- (0, import_react68.useEffect)(() => {
71611
+ (0, import_react67.useEffect)(() => {
71015
71612
  if (isClientLoading) return;
71016
71613
  if (reportId && specificReportFilters) {
71017
71614
  fetchReportHelper(reportId, {
@@ -71051,10 +71648,10 @@ var useQuill = (reportId, pagination) => {
71051
71648
 
71052
71649
  // src/hooks/useFormat.ts
71053
71650
  init_valueFormatter();
71054
- var import_react69 = require("react");
71651
+ var import_react68 = require("react");
71055
71652
  var useMemoizedRows = (reportId) => {
71056
71653
  const { data } = useQuill(reportId);
71057
- const formattedRows = (0, import_react69.useMemo)(() => {
71654
+ const formattedRows = (0, import_react68.useMemo)(() => {
71058
71655
  if (!data || !data.rows || !data.columns)
71059
71656
  return { rows: [], loading: true };
71060
71657
  return {
@@ -71078,7 +71675,7 @@ var useMemoizedRows = (reportId) => {
71078
71675
  };
71079
71676
 
71080
71677
  // src/hooks/useAskQuill.tsx
71081
- var import_react70 = require("react");
71678
+ var import_react69 = require("react");
71082
71679
  init_astProcessing();
71083
71680
  init_astFilterProcessing();
71084
71681
  init_pivotProcessing();
@@ -71106,13 +71703,13 @@ function convertColumnInternalToAskQuillColumn(columns) {
71106
71703
  });
71107
71704
  }
71108
71705
  var useAskQuill = (dashboardName) => {
71109
- const [client] = (0, import_react70.useContext)(ClientContext);
71110
- const [schemaData] = (0, import_react70.useContext)(SchemaDataContext);
71111
- const { tenants } = (0, import_react70.useContext)(TenantContext);
71112
- const { getToken } = (0, import_react70.useContext)(FetchContext);
71113
- const { eventTracking } = (0, import_react70.useContext)(EventTrackingContext);
71114
- const [astInfo, setAstInfo] = (0, import_react70.useState)(void 0);
71115
- const [data, setData] = (0, import_react70.useState)({
71706
+ const [client] = (0, import_react69.useContext)(ClientContext);
71707
+ const [schemaData] = (0, import_react69.useContext)(SchemaDataContext);
71708
+ const { tenants } = (0, import_react69.useContext)(TenantContext);
71709
+ const { getToken } = (0, import_react69.useContext)(FetchContext);
71710
+ const { eventTracking } = (0, import_react69.useContext)(EventTrackingContext);
71711
+ const [astInfo, setAstInfo] = (0, import_react69.useState)(void 0);
71712
+ const [data, setData] = (0, import_react69.useState)({
71116
71713
  rows: [],
71117
71714
  columns: [],
71118
71715
  pivot: null,
@@ -71122,9 +71719,9 @@ var useAskQuill = (dashboardName) => {
71122
71719
  pivotColumnFields: [],
71123
71720
  pivotValueFields: []
71124
71721
  });
71125
- const [loading, setLoading] = (0, import_react70.useState)(false);
71126
- const [error, setError] = (0, import_react70.useState)(void 0);
71127
- const [ask, setAsk] = (0, import_react70.useState)(
71722
+ const [loading, setLoading] = (0, import_react69.useState)(false);
71723
+ const [error, setError] = (0, import_react69.useState)(void 0);
71724
+ const [ask, setAsk] = (0, import_react69.useState)(
71128
71725
  async () => void 0
71129
71726
  );
71130
71727
  const askHelper = async (query) => {
@@ -71324,7 +71921,7 @@ var useAskQuill = (dashboardName) => {
71324
71921
  });
71325
71922
  setLoading(false);
71326
71923
  };
71327
- (0, import_react70.useEffect)(() => {
71924
+ (0, import_react69.useEffect)(() => {
71328
71925
  setAsk(() => askHelper);
71329
71926
  }, [schemaData.schema]);
71330
71927
  return {
@@ -71338,13 +71935,13 @@ var useAskQuill = (dashboardName) => {
71338
71935
  };
71339
71936
 
71340
71937
  // src/hooks/useVirtualTables.tsx
71341
- var import_react71 = require("react");
71938
+ var import_react70 = require("react");
71342
71939
  var useVirtualTables = () => {
71343
- const [schemaData, setSchemaData] = (0, import_react71.useContext)(SchemaDataContext);
71344
- const { tenants } = (0, import_react71.useContext)(TenantContext);
71345
- const { getToken, quillFetchWithToken } = (0, import_react71.useContext)(FetchContext);
71346
- const { eventTracking } = (0, import_react71.useContext)(EventTrackingContext);
71347
- const [loadingTables, setLoadingTables] = (0, import_react71.useState)({});
71940
+ const [schemaData, setSchemaData] = (0, import_react70.useContext)(SchemaDataContext);
71941
+ const { tenants } = (0, import_react70.useContext)(TenantContext);
71942
+ const { getToken, quillFetchWithToken } = (0, import_react70.useContext)(FetchContext);
71943
+ const { eventTracking } = (0, import_react70.useContext)(EventTrackingContext);
71944
+ const [loadingTables, setLoadingTables] = (0, import_react70.useState)({});
71348
71945
  const handleReload = async (client, caller) => {
71349
71946
  setSchemaData({ ...schemaData, isSchemaLoading: true });
71350
71947
  setLoadingTables(
@@ -71482,7 +72079,7 @@ var useVirtualTables = () => {
71482
72079
  };
71483
72080
 
71484
72081
  // src/hooks/useChangelogRefresh.ts
71485
- var import_react72 = require("react");
72082
+ var import_react71 = require("react");
71486
72083
  init_filterProcessing();
71487
72084
  var CALLER = "agent-changelog";
71488
72085
  var getChangeType = (entry) => {
@@ -71503,15 +72100,15 @@ var getChangeType = (entry) => {
71503
72100
  return typeof changeType === "string" ? changeType.toUpperCase() : "UNKNOWN";
71504
72101
  };
71505
72102
  var useChangelogRefresh = () => {
71506
- const { loadDashboard, dashboardConfig, dashboardConfigDispatch } = (0, import_react72.useContext)(DashboardConfigContext);
72103
+ const { loadDashboard, dashboardConfig, dashboardConfigDispatch } = (0, import_react71.useContext)(DashboardConfigContext);
71507
72104
  const {
71508
72105
  loadFiltersForDashboard,
71509
72106
  dispatch: dashboardFiltersDispatch,
71510
72107
  customFilterDispatch
71511
- } = (0, import_react72.useContext)(DashboardFiltersContext);
71512
- const [, dashboardDispatch] = (0, import_react72.useContext)(DashboardContext);
71513
- const { reportsDispatch } = (0, import_react72.useContext)(ReportsContext);
71514
- const [, setSchemaData] = (0, import_react72.useContext)(SchemaDataContext);
72108
+ } = (0, import_react71.useContext)(DashboardFiltersContext);
72109
+ const [, dashboardDispatch] = (0, import_react71.useContext)(DashboardContext);
72110
+ const { reportsDispatch } = (0, import_react71.useContext)(ReportsContext);
72111
+ const [, setSchemaData] = (0, import_react71.useContext)(SchemaDataContext);
71515
72112
  const { allReportsById } = useAllReports();
71516
72113
  const { reloadSome } = useVirtualTables();
71517
72114
  const refreshChangelogEntries = async (entries2, client) => {