@dloizides/ui-tables 3.1.0 → 3.3.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
@@ -2478,6 +2478,7 @@ function FilterSidePanel({ visible, onClose, title, closeLabel, closeHint, child
2478
2478
  const { theme } = useUi();
2479
2479
  const { width } = useWindowDimensions();
2480
2480
  const panelWidth = Math.min(PANEL_MAX_WIDTH, Math.round(width * PANEL_SCREEN_SHARE));
2481
+ const focusTitleOnOpen = useCallback((node) => node?.focus(), []);
2481
2482
  return /* @__PURE__ */ jsx(Modal, { transparent: true, animationType: "fade", visible, onRequestClose: onClose, children: /* @__PURE__ */ jsxs(View, { style: styles6.root, children: [
2482
2483
  /* @__PURE__ */ jsx(
2483
2484
  Pressable,
@@ -2498,7 +2499,7 @@ function FilterSidePanel({ visible, onClose, title, closeLabel, closeHint, child
2498
2499
  testID,
2499
2500
  children: [
2500
2501
  /* @__PURE__ */ jsxs(View, { style: styles6.header, children: [
2501
- /* @__PURE__ */ jsx(Text, { accessibilityRole: "header", style: [styles6.title, { color: theme.colors.text }], children: title }),
2502
+ /* @__PURE__ */ jsx(View, { ref: focusTitleOnOpen, focusable: true, style: styles6.titleBox, testID: `${testID}-title`, children: /* @__PURE__ */ jsx(Text, { accessibilityRole: "header", style: [styles6.title, { color: theme.colors.text }], children: title }) }),
2502
2503
  /* @__PURE__ */ jsx(ActionButton, { label: closeLabel, hint: closeHint, tone: "primary", onPress: onClose, testID: `${testID}-close` })
2503
2504
  ] }),
2504
2505
  /* @__PURE__ */ jsx(ScrollView, { children })
@@ -2511,6 +2512,7 @@ var styles6 = StyleSheet.create({
2511
2512
  root: { flex: 1, flexDirection: "row", justifyContent: "flex-end" },
2512
2513
  panel: { height: "100%", padding: PANEL_PAD, borderLeftWidth: PANEL_BORDER },
2513
2514
  header: { flexDirection: "row", alignItems: "center", justifyContent: "space-between", gap: HEADER_GAP, marginBottom: HEADER_BOTTOM },
2515
+ titleBox: { flexShrink: 1 },
2514
2516
  title: { flexShrink: 1, fontSize: TITLE_FONT, fontWeight: "700" }
2515
2517
  });
2516
2518
 
@@ -2565,6 +2567,11 @@ function reportFiltersToQuery(values, keys = DEFAULT_REPORT_QUERY_KEYS) {
2565
2567
  ];
2566
2568
  return Object.fromEntries(entries.filter(([, value]) => value !== ""));
2567
2569
  }
2570
+ function reportFiltersToParams(values, keys = DEFAULT_REPORT_QUERY_KEYS) {
2571
+ const query = reportFiltersToQuery(values, keys);
2572
+ const allKeys = [keys.scope, keys.from, keys.to, keys.statuses, keys.currency];
2573
+ return Object.fromEntries(allKeys.map((key) => [key, query[key]]));
2574
+ }
2568
2575
  function reportFiltersToSearch(values, keys = DEFAULT_REPORT_QUERY_KEYS) {
2569
2576
  return new URLSearchParams(reportFiltersToQuery(values, keys)).toString();
2570
2577
  }
@@ -2680,10 +2687,23 @@ function ReportFilters({
2680
2687
  var styles7 = StyleSheet.create({
2681
2688
  compactRow: { flexDirection: "row", flexWrap: "wrap", alignItems: "center", gap: COMPACT_GAP }
2682
2689
  });
2690
+ function useReportFilterQuery({
2691
+ params,
2692
+ setParams,
2693
+ keys = DEFAULT_REPORT_QUERY_KEYS
2694
+ }) {
2695
+ const values = useMemo(() => reportFiltersFromQuery(params, keys), [params, keys]);
2696
+ const setValues = useCallback(
2697
+ (next) => setParams(reportFiltersToParams(next, keys)),
2698
+ [setParams, keys]
2699
+ );
2700
+ return { values, setValues };
2701
+ }
2683
2702
 
2684
2703
  // src/ExportCsvAction/ExportOutcome.ts
2685
2704
  var ExportOutcome = /* @__PURE__ */ ((ExportOutcome2) => {
2686
2705
  ExportOutcome2["Downloaded"] = "downloaded";
2706
+ ExportOutcome2["Truncated"] = "truncated";
2687
2707
  ExportOutcome2["Unsupported"] = "unsupported";
2688
2708
  ExportOutcome2["Failed"] = "failed";
2689
2709
  return ExportOutcome2;
@@ -2697,6 +2717,9 @@ var UNSAFE_FILENAME_CHARS = /[^A-Za-z0-9._-]+/g;
2697
2717
  var SAFE_REPLACEMENT = "-";
2698
2718
  var RANGE_JOINER = "--";
2699
2719
  var PART_JOINER = "_";
2720
+ function isFetchedRows(data) {
2721
+ return !Array.isArray(data);
2722
+ }
2700
2723
  function csvFilename(base, range) {
2701
2724
  const safeBase = base.trim().replace(UNSAFE_FILENAME_CHARS, SAFE_REPLACEMENT);
2702
2725
  if (range === void 0) return `${safeBase}${CSV_EXTENSION}`;
@@ -2720,8 +2743,11 @@ function downloadCsv(csv, filename) {
2720
2743
  }
2721
2744
  async function runCsvExport(rows, columns, filename, download = downloadCsv) {
2722
2745
  try {
2723
- const data = typeof rows === "function" ? await rows() : rows;
2724
- return download(toCsv(data, columns), filename) ? "downloaded" /* Downloaded */ : "unsupported" /* Unsupported */;
2746
+ const loaded = typeof rows === "function" ? await rows() : rows;
2747
+ const data = isFetchedRows(loaded) ? loaded.rows : loaded;
2748
+ const truncated = isFetchedRows(loaded) && loaded.truncated;
2749
+ if (!download(toCsv(data, columns), filename)) return "unsupported" /* Unsupported */;
2750
+ return truncated ? "truncated" /* Truncated */ : "downloaded" /* Downloaded */;
2725
2751
  } catch {
2726
2752
  return "failed" /* Failed */;
2727
2753
  }
@@ -2760,6 +2786,27 @@ function ExportCsvAction({
2760
2786
  );
2761
2787
  }
2762
2788
 
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 };
2789
+ // src/ExportCsvAction/utils/fetchAllPages.ts
2790
+ var FIRST_PAGE3 = 1;
2791
+ var DEFAULT_FETCH_CONCURRENCY = 2;
2792
+ function pageNumbers(from, to) {
2793
+ return Array.from({ length: Math.max(to - from + 1, 0) }, (_unused, index) => from + index);
2794
+ }
2795
+ function chunk(pages, size) {
2796
+ const step = Math.max(Math.floor(size), 1);
2797
+ const count = Math.ceil(pages.length / step);
2798
+ return Array.from({ length: count }, (_unused, index) => pages.slice(index * step, index * step + step));
2799
+ }
2800
+ async function fetchAllPages(fetchPage, { pageSize, maxPages, concurrency = DEFAULT_FETCH_CONCURRENCY }) {
2801
+ const first = await fetchPage(FIRST_PAGE3, pageSize);
2802
+ const lastPage = Math.min(first.totalPages, maxPages);
2803
+ const pages = [first];
2804
+ for (const batch of chunk(pageNumbers(FIRST_PAGE3 + 1, lastPage), concurrency)) {
2805
+ pages.push(...await Promise.all(batch.map((page) => fetchPage(page, pageSize))));
2806
+ }
2807
+ return { rows: pages.flatMap((page) => [...page.items]), truncated: first.totalPages > maxPages };
2808
+ }
2809
+
2810
+ 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
2811
  //# sourceMappingURL=index.mjs.map
2765
2812
  //# sourceMappingURL=index.mjs.map