@dloizides/ui-tables 3.1.0 → 3.2.0

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.mjs CHANGED
@@ -2565,6 +2565,11 @@ function reportFiltersToQuery(values, keys = DEFAULT_REPORT_QUERY_KEYS) {
2565
2565
  ];
2566
2566
  return Object.fromEntries(entries.filter(([, value]) => value !== ""));
2567
2567
  }
2568
+ function reportFiltersToParams(values, keys = DEFAULT_REPORT_QUERY_KEYS) {
2569
+ const query = reportFiltersToQuery(values, keys);
2570
+ const allKeys = [keys.scope, keys.from, keys.to, keys.statuses, keys.currency];
2571
+ return Object.fromEntries(allKeys.map((key) => [key, query[key]]));
2572
+ }
2568
2573
  function reportFiltersToSearch(values, keys = DEFAULT_REPORT_QUERY_KEYS) {
2569
2574
  return new URLSearchParams(reportFiltersToQuery(values, keys)).toString();
2570
2575
  }
@@ -2680,10 +2685,23 @@ function ReportFilters({
2680
2685
  var styles7 = StyleSheet.create({
2681
2686
  compactRow: { flexDirection: "row", flexWrap: "wrap", alignItems: "center", gap: COMPACT_GAP }
2682
2687
  });
2688
+ function useReportFilterQuery({
2689
+ params,
2690
+ setParams,
2691
+ keys = DEFAULT_REPORT_QUERY_KEYS
2692
+ }) {
2693
+ const values = useMemo(() => reportFiltersFromQuery(params, keys), [params, keys]);
2694
+ const setValues = useCallback(
2695
+ (next) => setParams(reportFiltersToParams(next, keys)),
2696
+ [setParams, keys]
2697
+ );
2698
+ return { values, setValues };
2699
+ }
2683
2700
 
2684
2701
  // src/ExportCsvAction/ExportOutcome.ts
2685
2702
  var ExportOutcome = /* @__PURE__ */ ((ExportOutcome2) => {
2686
2703
  ExportOutcome2["Downloaded"] = "downloaded";
2704
+ ExportOutcome2["Truncated"] = "truncated";
2687
2705
  ExportOutcome2["Unsupported"] = "unsupported";
2688
2706
  ExportOutcome2["Failed"] = "failed";
2689
2707
  return ExportOutcome2;
@@ -2697,6 +2715,9 @@ var UNSAFE_FILENAME_CHARS = /[^A-Za-z0-9._-]+/g;
2697
2715
  var SAFE_REPLACEMENT = "-";
2698
2716
  var RANGE_JOINER = "--";
2699
2717
  var PART_JOINER = "_";
2718
+ function isFetchedRows(data) {
2719
+ return !Array.isArray(data);
2720
+ }
2700
2721
  function csvFilename(base, range) {
2701
2722
  const safeBase = base.trim().replace(UNSAFE_FILENAME_CHARS, SAFE_REPLACEMENT);
2702
2723
  if (range === void 0) return `${safeBase}${CSV_EXTENSION}`;
@@ -2720,8 +2741,11 @@ function downloadCsv(csv, filename) {
2720
2741
  }
2721
2742
  async function runCsvExport(rows, columns, filename, download = downloadCsv) {
2722
2743
  try {
2723
- const data = typeof rows === "function" ? await rows() : rows;
2724
- return download(toCsv(data, columns), filename) ? "downloaded" /* Downloaded */ : "unsupported" /* Unsupported */;
2744
+ const loaded = typeof rows === "function" ? await rows() : rows;
2745
+ const data = isFetchedRows(loaded) ? loaded.rows : loaded;
2746
+ const truncated = isFetchedRows(loaded) && loaded.truncated;
2747
+ if (!download(toCsv(data, columns), filename)) return "unsupported" /* Unsupported */;
2748
+ return truncated ? "truncated" /* Truncated */ : "downloaded" /* Downloaded */;
2725
2749
  } catch {
2726
2750
  return "failed" /* Failed */;
2727
2751
  }
@@ -2760,6 +2784,27 @@ function ExportCsvAction({
2760
2784
  );
2761
2785
  }
2762
2786
 
2763
- export { CARD_STACK_BREAKPOINT, DEFAULT_PAGE_SIZE, DEFAULT_PAGE_SIZE_OPTIONS, DEFAULT_REPORT_QUERY_KEYS, DataTable, EMPTY_REPORT_FILTERS, EXPORT_CSV_TEST_ID, ExportCsvAction, ExportOutcome, FIELD_MIN_WIDTH, FILTERS_I18N, FILTERS_TEST_ID, FilterBar, FilterSidePanel, Filters, LedgerLayout, MONTH_STATUS_GRID_TEST_ID, MonthGridColumns, MonthStatusGrid, PagedTableLayout, PagedTableLayoutKind, Pager, REPORT_FIELD_KEYS, REPORT_FILTERS_TEST_ID, RelativeTime, ReportFilters, STATUS_LEDGER_TEST_ID, SortDirection, StatCard, StatTone, StatusLedger, StatusPill, StatusTone, TABLE_I18N, TABLE_TEST_IDS, applyTestID, buildReportFields, clearTestID, countActiveReportFilters, csvFilename, distinctValues, downloadCsv, fieldTestID, filterLedgerRows, fitMonthGridColumns, formatRelativeTime, fromFilterValues, isAttentionTone, isIsoDate, isRangeInverted, ledgerSectionTestID, ledgerSortDirectionTestID, monthCellTestID, openPanelTestID, panelFiltersTestID, panelTestID, reportFiltersFromQuery, reportFiltersToQuery, reportFiltersToSearch, resolveStatToneColor, rowDetailTestID, rowFadeTestID, rowSelectTestID, rowTestID, runCsvExport, selectAllTestID, sortLedgerRows, splitNeedsLook, toEpochMs, toFilterValues, useFilterDraft, usePagedRows, useReportDraft };
2787
+ // src/ExportCsvAction/utils/fetchAllPages.ts
2788
+ var FIRST_PAGE3 = 1;
2789
+ var DEFAULT_FETCH_CONCURRENCY = 2;
2790
+ function pageNumbers(from, to) {
2791
+ return Array.from({ length: Math.max(to - from + 1, 0) }, (_unused, index) => from + index);
2792
+ }
2793
+ function chunk(pages, size) {
2794
+ const step = Math.max(Math.floor(size), 1);
2795
+ const count = Math.ceil(pages.length / step);
2796
+ return Array.from({ length: count }, (_unused, index) => pages.slice(index * step, index * step + step));
2797
+ }
2798
+ async function fetchAllPages(fetchPage, { pageSize, maxPages, concurrency = DEFAULT_FETCH_CONCURRENCY }) {
2799
+ const first = await fetchPage(FIRST_PAGE3, pageSize);
2800
+ const lastPage = Math.min(first.totalPages, maxPages);
2801
+ const pages = [first];
2802
+ for (const batch of chunk(pageNumbers(FIRST_PAGE3 + 1, lastPage), concurrency)) {
2803
+ pages.push(...await Promise.all(batch.map((page) => fetchPage(page, pageSize))));
2804
+ }
2805
+ return { rows: pages.flatMap((page) => [...page.items]), truncated: first.totalPages > maxPages };
2806
+ }
2807
+
2808
+ export { CARD_STACK_BREAKPOINT, DEFAULT_FETCH_CONCURRENCY, DEFAULT_PAGE_SIZE, DEFAULT_PAGE_SIZE_OPTIONS, DEFAULT_REPORT_QUERY_KEYS, DataTable, EMPTY_REPORT_FILTERS, EXPORT_CSV_TEST_ID, ExportCsvAction, ExportOutcome, FIELD_MIN_WIDTH, FILTERS_I18N, FILTERS_TEST_ID, FilterBar, FilterSidePanel, Filters, LedgerLayout, MONTH_STATUS_GRID_TEST_ID, MonthGridColumns, MonthStatusGrid, PagedTableLayout, PagedTableLayoutKind, Pager, REPORT_FIELD_KEYS, REPORT_FILTERS_TEST_ID, RelativeTime, ReportFilters, STATUS_LEDGER_TEST_ID, SortDirection, StatCard, StatTone, StatusLedger, StatusPill, StatusTone, TABLE_I18N, TABLE_TEST_IDS, applyTestID, buildReportFields, clearTestID, countActiveReportFilters, csvFilename, distinctValues, downloadCsv, fetchAllPages, fieldTestID, filterLedgerRows, fitMonthGridColumns, formatRelativeTime, fromFilterValues, isAttentionTone, isIsoDate, isRangeInverted, ledgerSectionTestID, ledgerSortDirectionTestID, monthCellTestID, openPanelTestID, panelFiltersTestID, panelTestID, reportFiltersFromQuery, reportFiltersToParams, reportFiltersToQuery, reportFiltersToSearch, resolveStatToneColor, rowDetailTestID, rowFadeTestID, rowSelectTestID, rowTestID, runCsvExport, selectAllTestID, sortLedgerRows, splitNeedsLook, toEpochMs, toFilterValues, useFilterDraft, usePagedRows, useReportDraft, useReportFilterQuery };
2764
2809
  //# sourceMappingURL=index.mjs.map
2765
2810
  //# sourceMappingURL=index.mjs.map