@dloizides/ui-tables 3.0.2 → 3.1.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/CHANGELOG.md +6 -0
- package/dist/index.d.mts +122 -4
- package/dist/index.d.ts +122 -4
- package/dist/index.js +379 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +358 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -2
package/dist/index.mjs
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import React2, { memo, createContext, useContext, useState, useMemo, useCallback, useEffect, useRef, useLayoutEffect } from 'react';
|
|
2
|
-
import { StyleSheet, View, Text, Platform, useWindowDimensions, Pressable, Switch, TextInput } from 'react-native';
|
|
3
|
-
import { useUi } from '@dloizides/ui-feedback';
|
|
2
|
+
import { StyleSheet, View, Text, Platform, useWindowDimensions, Pressable, Modal, ScrollView, Switch, TextInput } from 'react-native';
|
|
3
|
+
import { useUi, MODAL_OVERLAY_COLOR } from '@dloizides/ui-feedback';
|
|
4
4
|
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
5
5
|
import { useReducedMotion, FadeIn } from '@dloizides/ui-motion';
|
|
6
6
|
import { Z_INDEX } from '@dloizides/design-tokens';
|
|
7
7
|
import { createPortal } from 'react-dom';
|
|
8
|
-
import { DateRangeControl, DateInput, Field, controlStyles, TypeaheadControl, DEFAULT_TYPEAHEAD_MIN_CHARS, DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS, SelectControl } from '@dloizides/ui-forms';
|
|
8
|
+
import { DateRangeControl, DateInput, Field, controlStyles, TypeaheadControl, DEFAULT_TYPEAHEAD_MIN_CHARS, DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS, ChipSelector, SelectControl } from '@dloizides/ui-forms';
|
|
9
9
|
export { DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS, DEFAULT_TYPEAHEAD_MIN_CHARS, isUnmatched, suggestOptions } from '@dloizides/ui-forms';
|
|
10
10
|
import { useA11y } from '@dloizides/a11y';
|
|
11
|
+
import { Button } from '@dloizides/ui-buttons';
|
|
12
|
+
import { toCsv } from '@dloizides/utils';
|
|
11
13
|
|
|
12
14
|
// src/StatCard/StatCard.tsx
|
|
13
15
|
|
|
@@ -1581,6 +1583,7 @@ function ActionButton({ label, hint, tone, disabled = false, onPress, testID })
|
|
|
1581
1583
|
var FILTERS_TEST_ID = "ui-filters-declarative";
|
|
1582
1584
|
var FIELD_MIN_WIDTH = {
|
|
1583
1585
|
select: 150,
|
|
1586
|
+
multiSelect: 200,
|
|
1584
1587
|
text: 200,
|
|
1585
1588
|
number: 130,
|
|
1586
1589
|
date: 160,
|
|
@@ -1642,6 +1645,25 @@ function BooleanField({ field, barTestID, value, onChange }) {
|
|
|
1642
1645
|
)
|
|
1643
1646
|
] });
|
|
1644
1647
|
}
|
|
1648
|
+
|
|
1649
|
+
// src/Filters/utils/toggleValue.ts
|
|
1650
|
+
function toggleValue(list, value) {
|
|
1651
|
+
return list.includes(value) ? list.filter((item) => item !== value) : [...list, value];
|
|
1652
|
+
}
|
|
1653
|
+
function MultiSelectField({ field, barTestID, value, onChange }) {
|
|
1654
|
+
const options = useMemo(() => field.options.map((option) => ({ value: option.value, label: option.label })), [field.options]);
|
|
1655
|
+
const testID = field.testID ?? fieldTestID(barTestID, field.key);
|
|
1656
|
+
return /* @__PURE__ */ jsx(
|
|
1657
|
+
ChipSelector,
|
|
1658
|
+
{
|
|
1659
|
+
multiple: true,
|
|
1660
|
+
options,
|
|
1661
|
+
value: [...value],
|
|
1662
|
+
onChange: (picked) => onChange(toggleValue(value, picked)),
|
|
1663
|
+
testID: `${testID}-chips`
|
|
1664
|
+
}
|
|
1665
|
+
);
|
|
1666
|
+
}
|
|
1645
1667
|
function SelectField({ field, barTestID, value, onChange, placeholder, dropdownHint, optionHint }) {
|
|
1646
1668
|
const { t } = useUi();
|
|
1647
1669
|
const testID = field.testID ?? fieldTestID(barTestID, field.key);
|
|
@@ -1724,6 +1746,9 @@ function asString(value) {
|
|
|
1724
1746
|
function asBool(value) {
|
|
1725
1747
|
return value === true;
|
|
1726
1748
|
}
|
|
1749
|
+
function asList(value) {
|
|
1750
|
+
return Array.isArray(value) ? value : [];
|
|
1751
|
+
}
|
|
1727
1752
|
function asRange(value) {
|
|
1728
1753
|
if (typeof value === "object" && value !== null && "from" in value && "to" in value) return value;
|
|
1729
1754
|
return EMPTY_RANGE;
|
|
@@ -1780,6 +1805,16 @@ function FilterFieldView({ field, barTestID, values, setField, onSubmit, strings
|
|
|
1780
1805
|
optionHint: strings.optionHint
|
|
1781
1806
|
}
|
|
1782
1807
|
);
|
|
1808
|
+
case "multiSelect":
|
|
1809
|
+
return /* @__PURE__ */ jsx(
|
|
1810
|
+
MultiSelectField,
|
|
1811
|
+
{
|
|
1812
|
+
field,
|
|
1813
|
+
barTestID,
|
|
1814
|
+
value: asList(raw),
|
|
1815
|
+
onChange: (v) => setField(field.key, v)
|
|
1816
|
+
}
|
|
1817
|
+
);
|
|
1783
1818
|
case "typeahead":
|
|
1784
1819
|
return /* @__PURE__ */ jsx(
|
|
1785
1820
|
TypeaheadField,
|
|
@@ -1822,6 +1857,7 @@ function FilterFieldView({ field, barTestID, values, setField, onSubmit, strings
|
|
|
1822
1857
|
Field,
|
|
1823
1858
|
{
|
|
1824
1859
|
containerStyle,
|
|
1860
|
+
error: field.kind === "dateRange" ? field.error : void 0,
|
|
1825
1861
|
label: field.label,
|
|
1826
1862
|
labelVariant: "control",
|
|
1827
1863
|
testID,
|
|
@@ -2406,6 +2442,324 @@ var MonthStatusGrid = ({
|
|
|
2406
2442
|
] }, row[0]?.id)) });
|
|
2407
2443
|
};
|
|
2408
2444
|
|
|
2409
|
-
|
|
2445
|
+
// src/ReportFilters/constants.ts
|
|
2446
|
+
var REPORT_FILTERS_TEST_ID = "ui-report-filters";
|
|
2447
|
+
var REPORT_FIELD_KEYS = {
|
|
2448
|
+
scope: "scope",
|
|
2449
|
+
range: "range",
|
|
2450
|
+
statuses: "statuses",
|
|
2451
|
+
currency: "currency"
|
|
2452
|
+
};
|
|
2453
|
+
var DEFAULT_REPORT_QUERY_KEYS = {
|
|
2454
|
+
scope: "scope",
|
|
2455
|
+
from: "from",
|
|
2456
|
+
to: "to",
|
|
2457
|
+
statuses: "status",
|
|
2458
|
+
currency: "currency"
|
|
2459
|
+
};
|
|
2460
|
+
var EMPTY_REPORT_FILTERS = {
|
|
2461
|
+
scope: "",
|
|
2462
|
+
range: { from: "", to: "" },
|
|
2463
|
+
statuses: [],
|
|
2464
|
+
currency: ""
|
|
2465
|
+
};
|
|
2466
|
+
var LIST_SEPARATOR = ",";
|
|
2467
|
+
var PANEL_MAX_WIDTH = 360;
|
|
2468
|
+
var PANEL_SCREEN_SHARE = 0.88;
|
|
2469
|
+
var openPanelTestID = (testID) => `${testID}-open`;
|
|
2470
|
+
var panelTestID = (testID) => `${testID}-panel`;
|
|
2471
|
+
var panelFiltersTestID = (testID) => `${testID}-panel-filters`;
|
|
2472
|
+
var PANEL_PAD = 16;
|
|
2473
|
+
var HEADER_GAP = 8;
|
|
2474
|
+
var HEADER_BOTTOM = 12;
|
|
2475
|
+
var TITLE_FONT = 16;
|
|
2476
|
+
var PANEL_BORDER = 1;
|
|
2477
|
+
function FilterSidePanel({ visible, onClose, title, closeLabel, closeHint, children, testID }) {
|
|
2478
|
+
const { theme } = useUi();
|
|
2479
|
+
const { width } = useWindowDimensions();
|
|
2480
|
+
const panelWidth = Math.min(PANEL_MAX_WIDTH, Math.round(width * PANEL_SCREEN_SHARE));
|
|
2481
|
+
return /* @__PURE__ */ jsx(Modal, { transparent: true, animationType: "fade", visible, onRequestClose: onClose, children: /* @__PURE__ */ jsxs(View, { style: styles6.root, children: [
|
|
2482
|
+
/* @__PURE__ */ jsx(
|
|
2483
|
+
Pressable,
|
|
2484
|
+
{
|
|
2485
|
+
accessibilityRole: "button",
|
|
2486
|
+
accessibilityLabel: closeLabel,
|
|
2487
|
+
accessibilityHint: closeHint,
|
|
2488
|
+
onPress: onClose,
|
|
2489
|
+
style: [StyleSheet.absoluteFill, { backgroundColor: MODAL_OVERLAY_COLOR }],
|
|
2490
|
+
testID: `${testID}-backdrop`
|
|
2491
|
+
}
|
|
2492
|
+
),
|
|
2493
|
+
/* @__PURE__ */ jsxs(
|
|
2494
|
+
View,
|
|
2495
|
+
{
|
|
2496
|
+
accessibilityViewIsModal: true,
|
|
2497
|
+
style: [styles6.panel, { width: panelWidth, backgroundColor: theme.colors.surface, borderColor: theme.colors.border }],
|
|
2498
|
+
testID,
|
|
2499
|
+
children: [
|
|
2500
|
+
/* @__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(ActionButton, { label: closeLabel, hint: closeHint, tone: "primary", onPress: onClose, testID: `${testID}-close` })
|
|
2503
|
+
] }),
|
|
2504
|
+
/* @__PURE__ */ jsx(ScrollView, { children })
|
|
2505
|
+
]
|
|
2506
|
+
}
|
|
2507
|
+
)
|
|
2508
|
+
] }) });
|
|
2509
|
+
}
|
|
2510
|
+
var styles6 = StyleSheet.create({
|
|
2511
|
+
root: { flex: 1, flexDirection: "row", justifyContent: "flex-end" },
|
|
2512
|
+
panel: { height: "100%", padding: PANEL_PAD, borderLeftWidth: PANEL_BORDER },
|
|
2513
|
+
header: { flexDirection: "row", alignItems: "center", justifyContent: "space-between", gap: HEADER_GAP, marginBottom: HEADER_BOTTOM },
|
|
2514
|
+
title: { flexShrink: 1, fontSize: TITLE_FONT, fontWeight: "700" }
|
|
2515
|
+
});
|
|
2516
|
+
|
|
2517
|
+
// src/ReportFilters/utils/reportQuery.ts
|
|
2518
|
+
var ISO_DATE = /^\d{4}-\d{2}-\d{2}$/;
|
|
2519
|
+
var ISO_DATE_LENGTH = 10;
|
|
2520
|
+
function isIsoDate(value) {
|
|
2521
|
+
if (!ISO_DATE.test(value)) return false;
|
|
2522
|
+
const parsed = /* @__PURE__ */ new Date(`${value}T00:00:00Z`);
|
|
2523
|
+
return !Number.isNaN(parsed.getTime()) && parsed.toISOString().slice(0, ISO_DATE_LENGTH) === value;
|
|
2524
|
+
}
|
|
2525
|
+
function isRangeInverted(range) {
|
|
2526
|
+
const bothSet = range.from !== "" && range.to !== "";
|
|
2527
|
+
return bothSet && range.from > range.to;
|
|
2528
|
+
}
|
|
2529
|
+
function countActiveReportFilters(values) {
|
|
2530
|
+
const hasRange = values.range.from !== "" || values.range.to !== "";
|
|
2531
|
+
return [values.scope !== "", hasRange, values.statuses.length > 0, values.currency !== ""].filter(Boolean).length;
|
|
2532
|
+
}
|
|
2533
|
+
function readAll(source, key) {
|
|
2534
|
+
if (source instanceof URLSearchParams) return source.getAll(key);
|
|
2535
|
+
const raw = source[key];
|
|
2536
|
+
if (raw === void 0 || raw === null) return [];
|
|
2537
|
+
return typeof raw === "string" ? [raw] : [...raw];
|
|
2538
|
+
}
|
|
2539
|
+
function readOne(source, key) {
|
|
2540
|
+
return (readAll(source, key)[0] ?? "").trim();
|
|
2541
|
+
}
|
|
2542
|
+
function readDate(source, key) {
|
|
2543
|
+
const value = readOne(source, key);
|
|
2544
|
+
return isIsoDate(value) ? value : "";
|
|
2545
|
+
}
|
|
2546
|
+
function readList(source, key) {
|
|
2547
|
+
const items = readAll(source, key).flatMap((entry) => entry.split(LIST_SEPARATOR)).map((entry) => entry.trim()).filter((entry) => entry !== "");
|
|
2548
|
+
return Array.from(new Set(items));
|
|
2549
|
+
}
|
|
2550
|
+
function reportFiltersFromQuery(source, keys = DEFAULT_REPORT_QUERY_KEYS) {
|
|
2551
|
+
return {
|
|
2552
|
+
scope: readOne(source, keys.scope),
|
|
2553
|
+
range: { from: readDate(source, keys.from), to: readDate(source, keys.to) },
|
|
2554
|
+
statuses: readList(source, keys.statuses),
|
|
2555
|
+
currency: readOne(source, keys.currency)
|
|
2556
|
+
};
|
|
2557
|
+
}
|
|
2558
|
+
function reportFiltersToQuery(values, keys = DEFAULT_REPORT_QUERY_KEYS) {
|
|
2559
|
+
const entries = [
|
|
2560
|
+
[keys.scope, values.scope],
|
|
2561
|
+
[keys.from, values.range.from],
|
|
2562
|
+
[keys.to, values.range.to],
|
|
2563
|
+
[keys.statuses, values.statuses.join(LIST_SEPARATOR)],
|
|
2564
|
+
[keys.currency, values.currency]
|
|
2565
|
+
];
|
|
2566
|
+
return Object.fromEntries(entries.filter(([, value]) => value !== ""));
|
|
2567
|
+
}
|
|
2568
|
+
function reportFiltersToSearch(values, keys = DEFAULT_REPORT_QUERY_KEYS) {
|
|
2569
|
+
return new URLSearchParams(reportFiltersToQuery(values, keys)).toString();
|
|
2570
|
+
}
|
|
2571
|
+
|
|
2572
|
+
// src/ReportFilters/hooks/useReportDraft.ts
|
|
2573
|
+
function useReportDraft(value, onChange) {
|
|
2574
|
+
const committedKey = reportFiltersToSearch(value);
|
|
2575
|
+
const [draft, setDraft] = useState(value);
|
|
2576
|
+
const [seenKey, setSeenKey] = useState(committedKey);
|
|
2577
|
+
if (seenKey !== committedKey) {
|
|
2578
|
+
setSeenKey(committedKey);
|
|
2579
|
+
setDraft(value);
|
|
2580
|
+
}
|
|
2581
|
+
const edit = useCallback(
|
|
2582
|
+
(next) => {
|
|
2583
|
+
setDraft(next);
|
|
2584
|
+
if (!isRangeInverted(next.range)) onChange(next);
|
|
2585
|
+
},
|
|
2586
|
+
[onChange]
|
|
2587
|
+
);
|
|
2588
|
+
return { draft, edit };
|
|
2589
|
+
}
|
|
2590
|
+
|
|
2591
|
+
// src/ReportFilters/utils/reportFields.ts
|
|
2592
|
+
var EMPTY_RANGE2 = { from: "", to: "" };
|
|
2593
|
+
function buildReportFields(options, labels, values) {
|
|
2594
|
+
return [
|
|
2595
|
+
{ key: REPORT_FIELD_KEYS.scope, kind: "select", label: labels.scope, options: options.scopes },
|
|
2596
|
+
{
|
|
2597
|
+
key: REPORT_FIELD_KEYS.range,
|
|
2598
|
+
kind: "dateRange",
|
|
2599
|
+
label: labels.range,
|
|
2600
|
+
fromLabel: labels.from,
|
|
2601
|
+
toLabel: labels.to,
|
|
2602
|
+
error: isRangeInverted(values.range) ? labels.invalidRange : void 0
|
|
2603
|
+
},
|
|
2604
|
+
{ key: REPORT_FIELD_KEYS.statuses, kind: "multiSelect", label: labels.statuses, options: options.statuses },
|
|
2605
|
+
{ key: REPORT_FIELD_KEYS.currency, kind: "select", label: labels.currency, options: options.currencies }
|
|
2606
|
+
];
|
|
2607
|
+
}
|
|
2608
|
+
function toFilterValues(values) {
|
|
2609
|
+
return {
|
|
2610
|
+
[REPORT_FIELD_KEYS.scope]: values.scope,
|
|
2611
|
+
[REPORT_FIELD_KEYS.range]: values.range,
|
|
2612
|
+
[REPORT_FIELD_KEYS.statuses]: values.statuses,
|
|
2613
|
+
[REPORT_FIELD_KEYS.currency]: values.currency
|
|
2614
|
+
};
|
|
2615
|
+
}
|
|
2616
|
+
function asText(value) {
|
|
2617
|
+
return typeof value === "string" ? value : "";
|
|
2618
|
+
}
|
|
2619
|
+
function asList2(value) {
|
|
2620
|
+
return Array.isArray(value) ? value : [];
|
|
2621
|
+
}
|
|
2622
|
+
function asRange2(value) {
|
|
2623
|
+
const isRange = typeof value === "object" && !Array.isArray(value) && "from" in value;
|
|
2624
|
+
return isRange ? value : EMPTY_RANGE2;
|
|
2625
|
+
}
|
|
2626
|
+
function fromFilterValues(map) {
|
|
2627
|
+
return {
|
|
2628
|
+
scope: asText(map[REPORT_FIELD_KEYS.scope]),
|
|
2629
|
+
range: asRange2(map[REPORT_FIELD_KEYS.range]),
|
|
2630
|
+
statuses: asList2(map[REPORT_FIELD_KEYS.statuses]),
|
|
2631
|
+
currency: asText(map[REPORT_FIELD_KEYS.currency])
|
|
2632
|
+
};
|
|
2633
|
+
}
|
|
2634
|
+
var COMPACT_GAP = 8;
|
|
2635
|
+
function ReportFilters({
|
|
2636
|
+
value,
|
|
2637
|
+
onChange,
|
|
2638
|
+
options,
|
|
2639
|
+
labels,
|
|
2640
|
+
actions,
|
|
2641
|
+
compact,
|
|
2642
|
+
renderSelect,
|
|
2643
|
+
testID = REPORT_FILTERS_TEST_ID
|
|
2644
|
+
}) {
|
|
2645
|
+
const { width } = useWindowDimensions();
|
|
2646
|
+
const [panelOpen, setPanelOpen] = useState(false);
|
|
2647
|
+
const { draft, edit } = useReportDraft(value, onChange);
|
|
2648
|
+
const fields = useMemo(() => buildReportFields(options, labels, draft), [options, labels, draft]);
|
|
2649
|
+
const values = useMemo(() => toFilterValues(draft), [draft]);
|
|
2650
|
+
const handleChange = useCallback((next) => edit(fromFilterValues(next)), [edit]);
|
|
2651
|
+
const isCompact = compact ?? width < CARD_STACK_BREAKPOINT;
|
|
2652
|
+
const renderBar = (barTestID, barActions) => /* @__PURE__ */ jsx(Filters, { fields, values, onChange: handleChange, actions: barActions, renderSelect, testID: barTestID });
|
|
2653
|
+
if (!isCompact) return renderBar(testID, actions);
|
|
2654
|
+
return /* @__PURE__ */ jsxs(View, { style: styles7.compactRow, testID, children: [
|
|
2655
|
+
/* @__PURE__ */ jsx(
|
|
2656
|
+
ActionButton,
|
|
2657
|
+
{
|
|
2658
|
+
label: labels.openPanel,
|
|
2659
|
+
hint: labels.openPanelHint,
|
|
2660
|
+
tone: "ghost",
|
|
2661
|
+
onPress: () => setPanelOpen(true),
|
|
2662
|
+
testID: openPanelTestID(testID)
|
|
2663
|
+
}
|
|
2664
|
+
),
|
|
2665
|
+
actions,
|
|
2666
|
+
/* @__PURE__ */ jsx(
|
|
2667
|
+
FilterSidePanel,
|
|
2668
|
+
{
|
|
2669
|
+
visible: panelOpen,
|
|
2670
|
+
onClose: () => setPanelOpen(false),
|
|
2671
|
+
title: labels.panelTitle,
|
|
2672
|
+
closeLabel: labels.closePanel,
|
|
2673
|
+
closeHint: labels.closePanelHint,
|
|
2674
|
+
testID: panelTestID(testID),
|
|
2675
|
+
children: renderBar(panelFiltersTestID(testID))
|
|
2676
|
+
}
|
|
2677
|
+
)
|
|
2678
|
+
] });
|
|
2679
|
+
}
|
|
2680
|
+
var styles7 = StyleSheet.create({
|
|
2681
|
+
compactRow: { flexDirection: "row", flexWrap: "wrap", alignItems: "center", gap: COMPACT_GAP }
|
|
2682
|
+
});
|
|
2683
|
+
|
|
2684
|
+
// src/ExportCsvAction/ExportOutcome.ts
|
|
2685
|
+
var ExportOutcome = /* @__PURE__ */ ((ExportOutcome2) => {
|
|
2686
|
+
ExportOutcome2["Downloaded"] = "downloaded";
|
|
2687
|
+
ExportOutcome2["Unsupported"] = "unsupported";
|
|
2688
|
+
ExportOutcome2["Failed"] = "failed";
|
|
2689
|
+
return ExportOutcome2;
|
|
2690
|
+
})(ExportOutcome || {});
|
|
2691
|
+
|
|
2692
|
+
// src/ExportCsvAction/utils/downloadCsv.ts
|
|
2693
|
+
var CSV_MIME = "text/csv;charset=utf-8";
|
|
2694
|
+
var UTF8_BOM = "\uFEFF";
|
|
2695
|
+
var CSV_EXTENSION = ".csv";
|
|
2696
|
+
var UNSAFE_FILENAME_CHARS = /[^A-Za-z0-9._-]+/g;
|
|
2697
|
+
var SAFE_REPLACEMENT = "-";
|
|
2698
|
+
var RANGE_JOINER = "--";
|
|
2699
|
+
var PART_JOINER = "_";
|
|
2700
|
+
function csvFilename(base, range) {
|
|
2701
|
+
const safeBase = base.trim().replace(UNSAFE_FILENAME_CHARS, SAFE_REPLACEMENT);
|
|
2702
|
+
if (range === void 0) return `${safeBase}${CSV_EXTENSION}`;
|
|
2703
|
+
const hasRange = range.from !== "" || range.to !== "";
|
|
2704
|
+
const name = hasRange ? `${safeBase}${PART_JOINER}${range.from}${RANGE_JOINER}${range.to}` : safeBase;
|
|
2705
|
+
return `${name}${CSV_EXTENSION}`;
|
|
2706
|
+
}
|
|
2707
|
+
function downloadCsv(csv, filename) {
|
|
2708
|
+
const hasDom = typeof document !== "undefined" && typeof URL !== "undefined";
|
|
2709
|
+
if (!hasDom || typeof URL.createObjectURL !== "function") return false;
|
|
2710
|
+
const url = URL.createObjectURL(new Blob([UTF8_BOM, csv], { type: CSV_MIME }));
|
|
2711
|
+
const link = document.createElement("a");
|
|
2712
|
+
link.href = url;
|
|
2713
|
+
link.download = filename;
|
|
2714
|
+
link.style.display = "none";
|
|
2715
|
+
document.body.appendChild(link);
|
|
2716
|
+
link.click();
|
|
2717
|
+
document.body.removeChild(link);
|
|
2718
|
+
URL.revokeObjectURL(url);
|
|
2719
|
+
return true;
|
|
2720
|
+
}
|
|
2721
|
+
async function runCsvExport(rows, columns, filename, download = downloadCsv) {
|
|
2722
|
+
try {
|
|
2723
|
+
const data = typeof rows === "function" ? await rows() : rows;
|
|
2724
|
+
return download(toCsv(data, columns), filename) ? "downloaded" /* Downloaded */ : "unsupported" /* Unsupported */;
|
|
2725
|
+
} catch {
|
|
2726
|
+
return "failed" /* Failed */;
|
|
2727
|
+
}
|
|
2728
|
+
}
|
|
2729
|
+
var EXPORT_CSV_TEST_ID = "ui-export-csv";
|
|
2730
|
+
function ExportCsvAction({
|
|
2731
|
+
rows,
|
|
2732
|
+
columns,
|
|
2733
|
+
filename,
|
|
2734
|
+
label,
|
|
2735
|
+
hint,
|
|
2736
|
+
disabled = false,
|
|
2737
|
+
onDone,
|
|
2738
|
+
testID = EXPORT_CSV_TEST_ID
|
|
2739
|
+
}) {
|
|
2740
|
+
const [busy, setBusy] = useState(false);
|
|
2741
|
+
const run = useCallback(async () => {
|
|
2742
|
+
setBusy(true);
|
|
2743
|
+
const outcome = await runCsvExport(rows, columns, filename);
|
|
2744
|
+
setBusy(false);
|
|
2745
|
+
onDone?.(outcome);
|
|
2746
|
+
}, [rows, columns, filename, onDone]);
|
|
2747
|
+
return /* @__PURE__ */ jsx(
|
|
2748
|
+
Button,
|
|
2749
|
+
{
|
|
2750
|
+
label,
|
|
2751
|
+
accessibilityLabel: label,
|
|
2752
|
+
accessibilityHint: hint,
|
|
2753
|
+
disabled,
|
|
2754
|
+
loading: busy,
|
|
2755
|
+
onPress: () => {
|
|
2756
|
+
void run();
|
|
2757
|
+
},
|
|
2758
|
+
testID
|
|
2759
|
+
}
|
|
2760
|
+
);
|
|
2761
|
+
}
|
|
2762
|
+
|
|
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 };
|
|
2410
2764
|
//# sourceMappingURL=index.mjs.map
|
|
2411
2765
|
//# sourceMappingURL=index.mjs.map
|