@dloizides/ui-tables 1.15.0 → 1.18.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 +63 -0
- package/README.md +14 -4
- package/dist/index.d.mts +39 -4
- package/dist/index.d.ts +39 -4
- package/dist/index.js +112 -75
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +67 -35
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -3
package/dist/index.js
CHANGED
|
@@ -1,17 +1,25 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var React2 = require('react');
|
|
4
4
|
var reactNative = require('react-native');
|
|
5
5
|
var uiFeedback = require('@dloizides/ui-feedback');
|
|
6
6
|
var jsxRuntime = require('react/jsx-runtime');
|
|
7
|
+
var uiMotion = require('@dloizides/ui-motion');
|
|
7
8
|
var reactDom = require('react-dom');
|
|
8
9
|
var uiForms = require('@dloizides/ui-forms');
|
|
9
10
|
|
|
11
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
+
|
|
13
|
+
var React2__default = /*#__PURE__*/_interopDefault(React2);
|
|
14
|
+
|
|
10
15
|
// src/StatCard/StatCard.tsx
|
|
11
16
|
|
|
12
17
|
// src/DataTable/constants.ts
|
|
13
|
-
var CARD_STACK_BREAKPOINT =
|
|
18
|
+
var CARD_STACK_BREAKPOINT = 768;
|
|
14
19
|
var DEFAULT_PAGE_SIZE_OPTIONS = [25, 50, 100, 200];
|
|
20
|
+
var ROW_ENTRANCE_STAGGER_CAP = 10;
|
|
21
|
+
var ROW_ENTRANCE_STAGGER_STEP_MS = 30;
|
|
22
|
+
var rowEntranceDelayMs = (index) => Math.min(index, ROW_ENTRANCE_STAGGER_CAP) * ROW_ENTRANCE_STAGGER_STEP_MS;
|
|
15
23
|
var TABLE_TEST_IDS = {
|
|
16
24
|
root: "ui-data-table",
|
|
17
25
|
head: "ui-data-table-head",
|
|
@@ -21,6 +29,8 @@ var TABLE_TEST_IDS = {
|
|
|
21
29
|
rowDetailInfix: "row-detail",
|
|
22
30
|
/** Infix of a row's select checkbox: `${tableTestID}-select-${key}`. */
|
|
23
31
|
rowSelectInfix: "select",
|
|
32
|
+
/** Infix of a row's entrance-fade wrapper: `${tableTestID}-fade-${key}`. */
|
|
33
|
+
rowFadeInfix: "fade",
|
|
24
34
|
/** Suffix of the header (select-all-on-page) checkbox: `${tableTestID}-select-all`. */
|
|
25
35
|
selectAllSuffix: "select-all",
|
|
26
36
|
/** Suffix of the select-all-matching banner: `${tableTestID}-select-banner`. */
|
|
@@ -40,6 +50,7 @@ var rowTestID = (tableTestID, key) => `${tableTestID}-${TABLE_TEST_IDS.rowInfix}
|
|
|
40
50
|
var rowDetailTestID = (tableTestID, key) => `${tableTestID}-${TABLE_TEST_IDS.rowDetailInfix}-${key}`;
|
|
41
51
|
var rowSelectTestID = (tableTestID, key) => `${tableTestID}-${TABLE_TEST_IDS.rowSelectInfix}-${key}`;
|
|
42
52
|
var selectAllTestID = (tableTestID) => `${tableTestID}-${TABLE_TEST_IDS.selectAllSuffix}`;
|
|
53
|
+
var rowFadeTestID = (tableTestID, key) => `${tableTestID}-${TABLE_TEST_IDS.rowFadeInfix}-${key}`;
|
|
43
54
|
var TABLE_I18N = {
|
|
44
55
|
loading: "uiTables.loading",
|
|
45
56
|
empty: "uiTables.empty",
|
|
@@ -120,7 +131,7 @@ var styles = reactNative.StyleSheet.create({
|
|
|
120
131
|
lineHeight: VALUE_LINE_HEIGHT
|
|
121
132
|
}
|
|
122
133
|
});
|
|
123
|
-
var StatCard =
|
|
134
|
+
var StatCard = React2.memo(({ label, value, testID }) => {
|
|
124
135
|
const { theme, t } = uiFeedback.useUi();
|
|
125
136
|
const { colors } = theme;
|
|
126
137
|
const formattedValue = value.toLocaleString();
|
|
@@ -150,8 +161,8 @@ var STATE_PAD_V = 34;
|
|
|
150
161
|
var HEAD_FONT = 12;
|
|
151
162
|
var CELL_FONT = 14;
|
|
152
163
|
var STATE_FONT = 14;
|
|
153
|
-
var CARD_LINE_PAD_V =
|
|
154
|
-
var
|
|
164
|
+
var CARD_LINE_PAD_V = 5;
|
|
165
|
+
var CARD_LABEL_GAP = 3;
|
|
155
166
|
var PILL_RADIUS = 999;
|
|
156
167
|
var PAGER_GAP = 8;
|
|
157
168
|
var PAGER_SIZE_GAP = 6;
|
|
@@ -205,9 +216,22 @@ var tableStyles = reactNative.StyleSheet.create({
|
|
|
205
216
|
/** Full-width panel under an expanded row — spans every column (the wrap is a column flexbox). */
|
|
206
217
|
rowDetail: { width: FULL_WIDTH, paddingHorizontal: ROW_PAD_H, paddingVertical: ROW_PAD_V, borderTopWidth: BORDER_WIDTH },
|
|
207
218
|
card: { paddingHorizontal: ROW_PAD_H, paddingVertical: ROW_PAD_V, borderTopWidth: BORDER_WIDTH },
|
|
208
|
-
|
|
219
|
+
/**
|
|
220
|
+
* A card line is a VERTICAL label:value pair — the header sits ABOVE its value, both
|
|
221
|
+
* left-aligned, so a narrow phone column never cramps the value against the label the
|
|
222
|
+
* way the old `space-between` row did (an Actions cell of buttons or a long text value
|
|
223
|
+
* now gets the full card width). `paddingVertical` gives the stacked lines their rhythm.
|
|
224
|
+
*/
|
|
225
|
+
cardLine: { flexDirection: "column", alignItems: "stretch", paddingVertical: CARD_LINE_PAD_V, gap: CARD_LABEL_GAP },
|
|
209
226
|
cardLabel: { fontSize: HEAD_FONT, fontWeight: "600", textTransform: "uppercase", letterSpacing: LABEL_LETTER_SPACING },
|
|
210
|
-
cardValue: {
|
|
227
|
+
cardValue: { alignItems: "flex-start" },
|
|
228
|
+
/**
|
|
229
|
+
* A zero-footprint carrier for the `ui-data-table-head` test id in the card-stack layout
|
|
230
|
+
* (which has no visible header row). `display: 'none'` keeps it out of layout AND the
|
|
231
|
+
* accessibility tree, while the `data-testid` stays queryable — so an E2E selector that
|
|
232
|
+
* targets the head survives at every viewport width.
|
|
233
|
+
*/
|
|
234
|
+
headSentinel: { display: "none" }
|
|
211
235
|
});
|
|
212
236
|
var selectionStyles = reactNative.StyleSheet.create({
|
|
213
237
|
/** The fixed-width gutter holding the checkbox, in both the header and every row. */
|
|
@@ -314,10 +338,15 @@ function RowCells({
|
|
|
314
338
|
styleOverrides: o
|
|
315
339
|
}) {
|
|
316
340
|
if (stacked) {
|
|
317
|
-
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: columns.map((col) =>
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
341
|
+
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: columns.map((col) => (
|
|
342
|
+
// The SAME per-cell test id the desktop cell carries (`${rowTestID}-${col.key}`),
|
|
343
|
+
// so an E2E selector like `${rowTestID}-${col.key}` resolves in BOTH layouts — the
|
|
344
|
+
// card-stack must not silently drop the hooks a wide-viewport test relies on.
|
|
345
|
+
/* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: [tableStyles.cardLine, o?.cardLine], testID: `${rowTestID2}-${col.key}`, children: [
|
|
346
|
+
/* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [tableStyles.cardLabel, { color: labelColor }, o?.cardLabel], children: col.header }),
|
|
347
|
+
/* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: [tableStyles.cardValue, o?.cardValue], children: cellContent(col, row, textColor, o) })
|
|
348
|
+
] }, col.key)
|
|
349
|
+
)) });
|
|
321
350
|
}
|
|
322
351
|
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: columns.map((col) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
323
352
|
DesktopCell,
|
|
@@ -652,21 +681,21 @@ var TAB_INDEX_ACTIVE = 0;
|
|
|
652
681
|
var TAB_INDEX_INACTIVE2 = -1;
|
|
653
682
|
var IS_WEB = reactNative.Platform.OS === "web";
|
|
654
683
|
function useRovingFocus({ rowKeys, enabled, onToggleKey, onActivateKey }) {
|
|
655
|
-
const [focusedKey, setFocusedKey] =
|
|
656
|
-
const nodes =
|
|
684
|
+
const [focusedKey, setFocusedKey] = React2.useState(void 0);
|
|
685
|
+
const nodes = React2.useRef(/* @__PURE__ */ new Map());
|
|
657
686
|
const tabbableKey = enabled ? resolveTabbableKey(rowKeys, focusedKey) : void 0;
|
|
658
|
-
const registerRow =
|
|
687
|
+
const registerRow = React2.useCallback((key, node) => {
|
|
659
688
|
if (node === null || node === void 0) {
|
|
660
689
|
nodes.current.delete(key);
|
|
661
690
|
return;
|
|
662
691
|
}
|
|
663
692
|
nodes.current.set(key, node);
|
|
664
693
|
}, []);
|
|
665
|
-
const focusRow =
|
|
694
|
+
const focusRow = React2.useCallback((key) => {
|
|
666
695
|
setFocusedKey(key);
|
|
667
696
|
nodes.current.get(key)?.focus?.();
|
|
668
697
|
}, []);
|
|
669
|
-
const handleKey =
|
|
698
|
+
const handleKey = React2.useCallback(
|
|
670
699
|
(event, key) => {
|
|
671
700
|
const action = toRowNavAction(event.key);
|
|
672
701
|
if (action === void 0) return;
|
|
@@ -691,18 +720,18 @@ function useRovingFocus({ rowKeys, enabled, onToggleKey, onActivateKey }) {
|
|
|
691
720
|
},
|
|
692
721
|
[rowKeys, onToggleKey, onActivateKey, focusRow]
|
|
693
722
|
);
|
|
694
|
-
const keyDownFor =
|
|
723
|
+
const keyDownFor = React2.useCallback(
|
|
695
724
|
(key) => {
|
|
696
725
|
if (!enabled || !IS_WEB) return void 0;
|
|
697
726
|
return (event) => handleKey(event, key);
|
|
698
727
|
},
|
|
699
728
|
[enabled, handleKey]
|
|
700
729
|
);
|
|
701
|
-
const tabIndexFor =
|
|
730
|
+
const tabIndexFor = React2.useCallback(
|
|
702
731
|
(key) => key === tabbableKey ? TAB_INDEX_ACTIVE : TAB_INDEX_INACTIVE2,
|
|
703
732
|
[tabbableKey]
|
|
704
733
|
);
|
|
705
|
-
const onRowFocus =
|
|
734
|
+
const onRowFocus = React2.useCallback((key) => setFocusedKey(key), []);
|
|
706
735
|
return { tabIndexFor, registerRow, onRowFocus, keyDownFor };
|
|
707
736
|
}
|
|
708
737
|
|
|
@@ -754,20 +783,20 @@ function useTableSelection({
|
|
|
754
783
|
const selected = selectedRowKeys ?? NO_KEYS;
|
|
755
784
|
const allMatching = allMatchingSelected ?? false;
|
|
756
785
|
const matching = matchingCount ?? NO_MATCHES;
|
|
757
|
-
const pageHeaderState =
|
|
786
|
+
const pageHeaderState = React2.useMemo(
|
|
758
787
|
() => resolveHeaderCheckboxState(selected, pageKeys),
|
|
759
788
|
[selected, pageKeys]
|
|
760
789
|
);
|
|
761
790
|
const headerState = allMatching ? "all" /* All */ : pageHeaderState;
|
|
762
|
-
const bannerMode =
|
|
791
|
+
const bannerMode = React2.useMemo(
|
|
763
792
|
() => onSelectAllMatchingChange === void 0 ? "hidden" /* Hidden */ : resolveSelectAllBannerMode(pageHeaderState, allMatching, pageKeys.length, matching),
|
|
764
793
|
[onSelectAllMatchingChange, pageHeaderState, allMatching, pageKeys.length, matching]
|
|
765
794
|
);
|
|
766
|
-
const isSelected =
|
|
795
|
+
const isSelected = React2.useCallback(
|
|
767
796
|
(key) => isRowSelected(selected, key, allMatching),
|
|
768
797
|
[selected, allMatching]
|
|
769
798
|
);
|
|
770
|
-
const toggleRow =
|
|
799
|
+
const toggleRow = React2.useCallback(
|
|
771
800
|
(key) => {
|
|
772
801
|
if (allMatching) {
|
|
773
802
|
onSelectAllMatchingChange?.(false);
|
|
@@ -778,7 +807,7 @@ function useTableSelection({
|
|
|
778
807
|
},
|
|
779
808
|
[allMatching, onSelectAllMatchingChange, onSelectionChange, pageKeys, selected]
|
|
780
809
|
);
|
|
781
|
-
const toggleAll =
|
|
810
|
+
const toggleAll = React2.useCallback(() => {
|
|
782
811
|
if (allMatching) {
|
|
783
812
|
onSelectAllMatchingChange?.(false);
|
|
784
813
|
onSelectionChange?.(NO_KEYS);
|
|
@@ -786,7 +815,7 @@ function useTableSelection({
|
|
|
786
815
|
}
|
|
787
816
|
onSelectionChange?.(toggleAllOnPage(selected, pageKeys));
|
|
788
817
|
}, [allMatching, onSelectAllMatchingChange, onSelectionChange, selected, pageKeys]);
|
|
789
|
-
const toggleAllMatching =
|
|
818
|
+
const toggleAllMatching = React2.useCallback(() => {
|
|
790
819
|
const next = !allMatching;
|
|
791
820
|
onSelectAllMatchingChange?.(next);
|
|
792
821
|
if (!next) onSelectionChange?.(NO_KEYS);
|
|
@@ -818,18 +847,21 @@ function DataTable(props) {
|
|
|
818
847
|
allMatchingSelected,
|
|
819
848
|
onSelectAllMatchingChange,
|
|
820
849
|
keyboardNavigation = false,
|
|
850
|
+
animateRows = true,
|
|
821
851
|
stackBreakpoint = CARD_STACK_BREAKPOINT,
|
|
822
852
|
testID = TABLE_TEST_IDS.root
|
|
823
853
|
} = props;
|
|
824
854
|
const { theme, t } = uiFeedback.useUi();
|
|
855
|
+
const reducedMotion = uiMotion.useReducedMotion();
|
|
856
|
+
const animateRowEntrance = animateRows && !reducedMotion;
|
|
825
857
|
const { colors } = theme;
|
|
826
858
|
const { width } = reactNative.useWindowDimensions();
|
|
827
859
|
const stacked = width < stackBreakpoint;
|
|
828
860
|
const frame = { backgroundColor: colors.surface, borderColor: colors.border };
|
|
829
861
|
const interactive = onRowPress !== void 0;
|
|
830
|
-
const [hoveredKey, setHoveredKey] =
|
|
862
|
+
const [hoveredKey, setHoveredKey] = React2.useState(void 0);
|
|
831
863
|
const hoverTint = softBrandTint(theme.palette.primary["500"]) ?? colors.background;
|
|
832
|
-
const rowKeys =
|
|
864
|
+
const rowKeys = React2.useMemo(() => rows.map(keyExtractor), [rows, keyExtractor]);
|
|
833
865
|
const selection = useTableSelection({
|
|
834
866
|
pageKeys: rowKeys,
|
|
835
867
|
selectedRowKeys,
|
|
@@ -838,7 +870,7 @@ function DataTable(props) {
|
|
|
838
870
|
allMatchingSelected,
|
|
839
871
|
onSelectAllMatchingChange
|
|
840
872
|
});
|
|
841
|
-
const activateKey =
|
|
873
|
+
const activateKey = React2.useCallback(
|
|
842
874
|
(key) => {
|
|
843
875
|
const row = rows[rowKeys.indexOf(key)];
|
|
844
876
|
if (row !== void 0) onRowPress?.(row);
|
|
@@ -851,7 +883,7 @@ function DataTable(props) {
|
|
|
851
883
|
onToggleKey: selection.selectable ? selection.toggleRow : void 0,
|
|
852
884
|
onActivateKey: interactive ? activateKey : void 0
|
|
853
885
|
});
|
|
854
|
-
const rowBackground =
|
|
886
|
+
const rowBackground = React2.useCallback(
|
|
855
887
|
(row, index) => {
|
|
856
888
|
const tint = rowTint?.(row);
|
|
857
889
|
if (tint) return tint;
|
|
@@ -864,28 +896,31 @@ function DataTable(props) {
|
|
|
864
896
|
if (rows.length === 0) {
|
|
865
897
|
return stateView(loading ? loadingLabel ?? t(TABLE_I18N.loading) : emptyLabel ?? t(TABLE_I18N.empty));
|
|
866
898
|
}
|
|
867
|
-
const renderRow = (row, key, style) =>
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
899
|
+
const renderRow = (row, key, index, style) => {
|
|
900
|
+
const node = /* @__PURE__ */ jsxRuntime.jsx(
|
|
901
|
+
DataTableRow,
|
|
902
|
+
{
|
|
903
|
+
columns,
|
|
904
|
+
expanded: expandedRowKeys?.includes(key) ?? false,
|
|
905
|
+
getRowAccessibilityLabel,
|
|
906
|
+
keyboardNavigation,
|
|
907
|
+
renderRowDetail,
|
|
908
|
+
roving,
|
|
909
|
+
row,
|
|
910
|
+
rowKey: key,
|
|
911
|
+
selection,
|
|
912
|
+
stacked,
|
|
913
|
+
style,
|
|
914
|
+
styleOverrides: o,
|
|
915
|
+
tableTestID: testID,
|
|
916
|
+
onHoverIn: () => setHoveredKey(key),
|
|
917
|
+
onHoverOut: () => setHoveredKey((current) => current === key ? void 0 : current),
|
|
918
|
+
onRowPress
|
|
919
|
+
}
|
|
920
|
+
);
|
|
921
|
+
if (!animateRowEntrance) return /* @__PURE__ */ jsxRuntime.jsx(React2__default.default.Fragment, { children: node }, key);
|
|
922
|
+
return /* @__PURE__ */ jsxRuntime.jsx(uiMotion.FadeIn, { delay: rowEntranceDelayMs(index), testID: rowFadeTestID(testID, key), children: node }, key);
|
|
923
|
+
};
|
|
889
924
|
const banner = /* @__PURE__ */ jsxRuntime.jsx(
|
|
890
925
|
SelectAllBanner,
|
|
891
926
|
{
|
|
@@ -901,10 +936,11 @@ function DataTable(props) {
|
|
|
901
936
|
if (stacked) {
|
|
902
937
|
return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: [tableStyles.wrap, frame, o?.wrap], testID, "aria-busy": loading, children: [
|
|
903
938
|
banner,
|
|
939
|
+
/* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: tableStyles.headSentinel, testID: TABLE_TEST_IDS.head, "aria-hidden": true }),
|
|
904
940
|
rows.map((row, i) => {
|
|
905
941
|
const key = rowKeys[i] ?? keyExtractor(row);
|
|
906
942
|
const bg = rowBg(row, i, key);
|
|
907
|
-
return renderRow(row, key, [
|
|
943
|
+
return renderRow(row, key, i, [
|
|
908
944
|
tableStyles.card,
|
|
909
945
|
{ borderTopColor: colors.border },
|
|
910
946
|
i === FIRST_ROW_INDEX ? { borderTopWidth: 0 } : null,
|
|
@@ -938,7 +974,7 @@ function DataTable(props) {
|
|
|
938
974
|
rows.map((row, i) => {
|
|
939
975
|
const key = rowKeys[i] ?? keyExtractor(row);
|
|
940
976
|
const bg = rowBg(row, i, key);
|
|
941
|
-
return renderRow(row, key, [tableStyles.row, { borderTopColor: colors.border }, bg ? { backgroundColor: bg } : null, o?.row]);
|
|
977
|
+
return renderRow(row, key, i, [tableStyles.row, { borderTopColor: colors.border }, bg ? { backgroundColor: bg } : null, o?.row]);
|
|
942
978
|
})
|
|
943
979
|
]
|
|
944
980
|
}
|
|
@@ -1004,8 +1040,8 @@ function buildWebFixedStyle(rect, viewportWidth) {
|
|
|
1004
1040
|
};
|
|
1005
1041
|
}
|
|
1006
1042
|
function useTriggerRect(anchorRef, isOpen) {
|
|
1007
|
-
const [rect, setRect] =
|
|
1008
|
-
|
|
1043
|
+
const [rect, setRect] = React2.useState(null);
|
|
1044
|
+
React2.useLayoutEffect(() => {
|
|
1009
1045
|
if (!IS_WEB2 || !isOpen) return void 0;
|
|
1010
1046
|
const measure = () => {
|
|
1011
1047
|
setRect(readTriggerRect(anchorRef));
|
|
@@ -1021,7 +1057,7 @@ function useTriggerRect(anchorRef, isOpen) {
|
|
|
1021
1057
|
return rect;
|
|
1022
1058
|
}
|
|
1023
1059
|
function useDismissOnOutside(anchorRef, menuRef, isOpen, onClose) {
|
|
1024
|
-
|
|
1060
|
+
React2.useEffect(() => {
|
|
1025
1061
|
if (!IS_WEB2 || !isOpen) return void 0;
|
|
1026
1062
|
const onMouseDown = (event) => {
|
|
1027
1063
|
const anchorNode = anchorRef.current;
|
|
@@ -1059,16 +1095,16 @@ function SizeDropdown({
|
|
|
1059
1095
|
triggerStyle,
|
|
1060
1096
|
triggerTextStyle
|
|
1061
1097
|
}) {
|
|
1062
|
-
const anchorRef =
|
|
1063
|
-
const menuRef =
|
|
1064
|
-
const [isOpen, setIsOpen] =
|
|
1065
|
-
const close =
|
|
1098
|
+
const anchorRef = React2.useRef(null);
|
|
1099
|
+
const menuRef = React2.useRef(null);
|
|
1100
|
+
const [isOpen, setIsOpen] = React2.useState(false);
|
|
1101
|
+
const close = React2.useCallback(() => {
|
|
1066
1102
|
setIsOpen(false);
|
|
1067
1103
|
}, []);
|
|
1068
|
-
const toggle =
|
|
1104
|
+
const toggle = React2.useCallback(() => {
|
|
1069
1105
|
setIsOpen((prev) => !prev);
|
|
1070
1106
|
}, []);
|
|
1071
|
-
const select =
|
|
1107
|
+
const select = React2.useCallback(
|
|
1072
1108
|
(size) => {
|
|
1073
1109
|
onPageSizeChange(size);
|
|
1074
1110
|
setIsOpen(false);
|
|
@@ -1647,16 +1683,16 @@ function Filters({
|
|
|
1647
1683
|
testID = FILTERS_TEST_ID
|
|
1648
1684
|
}) {
|
|
1649
1685
|
const { t } = uiFeedback.useUi();
|
|
1650
|
-
const setField =
|
|
1686
|
+
const setField = React2.useCallback(
|
|
1651
1687
|
(key, value) => {
|
|
1652
1688
|
onChange({ ...values, [key]: value });
|
|
1653
1689
|
},
|
|
1654
1690
|
[onChange, values]
|
|
1655
1691
|
);
|
|
1656
|
-
const onSubmit =
|
|
1692
|
+
const onSubmit = React2.useCallback(() => {
|
|
1657
1693
|
if (onApply !== void 0 && !applyDisabled) onApply();
|
|
1658
1694
|
}, [onApply, applyDisabled]);
|
|
1659
|
-
const strings =
|
|
1695
|
+
const strings = React2.useMemo(
|
|
1660
1696
|
() => ({
|
|
1661
1697
|
selectPlaceholder: selectPlaceholder ?? t(FILTERS_I18N.selectPlaceholder),
|
|
1662
1698
|
dropdownHint: t(FILTERS_I18N.dropdownHint),
|
|
@@ -1719,37 +1755,37 @@ function shallowEqual(a, b) {
|
|
|
1719
1755
|
return JSON.stringify(a) === JSON.stringify(b);
|
|
1720
1756
|
}
|
|
1721
1757
|
function useFilterDraft({ initial, onApply, onReset }) {
|
|
1722
|
-
const [draft, setDraft] =
|
|
1723
|
-
const [committed, setCommitted] =
|
|
1724
|
-
const setField =
|
|
1758
|
+
const [draft, setDraft] = React2.useState(initial);
|
|
1759
|
+
const [committed, setCommitted] = React2.useState(initial);
|
|
1760
|
+
const setField = React2.useCallback((key, value) => {
|
|
1725
1761
|
setDraft((prev) => ({ ...prev, [key]: value }));
|
|
1726
1762
|
}, []);
|
|
1727
|
-
const apply =
|
|
1763
|
+
const apply = React2.useCallback(() => {
|
|
1728
1764
|
setCommitted(draft);
|
|
1729
1765
|
onApply?.(draft);
|
|
1730
1766
|
}, [draft, onApply]);
|
|
1731
|
-
const reset =
|
|
1767
|
+
const reset = React2.useCallback(() => {
|
|
1732
1768
|
setDraft(initial);
|
|
1733
1769
|
setCommitted(initial);
|
|
1734
1770
|
onReset?.();
|
|
1735
1771
|
}, [initial, onReset]);
|
|
1736
|
-
const dirty =
|
|
1772
|
+
const dirty = React2.useMemo(() => !shallowEqual(draft, committed), [draft, committed]);
|
|
1737
1773
|
return { draft, committed, setField, setDraft, apply, reset, dirty };
|
|
1738
1774
|
}
|
|
1739
1775
|
var DEFAULT_PAGE_SIZE = 10;
|
|
1740
1776
|
function usePagedRows(rows, options = {}) {
|
|
1741
1777
|
const pageSize = Math.max(1, options.pageSize ?? DEFAULT_PAGE_SIZE);
|
|
1742
|
-
const [currentPage, setCurrentPage] =
|
|
1778
|
+
const [currentPage, setCurrentPage] = React2.useState(0);
|
|
1743
1779
|
const totalPages = Math.ceil(rows.length / pageSize);
|
|
1744
|
-
|
|
1780
|
+
React2.useEffect(() => {
|
|
1745
1781
|
const lastValidPage = totalPages > 0 ? totalPages - 1 : 0;
|
|
1746
1782
|
if (currentPage > lastValidPage) setCurrentPage(lastValidPage);
|
|
1747
1783
|
}, [currentPage, totalPages]);
|
|
1748
|
-
const pageRows =
|
|
1784
|
+
const pageRows = React2.useMemo(() => {
|
|
1749
1785
|
const start = currentPage * pageSize;
|
|
1750
1786
|
return rows.slice(start, start + pageSize);
|
|
1751
1787
|
}, [rows, currentPage, pageSize]);
|
|
1752
|
-
const setPage =
|
|
1788
|
+
const setPage = React2.useCallback(
|
|
1753
1789
|
(page) => {
|
|
1754
1790
|
const lastValidPage = totalPages > 0 ? totalPages - 1 : 0;
|
|
1755
1791
|
const clamped = Math.min(Math.max(0, page), lastValidPage);
|
|
@@ -1800,6 +1836,7 @@ exports.applyTestID = applyTestID;
|
|
|
1800
1836
|
exports.clearTestID = clearTestID;
|
|
1801
1837
|
exports.fieldTestID = fieldTestID;
|
|
1802
1838
|
exports.rowDetailTestID = rowDetailTestID;
|
|
1839
|
+
exports.rowFadeTestID = rowFadeTestID;
|
|
1803
1840
|
exports.rowSelectTestID = rowSelectTestID;
|
|
1804
1841
|
exports.rowTestID = rowTestID;
|
|
1805
1842
|
exports.selectAllTestID = selectAllTestID;
|