@dloizides/ui-tables 1.20.0 → 1.21.1

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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.21.0
4
+
5
+ **New `StatusLedger` (JOBS-UX-1 "Jobs page: one clear, consistent view of every job and source").**
6
+
7
+ A status-first ledger built on `DataTable` + `Filters`: one sortable, filterable table at or above
8
+ the breakpoint (768 by default, from `useWindowDimensions`), and a "needs a look first" feed below
9
+ it (bad then warn rows on top, then the rest). Filters: free text, status, group; sort by any column
10
+ with a `sortValue`, plus a 44px direction toggle. Generic row shape through accessors; every string
11
+ via `labels`/`statusLabel`; tone colours from the theme (`toneColors` overrides). Also exports
12
+ `StatusPill`, `RelativeTime` (tap swaps to absolute), `formatRelativeTime` and the pure
13
+ `filterLedgerRows` / `sortLedgerRows` / `splitNeedsLook` helpers. Additive, nothing existing changes.
14
+
3
15
  ## 1.20.0
4
16
 
5
17
  **The rows-per-page menu opens above an RN-web Modal (UI-ZINDEX-SCALE-1 "Shared overlay z-index scale").**
package/dist/index.d.mts CHANGED
@@ -783,4 +783,140 @@ interface PagedRows<T> {
783
783
  */
784
784
  declare function usePagedRows<T>(rows: readonly T[], options?: UsePagedRowsOptions): PagedRows<T>;
785
785
 
786
- export { type BooleanFilterField, CARD_STACK_BREAKPOINT, DEFAULT_PAGE_SIZE, DEFAULT_PAGE_SIZE_OPTIONS, DataTable, type DataTableColumn, type DataTableProps, type DataTableStyleOverrides, type DateRangeFilterField, FIELD_MIN_WIDTH, FILTERS_I18N, FILTERS_TEST_ID, type FieldStrings, FilterBar, type FilterBarProps, type FilterBarStyleOverrides, type FilterDraft, type FilterField, type FilterFieldKind, type FilterOption, type FilterValue, type FilterValues, Filters, type FiltersProps, type NumberFilterField, type PagedRows, Pager, type PagerProps, type PagerStyleOverrides, type RenderSelectArgs, type SelectFilterField, StatCard, type StatCardProps, TABLE_I18N, TABLE_TEST_IDS, type TextFilterField, type TypeaheadFilterField, type UseFilterDraftOptions, type UsePagedRowsOptions, applyTestID, clearTestID, fieldTestID, rowDetailTestID, rowFadeTestID, rowSelectTestID, rowTestID, selectAllTestID, useFilterDraft, usePagedRows };
786
+ /** Ledger layout: `Auto` picks `Table` at or above the breakpoint and `Feed` below it. */
787
+ declare const enum LedgerLayout {
788
+ Auto = "auto",
789
+ Table = "table",
790
+ Feed = "feed"
791
+ }
792
+
793
+ /** Visual tone a status maps to; drives colour, glyph and "needs a look" ordering. */
794
+ declare const enum StatusTone {
795
+ Bad = "bad",
796
+ Warn = "warn",
797
+ Active = "active",
798
+ Good = "good",
799
+ Neutral = "neutral"
800
+ }
801
+
802
+ type SortValue = string | number | null | undefined;
803
+ /** A DataTable column that can also be sorted by `sortValue`. */
804
+ interface StatusLedgerColumn<T> extends DataTableColumn<T> {
805
+ sortValue?: (row: T) => SortValue;
806
+ }
807
+ /** Every user-facing string the ledger renders, already translated by the caller. */
808
+ interface StatusLedgerLabels {
809
+ status: string;
810
+ group: string;
811
+ search: string;
812
+ sortBy: string;
813
+ all: string;
814
+ sortAscending: string;
815
+ sortDescending: string;
816
+ sortDirectionHint: string;
817
+ clear: string;
818
+ clearHint: string;
819
+ results: string;
820
+ needsLook: string;
821
+ everythingElse: string;
822
+ allClear: string;
823
+ empty: string;
824
+ actions: string;
825
+ }
826
+ type ToneColors = Partial<Record<StatusTone, string>>;
827
+ interface StatusLedgerProps<T> {
828
+ rows: readonly T[];
829
+ columns: ReadonlyArray<StatusLedgerColumn<T>>;
830
+ keyExtractor: (row: T) => string;
831
+ getStatus: (row: T) => string;
832
+ statusLabel: (status: string) => string;
833
+ statusTone: (status: string) => StatusTone;
834
+ labels: StatusLedgerLabels;
835
+ getGroup?: (row: T) => string;
836
+ groupLabel?: (group: string) => string;
837
+ getSearchText?: (row: T) => string;
838
+ needsLook?: (row: T) => boolean;
839
+ getRowAccessibilityLabel?: (row: T) => string;
840
+ onRowPress?: (row: T) => void;
841
+ renderActions?: (row: T) => React.ReactNode;
842
+ toneColors?: ToneColors;
843
+ layout?: LedgerLayout;
844
+ breakpoint?: number;
845
+ loading?: boolean;
846
+ testID?: string;
847
+ }
848
+ interface LedgerFilter {
849
+ status: string;
850
+ group: string;
851
+ text: string;
852
+ }
853
+ interface LedgerAccessors<T> {
854
+ getStatus: (row: T) => string;
855
+ getGroup?: (row: T) => string;
856
+ getSearchText?: (row: T) => string;
857
+ }
858
+
859
+ /** Status-first ledger: one sortable, filterable table on wide screens, "needs a look first" on narrow ones. */
860
+ declare function StatusLedger<T>(props: StatusLedgerProps<T>): React.ReactElement;
861
+
862
+ interface StatusPillProps {
863
+ label: string;
864
+ tone: StatusTone;
865
+ color: string;
866
+ testID?: string;
867
+ }
868
+ /** A status label with a tone glyph, so the tone never relies on colour alone. */
869
+ declare function StatusPill({ label, tone, color, testID }: StatusPillProps): React.ReactElement;
870
+
871
+ type TimeInput = string | number | Date | null | undefined;
872
+ interface RelativeUnitStrings {
873
+ minutes: string;
874
+ hours: string;
875
+ days: string;
876
+ }
877
+ /** Caller-translated templates; `{{n}}` is replaced by the count, e.g. "{{n}} min ago". */
878
+ interface RelativeTimeStrings extends RelativeUnitStrings {
879
+ justNow: string;
880
+ never: string;
881
+ future?: RelativeUnitStrings;
882
+ }
883
+ /** Parses a time input to epoch ms; `null` when absent or unparseable. */
884
+ declare function toEpochMs(value: TimeInput): number | null;
885
+ /** One relative-time format for every ledger: just now, then minutes, hours, days. */
886
+ declare function formatRelativeTime(value: TimeInput, nowMs: number, strings: RelativeTimeStrings): string;
887
+
888
+ interface RelativeTimeProps {
889
+ value: TimeInput;
890
+ nowMs: number;
891
+ strings: RelativeTimeStrings;
892
+ hint: string;
893
+ formatAbsolute?: (epochMs: number) => string;
894
+ testID?: string;
895
+ }
896
+ /** Shows "5 min ago"; a tap or click swaps to the absolute time, which is also the accessible name. */
897
+ declare function RelativeTime({ value, nowMs, strings, hint, formatAbsolute, testID }: RelativeTimeProps): React.ReactElement;
898
+
899
+ /** Sort direction of a ledger column. */
900
+ declare const enum SortDirection {
901
+ Asc = "asc",
902
+ Desc = "desc"
903
+ }
904
+
905
+ declare const STATUS_LEDGER_TEST_ID = "ui-status-ledger";
906
+ declare const ledgerSectionTestID: (testID: string, section: string) => string;
907
+ declare const ledgerSortDirectionTestID: (testID: string) => string;
908
+
909
+ /** Keeps rows matching the status, group and free-text filter; an empty value matches all. */
910
+ declare function filterLedgerRows<T>(rows: readonly T[], filter: LedgerFilter, accessors: LedgerAccessors<T>): T[];
911
+ /** Stable sort by `sortValue`; missing values always sort last, whatever the direction. */
912
+ declare function sortLedgerRows<T>(rows: readonly T[], sortValue: (row: T) => SortValue, direction: SortDirection): T[];
913
+ declare const isAttentionTone: (tone: StatusTone) => boolean;
914
+ /** Splits rows into "needs a look" (worst tone first, input order kept within a tone) and the rest. */
915
+ declare function splitNeedsLook<T>(rows: readonly T[], needsLook: (row: T) => boolean, toneOf: (row: T) => StatusTone): {
916
+ attention: T[];
917
+ rest: T[];
918
+ };
919
+ /** Distinct non-empty values in first-seen order. */
920
+ declare function distinctValues<T>(rows: readonly T[], pick: (row: T) => string | undefined): string[];
921
+
922
+ export { type BooleanFilterField, CARD_STACK_BREAKPOINT, DEFAULT_PAGE_SIZE, DEFAULT_PAGE_SIZE_OPTIONS, DataTable, type DataTableColumn, type DataTableProps, type DataTableStyleOverrides, type DateRangeFilterField, FIELD_MIN_WIDTH, FILTERS_I18N, FILTERS_TEST_ID, type FieldStrings, FilterBar, type FilterBarProps, type FilterBarStyleOverrides, type FilterDraft, type FilterField, type FilterFieldKind, type FilterOption, type FilterValue, type FilterValues, Filters, type FiltersProps, type LedgerFilter, LedgerLayout, type NumberFilterField, type PagedRows, Pager, type PagerProps, type PagerStyleOverrides, RelativeTime, type RelativeTimeProps, type RelativeTimeStrings, type RelativeUnitStrings, type RenderSelectArgs, STATUS_LEDGER_TEST_ID, type SelectFilterField, SortDirection, type SortValue, StatCard, type StatCardProps, StatusLedger, type StatusLedgerColumn, type StatusLedgerLabels, type StatusLedgerProps, StatusPill, type StatusPillProps, StatusTone, TABLE_I18N, TABLE_TEST_IDS, type TextFilterField, type TimeInput, type ToneColors, type TypeaheadFilterField, type UseFilterDraftOptions, type UsePagedRowsOptions, applyTestID, clearTestID, distinctValues, fieldTestID, filterLedgerRows, formatRelativeTime, isAttentionTone, ledgerSectionTestID, ledgerSortDirectionTestID, rowDetailTestID, rowFadeTestID, rowSelectTestID, rowTestID, selectAllTestID, sortLedgerRows, splitNeedsLook, toEpochMs, useFilterDraft, usePagedRows };
package/dist/index.d.ts CHANGED
@@ -783,4 +783,140 @@ interface PagedRows<T> {
783
783
  */
784
784
  declare function usePagedRows<T>(rows: readonly T[], options?: UsePagedRowsOptions): PagedRows<T>;
785
785
 
786
- export { type BooleanFilterField, CARD_STACK_BREAKPOINT, DEFAULT_PAGE_SIZE, DEFAULT_PAGE_SIZE_OPTIONS, DataTable, type DataTableColumn, type DataTableProps, type DataTableStyleOverrides, type DateRangeFilterField, FIELD_MIN_WIDTH, FILTERS_I18N, FILTERS_TEST_ID, type FieldStrings, FilterBar, type FilterBarProps, type FilterBarStyleOverrides, type FilterDraft, type FilterField, type FilterFieldKind, type FilterOption, type FilterValue, type FilterValues, Filters, type FiltersProps, type NumberFilterField, type PagedRows, Pager, type PagerProps, type PagerStyleOverrides, type RenderSelectArgs, type SelectFilterField, StatCard, type StatCardProps, TABLE_I18N, TABLE_TEST_IDS, type TextFilterField, type TypeaheadFilterField, type UseFilterDraftOptions, type UsePagedRowsOptions, applyTestID, clearTestID, fieldTestID, rowDetailTestID, rowFadeTestID, rowSelectTestID, rowTestID, selectAllTestID, useFilterDraft, usePagedRows };
786
+ /** Ledger layout: `Auto` picks `Table` at or above the breakpoint and `Feed` below it. */
787
+ declare const enum LedgerLayout {
788
+ Auto = "auto",
789
+ Table = "table",
790
+ Feed = "feed"
791
+ }
792
+
793
+ /** Visual tone a status maps to; drives colour, glyph and "needs a look" ordering. */
794
+ declare const enum StatusTone {
795
+ Bad = "bad",
796
+ Warn = "warn",
797
+ Active = "active",
798
+ Good = "good",
799
+ Neutral = "neutral"
800
+ }
801
+
802
+ type SortValue = string | number | null | undefined;
803
+ /** A DataTable column that can also be sorted by `sortValue`. */
804
+ interface StatusLedgerColumn<T> extends DataTableColumn<T> {
805
+ sortValue?: (row: T) => SortValue;
806
+ }
807
+ /** Every user-facing string the ledger renders, already translated by the caller. */
808
+ interface StatusLedgerLabels {
809
+ status: string;
810
+ group: string;
811
+ search: string;
812
+ sortBy: string;
813
+ all: string;
814
+ sortAscending: string;
815
+ sortDescending: string;
816
+ sortDirectionHint: string;
817
+ clear: string;
818
+ clearHint: string;
819
+ results: string;
820
+ needsLook: string;
821
+ everythingElse: string;
822
+ allClear: string;
823
+ empty: string;
824
+ actions: string;
825
+ }
826
+ type ToneColors = Partial<Record<StatusTone, string>>;
827
+ interface StatusLedgerProps<T> {
828
+ rows: readonly T[];
829
+ columns: ReadonlyArray<StatusLedgerColumn<T>>;
830
+ keyExtractor: (row: T) => string;
831
+ getStatus: (row: T) => string;
832
+ statusLabel: (status: string) => string;
833
+ statusTone: (status: string) => StatusTone;
834
+ labels: StatusLedgerLabels;
835
+ getGroup?: (row: T) => string;
836
+ groupLabel?: (group: string) => string;
837
+ getSearchText?: (row: T) => string;
838
+ needsLook?: (row: T) => boolean;
839
+ getRowAccessibilityLabel?: (row: T) => string;
840
+ onRowPress?: (row: T) => void;
841
+ renderActions?: (row: T) => React.ReactNode;
842
+ toneColors?: ToneColors;
843
+ layout?: LedgerLayout;
844
+ breakpoint?: number;
845
+ loading?: boolean;
846
+ testID?: string;
847
+ }
848
+ interface LedgerFilter {
849
+ status: string;
850
+ group: string;
851
+ text: string;
852
+ }
853
+ interface LedgerAccessors<T> {
854
+ getStatus: (row: T) => string;
855
+ getGroup?: (row: T) => string;
856
+ getSearchText?: (row: T) => string;
857
+ }
858
+
859
+ /** Status-first ledger: one sortable, filterable table on wide screens, "needs a look first" on narrow ones. */
860
+ declare function StatusLedger<T>(props: StatusLedgerProps<T>): React.ReactElement;
861
+
862
+ interface StatusPillProps {
863
+ label: string;
864
+ tone: StatusTone;
865
+ color: string;
866
+ testID?: string;
867
+ }
868
+ /** A status label with a tone glyph, so the tone never relies on colour alone. */
869
+ declare function StatusPill({ label, tone, color, testID }: StatusPillProps): React.ReactElement;
870
+
871
+ type TimeInput = string | number | Date | null | undefined;
872
+ interface RelativeUnitStrings {
873
+ minutes: string;
874
+ hours: string;
875
+ days: string;
876
+ }
877
+ /** Caller-translated templates; `{{n}}` is replaced by the count, e.g. "{{n}} min ago". */
878
+ interface RelativeTimeStrings extends RelativeUnitStrings {
879
+ justNow: string;
880
+ never: string;
881
+ future?: RelativeUnitStrings;
882
+ }
883
+ /** Parses a time input to epoch ms; `null` when absent or unparseable. */
884
+ declare function toEpochMs(value: TimeInput): number | null;
885
+ /** One relative-time format for every ledger: just now, then minutes, hours, days. */
886
+ declare function formatRelativeTime(value: TimeInput, nowMs: number, strings: RelativeTimeStrings): string;
887
+
888
+ interface RelativeTimeProps {
889
+ value: TimeInput;
890
+ nowMs: number;
891
+ strings: RelativeTimeStrings;
892
+ hint: string;
893
+ formatAbsolute?: (epochMs: number) => string;
894
+ testID?: string;
895
+ }
896
+ /** Shows "5 min ago"; a tap or click swaps to the absolute time, which is also the accessible name. */
897
+ declare function RelativeTime({ value, nowMs, strings, hint, formatAbsolute, testID }: RelativeTimeProps): React.ReactElement;
898
+
899
+ /** Sort direction of a ledger column. */
900
+ declare const enum SortDirection {
901
+ Asc = "asc",
902
+ Desc = "desc"
903
+ }
904
+
905
+ declare const STATUS_LEDGER_TEST_ID = "ui-status-ledger";
906
+ declare const ledgerSectionTestID: (testID: string, section: string) => string;
907
+ declare const ledgerSortDirectionTestID: (testID: string) => string;
908
+
909
+ /** Keeps rows matching the status, group and free-text filter; an empty value matches all. */
910
+ declare function filterLedgerRows<T>(rows: readonly T[], filter: LedgerFilter, accessors: LedgerAccessors<T>): T[];
911
+ /** Stable sort by `sortValue`; missing values always sort last, whatever the direction. */
912
+ declare function sortLedgerRows<T>(rows: readonly T[], sortValue: (row: T) => SortValue, direction: SortDirection): T[];
913
+ declare const isAttentionTone: (tone: StatusTone) => boolean;
914
+ /** Splits rows into "needs a look" (worst tone first, input order kept within a tone) and the rest. */
915
+ declare function splitNeedsLook<T>(rows: readonly T[], needsLook: (row: T) => boolean, toneOf: (row: T) => StatusTone): {
916
+ attention: T[];
917
+ rest: T[];
918
+ };
919
+ /** Distinct non-empty values in first-seen order. */
920
+ declare function distinctValues<T>(rows: readonly T[], pick: (row: T) => string | undefined): string[];
921
+
922
+ export { type BooleanFilterField, CARD_STACK_BREAKPOINT, DEFAULT_PAGE_SIZE, DEFAULT_PAGE_SIZE_OPTIONS, DataTable, type DataTableColumn, type DataTableProps, type DataTableStyleOverrides, type DateRangeFilterField, FIELD_MIN_WIDTH, FILTERS_I18N, FILTERS_TEST_ID, type FieldStrings, FilterBar, type FilterBarProps, type FilterBarStyleOverrides, type FilterDraft, type FilterField, type FilterFieldKind, type FilterOption, type FilterValue, type FilterValues, Filters, type FiltersProps, type LedgerFilter, LedgerLayout, type NumberFilterField, type PagedRows, Pager, type PagerProps, type PagerStyleOverrides, RelativeTime, type RelativeTimeProps, type RelativeTimeStrings, type RelativeUnitStrings, type RenderSelectArgs, STATUS_LEDGER_TEST_ID, type SelectFilterField, SortDirection, type SortValue, StatCard, type StatCardProps, StatusLedger, type StatusLedgerColumn, type StatusLedgerLabels, type StatusLedgerProps, StatusPill, type StatusPillProps, StatusTone, TABLE_I18N, TABLE_TEST_IDS, type TextFilterField, type TimeInput, type ToneColors, type TypeaheadFilterField, type UseFilterDraftOptions, type UsePagedRowsOptions, applyTestID, clearTestID, distinctValues, fieldTestID, filterLedgerRows, formatRelativeTime, isAttentionTone, ledgerSectionTestID, ledgerSortDirectionTestID, rowDetailTestID, rowFadeTestID, rowSelectTestID, rowTestID, selectAllTestID, sortLedgerRows, splitNeedsLook, toEpochMs, useFilterDraft, usePagedRows };
package/dist/index.js CHANGED
@@ -1836,6 +1836,311 @@ function usePagedRows(rows, options = {}) {
1836
1836
  };
1837
1837
  }
1838
1838
 
1839
+ // src/StatusLedger/StatusTone.ts
1840
+ var StatusTone = /* @__PURE__ */ ((StatusTone2) => {
1841
+ StatusTone2["Bad"] = "bad";
1842
+ StatusTone2["Warn"] = "warn";
1843
+ StatusTone2["Active"] = "active";
1844
+ StatusTone2["Good"] = "good";
1845
+ StatusTone2["Neutral"] = "neutral";
1846
+ return StatusTone2;
1847
+ })(StatusTone || {});
1848
+
1849
+ // src/StatusLedger/constants.ts
1850
+ var STATUS_LEDGER_TEST_ID = "ui-status-ledger";
1851
+ var STATUS_COLUMN_KEY = "status";
1852
+ var ACTIONS_COLUMN_KEY = "actions";
1853
+ var ALL_VALUE = "";
1854
+ var TONE_RANK = {
1855
+ ["bad" /* Bad */]: 0,
1856
+ ["warn" /* Warn */]: 1,
1857
+ ["active" /* Active */]: 2,
1858
+ ["neutral" /* Neutral */]: 3,
1859
+ ["good" /* Good */]: 4
1860
+ };
1861
+ var TONE_GLYPH = {
1862
+ ["bad" /* Bad */]: "\u2715",
1863
+ ["warn" /* Warn */]: "!",
1864
+ ["active" /* Active */]: "\u25B8",
1865
+ ["neutral" /* Neutral */]: "\u2013",
1866
+ ["good" /* Good */]: "\u2713"
1867
+ };
1868
+ var ledgerSectionTestID = (testID, section) => `${testID}-section-${section}`;
1869
+ var ledgerSortDirectionTestID = (testID) => `${testID}-sort-direction`;
1870
+ var PILL_RADIUS2 = 999;
1871
+ var PILL_BORDER = 1;
1872
+ var PILL_PAD_H = 8;
1873
+ var PILL_PAD_V = 2;
1874
+ var PILL_GAP = 6;
1875
+ var PILL_FONT = 13;
1876
+ var PILL_WEIGHT = "600";
1877
+ var styles2 = reactNative.StyleSheet.create({
1878
+ pill: {
1879
+ flexDirection: "row",
1880
+ alignItems: "center",
1881
+ alignSelf: "flex-start",
1882
+ gap: PILL_GAP,
1883
+ borderWidth: PILL_BORDER,
1884
+ borderRadius: PILL_RADIUS2,
1885
+ paddingHorizontal: PILL_PAD_H,
1886
+ paddingVertical: PILL_PAD_V
1887
+ },
1888
+ text: { fontSize: PILL_FONT, fontWeight: PILL_WEIGHT }
1889
+ });
1890
+ function StatusPill({ label, tone, color, testID }) {
1891
+ return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { accessibilityLabel: label, accessibilityRole: "text", style: [styles2.pill, { borderColor: color }], testID, children: [
1892
+ /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { "aria-hidden": true, style: [styles2.text, { color }], children: TONE_GLYPH[tone] }),
1893
+ /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles2.text, { color }], children: label })
1894
+ ] });
1895
+ }
1896
+
1897
+ // src/StatusLedger/SortDirection.ts
1898
+ var SortDirection = /* @__PURE__ */ ((SortDirection2) => {
1899
+ SortDirection2["Asc"] = "asc";
1900
+ SortDirection2["Desc"] = "desc";
1901
+ return SortDirection2;
1902
+ })(SortDirection || {});
1903
+
1904
+ // src/StatusLedger/utils/ledgerLogic.ts
1905
+ var BEFORE = -1;
1906
+ var AFTER = 1;
1907
+ var SAME = 0;
1908
+ var isMissing = (value) => value === null || value === void 0 || value === "";
1909
+ var compareValues = (a, b) => {
1910
+ if (typeof a === "number" && typeof b === "number") return a - b;
1911
+ return String(a).localeCompare(String(b), void 0, { numeric: true, sensitivity: "base" });
1912
+ };
1913
+ function filterLedgerRows(rows, filter, accessors) {
1914
+ const needle = filter.text.trim().toLocaleLowerCase();
1915
+ return rows.filter((row) => {
1916
+ const statusOk = filter.status === ALL_VALUE || accessors.getStatus(row) === filter.status;
1917
+ const groupOk = filter.group === ALL_VALUE || accessors.getGroup?.(row) === filter.group;
1918
+ const haystack = accessors.getSearchText?.(row) ?? "";
1919
+ const textOk = needle === "" || haystack.toLocaleLowerCase().includes(needle);
1920
+ return statusOk && groupOk && textOk;
1921
+ });
1922
+ }
1923
+ function sortLedgerRows(rows, sortValue, direction) {
1924
+ const sign = direction === "asc" /* Asc */ ? AFTER : BEFORE;
1925
+ return [...rows].sort((left, right) => {
1926
+ const a = sortValue(left);
1927
+ const b = sortValue(right);
1928
+ if (isMissing(a) && isMissing(b)) return SAME;
1929
+ if (isMissing(a)) return AFTER;
1930
+ if (isMissing(b)) return BEFORE;
1931
+ return sign * compareValues(a, b);
1932
+ });
1933
+ }
1934
+ var toneRank = (tone) => TONE_RANK[tone];
1935
+ var isAttentionTone = (tone) => tone === "bad" /* Bad */ || tone === "warn" /* Warn */;
1936
+ function splitNeedsLook(rows, needsLook, toneOf) {
1937
+ const attention = rows.filter(needsLook);
1938
+ const rest = rows.filter((row) => !needsLook(row));
1939
+ return { attention: sortLedgerRows(attention, (row) => toneRank(toneOf(row)), "asc" /* Asc */), rest };
1940
+ }
1941
+ function distinctValues(rows, pick) {
1942
+ const seen = /* @__PURE__ */ new Set();
1943
+ rows.forEach((row) => {
1944
+ const value = pick(row);
1945
+ if (value !== void 0 && value !== "") seen.add(value);
1946
+ });
1947
+ return [...seen];
1948
+ }
1949
+ var readText = (values, key) => {
1950
+ const value = values[key];
1951
+ return typeof value === "string" ? value : ALL_VALUE;
1952
+ };
1953
+ function useToneColor(toneColors) {
1954
+ const { theme } = uiFeedback.useUi();
1955
+ return React2.useCallback(
1956
+ (tone) => {
1957
+ const override = toneColors?.[tone];
1958
+ if (override !== void 0) return override;
1959
+ if (tone === "bad" /* Bad */) return theme.semantic.error["500"];
1960
+ if (tone === "active" /* Active */) return theme.palette.primary["500"];
1961
+ return tone === "good" /* Good */ ? theme.colors.textSecondary : theme.colors.text;
1962
+ },
1963
+ [toneColors, theme]
1964
+ );
1965
+ }
1966
+ function useLedgerView(props) {
1967
+ const { rows, columns, getStatus, statusLabel, statusTone, labels, getGroup, groupLabel, getSearchText, needsLook, renderActions, toneColors } = props;
1968
+ const [values, setValues] = React2.useState({});
1969
+ const [direction, setDirection] = React2.useState("asc" /* Asc */);
1970
+ const toneColor = useToneColor(toneColors);
1971
+ const toneOf = React2.useCallback((row) => statusTone(getStatus(row)), [statusTone, getStatus]);
1972
+ const allColumns = React2.useMemo(() => {
1973
+ const status = {
1974
+ key: STATUS_COLUMN_KEY,
1975
+ header: labels.status,
1976
+ sortValue: (row) => toneRank(toneOf(row)),
1977
+ render: (row) => /* @__PURE__ */ jsxRuntime.jsx(StatusPill, { color: toneColor(toneOf(row)), label: statusLabel(getStatus(row)), tone: toneOf(row) })
1978
+ };
1979
+ const actions = renderActions === void 0 ? [] : [{ key: ACTIONS_COLUMN_KEY, header: labels.actions, render: renderActions }];
1980
+ return [columns[0], status, ...columns.slice(1), ...actions].filter((c) => c !== void 0);
1981
+ }, [columns, labels, toneOf, toneColor, statusLabel, getStatus, renderActions]);
1982
+ const fields = React2.useMemo(() => {
1983
+ const all = { value: ALL_VALUE, label: labels.all };
1984
+ const statuses = distinctValues(rows, getStatus).map((s) => ({ value: s, label: statusLabel(s) }));
1985
+ const groups = getGroup === void 0 ? [] : distinctValues(rows, getGroup).map((g) => ({ value: g, label: groupLabel?.(g) ?? g }));
1986
+ const sortable = allColumns.filter((c) => "sortValue" in c && c.sortValue !== void 0).map((c) => ({ value: c.key, label: c.header }));
1987
+ const groupField = groups.length === 0 ? [] : [{ kind: "select", key: "group" /* Group */, label: labels.group, options: [all, ...groups] }];
1988
+ return [
1989
+ { kind: "text", key: "search" /* Search */, label: labels.search, grow: true },
1990
+ { kind: "select", key: "status" /* Status */, label: labels.status, options: [all, ...statuses] },
1991
+ ...groupField,
1992
+ { kind: "select", key: "sort" /* Sort */, label: labels.sortBy, options: sortable }
1993
+ ];
1994
+ }, [rows, getStatus, statusLabel, getGroup, groupLabel, labels, allColumns]);
1995
+ const visible = React2.useMemo(() => {
1996
+ const filter = { status: readText(values, "status" /* Status */), group: readText(values, "group" /* Group */), text: readText(values, "search" /* Search */) };
1997
+ const filtered = filterLedgerRows(rows, filter, { getStatus, getGroup, getSearchText });
1998
+ const sortColumn = allColumns.find((c) => c.key === readText(values, "sort" /* Sort */));
1999
+ return sortColumn?.sortValue === void 0 ? filtered : sortLedgerRows(filtered, sortColumn.sortValue, direction);
2000
+ }, [rows, values, getStatus, getGroup, getSearchText, allColumns, direction]);
2001
+ const split = React2.useMemo(() => splitNeedsLook(visible, needsLook ?? ((row) => isAttentionTone(toneOf(row))), toneOf), [visible, needsLook, toneOf]);
2002
+ const toggleDirection = React2.useCallback(() => setDirection((d) => d === "asc" /* Asc */ ? "desc" /* Desc */ : "asc" /* Asc */), []);
2003
+ const clear = React2.useCallback(() => setValues({}), []);
2004
+ const tableColumns = allColumns;
2005
+ return { values, setValues, direction, toggleDirection, clear, fields, visible, split, tableColumns };
2006
+ }
2007
+
2008
+ // src/StatusLedger/LedgerLayout.ts
2009
+ var LedgerLayout = /* @__PURE__ */ ((LedgerLayout2) => {
2010
+ LedgerLayout2["Auto"] = "auto";
2011
+ LedgerLayout2["Table"] = "table";
2012
+ LedgerLayout2["Feed"] = "feed";
2013
+ return LedgerLayout2;
2014
+ })(LedgerLayout || {});
2015
+ var GAP = 12;
2016
+ var HEADING_FONT = 15;
2017
+ var HEADING_WEIGHT = "700";
2018
+ var styles3 = reactNative.StyleSheet.create({
2019
+ root: { gap: GAP },
2020
+ heading: { fontSize: HEADING_FONT, fontWeight: HEADING_WEIGHT },
2021
+ note: { paddingVertical: GAP }
2022
+ });
2023
+ function LedgerSection({ title, rows, columns, emptyLabel, testID, ledger }) {
2024
+ const { theme } = uiFeedback.useUi();
2025
+ return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles3.root, testID, children: [
2026
+ /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { accessibilityRole: "header", style: [styles3.heading, { color: theme.colors.text }], children: `${title} \xB7 ${rows.length}` }),
2027
+ rows.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles3.note, { color: theme.colors.textSecondary }], children: emptyLabel }) : /* @__PURE__ */ jsxRuntime.jsx(
2028
+ DataTable,
2029
+ {
2030
+ columns,
2031
+ getRowAccessibilityLabel: ledger.getRowAccessibilityLabel,
2032
+ keyExtractor: ledger.keyExtractor,
2033
+ onRowPress: ledger.onRowPress,
2034
+ rows,
2035
+ stackBreakpoint: ledger.breakpoint ?? CARD_STACK_BREAKPOINT,
2036
+ testID: `${testID}-table`
2037
+ }
2038
+ )
2039
+ ] });
2040
+ }
2041
+ function StatusLedger(props) {
2042
+ const { labels, layout = "auto" /* Auto */, breakpoint = CARD_STACK_BREAKPOINT, loading, testID = STATUS_LEDGER_TEST_ID } = props;
2043
+ const { width } = reactNative.useWindowDimensions();
2044
+ const view = useLedgerView(props);
2045
+ const feed = layout === "feed" /* Feed */ || layout === "auto" /* Auto */ && width < breakpoint;
2046
+ const ascending = view.direction === "asc" /* Asc */;
2047
+ const directionButton = /* @__PURE__ */ jsxRuntime.jsx(
2048
+ ActionButton,
2049
+ {
2050
+ hint: labels.sortDirectionHint,
2051
+ label: ascending ? labels.sortAscending : labels.sortDescending,
2052
+ onPress: view.toggleDirection,
2053
+ testID: ledgerSortDirectionTestID(testID),
2054
+ tone: "ghost"
2055
+ }
2056
+ );
2057
+ return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles3.root, testID, children: [
2058
+ /* @__PURE__ */ jsxRuntime.jsx(
2059
+ Filters,
2060
+ {
2061
+ actions: directionButton,
2062
+ clearHint: labels.clearHint,
2063
+ clearLabel: labels.clear,
2064
+ fields: view.fields,
2065
+ onChange: view.setValues,
2066
+ onClear: view.clear,
2067
+ resultsCount: view.visible.length,
2068
+ resultsLabel: labels.results,
2069
+ testID: `${testID}-filters`,
2070
+ values: view.values
2071
+ }
2072
+ ),
2073
+ feed && !loading ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2074
+ /* @__PURE__ */ jsxRuntime.jsx(LedgerSection, { columns: view.tableColumns, emptyLabel: labels.allClear, ledger: props, rows: view.split.attention, testID: ledgerSectionTestID(testID, "attention"), title: labels.needsLook }),
2075
+ /* @__PURE__ */ jsxRuntime.jsx(LedgerSection, { columns: view.tableColumns, emptyLabel: labels.empty, ledger: props, rows: view.split.rest, testID: ledgerSectionTestID(testID, "rest"), title: labels.everythingElse })
2076
+ ] }) : /* @__PURE__ */ jsxRuntime.jsx(
2077
+ DataTable,
2078
+ {
2079
+ columns: view.tableColumns,
2080
+ emptyLabel: labels.empty,
2081
+ getRowAccessibilityLabel: props.getRowAccessibilityLabel,
2082
+ keyExtractor: props.keyExtractor,
2083
+ loading,
2084
+ onRowPress: props.onRowPress,
2085
+ rows: view.visible,
2086
+ stackBreakpoint: feed ? breakpoint : 0,
2087
+ testID: `${testID}-table`
2088
+ }
2089
+ )
2090
+ ] });
2091
+ }
2092
+
2093
+ // src/StatusLedger/utils/relativeTime.ts
2094
+ var MS_PER_SECOND = 1e3;
2095
+ var SECONDS_PER_MINUTE = 60;
2096
+ var MINUTES_PER_HOUR = 60;
2097
+ var HOURS_PER_DAY = 24;
2098
+ var MS_PER_MINUTE = MS_PER_SECOND * SECONDS_PER_MINUTE;
2099
+ var MS_PER_HOUR = MS_PER_MINUTE * MINUTES_PER_HOUR;
2100
+ var MS_PER_DAY = MS_PER_HOUR * HOURS_PER_DAY;
2101
+ var COUNT_TOKEN = /\{\{n\}\}/g;
2102
+ function toEpochMs(value) {
2103
+ if (value === null || value === void 0 || value === "") return null;
2104
+ const ms = value instanceof Date ? value.getTime() : typeof value === "number" ? value : Date.parse(value);
2105
+ return Number.isFinite(ms) ? ms : null;
2106
+ }
2107
+ var fill = (template, count) => template.replace(COUNT_TOKEN, String(count));
2108
+ function formatRelativeTime(value, nowMs, strings) {
2109
+ const ms = toEpochMs(value);
2110
+ if (ms === null) return strings.never;
2111
+ const delta = nowMs - ms;
2112
+ const units = delta < 0 && strings.future !== void 0 ? strings.future : strings;
2113
+ const distance = Math.abs(delta);
2114
+ if (distance < MS_PER_MINUTE) return strings.justNow;
2115
+ if (distance < MS_PER_HOUR) return fill(units.minutes, Math.floor(distance / MS_PER_MINUTE));
2116
+ if (distance < MS_PER_DAY) return fill(units.hours, Math.floor(distance / MS_PER_HOUR));
2117
+ return fill(units.days, Math.floor(distance / MS_PER_DAY));
2118
+ }
2119
+ var styles4 = reactNative.StyleSheet.create({
2120
+ target: { minHeight: MIN_TARGET_PX, minWidth: MIN_TARGET_PX, justifyContent: "center" }
2121
+ });
2122
+ var defaultAbsolute = (ms) => new Date(ms).toLocaleString();
2123
+ function RelativeTime({ value, nowMs, strings, hint, formatAbsolute = defaultAbsolute, testID }) {
2124
+ const { theme } = uiFeedback.useUi();
2125
+ const [showAbsolute, setShowAbsolute] = React2.useState(false);
2126
+ const ms = toEpochMs(value);
2127
+ const relative = formatRelativeTime(value, nowMs, strings);
2128
+ const absolute = ms === null ? relative : formatAbsolute(ms);
2129
+ return /* @__PURE__ */ jsxRuntime.jsx(
2130
+ reactNative.Pressable,
2131
+ {
2132
+ accessibilityHint: hint,
2133
+ accessibilityLabel: absolute,
2134
+ accessibilityRole: "button",
2135
+ disabled: ms === null,
2136
+ onPress: () => setShowAbsolute((current) => !current),
2137
+ style: styles4.target,
2138
+ testID,
2139
+ children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: { color: theme.colors.text }, children: showAbsolute ? absolute : relative })
2140
+ }
2141
+ );
2142
+ }
2143
+
1839
2144
  Object.defineProperty(exports, "DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS", {
1840
2145
  enumerable: true,
1841
2146
  get: function () { return uiForms.DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS; }
@@ -1861,18 +2166,34 @@ exports.FILTERS_I18N = FILTERS_I18N;
1861
2166
  exports.FILTERS_TEST_ID = FILTERS_TEST_ID;
1862
2167
  exports.FilterBar = FilterBar;
1863
2168
  exports.Filters = Filters;
2169
+ exports.LedgerLayout = LedgerLayout;
1864
2170
  exports.Pager = Pager;
2171
+ exports.RelativeTime = RelativeTime;
2172
+ exports.STATUS_LEDGER_TEST_ID = STATUS_LEDGER_TEST_ID;
2173
+ exports.SortDirection = SortDirection;
1865
2174
  exports.StatCard = StatCard;
2175
+ exports.StatusLedger = StatusLedger;
2176
+ exports.StatusPill = StatusPill;
2177
+ exports.StatusTone = StatusTone;
1866
2178
  exports.TABLE_I18N = TABLE_I18N;
1867
2179
  exports.TABLE_TEST_IDS = TABLE_TEST_IDS;
1868
2180
  exports.applyTestID = applyTestID;
1869
2181
  exports.clearTestID = clearTestID;
2182
+ exports.distinctValues = distinctValues;
1870
2183
  exports.fieldTestID = fieldTestID;
2184
+ exports.filterLedgerRows = filterLedgerRows;
2185
+ exports.formatRelativeTime = formatRelativeTime;
2186
+ exports.isAttentionTone = isAttentionTone;
2187
+ exports.ledgerSectionTestID = ledgerSectionTestID;
2188
+ exports.ledgerSortDirectionTestID = ledgerSortDirectionTestID;
1871
2189
  exports.rowDetailTestID = rowDetailTestID;
1872
2190
  exports.rowFadeTestID = rowFadeTestID;
1873
2191
  exports.rowSelectTestID = rowSelectTestID;
1874
2192
  exports.rowTestID = rowTestID;
1875
2193
  exports.selectAllTestID = selectAllTestID;
2194
+ exports.sortLedgerRows = sortLedgerRows;
2195
+ exports.splitNeedsLook = splitNeedsLook;
2196
+ exports.toEpochMs = toEpochMs;
1876
2197
  exports.useFilterDraft = useFilterDraft;
1877
2198
  exports.usePagedRows = usePagedRows;
1878
2199
  //# sourceMappingURL=index.js.map