@quillsql/react 2.16.43 → 2.16.45

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
@@ -14976,6 +14976,9 @@ function resolvePivotDateBucket({
14976
14976
  if (override) {
14977
14977
  return override;
14978
14978
  }
14979
+ if (pivot?.dateBucket) {
14980
+ return pivot.dateBucket;
14981
+ }
14979
14982
  const inferred = inferDateBucketFromFilters(
14980
14983
  pivot ?? {},
14981
14984
  filters ?? []
@@ -19496,6 +19499,8 @@ var init_tableProcessing = __esm({
19496
19499
  pivot,
19497
19500
  getPivotRowCount = true,
19498
19501
  comparisonQuery,
19502
+ reportId,
19503
+ dateBucket,
19499
19504
  getToken,
19500
19505
  eventTracking
19501
19506
  }) => {
@@ -19507,9 +19512,26 @@ var init_tableProcessing = __esm({
19507
19512
  let referencedTables = void 0;
19508
19513
  try {
19509
19514
  if (pivot) {
19515
+ const dateFilter = filters?.find(
19516
+ (filter) => filter.filterType === "date_range" || filter.operator === "BETWEEN"
19517
+ );
19518
+ const normalizedDateFilter = dateFilter?.operator === "BETWEEN" ? {
19519
+ ...dateFilter,
19520
+ startDate: dateFilter.value?.[0],
19521
+ endDate: dateFilter.value?.[1]
19522
+ } : dateFilter;
19523
+ const resolvedDateBucket = resolvePivotDateBucket({
19524
+ pivot,
19525
+ filters,
19526
+ override: dateBucket
19527
+ });
19510
19528
  const pivotData = await generatePivotWithSQL({
19511
19529
  pivot,
19530
+ report: reportId ? { id: reportId } : void 0,
19512
19531
  client,
19532
+ dateBucket: resolvedDateBucket,
19533
+ dateFilter: normalizedDateFilter,
19534
+ dashboardFilters: filters,
19513
19535
  pivotQuery: query,
19514
19536
  comparisonPivotQuery: comparisonQuery,
19515
19537
  additionalProcessing: processing,
@@ -19647,6 +19669,7 @@ var init_tableProcessing = __esm({
19647
19669
  pivotQuery,
19648
19670
  comparisonPivotQuery,
19649
19671
  getPivotRowCount = true,
19672
+ dateBucket,
19650
19673
  getToken,
19651
19674
  eventTracking
19652
19675
  }) => {
@@ -19660,6 +19683,8 @@ var init_tableProcessing = __esm({
19660
19683
  customFields,
19661
19684
  filters,
19662
19685
  pivot,
19686
+ reportId,
19687
+ dateBucket,
19663
19688
  getPivotRowCount,
19664
19689
  getToken,
19665
19690
  eventTracking
@@ -20887,6 +20912,8 @@ __export(index_exports, {
20887
20912
  ChartDisplay: () => ChartDisplay,
20888
20913
  ChartEditor: () => ChartEditor,
20889
20914
  Chat: () => Chat,
20915
+ DEFAULT_PAGE_SIZE: () => DEFAULT_PAGE_SIZE,
20916
+ DEFAULT_USE_REPORT_ROWS_PER_REQUEST: () => DEFAULT_USE_REPORT_ROWS_PER_REQUEST,
20890
20917
  Dashboard: () => Dashboard,
20891
20918
  DashboardFilterType: () => DashboardFilterType,
20892
20919
  DashboardLegacy: () => DashboardLegacy,
@@ -21267,6 +21294,7 @@ async function cleanDashboardItem({
21267
21294
  dateField: item.dateField,
21268
21295
  pivot: pivotError ? void 0 : item.pivot ? {
21269
21296
  ...item.pivot,
21297
+ dateBucket: dateBucket ?? item.pivot.dateBucket,
21270
21298
  aggregations: item.pivot.aggregations ?? [
21271
21299
  {
21272
21300
  valueField: item.pivot.valueField,
@@ -21693,7 +21721,8 @@ function coalescePivotsForPivotTemplateMetadata(hookPivot, rbsPivot) {
21693
21721
  columnFieldType: hookPivot.columnFieldType ?? rbsPivot.columnFieldType,
21694
21722
  rowFieldTable: rowField ? hookPivot.rowFieldTable ?? rbsPivot.rowFieldTable : void 0,
21695
21723
  columnFieldTable: columnField ? hookPivot.columnFieldTable ?? rbsPivot.columnFieldTable : void 0,
21696
- aggregations: aggregations ?? hookPivot.aggregations ?? rbsPivot.aggregations
21724
+ aggregations: aggregations ?? hookPivot.aggregations ?? rbsPivot.aggregations,
21725
+ dateBucket: hookPivot.dateBucket ?? rbsPivot.dateBucket
21697
21726
  };
21698
21727
  }
21699
21728
  function shapePivotForPivotTemplateMetadata(pivot) {
@@ -21781,6 +21810,7 @@ function createPivotTemplateMetadata({
21781
21810
  }) {
21782
21811
  const { normalizedPivot, normalizedReportBuilderState } = preparePivotLayersForPivotTemplate(pivot, reportBuilderState);
21783
21812
  const normalizedAdditionalProcessing = normalizeLegacyAdditionalProcessingSort(additionalProcessing);
21813
+ const resolvedDateBucket = normalizedPivot?.dateBucket ?? normalizedReportBuilderState?.pivot?.dateBucket;
21784
21814
  return {
21785
21815
  reportId,
21786
21816
  dashboardItemId: reportId,
@@ -21794,7 +21824,8 @@ function createPivotTemplateMetadata({
21794
21824
  flags,
21795
21825
  overwriteCache,
21796
21826
  pivot: normalizedPivot ?? void 0,
21797
- reportBuilderState: normalizedReportBuilderState ?? void 0
21827
+ reportBuilderState: normalizedReportBuilderState ?? void 0,
21828
+ ...resolvedDateBucket ? { dateBucket: resolvedDateBucket } : {}
21798
21829
  };
21799
21830
  }
21800
21831
  async function requestPivotTemplateTask({
@@ -22158,6 +22189,11 @@ async function fetchReport({
22158
22189
  pivotForRequest = prepared.normalizedPivot ?? void 0;
22159
22190
  reportBuilderStateForRequest = prepared.normalizedReportBuilderState;
22160
22191
  }
22192
+ const resolvedDateBucket = usePivotTask ? resolvePivotDateBucket({
22193
+ pivot: pivotForRequest ?? void 0,
22194
+ filters,
22195
+ override: dateBucket
22196
+ }) : void 0;
22161
22197
  const fetchResp = await quillFetch({
22162
22198
  client,
22163
22199
  task,
@@ -22177,7 +22213,8 @@ async function fetchReport({
22177
22213
  flags,
22178
22214
  overwriteCache,
22179
22215
  pivot: pivotForRequest,
22180
- reportBuilderState: reportBuilderStateForRequest
22216
+ reportBuilderState: reportBuilderStateForRequest,
22217
+ ...resolvedDateBucket ? { dateBucket: resolvedDateBucket } : {}
22181
22218
  },
22182
22219
  abortSignal,
22183
22220
  getToken
@@ -32011,6 +32048,10 @@ function QuillTable({
32011
32048
  downloadCSV: downloadCSV2,
32012
32049
  onPageChange,
32013
32050
  onSortChange,
32051
+ manualPagination = false,
32052
+ pageCount,
32053
+ canNextPage,
32054
+ canPreviousPage,
32014
32055
  hideLabels,
32015
32056
  disableSort,
32016
32057
  headerBackgroundColor,
@@ -32029,10 +32070,19 @@ function QuillTable({
32029
32070
  setSortDirection(sort?.direction || "desc");
32030
32071
  }, [sort]);
32031
32072
  const holdFullPageLoader = rows?.length === 0 && isLoading;
32073
+ const pageCountUnknown = manualPagination && pageCount === -1;
32032
32074
  const { activeRows, maxPage } = (0, import_react14.useMemo)(() => {
32033
32075
  const start = currentPage * rowsPerPage;
32034
32076
  const end = (currentPage + 1) * rowsPerPage;
32035
32077
  const rowList = rows ?? [];
32078
+ if (manualPagination) {
32079
+ const total = rowCount ?? rowList.length;
32080
+ const resolvedPageCount = pageCount !== void 0 && pageCount >= 0 ? pageCount : total > 0 ? Math.ceil(total / rowsPerPage) : rowList.length > 0 ? 1 : 0;
32081
+ return {
32082
+ maxPage: Math.max(resolvedPageCount, 1),
32083
+ activeRows: rowList
32084
+ };
32085
+ }
32036
32086
  if (rowCount && onSortChange && rowCount !== rowList.length) {
32037
32087
  return {
32038
32088
  maxPage: Math.ceil(rowCount / rowsPerPage),
@@ -32052,6 +32102,8 @@ function QuillTable({
32052
32102
  };
32053
32103
  }, [
32054
32104
  currentPage,
32105
+ manualPagination,
32106
+ pageCount,
32055
32107
  rows,
32056
32108
  rowsPerPage,
32057
32109
  rowCount,
@@ -32061,21 +32113,30 @@ function QuillTable({
32061
32113
  overrideInMemortSort
32062
32114
  ]);
32063
32115
  (0, import_react14.useEffect)(() => {
32116
+ if (manualPagination) {
32117
+ return;
32118
+ }
32064
32119
  if (currentPage > 0 && rows.length <= currentPage * rowsPerPage) {
32065
32120
  onPageChange?.(0);
32066
32121
  }
32067
- }, [rows, currentPage, rowsPerPage, onPageChange]);
32122
+ }, [manualPagination, rows, currentPage, rowsPerPage, onPageChange]);
32068
32123
  const increasePage = () => {
32069
- if (!rowCountIsLoading && currentPage + 1 === maxPage) {
32124
+ if (canNextPage === false) {
32070
32125
  return;
32071
32126
  }
32072
- onPageChange && onPageChange(currentPage + 1);
32127
+ if (canNextPage !== true && !pageCountUnknown && !rowCountIsLoading && currentPage + 1 >= maxPage) {
32128
+ return;
32129
+ }
32130
+ onPageChange?.(currentPage + 1);
32073
32131
  };
32074
32132
  const decreasePage = () => {
32133
+ if (canPreviousPage === false) {
32134
+ return;
32135
+ }
32075
32136
  if (currentPage === 0) {
32076
32137
  return;
32077
32138
  }
32078
- onPageChange && onPageChange(currentPage - 1);
32139
+ onPageChange?.(currentPage - 1);
32079
32140
  };
32080
32141
  const toggleSort = (column) => {
32081
32142
  if (disableSort) {
@@ -32457,7 +32518,7 @@ function QuillTable({
32457
32518
  children: [
32458
32519
  currentPage + 1,
32459
32520
  " of ",
32460
- rowCountIsLoading && maxPage > 1 ? "many" : maxPage
32521
+ pageCountUnknown || rowCountIsLoading && maxPage > 1 ? "many" : maxPage
32461
32522
  ]
32462
32523
  }
32463
32524
  ),
@@ -37144,6 +37205,7 @@ function DataLoader({
37144
37205
  pivot: chartReport.pivot || item.pivot,
37145
37206
  pivotQuery,
37146
37207
  comparisonPivotQuery,
37208
+ dateBucket: chartReport.pivot?.dateBucket ?? item.pivot?.dateBucket,
37147
37209
  getPivotRowCount: false,
37148
37210
  getToken,
37149
37211
  eventTracking
@@ -44173,8 +44235,10 @@ var Table = ({
44173
44235
  clientLoading,
44174
44236
  !reports[props.reportId ?? ""]
44175
44237
  ]);
44176
- const [page, setPage] = (0, import_react44.useState)(0);
44238
+ const [internalPage, setInternalPage] = (0, import_react44.useState)(0);
44177
44239
  if ("rows" in data && "columns" in data) {
44240
+ const currentPage = data.currentPage ?? internalPage;
44241
+ const onPageChange = data.onPageChange ?? setInternalPage;
44178
44242
  return /* @__PURE__ */ (0, import_jsx_runtime63.jsx)(
44179
44243
  QuillTable,
44180
44244
  {
@@ -44191,8 +44255,16 @@ var Table = ({
44191
44255
  LoadingComponent: data.LoadingComponent,
44192
44256
  isLoading: data.isLoading || loading,
44193
44257
  downloadCSV: data.downloadCSV,
44194
- currentPage: page,
44195
- onPageChange: setPage
44258
+ currentPage,
44259
+ rowsPerPage: data.rowsPerPage,
44260
+ rowCount: data.rowCount,
44261
+ rowCountIsLoading: data.rowCountIsLoading,
44262
+ onPageChange,
44263
+ manualPagination: data.manualPagination,
44264
+ pageCount: data.pageCount,
44265
+ canNextPage: data.canNextPage,
44266
+ canPreviousPage: data.canPreviousPage,
44267
+ disableSort: data.disableSort
44196
44268
  }
44197
44269
  );
44198
44270
  }
@@ -44227,7 +44299,7 @@ var Table = ({
44227
44299
  error,
44228
44300
  rowCount: rowCount ?? data2?.rowCount ?? data2?.rows?.length ?? 0,
44229
44301
  rowCountIsLoading,
44230
- onPageChange: (page2) => onPageChange(page2),
44302
+ onPageChange: (page) => onPageChange(page),
44231
44303
  onSortChange: (sort) => onSortChange(sort),
44232
44304
  hideName: true
44233
44305
  }
@@ -59620,6 +59692,19 @@ function createUseFormPivotTableDataRefreshQueryKey(input) {
59620
59692
  input.clientHash
59621
59693
  ];
59622
59694
  }
59695
+ function createUseFormTablePageQueryKey(input) {
59696
+ return [
59697
+ "useReport",
59698
+ "table-page",
59699
+ input.reportId,
59700
+ input.pageIndex,
59701
+ input.pageSize,
59702
+ input.sortHash,
59703
+ input.reportBuilderStateHash,
59704
+ input.tenantHash,
59705
+ input.clientHash
59706
+ ];
59707
+ }
59623
59708
  function createUseFormReportNameQueryKey(input) {
59624
59709
  return [
59625
59710
  "useReport",
@@ -59632,6 +59717,51 @@ function createUseFormQueryFn(loader) {
59632
59717
  return async () => loader();
59633
59718
  }
59634
59719
 
59720
+ // src/hooks/useForm.pagination.ts
59721
+ var DEFAULT_PAGE_INDEX = 0;
59722
+ var DEFAULT_PAGE_SIZE = 10;
59723
+ var DEFAULT_USE_REPORT_ROWS_PER_REQUEST = DEFAULT_PAGE_SIZE * 10;
59724
+ function getDefaultPaginationState() {
59725
+ return { pageIndex: DEFAULT_PAGE_INDEX, pageSize: DEFAULT_PAGE_SIZE };
59726
+ }
59727
+ function functionalUpdate(updater, input) {
59728
+ return typeof updater === "function" ? updater(input) : updater;
59729
+ }
59730
+ function clampPageIndex(pageIndex, pageCount) {
59731
+ const maxPageIndex = pageCount === -1 ? Number.MAX_SAFE_INTEGER : Math.max(0, pageCount - 1);
59732
+ return Math.max(0, Math.min(pageIndex, maxPageIndex));
59733
+ }
59734
+ function paginationStateAfterPageSizeChange(old, nextPageSizeRaw) {
59735
+ const pageSize = Math.max(1, nextPageSizeRaw);
59736
+ const topRowIndex = old.pageSize * old.pageIndex;
59737
+ const pageIndex = Math.floor(topRowIndex / pageSize);
59738
+ return { pageIndex, pageSize };
59739
+ }
59740
+ function getPageCountFromRowCount(rowCount, pageSize) {
59741
+ if (rowCount === void 0) {
59742
+ return -1;
59743
+ }
59744
+ return Math.ceil(Math.max(0, rowCount) / Math.max(1, pageSize));
59745
+ }
59746
+ function getCanPreviousPageFromState(pageIndex) {
59747
+ return pageIndex > 0;
59748
+ }
59749
+ function getCanNextPageFromState(pageIndex, pageCount) {
59750
+ if (pageCount === -1) {
59751
+ return true;
59752
+ }
59753
+ if (pageCount === 0) {
59754
+ return false;
59755
+ }
59756
+ return pageIndex < pageCount - 1;
59757
+ }
59758
+ function getPageOptionsFromPageCount(pageCount) {
59759
+ if (!pageCount || pageCount <= 0) {
59760
+ return [];
59761
+ }
59762
+ return Array.from({ length: pageCount }, (_, index) => index);
59763
+ }
59764
+
59635
59765
  // src/hooks/useForm.tsx
59636
59766
  var INTERNAL_PIVOT_ROW_FIELDS = /* @__PURE__ */ new Set(["__quillRawDate"]);
59637
59767
  var LEGACY_SINGLE_Y_AXIS_COLUMN_PIVOT_REPORT_IDS = /* @__PURE__ */ new Set([
@@ -60527,6 +60657,17 @@ function chartDetailRowsMissingPivotRowBucket(chart) {
60527
60657
  const v = first[rowField];
60528
60658
  return v === void 0 || v === null;
60529
60659
  }
60660
+ function shouldUsePivotRowFieldAsXAxis(chartType, pivotRowField, rowColumnFormat) {
60661
+ const rowField = String(pivotRowField ?? "").trim();
60662
+ if (!rowField) return false;
60663
+ const isMetricOrGauge = ["metric", "gauge"].includes(
60664
+ String(chartType ?? "").toLowerCase()
60665
+ );
60666
+ if (isMetricOrGauge && !NUMBER_FORMAT_TYPES.includes(String(rowColumnFormat ?? "").trim())) {
60667
+ return false;
60668
+ }
60669
+ return true;
60670
+ }
60530
60671
  function normalizePivotChartForDisplay(chart) {
60531
60672
  const swapPivotRowsForChartRows = Boolean(chart?.pivot) && Array.isArray(chart?.pivotRows) && chart.pivotRows.length > 0;
60532
60673
  const syntheticAggregationOnlyRows = chart && !swapPivotRowsForChartRows ? buildSyntheticAggregationOnlyDisplayRows(chart) : null;
@@ -60555,8 +60696,19 @@ function normalizePivotChartForDisplay(chart) {
60555
60696
  stillUsingDetailRows: Boolean(config.pivot) && !swapPivotRowsForChartRows && Array.isArray(config.rows) && config.rows.length > 0
60556
60697
  });
60557
60698
  if (!config.pivot) return config;
60558
- const resolvedXAxisField = config.pivot?.rowField || config.xAxisField;
60699
+ const pivotRowFieldEarly = String(config.pivot?.rowField ?? "").trim();
60700
+ const rowColumn = (config.pivotColumns ?? config.columns ?? []).find(
60701
+ (col) => String(col.field ?? "").trim() === pivotRowFieldEarly
60702
+ );
60703
+ const resolvedXAxisField = shouldUsePivotRowFieldAsXAxis(
60704
+ config.chartType,
60705
+ pivotRowFieldEarly,
60706
+ String(rowColumn?.format ?? "")
60707
+ ) ? pivotRowFieldEarly : config.xAxisField;
60559
60708
  const withResolvedXAxis = resolvedXAxisField && resolvedXAxisField !== config.xAxisField ? { ...config, xAxisField: resolvedXAxisField } : config;
60709
+ const isMetricOrGauge = ["metric", "gauge"].includes(
60710
+ String(withResolvedXAxis.chartType ?? "").toLowerCase()
60711
+ );
60560
60712
  const aggregations = getPivotAggregations(withResolvedXAxis);
60561
60713
  const hasMultipleAggregations = aggregations.length > 1;
60562
60714
  const yAxisFallbackFormat = withResolvedXAxis.yAxisFields?.[0]?.format ?? withResolvedXAxis.xAxisFormat ?? "whole_number";
@@ -60669,7 +60821,7 @@ function normalizePivotChartForDisplay(chart) {
60669
60821
  const normalizedPivotColumns = pivotColumnFields.length > 0 ? pivotColumnFields.map((field) => {
60670
60822
  const knownColumn = knownColumnsByField.get(field);
60671
60823
  const yAxis = yAxisFields.find((axis) => axis.field === field);
60672
- const format9 = yAxis?.format ?? knownColumn?.format ?? (field === withResolvedXAxis.pivot?.rowField ? withResolvedXAxis.xAxisFormat ?? "string" : yAxisFallbackFormat);
60824
+ const format9 = yAxis?.format ?? knownColumn?.format ?? (field === withResolvedXAxis.pivot?.rowField ? isMetricOrGauge ? "string" : withResolvedXAxis.xAxisFormat ?? "string" : yAxisFallbackFormat);
60673
60825
  return {
60674
60826
  field,
60675
60827
  label: yAxis?.label ?? knownColumn?.label ?? field,
@@ -60677,9 +60829,10 @@ function normalizePivotChartForDisplay(chart) {
60677
60829
  };
60678
60830
  }) : withResolvedXAxis.columns ?? [];
60679
60831
  const isPivotTableChart = String(withResolvedXAxis.chartType ?? "").toLowerCase() === "table" && Boolean(withResolvedXAxis.pivot);
60832
+ const pivotTableSlotColumns = isPivotTableChart && Array.isArray(withResolvedXAxis.pivotColumns) && withResolvedXAxis.pivotColumns.length > 0 ? withResolvedXAxis.pivotColumns : withResolvedXAxis.columns;
60680
60833
  const pivotTableDisplayColumns = isPivotTableChart && pivotColumnFields.length > 0 ? normalizedPivotColumns.map((col) => {
60681
60834
  const slotCol = getPivotTableSlotReportColumn(
60682
- withResolvedXAxis.columns,
60835
+ pivotTableSlotColumns,
60683
60836
  aggregations,
60684
60837
  withResolvedXAxis.pivot?.rowField,
60685
60838
  col.field
@@ -60694,9 +60847,6 @@ function normalizePivotChartForDisplay(chart) {
60694
60847
  }
60695
60848
  return next;
60696
60849
  }) : normalizedPivotColumns;
60697
- const isMetricOrGauge = ["metric", "gauge"].includes(
60698
- String(withResolvedXAxis.chartType ?? "").toLowerCase()
60699
- );
60700
60850
  const hasXAxisValueInPivotRows = Boolean(firstPivotRow) && Boolean(withResolvedXAxis.xAxisField) && Object.prototype.hasOwnProperty.call(
60701
60851
  firstPivotRow,
60702
60852
  String(withResolvedXAxis.xAxisField)
@@ -62166,7 +62316,12 @@ async function loadViaInMemoryEngines({
62166
62316
  draftSessionId
62167
62317
  }) {
62168
62318
  const requestedTask = allowReportTaskBootstrap ? "report" : "item";
62169
- const additionalProcessing = allowReportTaskBootstrap ? { page: { ...DEFAULT_PAGINATION, rowsPerRequest: 20 } } : {};
62319
+ const additionalProcessing = allowReportTaskBootstrap ? {
62320
+ page: {
62321
+ ...DEFAULT_PAGINATION,
62322
+ rowsPerRequest: DEFAULT_USE_REPORT_ROWS_PER_REQUEST
62323
+ }
62324
+ } : {};
62170
62325
  const { report, error } = await fetchReport({
62171
62326
  reportId,
62172
62327
  client,
@@ -62590,7 +62745,9 @@ async function loadViaReportBuilderState({
62590
62745
  customFields,
62591
62746
  dashboardName,
62592
62747
  report,
62593
- draftSessionId
62748
+ draftSessionId,
62749
+ pagination,
62750
+ paginationSort
62594
62751
  }) {
62595
62752
  const baseReport = {
62596
62753
  ...EMPTY_INTERNAL_REPORT,
@@ -62611,8 +62768,18 @@ async function loadViaReportBuilderState({
62611
62768
  // refresh queries are not blocked on `report-builder-unique-values`.
62612
62769
  skipUniqueValues: true,
62613
62770
  previousRelevant: previousRelevantWhenSkippingInlineUniqueFetch(report),
62614
- processing: {
62615
- page: { ...DEFAULT_PAGINATION, rowsPerRequest: 20 }
62771
+ processing: pagination ? {
62772
+ page: {
62773
+ page: pagination.pageIndex,
62774
+ rowsPerPage: pagination.pageSize,
62775
+ rowsPerRequest: pagination.pageSize
62776
+ },
62777
+ ...paginationSort?.field ? { sort: paginationSort } : {}
62778
+ } : {
62779
+ page: {
62780
+ ...DEFAULT_PAGINATION,
62781
+ rowsPerRequest: DEFAULT_USE_REPORT_ROWS_PER_REQUEST
62782
+ }
62616
62783
  },
62617
62784
  dashboardName,
62618
62785
  getToken,
@@ -62809,6 +62976,98 @@ function useReport(reportIdArg, options = {}) {
62809
62976
  const destinationDashboardName = String(
62810
62977
  options.destinationDashboardName ?? ""
62811
62978
  ).trim();
62979
+ const controlledPagination = options.state?.pagination;
62980
+ const initialPaginationRef = (0, import_react62.useRef)({
62981
+ ...getDefaultPaginationState(),
62982
+ ...options.initialState?.pagination ?? {}
62983
+ });
62984
+ const [internalPagination, setInternalPagination] = (0, import_react62.useState)(
62985
+ initialPaginationRef.current
62986
+ );
62987
+ const [paginationInteracted, setPaginationInteracted] = (0, import_react62.useState)(
62988
+ () => Boolean(
62989
+ options.state?.pagination || options.initialState?.pagination || options.onPaginationChange
62990
+ )
62991
+ );
62992
+ const pagination = controlledPagination ?? internalPagination;
62993
+ const paginationActive = paginationInteracted || Boolean(controlledPagination);
62994
+ const paginationRef = (0, import_react62.useRef)(pagination);
62995
+ paginationRef.current = pagination;
62996
+ const onPaginationChangeRef = (0, import_react62.useRef)(options.onPaginationChange);
62997
+ onPaginationChangeRef.current = options.onPaginationChange;
62998
+ const controlledPaginationRef = (0, import_react62.useRef)(Boolean(controlledPagination));
62999
+ controlledPaginationRef.current = Boolean(controlledPagination);
63000
+ const autoResetPageIndexRef = (0, import_react62.useRef)(true);
63001
+ autoResetPageIndexRef.current = options.autoResetPageIndex ?? true;
63002
+ const paginationPageCountRef = (0, import_react62.useRef)(-1);
63003
+ const applyPaginationUpdate = (0, import_react62.useCallback)(
63004
+ (updater, { activate = true } = {}) => {
63005
+ if (activate) {
63006
+ setPaginationInteracted(true);
63007
+ }
63008
+ onPaginationChangeRef.current?.(updater);
63009
+ if (!controlledPaginationRef.current) {
63010
+ setInternalPagination((old) => functionalUpdate(updater, old));
63011
+ }
63012
+ },
63013
+ []
63014
+ );
63015
+ const setPagination = (0, import_react62.useCallback)(
63016
+ (updater) => applyPaginationUpdate(updater),
63017
+ [applyPaginationUpdate]
63018
+ );
63019
+ const setPageIndex = (0, import_react62.useCallback)(
63020
+ (updater) => applyPaginationUpdate((old) => ({
63021
+ ...old,
63022
+ pageIndex: clampPageIndex(
63023
+ functionalUpdate(updater, old.pageIndex),
63024
+ paginationPageCountRef.current
63025
+ )
63026
+ })),
63027
+ [applyPaginationUpdate]
63028
+ );
63029
+ const setPageSize = (0, import_react62.useCallback)(
63030
+ (updater) => applyPaginationUpdate(
63031
+ (old) => paginationStateAfterPageSizeChange(
63032
+ old,
63033
+ functionalUpdate(updater, old.pageSize)
63034
+ )
63035
+ ),
63036
+ [applyPaginationUpdate]
63037
+ );
63038
+ const resetPagination = (0, import_react62.useCallback)(
63039
+ (defaultState) => applyPaginationUpdate(
63040
+ defaultState ? getDefaultPaginationState() : initialPaginationRef.current
63041
+ ),
63042
+ [applyPaginationUpdate]
63043
+ );
63044
+ const resetPageIndex = (0, import_react62.useCallback)(
63045
+ (defaultState) => {
63046
+ const target = defaultState ? 0 : initialPaginationRef.current.pageIndex;
63047
+ setPageIndex(target);
63048
+ },
63049
+ [setPageIndex]
63050
+ );
63051
+ const resetPageSize = (0, import_react62.useCallback)(
63052
+ (defaultState) => {
63053
+ const target = defaultState ? getDefaultPaginationState().pageSize : initialPaginationRef.current.pageSize;
63054
+ setPageSize(target);
63055
+ },
63056
+ [setPageSize]
63057
+ );
63058
+ const nextPage = (0, import_react62.useCallback)(
63059
+ () => setPageIndex((old) => old + 1),
63060
+ [setPageIndex]
63061
+ );
63062
+ const previousPage = (0, import_react62.useCallback)(
63063
+ () => setPageIndex((old) => old - 1),
63064
+ [setPageIndex]
63065
+ );
63066
+ const firstPage = (0, import_react62.useCallback)(() => setPageIndex(0), [setPageIndex]);
63067
+ const lastPage = (0, import_react62.useCallback)(
63068
+ () => setPageIndex(paginationPageCountRef.current - 1),
63069
+ [setPageIndex]
63070
+ );
62812
63071
  const chartPivotHydratedFromSourceRef = (0, import_react62.useRef)(false);
62813
63072
  const lastPivotHydrateCompletedSourceIdRef = (0, import_react62.useRef)(null);
62814
63073
  const groupRowsBySetViaSetReportRef = (0, import_react62.useRef)(false);
@@ -64590,7 +64849,10 @@ function useReport(reportIdArg, options = {}) {
64590
64849
  direction: regularSort.sortDirection
64591
64850
  }
64592
64851
  ] : [],
64593
- limit: pivotState ? null : { value: 30 }
64852
+ // The user's limit caps the query (SQL LIMIT inside the base CTE); the
64853
+ // server row count respects it, so pagination sees `min(total, limit)`.
64854
+ // No hardcoded cap — page fetches window rows via additionalProcessing.
64855
+ limit: pivotState ? null : limit?.value ? { value: limit.value } : null
64594
64856
  };
64595
64857
  }, [
64596
64858
  effectiveReportBuilderColumns,
@@ -64607,6 +64869,23 @@ function useReport(reportIdArg, options = {}) {
64607
64869
  () => stableSerializeForQueryKey(effectiveReportBuilderState),
64608
64870
  [effectiveReportBuilderState]
64609
64871
  );
64872
+ const prevPaginationResetStateHashRef = (0, import_react62.useRef)(null);
64873
+ (0, import_react62.useEffect)(() => {
64874
+ const prevHash = prevPaginationResetStateHashRef.current;
64875
+ prevPaginationResetStateHashRef.current = effectiveReportBuilderStateHash;
64876
+ if (prevHash === null || prevHash === effectiveReportBuilderStateHash) {
64877
+ return;
64878
+ }
64879
+ if (!autoResetPageIndexRef.current) {
64880
+ return;
64881
+ }
64882
+ if (paginationRef.current.pageIndex === 0) {
64883
+ return;
64884
+ }
64885
+ applyPaginationUpdate((old) => ({ ...old, pageIndex: 0 }), {
64886
+ activate: false
64887
+ });
64888
+ }, [applyPaginationUpdate, effectiveReportBuilderStateHash]);
64610
64889
  const pivotTableDataReportBuilderState = (0, import_react62.useMemo)(() => {
64611
64890
  if (!effectiveReportBuilderState?.pivot) {
64612
64891
  return void 0;
@@ -65276,6 +65555,93 @@ function useReport(reportIdArg, options = {}) {
65276
65555
  enabled: pivotTableDataRefreshQueryEnabled,
65277
65556
  retry: false
65278
65557
  });
65558
+ const tablePageReportBuilderState = pivotTableDataReportBuilderState ?? effectiveReportBuilderState;
65559
+ const tablePageReportBuilderStateHash = pivotTableDataReportBuilderState ? pivotTableDataReportBuilderStateHash : effectiveReportBuilderStateHash;
65560
+ const tablePaginationSort = (0, import_react62.useMemo)(() => {
65561
+ const sortEntry = tablePageReportBuilderState?.sort?.[0];
65562
+ const field = String(sortEntry?.field ?? "").trim();
65563
+ if (!field || !/^[A-Za-z_][A-Za-z0-9_]*$/.test(field)) {
65564
+ return void 0;
65565
+ }
65566
+ const isOutputColumn = (tablePageReportBuilderState?.columns ?? []).some(
65567
+ (column) => String(column?.field ?? "").trim() === field
65568
+ );
65569
+ if (!isOutputColumn) {
65570
+ return void 0;
65571
+ }
65572
+ const direction = String(sortEntry?.direction ?? "ASC").toUpperCase() === "DESC" ? "DESC" : "ASC";
65573
+ return { field, direction };
65574
+ }, [tablePageReportBuilderState]);
65575
+ const baseWindowRowsLength = Array.isArray(sourceReport?.rows) ? sourceReport.rows.length : 0;
65576
+ const sourceReportRowCount = typeof sourceReport?.rowCount === "number" ? sourceReport.rowCount : void 0;
65577
+ const trustedSourceRowCount = sourceReportRowCount !== void 0 && (sourceReportRowCount > 0 || baseWindowRowsLength === 0) && sourceReportRowCount >= baseWindowRowsLength ? sourceReportRowCount : void 0;
65578
+ const paginationRangeStart = pagination.pageIndex * pagination.pageSize;
65579
+ const paginationRangeEnd = paginationRangeStart + pagination.pageSize;
65580
+ const pageWithinBaseWindow = paginationRangeEnd <= baseWindowRowsLength || trustedSourceRowCount !== void 0 && trustedSourceRowCount <= baseWindowRowsLength;
65581
+ const tablePageQueryEnabled = paginationActive && !pageWithinBaseWindow && !reportOverride && !useInMemoryEngines && Boolean(client) && Boolean(sourceReport) && Boolean(tablePageReportBuilderState) && sourceReportMatchesEffectiveReportId && !pendingPivotRefresh;
65582
+ const tablePageQuery = (0, import_react_query2.useQuery)({
65583
+ queryKey: createUseFormTablePageQueryKey({
65584
+ reportId: effectiveReportId,
65585
+ pageIndex: pagination.pageIndex,
65586
+ pageSize: pagination.pageSize,
65587
+ sortHash: stableSerializeForQueryKey(tablePaginationSort ?? null),
65588
+ reportBuilderStateHash: tablePageReportBuilderStateHash,
65589
+ tenantHash,
65590
+ clientHash
65591
+ }),
65592
+ queryFn: createUseFormQueryFn(async () => {
65593
+ if (!tablePageReportBuilderState || !sourceReport || !client) {
65594
+ return { report: null, error: "Missing table page prerequisites" };
65595
+ }
65596
+ return loadViaReportBuilderState({
65597
+ reportId: effectiveReportId,
65598
+ reportBuilderState: tablePageReportBuilderState,
65599
+ client,
65600
+ getToken,
65601
+ tenants,
65602
+ schema: schemaForReportBuilderState,
65603
+ customFields: schemaData.customFields,
65604
+ dashboardName: resolvedSourceDashboardName,
65605
+ report: sourceReport,
65606
+ draftSessionId: draftSessionId || void 0,
65607
+ pagination: {
65608
+ pageIndex: pagination.pageIndex,
65609
+ pageSize: pagination.pageSize
65610
+ },
65611
+ paginationSort: tablePaginationSort
65612
+ });
65613
+ }),
65614
+ enabled: tablePageQueryEnabled,
65615
+ retry: false,
65616
+ // Keep showing the previous page's rows while the next page loads.
65617
+ placeholderData: import_react_query2.keepPreviousData
65618
+ });
65619
+ const tablePageRows = tablePageQueryEnabled && !tablePageQuery.data?.error && Array.isArray(tablePageQuery.data?.report?.rows) ? tablePageQuery.data.report.rows : void 0;
65620
+ const tablePageRowCount = tablePageQueryEnabled && typeof tablePageQuery.data?.report?.rowCount === "number" && tablePageQuery.data.report.rowCount > 0 ? tablePageQuery.data.report.rowCount : void 0;
65621
+ const tablePageFetching = tablePageQueryEnabled && tablePageQuery.isFetching;
65622
+ const paginationTotalRowCount = (0, import_react62.useMemo)(() => {
65623
+ if (tablePageRowCount !== void 0) {
65624
+ return Math.max(tablePageRowCount, baseWindowRowsLength);
65625
+ }
65626
+ if (trustedSourceRowCount !== void 0) {
65627
+ return trustedSourceRowCount;
65628
+ }
65629
+ if (useInMemoryEngines || Boolean(reportOverride)) {
65630
+ return baseWindowRowsLength;
65631
+ }
65632
+ return void 0;
65633
+ }, [
65634
+ tablePageRowCount,
65635
+ trustedSourceRowCount,
65636
+ baseWindowRowsLength,
65637
+ useInMemoryEngines,
65638
+ reportOverride
65639
+ ]);
65640
+ const paginationPageCount = getPageCountFromRowCount(
65641
+ paginationTotalRowCount,
65642
+ pagination.pageSize
65643
+ );
65644
+ paginationPageCountRef.current = paginationPageCount;
65279
65645
  (0, import_react62.useEffect)(() => {
65280
65646
  if (!pivotTableDataRefreshQueryEnabled) return;
65281
65647
  if (pivotTableDataRefreshQuery.status !== "success" && pivotTableDataRefreshQuery.status !== "error") {
@@ -65577,11 +65943,19 @@ function useReport(reportIdArg, options = {}) {
65577
65943
  ]);
65578
65944
  const resolvedXAxisField = (0, import_react62.useMemo)(() => {
65579
65945
  if (!chartAxesBaseChart) return "";
65946
+ const chartType2 = String(chartAxesBaseChart.chartType ?? "").toLowerCase();
65580
65947
  const pivotRowField = String(
65581
65948
  chartAxesBaseChart.pivot?.rowField ?? ""
65582
65949
  ).trim();
65583
65950
  if (pivotRowField) {
65584
- return pivotRowField;
65951
+ const rowColumn = (chartAxesBaseChart.pivotColumns ?? chartAxesBaseChart.columns ?? []).find((col) => String(col.field ?? "").trim() === pivotRowField);
65952
+ if (shouldUsePivotRowFieldAsXAxis(
65953
+ chartType2,
65954
+ pivotRowField,
65955
+ String(rowColumn?.format ?? "")
65956
+ )) {
65957
+ return pivotRowField;
65958
+ }
65585
65959
  }
65586
65960
  const requestedXAxisField = String(chartAxisEdits.xAxisField ?? "").trim();
65587
65961
  if (requestedXAxisField && chartAxisOptionByField.has(requestedXAxisField)) {
@@ -65904,7 +66278,8 @@ function useReport(reportIdArg, options = {}) {
65904
66278
  ]
65905
66279
  );
65906
66280
  const table = (0, import_react62.useMemo)(() => {
65907
- const rawRows = Array.isArray(sourceReport?.rows) ? sourceReport.rows : [];
66281
+ const baseWindowRows = Array.isArray(sourceReport?.rows) ? sourceReport.rows : [];
66282
+ const rawRows = !paginationActive ? baseWindowRows : tablePageRows ?? baseWindowRows.slice(paginationRangeStart, paginationRangeEnd);
65908
66283
  const { columns: mergedFromReport } = mergeDisplayAndSourceForTableFormats({
65909
66284
  effectiveReportBuilderTableNames,
65910
66285
  scopedSchemaColumns,
@@ -65922,8 +66297,24 @@ function useReport(reportIdArg, options = {}) {
65922
66297
  format: pivotRowTableUsesAxisFormat ? String(resolvedXAxisFormat ?? column.format) : column.format
65923
66298
  } : column
65924
66299
  ) : mergedFromReport;
66300
+ const pivotLabeledColumns = String(chartType ?? "").toLowerCase() === "table" && sourceReport?.pivot ? mergePivotTableDisplayColumnLabelsFromYAxis({
66301
+ columns: columns2,
66302
+ yAxisFields: resolvedYAxisFieldsForDisplay,
66303
+ pivotRowField: String(sourceReport.pivot.rowField ?? ""),
66304
+ xAxisLabel: resolvedXAxisLabel
66305
+ }) ?? columns2 : columns2;
66306
+ const tableColumnsWithPivotDisplayLabels = pivotLabeledColumns.map(
66307
+ (column) => ({
66308
+ label: String(column.label ?? "").trim() || String(column.field ?? ""),
66309
+ field: String(column.field ?? "").trim(),
66310
+ format: String(column.format ?? "string").trim() || "string"
66311
+ })
66312
+ );
65925
66313
  const formatByField = new Map(
65926
- columns2.map((column) => [column.field, column.format])
66314
+ tableColumnsWithPivotDisplayLabels.map((column) => [
66315
+ column.field,
66316
+ column.format
66317
+ ])
65927
66318
  );
65928
66319
  const isCacheableValue = (value) => {
65929
66320
  return value === null || value === void 0 || typeof value === "string" || typeof value === "number" || typeof value === "boolean" || typeof value === "bigint";
@@ -65951,20 +66342,37 @@ function useReport(reportIdArg, options = {}) {
65951
66342
  cache.set(cacheKey, formatted);
65952
66343
  return formatted;
65953
66344
  };
65954
- const formattedRows = columns2.length === 0 ? rawRows : rawRows.map((rawRow) => {
66345
+ const formattedRows = tableColumnsWithPivotDisplayLabels.length === 0 ? rawRows : rawRows.map((rawRow) => {
65955
66346
  const out = { ...rawRow };
65956
- for (const col of columns2) {
66347
+ for (const col of tableColumnsWithPivotDisplayLabels) {
65957
66348
  out[col.field] = formatCellValue(col.field, rawRow[col.field]);
65958
66349
  }
65959
66350
  return out;
65960
66351
  });
65961
66352
  const getFormattedCellValue = (row, field) => String(row?.[field] ?? "");
65962
66353
  return {
65963
- columns: columns2,
66354
+ columns: tableColumnsWithPivotDisplayLabels,
65964
66355
  rows: formattedRows,
65965
66356
  getColumnFormat,
65966
66357
  formatCellValue,
65967
- getFormattedCellValue
66358
+ getFormattedCellValue,
66359
+ // TanStack Table–style pagination API.
66360
+ pagination,
66361
+ setPagination,
66362
+ setPageIndex,
66363
+ setPageSize,
66364
+ resetPagination,
66365
+ resetPageIndex,
66366
+ resetPageSize,
66367
+ nextPage,
66368
+ previousPage,
66369
+ firstPage,
66370
+ lastPage,
66371
+ getCanNextPage: () => getCanNextPageFromState(pagination.pageIndex, paginationPageCount),
66372
+ getCanPreviousPage: () => getCanPreviousPageFromState(pagination.pageIndex),
66373
+ getPageCount: () => paginationPageCount,
66374
+ getRowCount: () => paginationTotalRowCount ?? baseWindowRows.length,
66375
+ getPageOptions: () => getPageOptionsFromPageCount(paginationPageCount)
65968
66376
  };
65969
66377
  }, [
65970
66378
  chartAxisEdits.xAxisFormat,
@@ -65974,8 +66382,26 @@ function useReport(reportIdArg, options = {}) {
65974
66382
  resolvedXAxisField,
65975
66383
  resolvedXAxisFormat,
65976
66384
  resolvedXAxisLabel,
66385
+ resolvedYAxisFieldsForDisplay,
65977
66386
  scopedSchemaColumns,
65978
- sourceReport
66387
+ sourceReport,
66388
+ pagination,
66389
+ paginationActive,
66390
+ paginationPageCount,
66391
+ paginationRangeEnd,
66392
+ paginationRangeStart,
66393
+ paginationTotalRowCount,
66394
+ tablePageRows,
66395
+ setPagination,
66396
+ setPageIndex,
66397
+ setPageSize,
66398
+ resetPagination,
66399
+ resetPageIndex,
66400
+ resetPageSize,
66401
+ nextPage,
66402
+ previousPage,
66403
+ firstPage,
66404
+ lastPage
65979
66405
  ]);
65980
66406
  const {
65981
66407
  columnsOptions: tableFormattingColumnOptions,
@@ -66287,7 +66713,7 @@ function useReport(reportIdArg, options = {}) {
66287
66713
  const initialLoadInProgress = !reportOverride && Boolean(effectiveReportId) && (!client || initialLoadQuery.isPending || initialLoadQuery.isFetching);
66288
66714
  const filterUniqueValuesLoading = filterUniqueValuesEnabled && (filterUniqueValuesQuery.isPending || filterUniqueValuesQuery.isFetching);
66289
66715
  const chartLoading = initialLoadInProgress || (Boolean(nextPivot) ? pivotRefreshQuery.isFetching : tableRefreshQuery.isFetching);
66290
- const tableLoading = initialLoadInProgress || (Boolean(nextPivot) ? pivotTableDataRefreshQuery.isFetching : tableRefreshQuery.isFetching);
66716
+ const tableLoading = initialLoadInProgress || tablePageFetching || (Boolean(nextPivot) ? pivotTableDataRefreshQuery.isFetching : tableRefreshQuery.isFetching);
66291
66717
  const loading = chartLoading || tableLoading;
66292
66718
  const buildSetReportColumnsFromIds = (nextColumnIds, settingsById) => {
66293
66719
  const normalizedNextIds = nextColumnIds.map((columnId) => String(columnId ?? "").trim()).filter(Boolean);
@@ -68040,6 +68466,23 @@ var styles2 = {
68040
68466
  boxSizing: "border-box"
68041
68467
  }
68042
68468
  };
68469
+ function getTablePaginationBindings(table) {
68470
+ if (!table?.pagination || typeof table.setPageIndex !== "function") {
68471
+ return {};
68472
+ }
68473
+ const { pageIndex, pageSize } = table.pagination;
68474
+ return {
68475
+ manualPagination: true,
68476
+ currentPage: pageIndex,
68477
+ rowsPerPage: pageSize,
68478
+ rowCount: table.getRowCount?.() ?? table.rows?.length ?? 0,
68479
+ pageCount: table.getPageCount?.(),
68480
+ canNextPage: table.getCanNextPage?.(),
68481
+ canPreviousPage: table.getCanPreviousPage?.(),
68482
+ onPageChange: (page) => table.setPageIndex?.(page),
68483
+ disableSort: true
68484
+ };
68485
+ }
68043
68486
  function chartTypeFromConfig(chart) {
68044
68487
  return String(chart?.chartType ?? "").trim().toLowerCase();
68045
68488
  }
@@ -68090,6 +68533,7 @@ function ReportDetail({
68090
68533
  borderBottom: "none"
68091
68534
  } : void 0;
68092
68535
  const trimmedTitle = String(reportTitle ?? "").trim();
68536
+ const tablePagination = getTablePaginationBindings(table);
68093
68537
  return /* @__PURE__ */ (0, import_jsx_runtime89.jsxs)(
68094
68538
  "div",
68095
68539
  {
@@ -68121,6 +68565,7 @@ function ReportDetail({
68121
68565
  columns: Array.isArray(table?.columns) ? table.columns : [],
68122
68566
  rows: Array.isArray(table?.rows) ? table.rows : [],
68123
68567
  isLoading: chartLoading || tableLoading,
68568
+ rowCountIsLoading: tableLoading,
68124
68569
  hideCSVDownloadButton: true,
68125
68570
  containerStyle: {
68126
68571
  width: "100%",
@@ -68129,7 +68574,8 @@ function ReportDetail({
68129
68574
  padding: 0,
68130
68575
  margin: 0
68131
68576
  },
68132
- ...tableChartSlotBorders
68577
+ ...tableChartSlotBorders,
68578
+ ...tablePagination
68133
68579
  }
68134
68580
  ) : /* @__PURE__ */ (0, import_jsx_runtime89.jsx)(
68135
68581
  ChartDisplay,
@@ -68169,9 +68615,11 @@ function ReportDetail({
68169
68615
  columns: Array.isArray(table?.columns) ? table.columns : [],
68170
68616
  rows: Array.isArray(table?.rows) ? table.rows : [],
68171
68617
  isLoading: tableLoading,
68618
+ rowCountIsLoading: tableLoading,
68172
68619
  hideCSVDownloadButton: true,
68173
68620
  containerStyle: quillTableFramelessStyle,
68174
- ...quillTableFramelessBorders
68621
+ ...quillTableFramelessBorders,
68622
+ ...tablePagination
68175
68623
  }
68176
68624
  )
68177
68625
  }
@@ -69067,6 +69515,8 @@ init_constants();
69067
69515
  ChartDisplay,
69068
69516
  ChartEditor,
69069
69517
  Chat,
69518
+ DEFAULT_PAGE_SIZE,
69519
+ DEFAULT_USE_REPORT_ROWS_PER_REQUEST,
69070
69520
  Dashboard,
69071
69521
  DashboardFilterType,
69072
69522
  DashboardLegacy,