@makoai/app-sdk 2.29.0 → 2.30.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/README.md +64 -3
- package/components/period-picker.tsx +2 -2
- package/components/period.ts +10 -5
- package/index.js +1 -1
- package/locale.d.ts +64 -1
- package/locale.js +105 -8
- package/menu/filter-menu.tsx +4 -1
- package/package.json +1 -1
- package/tailwind.css +11 -0
- package/ui-core.js +56 -6
- package/ui.css +34 -1
- package/ui.d.ts +105 -1
- package/ui.js +280 -61
package/ui.js
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
import * as React from "react";
|
|
12
12
|
import { createPortal } from "react-dom";
|
|
13
13
|
import { bindingPhaseLabel, refreshBinding, useBindingProgress } from "./index.js";
|
|
14
|
+
import { bindingPhaseStage } from "./progress.js";
|
|
14
15
|
import {
|
|
15
16
|
claimPopover,
|
|
16
17
|
closePopovers,
|
|
@@ -46,8 +47,12 @@ import {
|
|
|
46
47
|
pageToSync,
|
|
47
48
|
refreshOrder,
|
|
48
49
|
releasePopover,
|
|
50
|
+
resizeWidth,
|
|
49
51
|
serializeResetKey,
|
|
50
52
|
sortRows,
|
|
53
|
+
splitSections,
|
|
54
|
+
fromSorting,
|
|
55
|
+
toSorting,
|
|
51
56
|
toCsv,
|
|
52
57
|
tooltipCellText,
|
|
53
58
|
tooltipSeriesRows,
|
|
@@ -87,8 +92,12 @@ export {
|
|
|
87
92
|
pageSlice,
|
|
88
93
|
pageToSync,
|
|
89
94
|
refreshOrder,
|
|
95
|
+
resizeWidth,
|
|
90
96
|
serializeResetKey,
|
|
91
97
|
sortRows,
|
|
98
|
+
splitSections,
|
|
99
|
+
fromSorting,
|
|
100
|
+
toSorting,
|
|
92
101
|
toCsv,
|
|
93
102
|
tooltipCellText,
|
|
94
103
|
tooltipSeriesRows,
|
|
@@ -367,8 +376,11 @@ export function tooltipCell(value, format, opts) {
|
|
|
367
376
|
* rate). A null or undefined cell shows a muted "–"; "" stays blank.
|
|
368
377
|
* `colWidth` sets the value columns' minimum width (default 7ch; a number is
|
|
369
378
|
* px), so the box keeps its size while the pointer moves.
|
|
379
|
+
* 2.30: a row's `rule: true` draws a rule above it (an "Ending MRR" line
|
|
380
|
+
* before the total), and `note` adds a muted line under the table (a caveat,
|
|
381
|
+
* "Click to list the opportunities").
|
|
370
382
|
*/
|
|
371
|
-
export function TableTooltip({ title, columns = [], rows = [], total, after, className, colWidth }) {
|
|
383
|
+
export function TableTooltip({ title, columns = [], rows = [], total, after, note, className, colWidth }) {
|
|
372
384
|
return h(
|
|
373
385
|
"div",
|
|
374
386
|
{
|
|
@@ -384,13 +396,14 @@ export function TableTooltip({ title, columns = [], rows = [], total, after, cla
|
|
|
384
396
|
h(
|
|
385
397
|
"tbody",
|
|
386
398
|
null,
|
|
387
|
-
...rows.map(r => h(TooltipRow, { key: r.key ?? r.label, row: r })),
|
|
388
|
-
total && h(TooltipRow, { key: "__total", row: total, className: cx("mk-tip-total", rows.length > 0 && "mk-tip-rule") }),
|
|
399
|
+
...rows.map(r => h(TooltipRow, { key: r.key ?? r.label, row: r, className: r.rule ? "mk-tip-rule" : undefined })),
|
|
400
|
+
total && h(TooltipRow, { key: "__total", row: total, className: cx("mk-tip-total", (rows.length > 0 || total.rule) && "mk-tip-rule") }),
|
|
389
401
|
...(after ?? []).map((r, i) =>
|
|
390
|
-
h(TooltipRow, { key: `__after_${r.key ?? r.label}`, row: r, className: i === 0 ? "mk-tip-rule" : undefined }),
|
|
402
|
+
h(TooltipRow, { key: `__after_${r.key ?? r.label}`, row: r, className: i === 0 || r.rule ? "mk-tip-rule" : undefined }),
|
|
391
403
|
),
|
|
392
404
|
),
|
|
393
405
|
),
|
|
406
|
+
note != null && note !== false && h("div", { className: "mk-tip-note" }, note),
|
|
394
407
|
);
|
|
395
408
|
}
|
|
396
409
|
|
|
@@ -561,6 +574,8 @@ export function saveCsv(filename, text) {
|
|
|
561
574
|
|
|
562
575
|
const fmtCount = n => n.toLocaleString("en-US");
|
|
563
576
|
const EMPTY_EXPANDED = Object.freeze({});
|
|
577
|
+
const EMPTY_SIZING = Object.freeze({});
|
|
578
|
+
const SKELETON_ROWS = 10;
|
|
564
579
|
|
|
565
580
|
/**
|
|
566
581
|
* The English text of a DataTable's footer, sort hints and export button.
|
|
@@ -589,6 +604,7 @@ export const DATA_TABLE_LABELS = {
|
|
|
589
604
|
expand: () => "Show details",
|
|
590
605
|
collapse: () => "Hide details",
|
|
591
606
|
info: label => `About ${label}`,
|
|
607
|
+
resizeHint: "Drag to resize · double-click to reset",
|
|
592
608
|
};
|
|
593
609
|
/**
|
|
594
610
|
* DataTable's texts for a locale (2.29), `labels` on top. No locale and no
|
|
@@ -676,26 +692,73 @@ export function DataTable({
|
|
|
676
692
|
totalRow,
|
|
677
693
|
onTotalRowClick,
|
|
678
694
|
exportTotalRow = false,
|
|
695
|
+
manualSorting = false,
|
|
696
|
+
manualPagination = false,
|
|
697
|
+
rowCount,
|
|
698
|
+
sorting,
|
|
699
|
+
onSortingChange,
|
|
700
|
+
pagination,
|
|
701
|
+
onPaginationChange,
|
|
702
|
+
loading = false,
|
|
703
|
+
enableColumnResizing = false,
|
|
704
|
+
columnResizeMode = "onEnd",
|
|
705
|
+
columnSizing: columnSizingProp,
|
|
706
|
+
onColumnSizingChange,
|
|
707
|
+
isSectionRow,
|
|
708
|
+
renderSection,
|
|
679
709
|
className,
|
|
680
710
|
style,
|
|
681
711
|
}) {
|
|
682
712
|
const L = dataTableLabels(locale, labelsProp);
|
|
683
713
|
const empty = emptyProp ?? L.empty;
|
|
684
714
|
const noun = nounProp ?? L.rows;
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
715
|
+
// TanStack Table's state shapes (2.30): `sorting` ([{ id, desc }]) and
|
|
716
|
+
// `pagination` ({ pageIndex, pageSize }, 0-based) drive the same state as
|
|
717
|
+
// `sort`, `page` and `pageSize`. Their callbacks get the next value.
|
|
718
|
+
const [sort, setSortState] = useControlled(sorting !== undefined ? fromSorting(sorting) : sortProp, defaultSort, onSortChange);
|
|
719
|
+
const [rawPage, setRawPage] = useControlled(pagination ? pagination.pageIndex + 1 : pageProp, 1, onPageChange);
|
|
720
|
+
const [pageSize, setPageSize] = useControlled(pagination ? pagination.pageSize : pageSizeProp, defaultPageSize, onPageSizeChange);
|
|
721
|
+
const setSort = next => {
|
|
722
|
+
setSortState(next);
|
|
723
|
+
onSortingChange?.(toSorting(next));
|
|
724
|
+
};
|
|
725
|
+
const reportPage = (p, size) => onPaginationChange?.({ pageIndex: p - 1, pageSize: size });
|
|
688
726
|
// A page size outside the list (defaultPageSize={200}) still shows as the selected option.
|
|
689
727
|
const sizeOptions = pageSizes.includes(pageSize) ? pageSizes : [...pageSizes, pageSize].sort((a, b) => a - b);
|
|
690
728
|
const [note, setNote] = React.useState(null);
|
|
691
729
|
const scrollRef = React.useRef(null);
|
|
692
730
|
|
|
693
|
-
|
|
694
|
-
|
|
731
|
+
// Section rows (2.30) split the rows into runs: a run's rows sort inside it
|
|
732
|
+
// and the section row heads them. `sorted` holds data rows only, so the
|
|
733
|
+
// pager, the footer, the CSV and the total never count a section row.
|
|
734
|
+
// `manualSorting` (2.30): the rows come sorted (by the server), as given.
|
|
735
|
+
const runsOfRows = React.useMemo(() => (isSectionRow ? splitSections(rows, isSectionRow) : null), [rows, isSectionRow]);
|
|
736
|
+
const sorted = React.useMemo(() => {
|
|
737
|
+
const order = rs => (manualSorting ? rs.slice() : sortRows(rs, columns, sort));
|
|
738
|
+
return runsOfRows ? runsOfRows.flatMap(r => order(r.rows)) : order(rows);
|
|
739
|
+
}, [rows, runsOfRows, columns, sort, manualSorting]);
|
|
740
|
+
const sectionOf = React.useMemo(
|
|
741
|
+
() => (runsOfRows ? new Map(runsOfRows.flatMap(r => r.rows.map(row => [row, r.section]))) : null),
|
|
742
|
+
[runsOfRows],
|
|
743
|
+
);
|
|
744
|
+
|
|
745
|
+
// Column resizing (2.30, TanStack Table's): a drag handle on each header's
|
|
746
|
+
// right edge. `columnSizing` ({ [id]: px }) is controlled or local.
|
|
747
|
+
const [sizing, setSizing] = useControlled(columnSizingProp, EMPTY_SIZING, onColumnSizingChange);
|
|
748
|
+
const sizingRef = React.useRef(sizing);
|
|
749
|
+
sizingRef.current = sizing;
|
|
750
|
+
const [drag, setDrag] = React.useState(null);
|
|
751
|
+
const dragRef = React.useRef(null);
|
|
752
|
+
const resizable = enableColumnResizing || columnSizingProp !== undefined;
|
|
753
|
+
const layoutSizing = resizable ? sizing : undefined;
|
|
754
|
+
const layout = React.useMemo(() => columnLayout(columns, layoutSizing), [columns, layoutSizing]);
|
|
695
755
|
const runs = React.useMemo(() => columnGroupRuns(columns), [columns]);
|
|
696
756
|
const sections = React.useMemo(() => new Set(runs?.filter(r => r.start).map(r => r.columns[0].id)), [runs]);
|
|
697
|
-
|
|
698
|
-
|
|
757
|
+
// `manualPagination` (2.30): `rows` is the current page and `rowCount` the
|
|
758
|
+
// total, so the footer and the pager count the server's rows.
|
|
759
|
+
const totalCount = manualPagination ? (rowCount ?? (Math.max(1, rawPage) - 1) * pageSize + sorted.length) : sorted.length;
|
|
760
|
+
const { page, pageCount, start, end } = pageSlice(totalCount, rawPage, pageSize);
|
|
761
|
+
const visible = manualPagination ? sorted : sorted.slice(start, end);
|
|
699
762
|
|
|
700
763
|
// Expandable rows. The state has TanStack Table's ExpandedState shape:
|
|
701
764
|
// `true` (every row) or `{ [rowId]: true }`, rowId being String(rowKey(row)).
|
|
@@ -721,13 +784,15 @@ export function DataTable({
|
|
|
721
784
|
|
|
722
785
|
// The total row: an object, or a function over the rows the table got (the
|
|
723
786
|
// filtered rows). It never sorts or pages; CSV only with `exportTotalRow`.
|
|
787
|
+
const dataRows = runsOfRows ? sorted : rows;
|
|
724
788
|
const total = React.useMemo(
|
|
725
|
-
() => (typeof totalRow === "function" ? totalRow(
|
|
726
|
-
[totalRow,
|
|
789
|
+
() => (typeof totalRow === "function" ? totalRow(dataRows) : (totalRow ?? null)),
|
|
790
|
+
[totalRow, dataRows],
|
|
727
791
|
);
|
|
728
792
|
|
|
729
|
-
const goTo = p => {
|
|
793
|
+
const goTo = (p, size = pageSize) => {
|
|
730
794
|
if (p !== rawPage) setRawPage(p);
|
|
795
|
+
if (p !== rawPage || size !== pageSize) reportPage(p, size);
|
|
731
796
|
scrollRef.current?.scrollTo?.({ top: 0 });
|
|
732
797
|
};
|
|
733
798
|
|
|
@@ -744,9 +809,11 @@ export function DataTable({
|
|
|
744
809
|
|
|
745
810
|
// A page past the end (rows shrank, a stale URL) shows the last page; report
|
|
746
811
|
// it so a controlled page matches. Skipped while there are no rows yet.
|
|
747
|
-
const syncTo = pageToSync(rawPage,
|
|
812
|
+
const syncTo = pageToSync(rawPage, totalCount, pageSize);
|
|
748
813
|
React.useEffect(() => {
|
|
749
|
-
if (syncTo
|
|
814
|
+
if (syncTo == null) return;
|
|
815
|
+
setRawPage(syncTo);
|
|
816
|
+
reportPage(syncTo, pageSize);
|
|
750
817
|
}, [syncTo]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
751
818
|
|
|
752
819
|
React.useEffect(() => {
|
|
@@ -764,6 +831,64 @@ export function DataTable({
|
|
|
764
831
|
setNote(res === "failed" ? L.exportFailed : null);
|
|
765
832
|
};
|
|
766
833
|
|
|
834
|
+
// A drag on a header's edge, ported from idx-portal's table on TanStack's
|
|
835
|
+
// semantics: "onChange" resizes as the pointer moves, "onEnd" (TanStack's
|
|
836
|
+
// default) moves only the handle and resizes on release. A double click
|
|
837
|
+
// resets the column (TanStack's resetSize). Pointer only, as TanStack.
|
|
838
|
+
const startResize = (e, col) => {
|
|
839
|
+
if (e.button != null && e.button !== 0) return;
|
|
840
|
+
e.preventDefault();
|
|
841
|
+
e.stopPropagation();
|
|
842
|
+
const th = e.currentTarget.closest("th");
|
|
843
|
+
dragRef.current = { col, x: e.clientX, w: th?.getBoundingClientRect().width || 0, to: null };
|
|
844
|
+
try {
|
|
845
|
+
e.currentTarget.setPointerCapture?.(e.pointerId);
|
|
846
|
+
} catch {
|
|
847
|
+
/* a synthetic pointer without capture */
|
|
848
|
+
}
|
|
849
|
+
document.body.classList.add("mk-dt-col-resizing");
|
|
850
|
+
setDrag({ id: col.id, delta: 0 });
|
|
851
|
+
};
|
|
852
|
+
const moveResize = e => {
|
|
853
|
+
const d = dragRef.current;
|
|
854
|
+
if (!d) return;
|
|
855
|
+
const w = resizeWidth(d.col, d.w, e.clientX - d.x);
|
|
856
|
+
d.to = w;
|
|
857
|
+
if (columnResizeMode === "onChange") {
|
|
858
|
+
if (sizingRef.current[d.col.id] !== w) setSizing({ ...sizingRef.current, [d.col.id]: w });
|
|
859
|
+
} else setDrag({ id: d.col.id, delta: w - d.w });
|
|
860
|
+
};
|
|
861
|
+
const endResize = () => {
|
|
862
|
+
const d = dragRef.current;
|
|
863
|
+
if (!d) return;
|
|
864
|
+
dragRef.current = null;
|
|
865
|
+
document.body.classList.remove("mk-dt-col-resizing");
|
|
866
|
+
setDrag(null);
|
|
867
|
+
if (columnResizeMode !== "onChange" && d.to != null && sizingRef.current[d.col.id] !== d.to) {
|
|
868
|
+
setSizing({ ...sizingRef.current, [d.col.id]: d.to });
|
|
869
|
+
}
|
|
870
|
+
};
|
|
871
|
+
const resetSize = col => {
|
|
872
|
+
if (sizingRef.current[col.id] == null) return;
|
|
873
|
+
const { [col.id]: _drop, ...rest } = sizingRef.current;
|
|
874
|
+
setSizing(rest);
|
|
875
|
+
};
|
|
876
|
+
React.useEffect(() => () => document.body?.classList.remove("mk-dt-col-resizing"), []);
|
|
877
|
+
const resizer = col =>
|
|
878
|
+
h("span", {
|
|
879
|
+
className: cx("mk-dt-resizer", drag?.id === col.id && "mk-dt-resizer--active"),
|
|
880
|
+
role: "separator",
|
|
881
|
+
"aria-orientation": "vertical",
|
|
882
|
+
title: L.resizeHint,
|
|
883
|
+
style: drag?.id === col.id && drag.delta ? { transform: `translateX(${drag.delta}px)` } : undefined,
|
|
884
|
+
onPointerDown: e => startResize(e, col),
|
|
885
|
+
onPointerMove: moveResize,
|
|
886
|
+
onPointerUp: endResize,
|
|
887
|
+
onPointerCancel: endResize,
|
|
888
|
+
onDoubleClick: () => resetSize(col),
|
|
889
|
+
onClick: e => e.stopPropagation(),
|
|
890
|
+
});
|
|
891
|
+
|
|
767
892
|
const cellClass = (col, extra) =>
|
|
768
893
|
cx(
|
|
769
894
|
col.num && "mk-dt-num",
|
|
@@ -793,13 +918,14 @@ export function DataTable({
|
|
|
793
918
|
h("span", { className: "mk-dt-th-text" }, col.label),
|
|
794
919
|
h(IconSort, { dir: active ? sort.dir : null }),
|
|
795
920
|
);
|
|
921
|
+
const canResize = enableColumnResizing && col.enableResizing !== false;
|
|
796
922
|
return h(
|
|
797
923
|
"th",
|
|
798
924
|
{
|
|
799
925
|
key: col.id,
|
|
800
926
|
scope: "col",
|
|
801
927
|
rowSpan,
|
|
802
|
-
className: cellClass(col, active && "mk-dt-sorted"),
|
|
928
|
+
className: cellClass(col, cx(active && "mk-dt-sorted", canResize && "mk-dt-resizable")),
|
|
803
929
|
"aria-sort": col.sortable === false ? undefined : active ? (sort.dir === "asc" ? "ascending" : "descending") : "none",
|
|
804
930
|
},
|
|
805
931
|
col.info == null
|
|
@@ -810,6 +936,7 @@ export function DataTable({
|
|
|
810
936
|
label,
|
|
811
937
|
h(HeaderInfo, { title: col.label, label: L.info(text) }, col.info),
|
|
812
938
|
),
|
|
939
|
+
canResize ? resizer(col) : null,
|
|
813
940
|
);
|
|
814
941
|
};
|
|
815
942
|
|
|
@@ -883,12 +1010,46 @@ export function DataTable({
|
|
|
883
1010
|
}
|
|
884
1011
|
: null;
|
|
885
1012
|
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
1013
|
+
// A body cell's class and style: the column's, plus its `cellClassName`
|
|
1014
|
+
// and `cellStyle` (2.30) of the cell's value and row (a heat cell).
|
|
1015
|
+
const bodyCellProps = (col, row) => {
|
|
1016
|
+
const own = typeof col.cellClassName === "function" ? col.cellClassName(col.value(row), row) : col.cellClassName;
|
|
1017
|
+
const props = { key: col.id, className: cellClass(col, own) || undefined };
|
|
1018
|
+
if (col.cellStyle) props.style = typeof col.cellStyle === "function" ? col.cellStyle(col.value(row), row) : col.cellStyle;
|
|
1019
|
+
return props;
|
|
1020
|
+
};
|
|
1021
|
+
|
|
1022
|
+
// `loading` (2.30): placeholder rows while there are none yet, else the
|
|
1023
|
+
// rows on screen dim until the next ones land.
|
|
1024
|
+
const skeleton = () =>
|
|
1025
|
+
Array.from({ length: Math.min(pageSize, SKELETON_ROWS) }, (_, i) =>
|
|
1026
|
+
h(
|
|
1027
|
+
"tr",
|
|
1028
|
+
{ key: `__skeleton_${i}`, className: "mk-dt-skeleton-row", "aria-hidden": "true" },
|
|
1029
|
+
...columns.map((col, c) =>
|
|
1030
|
+
h(
|
|
1031
|
+
"td",
|
|
1032
|
+
{ key: col.id, className: cellClass(col) || undefined },
|
|
1033
|
+
h("span", { className: "mk-dt-skeleton", style: { width: `${45 + ((i * 7 + c * 13) % 40)}%` } }),
|
|
1034
|
+
),
|
|
1035
|
+
),
|
|
1036
|
+
),
|
|
1037
|
+
);
|
|
1038
|
+
|
|
1039
|
+
// A section row (2.30): one cell across every column, before the first row
|
|
1040
|
+
// of its run on each page.
|
|
1041
|
+
const sectionRowEl = (section, i) =>
|
|
1042
|
+
h(
|
|
1043
|
+
"tr",
|
|
1044
|
+
{ key: `__section_${keyOf(section, i)}`, className: "mk-dt-section-row" },
|
|
1045
|
+
h(
|
|
1046
|
+
"td",
|
|
1047
|
+
{ colSpan: columns.length },
|
|
1048
|
+
h("div", { className: "mk-dt-section-label" }, renderSection ? renderSection(section) : columns[0].render ? columns[0].render(section) : columns[0].value(section)),
|
|
1049
|
+
),
|
|
1050
|
+
);
|
|
1051
|
+
|
|
1052
|
+
const rowsEl = visible.map((row, i) => {
|
|
892
1053
|
const key = keyOf(row, start + i);
|
|
893
1054
|
const click = clickProps(onRowClick, row, rowLabel ? rowLabel(row) : undefined);
|
|
894
1055
|
const rowClass = cx(click?.className, rowClassName?.(row)) || undefined;
|
|
@@ -896,7 +1057,7 @@ export function DataTable({
|
|
|
896
1057
|
return h(
|
|
897
1058
|
"tr",
|
|
898
1059
|
{ key, ...click, className: rowClass },
|
|
899
|
-
...columns.map(col => h("td",
|
|
1060
|
+
...columns.map(col => h("td", bodyCellProps(col, row), cell(col, row))),
|
|
900
1061
|
);
|
|
901
1062
|
}
|
|
902
1063
|
const id = String(key);
|
|
@@ -911,7 +1072,7 @@ export function DataTable({
|
|
|
911
1072
|
...columns.map((col, c) =>
|
|
912
1073
|
h(
|
|
913
1074
|
"td",
|
|
914
|
-
|
|
1075
|
+
bodyCellProps(col, row),
|
|
915
1076
|
c === 0 ? firstCell(col, row, can ? expander(row, id, open, detailId) : null) : cell(col, row),
|
|
916
1077
|
),
|
|
917
1078
|
),
|
|
@@ -927,7 +1088,30 @@ export function DataTable({
|
|
|
927
1088
|
h("td", { colSpan: columns.length }, h("div", { className: "mk-dt-detail-body" }, renderExpanded(row))),
|
|
928
1089
|
),
|
|
929
1090
|
);
|
|
930
|
-
})
|
|
1091
|
+
});
|
|
1092
|
+
// Each section row goes before the first row of its run on the page.
|
|
1093
|
+
const withSections = () => {
|
|
1094
|
+
const out = [];
|
|
1095
|
+
let last;
|
|
1096
|
+
visible.forEach((row, i) => {
|
|
1097
|
+
const section = sectionOf.get(row) ?? null;
|
|
1098
|
+
if (section !== last && section != null) out.push(sectionRowEl(section, start + i));
|
|
1099
|
+
last = section;
|
|
1100
|
+
out.push(rowsEl[i]);
|
|
1101
|
+
});
|
|
1102
|
+
return out;
|
|
1103
|
+
};
|
|
1104
|
+
|
|
1105
|
+
const body = h(
|
|
1106
|
+
"tbody",
|
|
1107
|
+
loading ? { className: "mk-dt-busy", "aria-busy": "true" } : null,
|
|
1108
|
+
visible.length === 0
|
|
1109
|
+
? loading
|
|
1110
|
+
? skeleton()
|
|
1111
|
+
: h("tr", { key: "__empty" }, h("td", { colSpan: columns.length, className: "mk-dt-empty" }, empty))
|
|
1112
|
+
: sectionOf
|
|
1113
|
+
? withSections()
|
|
1114
|
+
: rowsEl,
|
|
931
1115
|
);
|
|
932
1116
|
|
|
933
1117
|
// The pinned total row (a <tfoot> that sticks to the bottom), shown with rows only.
|
|
@@ -956,9 +1140,11 @@ export function DataTable({
|
|
|
956
1140
|
h(
|
|
957
1141
|
"span",
|
|
958
1142
|
{ "aria-live": "polite" },
|
|
959
|
-
|
|
960
|
-
? L.range(start + 1, end,
|
|
961
|
-
:
|
|
1143
|
+
totalCount
|
|
1144
|
+
? L.range(start + 1, end, totalCount, noun)
|
|
1145
|
+
: loading
|
|
1146
|
+
? null
|
|
1147
|
+
: L.none(noun),
|
|
962
1148
|
),
|
|
963
1149
|
h(
|
|
964
1150
|
"div",
|
|
@@ -971,8 +1157,9 @@ export function DataTable({
|
|
|
971
1157
|
"aria-label": L.rowsPerPage,
|
|
972
1158
|
value: pageSize,
|
|
973
1159
|
onChange: e => {
|
|
974
|
-
|
|
975
|
-
|
|
1160
|
+
const size = Number(e.target.value);
|
|
1161
|
+
setPageSize(size);
|
|
1162
|
+
goTo(1, size);
|
|
976
1163
|
},
|
|
977
1164
|
},
|
|
978
1165
|
...sizeOptions.map(n => h("option", { key: n, value: n }, L.perPage(n))),
|
|
@@ -987,6 +1174,7 @@ export function DataTable({
|
|
|
987
1174
|
|
|
988
1175
|
const exportButton =
|
|
989
1176
|
exportFilename != null &&
|
|
1177
|
+
!manualPagination &&
|
|
990
1178
|
h(
|
|
991
1179
|
Button,
|
|
992
1180
|
{ key: "__export", disabled: !sorted.length, onClick: exportCsv, title: L.exportTitle },
|
|
@@ -1008,7 +1196,10 @@ export function DataTable({
|
|
|
1008
1196
|
{ className: "mk-dt-scroll", ref: scrollRef, style: !fill && maxHeight != null ? { maxHeight } : undefined },
|
|
1009
1197
|
h(
|
|
1010
1198
|
"table",
|
|
1011
|
-
{
|
|
1199
|
+
{
|
|
1200
|
+
className: cx("mk-dt-table", runs && "mk-dt-table--grouped"),
|
|
1201
|
+
style: layout.fixed ? { minWidth: layout.minWidth, width: layout.minWidth } : { minWidth: layout.minWidth },
|
|
1202
|
+
},
|
|
1012
1203
|
h(
|
|
1013
1204
|
"colgroup",
|
|
1014
1205
|
null,
|
|
@@ -1314,6 +1505,9 @@ export function FilterItems({
|
|
|
1314
1505
|
*
|
|
1315
1506
|
* `searchable` (2.27) adds FilterItems' search input at the top of the menu:
|
|
1316
1507
|
* search, All, a separator, then the values.
|
|
1508
|
+
*
|
|
1509
|
+
* `disabled` (2.30) disables the trigger as shadcn's Button does: half
|
|
1510
|
+
* opacity, no pointer, out of the tab order. An open menu closes.
|
|
1317
1511
|
*/
|
|
1318
1512
|
export function MultiSelect({
|
|
1319
1513
|
options,
|
|
@@ -1334,6 +1528,7 @@ export function MultiSelect({
|
|
|
1334
1528
|
searchEmpty,
|
|
1335
1529
|
locale,
|
|
1336
1530
|
labels,
|
|
1531
|
+
disabled,
|
|
1337
1532
|
className,
|
|
1338
1533
|
triggerClassName,
|
|
1339
1534
|
label,
|
|
@@ -1351,6 +1546,9 @@ export function MultiSelect({
|
|
|
1351
1546
|
React.useEffect(() => {
|
|
1352
1547
|
if (!open) setNone(false);
|
|
1353
1548
|
}, [open]);
|
|
1549
|
+
React.useEffect(() => {
|
|
1550
|
+
if (disabled) setOpen(false);
|
|
1551
|
+
}, [disabled]);
|
|
1354
1552
|
const tree = options.map(toNode);
|
|
1355
1553
|
const selected = filterNormalize(tree, value ?? []);
|
|
1356
1554
|
const many = formatMany ?? L.many;
|
|
@@ -1370,6 +1568,7 @@ export function MultiSelect({
|
|
|
1370
1568
|
"aria-haspopup": "listbox",
|
|
1371
1569
|
"aria-expanded": open,
|
|
1372
1570
|
"aria-label": ariaLabel,
|
|
1571
|
+
disabled,
|
|
1373
1572
|
title: selected.length > 1
|
|
1374
1573
|
? selected.map(v => filterFind(tree, v)?.label ?? v).join(", ")
|
|
1375
1574
|
: text,
|
|
@@ -1421,6 +1620,7 @@ export function MultiSelect({
|
|
|
1421
1620
|
*
|
|
1422
1621
|
* sources: [{ key, label, note?, value?, detail?, tone? }]
|
|
1423
1622
|
* action: a node shown as a callout above the sources (e.g. "Load latest").
|
|
1623
|
+
* locale: (2.30) BCP 47 tag: the panel's and the list's screen-reader names in that language.
|
|
1424
1624
|
*/
|
|
1425
1625
|
export function FreshnessBadge({
|
|
1426
1626
|
tone = "neutral",
|
|
@@ -1432,8 +1632,10 @@ export function FreshnessBadge({
|
|
|
1432
1632
|
action,
|
|
1433
1633
|
footer,
|
|
1434
1634
|
align = "end",
|
|
1635
|
+
locale,
|
|
1435
1636
|
className,
|
|
1436
1637
|
}) {
|
|
1638
|
+
const T = localeStrings("freshness", locale);
|
|
1437
1639
|
const [open, setOpen] = React.useState(false);
|
|
1438
1640
|
const ref = React.useRef(null);
|
|
1439
1641
|
usePopover(open, setOpen, ref, align);
|
|
@@ -1466,7 +1668,7 @@ export function FreshnessBadge({
|
|
|
1466
1668
|
{
|
|
1467
1669
|
className: "mk-pop mk-fresh-pop",
|
|
1468
1670
|
role: "dialog",
|
|
1469
|
-
"aria-label":
|
|
1671
|
+
"aria-label": T.dialog,
|
|
1470
1672
|
onClick: cancelLabelActivation,
|
|
1471
1673
|
},
|
|
1472
1674
|
(title != null || meta != null) &&
|
|
@@ -1481,7 +1683,7 @@ export function FreshnessBadge({
|
|
|
1481
1683
|
sources.length > 0 &&
|
|
1482
1684
|
h(
|
|
1483
1685
|
"ul",
|
|
1484
|
-
{ className: "mk-fresh-sources", "aria-label":
|
|
1686
|
+
{ className: "mk-fresh-sources", "aria-label": T.sources },
|
|
1485
1687
|
...sources.map(s =>
|
|
1486
1688
|
h(
|
|
1487
1689
|
"li",
|
|
@@ -1506,6 +1708,20 @@ export function FreshnessBadge({
|
|
|
1506
1708
|
// ---------------------------------------------------------------------------
|
|
1507
1709
|
// RefreshAllButton
|
|
1508
1710
|
// ---------------------------------------------------------------------------
|
|
1711
|
+
const STAGE_KEY = { waiting: "stageWaiting", building: "stageBuilding", linking: "stageLinking", downloading: "stageDownloading", loading: "stageLoading", querying: "stageQuerying" };
|
|
1712
|
+
const fmtMb = n => (n < 1024 ? `${n} B` : n < 1048576 ? `${Math.round(n / 1024)} KB` : `${(n / 1048576).toFixed(1)} MB`);
|
|
1713
|
+
/** bindingPhaseLabel in a language (2.30): the stage, then rows or bytes when known. */
|
|
1714
|
+
function localPhaseLabel(progress, T, locale) {
|
|
1715
|
+
const p = typeof progress === "string" ? { phase: progress } : progress;
|
|
1716
|
+
const stage = p ? bindingPhaseStage(p.phase) : null;
|
|
1717
|
+
if (!stage) return "";
|
|
1718
|
+
const label = T[STAGE_KEY[stage]];
|
|
1719
|
+
if (stage === "building" && typeof p.rowsWritten === "number") return `${label} · ${T.rowsWritten(p.rowsWritten.toLocaleString(locale))}`;
|
|
1720
|
+
if (stage === "downloading" && typeof p.bytes === "number") {
|
|
1721
|
+
return `${label} · ${fmtMb(p.bytes)}${typeof p.bytesTotal === "number" ? ` ${T.of} ${fmtMb(p.bytesTotal)}` : ""}`;
|
|
1722
|
+
}
|
|
1723
|
+
return label;
|
|
1724
|
+
}
|
|
1509
1725
|
/**
|
|
1510
1726
|
* Re-runs every binding's warehouse query, `concurrency` at a time, and
|
|
1511
1727
|
* updates the app as each one lands (refreshBinding). The header shows one
|
|
@@ -1516,6 +1732,8 @@ export function FreshnessBadge({
|
|
|
1516
1732
|
* `bindings` is the app's binding names — usually a build-time define over
|
|
1517
1733
|
* `bindings/*.sql` (see the README). Keep `concurrency` low: stacked heavy
|
|
1518
1734
|
* warehouse builds fail transiently and can wedge a slot pool.
|
|
1735
|
+
* `locale` (2.30, BCP 47) writes every text and the finish time in that
|
|
1736
|
+
* language (`labels` stays the binding names' map).
|
|
1519
1737
|
*/
|
|
1520
1738
|
export function RefreshAllButton({
|
|
1521
1739
|
bindings,
|
|
@@ -1526,8 +1744,11 @@ export function RefreshAllButton({
|
|
|
1526
1744
|
concurrency = 3,
|
|
1527
1745
|
schedule,
|
|
1528
1746
|
refresh = refreshBinding,
|
|
1747
|
+
locale,
|
|
1529
1748
|
className,
|
|
1530
1749
|
}) {
|
|
1750
|
+
const T = localeStrings("refresh", locale);
|
|
1751
|
+
const phaseLabel = p => (localeLang(locale) === "en" ? bindingPhaseLabel(p) : localPhaseLabel(p, T, locale));
|
|
1531
1752
|
const sources = React.useMemo(
|
|
1532
1753
|
() => refreshOrder(bindings, { first, last, skip }),
|
|
1533
1754
|
// Patterns are usually literals; key them by content, not identity.
|
|
@@ -1605,7 +1826,7 @@ export function RefreshAllButton({
|
|
|
1605
1826
|
await Promise.all(Array.from({ length: Math.min(concurrency, sources.length) }, worker));
|
|
1606
1827
|
setState({
|
|
1607
1828
|
status: "done",
|
|
1608
|
-
at: new Date().toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" }),
|
|
1829
|
+
at: new Date().toLocaleTimeString(locale ?? [], { hour: "2-digit", minute: "2-digit" }),
|
|
1609
1830
|
failures,
|
|
1610
1831
|
seconds: Math.round((Date.now() - startedAt) / 1000),
|
|
1611
1832
|
});
|
|
@@ -1616,12 +1837,12 @@ export function RefreshAllButton({
|
|
|
1616
1837
|
|
|
1617
1838
|
const failedCount = state.status === "done" ? state.failures.length : 0;
|
|
1618
1839
|
const label = running
|
|
1619
|
-
?
|
|
1840
|
+
? T.running(state.done, total)
|
|
1620
1841
|
: state.status === "done"
|
|
1621
1842
|
? failedCount
|
|
1622
|
-
?
|
|
1623
|
-
:
|
|
1624
|
-
:
|
|
1843
|
+
? T.partial(total - failedCount, total)
|
|
1844
|
+
: T.doneAt(state.at)
|
|
1845
|
+
: T.button;
|
|
1625
1846
|
const elapsed = running
|
|
1626
1847
|
? Math.max(0, Math.round((now - state.startedAt) / 1000))
|
|
1627
1848
|
: state.status === "done"
|
|
@@ -1632,20 +1853,20 @@ export function RefreshAllButton({
|
|
|
1632
1853
|
|
|
1633
1854
|
const title =
|
|
1634
1855
|
state.status === "idle"
|
|
1635
|
-
?
|
|
1856
|
+
? T.titleIdle
|
|
1636
1857
|
: running
|
|
1637
|
-
?
|
|
1858
|
+
? T.titleRunning
|
|
1638
1859
|
: failedCount
|
|
1639
|
-
?
|
|
1640
|
-
:
|
|
1860
|
+
? T.titleFailed
|
|
1861
|
+
: T.titleDone;
|
|
1641
1862
|
const desc =
|
|
1642
1863
|
state.status === "idle"
|
|
1643
|
-
?
|
|
1864
|
+
? `${T.descIdle(total, concurrency)}${schedule ? ` ${schedule}` : ""}`
|
|
1644
1865
|
: running
|
|
1645
|
-
?
|
|
1866
|
+
? T.descRunning
|
|
1646
1867
|
: failedCount
|
|
1647
|
-
?
|
|
1648
|
-
:
|
|
1868
|
+
? T.descFailed
|
|
1869
|
+
: T.descDone(total, fmtSecs(elapsed));
|
|
1649
1870
|
|
|
1650
1871
|
const itemIcon = st =>
|
|
1651
1872
|
st === "done"
|
|
@@ -1659,14 +1880,14 @@ export function RefreshAllButton({
|
|
|
1659
1880
|
st === "queued"
|
|
1660
1881
|
? state.status === "idle"
|
|
1661
1882
|
? ""
|
|
1662
|
-
:
|
|
1883
|
+
: T.queued
|
|
1663
1884
|
: st === "running"
|
|
1664
|
-
?
|
|
1885
|
+
? phaseLabel(progress[name]) || T.running1
|
|
1665
1886
|
: st === "done"
|
|
1666
1887
|
? took[name] != null
|
|
1667
1888
|
? fmtSecs(took[name])
|
|
1668
|
-
:
|
|
1669
|
-
:
|
|
1889
|
+
: T.done1
|
|
1890
|
+
: T.failed1;
|
|
1670
1891
|
|
|
1671
1892
|
const modal =
|
|
1672
1893
|
open &&
|
|
@@ -1691,7 +1912,7 @@ export function RefreshAllButton({
|
|
|
1691
1912
|
),
|
|
1692
1913
|
h(
|
|
1693
1914
|
"button",
|
|
1694
|
-
{ ref: closeRef, type: "button", className: "mk-rf-x", "aria-label":
|
|
1915
|
+
{ ref: closeRef, type: "button", className: "mk-rf-x", "aria-label": T.close, onClick: () => setOpen(false) },
|
|
1695
1916
|
h(IconX),
|
|
1696
1917
|
),
|
|
1697
1918
|
),
|
|
@@ -1716,7 +1937,7 @@ export function RefreshAllButton({
|
|
|
1716
1937
|
h(
|
|
1717
1938
|
"div",
|
|
1718
1939
|
{ className: "mk-rf-meta" },
|
|
1719
|
-
h("span", null,
|
|
1940
|
+
h("span", null, T.progress(doneCount, total)),
|
|
1720
1941
|
h("span", null, fmtSecs(elapsed)),
|
|
1721
1942
|
),
|
|
1722
1943
|
),
|
|
@@ -1744,13 +1965,13 @@ export function RefreshAllButton({
|
|
|
1744
1965
|
"div",
|
|
1745
1966
|
{ className: "mk-rf-foot" },
|
|
1746
1967
|
state.status === "idle" && [
|
|
1747
|
-
h(Button, { key: "c", onClick: () => setOpen(false) },
|
|
1748
|
-
h(Button, { key: "s", variant: "primary", onClick: refreshAll },
|
|
1968
|
+
h(Button, { key: "c", onClick: () => setOpen(false) }, T.cancel),
|
|
1969
|
+
h(Button, { key: "s", variant: "primary", onClick: refreshAll }, T.start),
|
|
1749
1970
|
],
|
|
1750
|
-
running && h(Button, { onClick: () => setOpen(false) },
|
|
1971
|
+
running && h(Button, { onClick: () => setOpen(false) }, T.hide),
|
|
1751
1972
|
state.status === "done" && [
|
|
1752
|
-
h(Button, { key: "a", onClick: refreshAll },
|
|
1753
|
-
h(Button, { key: "d", variant: "primary", onClick: () => setOpen(false) },
|
|
1973
|
+
h(Button, { key: "a", onClick: refreshAll }, T.again),
|
|
1974
|
+
h(Button, { key: "d", variant: "primary", onClick: () => setOpen(false) }, T.finish),
|
|
1754
1975
|
],
|
|
1755
1976
|
),
|
|
1756
1977
|
),
|
|
@@ -1771,9 +1992,7 @@ export function RefreshAllButton({
|
|
|
1771
1992
|
state.status === "done" && (failedCount ? "failed" : "ok"),
|
|
1772
1993
|
className,
|
|
1773
1994
|
),
|
|
1774
|
-
title: running
|
|
1775
|
-
? "Refresh in progress — click to see details."
|
|
1776
|
-
: `Re-runs every binding's warehouse query.${schedule ? ` ${schedule}` : ""}`,
|
|
1995
|
+
title: running ? T.hintRunning : `${T.hint}${schedule ? ` ${schedule}` : ""}`,
|
|
1777
1996
|
disabled: !total,
|
|
1778
1997
|
onClick: () => setOpen(true),
|
|
1779
1998
|
"aria-haspopup": "dialog",
|