react-restyle-components 0.4.50 → 0.4.52
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/lib/src/core-components/src/components/Modal/BasicModal/modal.component.d.ts +4 -102
- package/lib/src/core-components/src/components/Modal/BasicModal/modal.component.js +4 -2
- package/lib/src/core-components/src/components/Modal/BasicModal/types.d.ts +103 -0
- package/lib/src/core-components/src/components/Modal/BasicModal/types.js +1 -0
- package/lib/src/core-components/src/components/Table/Table.js +93 -18
- package/lib/src/core-components/src/components/Table/filters.d.ts +203 -10
- package/lib/src/core-components/src/components/Table/filters.js +319 -203
- package/lib/src/core-components/src/components/Table/index.d.ts +2 -2
- package/lib/src/core-components/src/components/Table/index.js +1 -1
- package/lib/src/core-components/src/components/Table/types.d.ts +10 -3
- package/lib/src/core-components/src/tc.global.css +19 -1
- package/lib/src/core-components/src/tc.module.css +3 -1
- package/package.json +1 -1
|
@@ -1,102 +1,4 @@
|
|
|
1
|
-
import React
|
|
2
|
-
export type ModalSize
|
|
3
|
-
|
|
4
|
-
export
|
|
5
|
-
/** Custom className for the overlay */
|
|
6
|
-
overlay?: string;
|
|
7
|
-
/** Custom className for the modal container */
|
|
8
|
-
container?: string;
|
|
9
|
-
/** Custom className for the modal wrapper */
|
|
10
|
-
wrapper?: string;
|
|
11
|
-
/** Custom className for the modal content */
|
|
12
|
-
content?: string;
|
|
13
|
-
/** Custom className for the header */
|
|
14
|
-
header?: string;
|
|
15
|
-
/** Custom className for the title */
|
|
16
|
-
title?: string;
|
|
17
|
-
/** Custom className for the close button */
|
|
18
|
-
closeButton?: string;
|
|
19
|
-
/** Custom className for the body/children container */
|
|
20
|
-
body?: string;
|
|
21
|
-
}
|
|
22
|
-
export interface ModalStyles {
|
|
23
|
-
/** Custom style for the overlay */
|
|
24
|
-
overlay?: CSSProperties;
|
|
25
|
-
/** Custom style for the modal container */
|
|
26
|
-
container?: CSSProperties;
|
|
27
|
-
/** Custom style for the modal wrapper */
|
|
28
|
-
wrapper?: CSSProperties;
|
|
29
|
-
/** Custom style for the modal content */
|
|
30
|
-
content?: CSSProperties;
|
|
31
|
-
/** Custom style for the header */
|
|
32
|
-
header?: CSSProperties;
|
|
33
|
-
/** Custom style for the title */
|
|
34
|
-
title?: CSSProperties;
|
|
35
|
-
/** Custom style for the close button */
|
|
36
|
-
closeButton?: CSSProperties;
|
|
37
|
-
/** Custom style for the body/children container */
|
|
38
|
-
body?: CSSProperties;
|
|
39
|
-
}
|
|
40
|
-
export interface ModalProps {
|
|
41
|
-
/** Controls modal visibility */
|
|
42
|
-
visible: boolean;
|
|
43
|
-
/** Modal title text */
|
|
44
|
-
title?: string;
|
|
45
|
-
/** Additional className for the modal container */
|
|
46
|
-
className?: string;
|
|
47
|
-
/** Additional className for the modal content */
|
|
48
|
-
contentClassName?: string;
|
|
49
|
-
/** Additional className for the header */
|
|
50
|
-
headerClassName?: string;
|
|
51
|
-
/** Inline styles for the modal container */
|
|
52
|
-
style?: React.CSSProperties;
|
|
53
|
-
/** Inline styles for the modal content */
|
|
54
|
-
contentStyle?: React.CSSProperties;
|
|
55
|
-
/** Callback when modal should close */
|
|
56
|
-
onClose?: () => void;
|
|
57
|
-
/** Auto close modal after delay (in milliseconds) */
|
|
58
|
-
isAutoClose?: boolean | number;
|
|
59
|
-
/** Auto close delay in milliseconds (default: 1000) */
|
|
60
|
-
autoCloseDelay?: number;
|
|
61
|
-
/** Modal size: sm, md, lg, xl, full */
|
|
62
|
-
size?: ModalSize;
|
|
63
|
-
/** Modal vertical position */
|
|
64
|
-
position?: ModalPosition;
|
|
65
|
-
/** Show/hide close button */
|
|
66
|
-
showCloseButton?: boolean;
|
|
67
|
-
/** Custom close button element */
|
|
68
|
-
closeButton?: React.ReactNode;
|
|
69
|
-
/** Overlay background opacity (0-1) */
|
|
70
|
-
overlayOpacity?: number;
|
|
71
|
-
/** Overlay background color */
|
|
72
|
-
overlayColor?: string;
|
|
73
|
-
/** Base z-index for overlay/content stack */
|
|
74
|
-
zIndex?: number;
|
|
75
|
-
/** Click overlay to close */
|
|
76
|
-
closeOnOverlayClick?: boolean;
|
|
77
|
-
/** Close on Escape key */
|
|
78
|
-
closeOnEscape?: boolean;
|
|
79
|
-
/** Show header section */
|
|
80
|
-
showHeader?: boolean;
|
|
81
|
-
/** Header background color */
|
|
82
|
-
headerBgColor?: string;
|
|
83
|
-
/** Header text color */
|
|
84
|
-
headerTextColor?: string;
|
|
85
|
-
/** Border radius */
|
|
86
|
-
borderRadius?: string;
|
|
87
|
-
/** Max width (CSS value) */
|
|
88
|
-
maxWidth?: string;
|
|
89
|
-
/** Padding for content area */
|
|
90
|
-
contentPadding?: string;
|
|
91
|
-
/** Header padding */
|
|
92
|
-
headerPadding?: string;
|
|
93
|
-
/** Animation duration (in ms) */
|
|
94
|
-
animationDuration?: number;
|
|
95
|
-
/** Custom classNames for component parts */
|
|
96
|
-
classNames?: ModalClassNames;
|
|
97
|
-
/** Custom inline styles for component parts */
|
|
98
|
-
styles?: ModalStyles;
|
|
99
|
-
/** Modal content */
|
|
100
|
-
children: React.ReactNode;
|
|
101
|
-
}
|
|
102
|
-
export declare const Modal: ({ visible, title, className, contentClassName, headerClassName, style, contentStyle, onClose, isAutoClose, autoCloseDelay, size, position, showCloseButton, closeButton, overlayOpacity, overlayColor, zIndex, closeOnOverlayClick, closeOnEscape, showHeader, headerBgColor, headerTextColor, borderRadius, maxWidth, contentPadding, headerPadding, animationDuration, classNames, styles, children, }: ModalProps) => React.JSX.Element | null;
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export type { ModalSize, ModalPosition, ModalClassNames, ModalStyles, ModalProps } from './types';
|
|
3
|
+
import type { ModalProps } from './types';
|
|
4
|
+
export declare const Modal: ({ visible, title, className, contentClassName, headerClassName, style, contentStyle, onClose, isAutoClose, autoCloseDelay, isAutoCloseOutside, size, position, showCloseButton, closeButton, overlayOpacity, overlayColor, zIndex, closeOnOverlayClick, closeOnEscape, showHeader, headerBgColor, headerTextColor, borderRadius, maxWidth, contentPadding, headerPadding, animationDuration, classNames, styles, children, }: ModalProps) => React.JSX.Element | null;
|
|
@@ -2,7 +2,9 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
2
2
|
import { useEffect, useState } from 'react';
|
|
3
3
|
import s from '../../../tc.module.css';
|
|
4
4
|
import { cn } from '../../../utils';
|
|
5
|
-
export const Modal = ({ visible, title = '', className = '', contentClassName = '', headerClassName = '', style = {}, contentStyle = {}, onClose, isAutoClose = false, autoCloseDelay = 1000, size = 'md', position = 'center', showCloseButton = true, closeButton, overlayOpacity = 0.5, overlayColor, zIndex = 11000, closeOnOverlayClick
|
|
5
|
+
export const Modal = ({ visible, title = '', className = '', contentClassName = '', headerClassName = '', style = {}, contentStyle = {}, onClose, isAutoClose = false, autoCloseDelay = 1000, isAutoCloseOutside, size = 'md', position = 'center', showCloseButton = true, closeButton, overlayOpacity = 0.5, overlayColor, zIndex = 11000, closeOnOverlayClick, closeOnEscape = true, showHeader = true, headerBgColor, headerTextColor, borderRadius = '0.5rem', maxWidth, contentPadding = '1rem', headerPadding = '1rem', animationDuration = 300, classNames = {}, styles = {}, children, }) => {
|
|
6
|
+
// isAutoCloseOutside takes priority, then closeOnOverlayClick, default true
|
|
7
|
+
const shouldCloseOnOutsideClick = isAutoCloseOutside ?? closeOnOverlayClick ?? true;
|
|
6
8
|
const [showModal, setShowModal] = useState(visible);
|
|
7
9
|
const [isAnimating, setIsAnimating] = useState(false);
|
|
8
10
|
useEffect(() => {
|
|
@@ -36,7 +38,7 @@ export const Modal = ({ visible, title = '', className = '', contentClassName =
|
|
|
36
38
|
return () => document.removeEventListener('keydown', handleEscape);
|
|
37
39
|
}, [showModal, closeOnEscape, onClose]);
|
|
38
40
|
const handleOverlayClick = (e) => {
|
|
39
|
-
if (
|
|
41
|
+
if (shouldCloseOnOutsideClick && e.target === e.currentTarget) {
|
|
40
42
|
onClose && onClose();
|
|
41
43
|
}
|
|
42
44
|
};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import React, { CSSProperties } from 'react';
|
|
2
|
+
export type ModalSize = 'sm' | 'md' | 'lg' | 'xl' | 'full';
|
|
3
|
+
export type ModalPosition = 'center' | 'top' | 'bottom';
|
|
4
|
+
export interface ModalClassNames {
|
|
5
|
+
/** Custom className for the overlay */
|
|
6
|
+
overlay?: string;
|
|
7
|
+
/** Custom className for the modal container */
|
|
8
|
+
container?: string;
|
|
9
|
+
/** Custom className for the modal wrapper */
|
|
10
|
+
wrapper?: string;
|
|
11
|
+
/** Custom className for the modal content */
|
|
12
|
+
content?: string;
|
|
13
|
+
/** Custom className for the header */
|
|
14
|
+
header?: string;
|
|
15
|
+
/** Custom className for the title */
|
|
16
|
+
title?: string;
|
|
17
|
+
/** Custom className for the close button */
|
|
18
|
+
closeButton?: string;
|
|
19
|
+
/** Custom className for the body/children container */
|
|
20
|
+
body?: string;
|
|
21
|
+
}
|
|
22
|
+
export interface ModalStyles {
|
|
23
|
+
/** Custom style for the overlay */
|
|
24
|
+
overlay?: CSSProperties;
|
|
25
|
+
/** Custom style for the modal container */
|
|
26
|
+
container?: CSSProperties;
|
|
27
|
+
/** Custom style for the modal wrapper */
|
|
28
|
+
wrapper?: CSSProperties;
|
|
29
|
+
/** Custom style for the modal content */
|
|
30
|
+
content?: CSSProperties;
|
|
31
|
+
/** Custom style for the header */
|
|
32
|
+
header?: CSSProperties;
|
|
33
|
+
/** Custom style for the title */
|
|
34
|
+
title?: CSSProperties;
|
|
35
|
+
/** Custom style for the close button */
|
|
36
|
+
closeButton?: CSSProperties;
|
|
37
|
+
/** Custom style for the body/children container */
|
|
38
|
+
body?: CSSProperties;
|
|
39
|
+
}
|
|
40
|
+
export interface ModalProps {
|
|
41
|
+
/** Controls modal visibility */
|
|
42
|
+
visible: boolean;
|
|
43
|
+
/** Modal title text */
|
|
44
|
+
title?: string;
|
|
45
|
+
/** Additional className for the modal container */
|
|
46
|
+
className?: string;
|
|
47
|
+
/** Additional className for the modal content */
|
|
48
|
+
contentClassName?: string;
|
|
49
|
+
/** Additional className for the header */
|
|
50
|
+
headerClassName?: string;
|
|
51
|
+
/** Inline styles for the modal container */
|
|
52
|
+
style?: CSSProperties;
|
|
53
|
+
/** Inline styles for the modal content */
|
|
54
|
+
contentStyle?: CSSProperties;
|
|
55
|
+
/** Callback when modal should close */
|
|
56
|
+
onClose?: () => void;
|
|
57
|
+
/** Auto close modal after delay (in milliseconds) */
|
|
58
|
+
isAutoClose?: boolean | number;
|
|
59
|
+
/** Auto close delay in milliseconds (default: 1000) */
|
|
60
|
+
autoCloseDelay?: number;
|
|
61
|
+
/** Auto close modal on outside click (default: true) */
|
|
62
|
+
isAutoCloseOutside?: boolean;
|
|
63
|
+
/** Modal size: sm, md, lg, xl, full */
|
|
64
|
+
size?: ModalSize;
|
|
65
|
+
/** Modal vertical position */
|
|
66
|
+
position?: ModalPosition;
|
|
67
|
+
/** Show/hide close button */
|
|
68
|
+
showCloseButton?: boolean;
|
|
69
|
+
/** Custom close button element */
|
|
70
|
+
closeButton?: React.ReactNode;
|
|
71
|
+
/** Overlay background opacity (0-1) */
|
|
72
|
+
overlayOpacity?: number;
|
|
73
|
+
/** Overlay background color */
|
|
74
|
+
overlayColor?: string;
|
|
75
|
+
/** Base z-index for overlay/content stack */
|
|
76
|
+
zIndex?: number;
|
|
77
|
+
/** Click overlay to close (alias for isAutoCloseOutside) */
|
|
78
|
+
closeOnOverlayClick?: boolean;
|
|
79
|
+
/** Close on Escape key */
|
|
80
|
+
closeOnEscape?: boolean;
|
|
81
|
+
/** Show header section */
|
|
82
|
+
showHeader?: boolean;
|
|
83
|
+
/** Header background color */
|
|
84
|
+
headerBgColor?: string;
|
|
85
|
+
/** Header text color */
|
|
86
|
+
headerTextColor?: string;
|
|
87
|
+
/** Border radius */
|
|
88
|
+
borderRadius?: string;
|
|
89
|
+
/** Max width (CSS value) */
|
|
90
|
+
maxWidth?: string;
|
|
91
|
+
/** Padding for content area */
|
|
92
|
+
contentPadding?: string;
|
|
93
|
+
/** Header padding */
|
|
94
|
+
headerPadding?: string;
|
|
95
|
+
/** Animation duration (in ms) */
|
|
96
|
+
animationDuration?: number;
|
|
97
|
+
/** Custom classNames for component parts */
|
|
98
|
+
classNames?: ModalClassNames;
|
|
99
|
+
/** Custom inline styles for component parts */
|
|
100
|
+
styles?: ModalStyles;
|
|
101
|
+
/** Modal content */
|
|
102
|
+
children: React.ReactNode;
|
|
103
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -49,6 +49,7 @@ const EmptyIcon = () => (_jsxs("svg", { viewBox: "0 0 24 24", fill: "none", stro
|
|
|
49
49
|
const RefreshIcon = () => (_jsxs("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [_jsx("path", { d: "M23 4v6h-6M1 20v-6h6", strokeLinecap: "round", strokeLinejoin: "round" }), _jsx("path", { d: "M3.51 9a9 9 0 0114.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0020.49 15", strokeLinecap: "round", strokeLinejoin: "round" })] }));
|
|
50
50
|
const PrintIcon = () => (_jsxs("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [_jsx("path", { d: "M6 9V2h12v7M6 18H4a2 2 0 01-2-2v-5a2 2 0 012-2h16a2 2 0 012 2v5a2 2 0 01-2 2h-2", strokeLinecap: "round", strokeLinejoin: "round" }), _jsx("rect", { x: "6", y: "14", width: "12", height: "8" })] }));
|
|
51
51
|
const ErrorIcon = () => (_jsxs("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [_jsx("circle", { cx: "12", cy: "12", r: "10" }), _jsx("path", { d: "M12 8v4M12 16h.01", strokeLinecap: "round", strokeLinejoin: "round" })] }));
|
|
52
|
+
const tableFilterCache = new Map();
|
|
52
53
|
export const Table = forwardRef(function TableComponent(props, ref) {
|
|
53
54
|
const { id, data, columns, keyField = '_id', loading = false, loadingIndicator, pagination = true, paginationConfig, totalSize, remote = true, defaultSort, sort: controlledSort, filterable = false, defaultFilters, filters: controlledFilters, defaultShowFilters = true, showFilters: controlledShowFilters, onShowFiltersChange, showFilterToggle = true, searchable = true, searchPlaceholder = 'Search...', defaultSearchValue = '', searchValue: controlledSearchValue, searchDebounce = 300, rowSelection, expandable, editMode = 'dblclick', showEditIcon = false, onCellEdit, exportable = true, exportFileName = 'table_export', exportFormat = 'csv', columnToggle = false, isFieldSelector = true, bordered = true, striped = false, hover = true, compact = false, cellPadding, stickyHeader = false, maxHeight, rowClassName, rowStyle, classNames = {}, styles = {}, className, style, emptyText = 'No data available', onChange, onPageChange, onSortChange, onFilterChange, onSearch, onRowClick, onRowDoubleClick, onClearFilters, toolbar, hideToolbar = false, showFooter = false, caption,
|
|
54
55
|
// Quick configuration props
|
|
@@ -62,7 +63,7 @@ export const Table = forwardRef(function TableComponent(props, ref) {
|
|
|
62
63
|
// Toolbar customization
|
|
63
64
|
toolbarPosition = 'top', toolbarLeft, toolbarRight, toolbarCenter,
|
|
64
65
|
// Refresh
|
|
65
|
-
refreshable = false, onRefresh,
|
|
66
|
+
refreshable = false, onRefresh, isForceReload,
|
|
66
67
|
// Print
|
|
67
68
|
printable = false, onPrint,
|
|
68
69
|
// Size
|
|
@@ -84,8 +85,15 @@ export const Table = forwardRef(function TableComponent(props, ref) {
|
|
|
84
85
|
// Resolve aliases
|
|
85
86
|
const resolvedExportable = isExport ?? exportable;
|
|
86
87
|
const resolvedExportFileName = fileName ?? exportFileName;
|
|
88
|
+
// Read cached filter/search state (survives remounts when parent changes React key)
|
|
89
|
+
const cachedFilterState = tableFilterCache.get(id);
|
|
87
90
|
// Auto-detect remote mode: if totalSize <= data.length, use client-side (remote=false)
|
|
91
|
+
// Exception: if onFilter is provided, always use remote mode (server handles filtering)
|
|
88
92
|
const resolvedRemote = useMemo(() => {
|
|
93
|
+
// If onFilter callback is provided, data is server-filtered - never re-filter client-side
|
|
94
|
+
if (onFilter) {
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
89
97
|
// If totalSize is provided and is <= data.length, all data is loaded - use client-side
|
|
90
98
|
if (totalSize !== undefined &&
|
|
91
99
|
totalSize > 0 &&
|
|
@@ -94,7 +102,7 @@ export const Table = forwardRef(function TableComponent(props, ref) {
|
|
|
94
102
|
}
|
|
95
103
|
// Otherwise use the prop value (default: true)
|
|
96
104
|
return remote;
|
|
97
|
-
}, [remote, totalSize, data.length]);
|
|
105
|
+
}, [remote, totalSize, data.length, onFilter]);
|
|
98
106
|
// Handle isSelectRow shorthand
|
|
99
107
|
const resolvedRowSelection = isSelectRow
|
|
100
108
|
? {
|
|
@@ -146,8 +154,12 @@ export const Table = forwardRef(function TableComponent(props, ref) {
|
|
|
146
154
|
const tableRef = useRef(null);
|
|
147
155
|
const columnToggleRef = useRef(null);
|
|
148
156
|
const prevSelectionCountRef = useRef(0);
|
|
149
|
-
//
|
|
150
|
-
|
|
157
|
+
// Cache filter component references per dataField to keep stable React element types.
|
|
158
|
+
// Without this, factory functions like TextFilter({...}) create a new component ref
|
|
159
|
+
// on every render, causing React to unmount/remount the filter and lose typed text.
|
|
160
|
+
const filterComponentCacheRef = useRef(new Map());
|
|
161
|
+
// State (use cached values if available to survive remounts from key changes)
|
|
162
|
+
const [internalSearchValue, setInternalSearchValue] = useState(cachedFilterState?.searchValue ?? defaultSearchValue);
|
|
151
163
|
const [internalShowFilters, setInternalShowFilters] = useState(defaultShowFilters);
|
|
152
164
|
const [columnToggleOpen, setColumnToggleOpen] = useState(false);
|
|
153
165
|
const [columnSearch, setColumnSearch] = useState('');
|
|
@@ -179,6 +191,13 @@ export const Table = forwardRef(function TableComponent(props, ref) {
|
|
|
179
191
|
// Add new columns at the end
|
|
180
192
|
const added = columns.filter((c) => !existingDataFields.has(c.dataField));
|
|
181
193
|
setReorderedColumns([...preserved, ...added]);
|
|
194
|
+
// Clean up filter component cache for removed columns
|
|
195
|
+
const newFieldSet = new Set(columns.map((c) => c.dataField));
|
|
196
|
+
for (const key of filterComponentCacheRef.current.keys()) {
|
|
197
|
+
if (!newFieldSet.has(key)) {
|
|
198
|
+
filterComponentCacheRef.current.delete(key);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
182
201
|
}
|
|
183
202
|
else {
|
|
184
203
|
// Same columns but maybe different data - update column data while preserving order
|
|
@@ -226,34 +245,53 @@ export const Table = forwardRef(function TableComponent(props, ref) {
|
|
|
226
245
|
// Clear cache when editing target changes
|
|
227
246
|
editorRendererCacheRef.current.clear();
|
|
228
247
|
}, [editingCell]);
|
|
248
|
+
// Force reload: when isForceReload toggles, trigger onRefresh
|
|
249
|
+
const prevForceReloadRef = useRef(isForceReload);
|
|
250
|
+
useEffect(() => {
|
|
251
|
+
if (prevForceReloadRef.current !== isForceReload &&
|
|
252
|
+
isForceReload !== undefined) {
|
|
253
|
+
prevForceReloadRef.current = isForceReload;
|
|
254
|
+
onRefresh?.();
|
|
255
|
+
}
|
|
256
|
+
}, [isForceReload, onRefresh]);
|
|
229
257
|
const searchValue = controlledSearchValue ?? internalSearchValue;
|
|
230
258
|
const debouncedSearchValue = useTableDebounce(searchValue, searchDebounce);
|
|
231
259
|
// Sort state
|
|
232
260
|
const { sort, handleSort } = useSortState(defaultSort, controlledSort);
|
|
233
|
-
// Filter state
|
|
234
|
-
const { filters, setFilter, clearFilters } = useFilterState(defaultFilters, controlledFilters);
|
|
261
|
+
// Filter state (prefer cached filters over defaultFilters to survive remounts)
|
|
262
|
+
const { filters, setFilter, clearFilters } = useFilterState(cachedFilterState?.filters ?? defaultFilters, controlledFilters);
|
|
235
263
|
// Track if onFilter should be called (only after user interaction)
|
|
236
264
|
const shouldCallOnFilter = useRef(false);
|
|
237
265
|
const filterTypeRef = useRef('filter');
|
|
238
266
|
const onFilterRef = useRef(onFilter);
|
|
239
267
|
// Track last called values to prevent duplicate calls
|
|
240
268
|
const lastOnFilterCallRef = useRef(null);
|
|
241
|
-
// Track focused filter field to restore focus after data changes
|
|
242
|
-
const focusedFilterFieldRef = useRef(null);
|
|
269
|
+
// Track focused filter field to restore focus after data changes (or remounts)
|
|
270
|
+
const focusedFilterFieldRef = useRef(cachedFilterState?.focusedField ?? null);
|
|
243
271
|
const tableContainerRef = useRef(null);
|
|
272
|
+
// Helper: save current filter/search/focus state to module-level cache
|
|
273
|
+
const saveFilterCache = useCallback((updates) => {
|
|
274
|
+
const current = tableFilterCache.get(id) || {
|
|
275
|
+
filters: {},
|
|
276
|
+
searchValue: '',
|
|
277
|
+
focusedField: null,
|
|
278
|
+
};
|
|
279
|
+
tableFilterCache.set(id, { ...current, ...updates });
|
|
280
|
+
}, [id]);
|
|
244
281
|
// Clear focus ref when clicking outside the table
|
|
245
282
|
useEffect(() => {
|
|
246
283
|
const handleClickOutside = (event) => {
|
|
247
284
|
if (tableContainerRef.current &&
|
|
248
285
|
!tableContainerRef.current.contains(event.target)) {
|
|
249
286
|
focusedFilterFieldRef.current = null;
|
|
287
|
+
saveFilterCache({ focusedField: null });
|
|
250
288
|
}
|
|
251
289
|
};
|
|
252
290
|
document.addEventListener('mousedown', handleClickOutside);
|
|
253
291
|
return () => {
|
|
254
292
|
document.removeEventListener('mousedown', handleClickOutside);
|
|
255
293
|
};
|
|
256
|
-
}, []);
|
|
294
|
+
}, [saveFilterCache]);
|
|
257
295
|
// Restore filter focus after data changes
|
|
258
296
|
useEffect(() => {
|
|
259
297
|
const restoreFocus = () => {
|
|
@@ -283,7 +321,18 @@ export const Table = forwardRef(function TableComponent(props, ref) {
|
|
|
283
321
|
};
|
|
284
322
|
}, [data]);
|
|
285
323
|
// Pagination state
|
|
286
|
-
const { page, pageSize, totalPages, goToPage, goToNextPage, goToPrevPage, goToFirstPage, goToLastPage, changePageSize, } = usePaginationState(resolvedPaginationConfig?.page || 0, resolvedPaginationConfig?.pageSize || 10, totalSize ?? data.length);
|
|
324
|
+
const { page, pageSize, totalPages, goToPage, goToNextPage, goToPrevPage, goToFirstPage, goToLastPage, changePageSize, setPage, } = usePaginationState(resolvedPaginationConfig?.page || 0, resolvedPaginationConfig?.pageSize || 10, totalSize ?? data.length);
|
|
325
|
+
// Reset page to 0 when data changes (e.g., after server-side onFilter response)
|
|
326
|
+
// This ensures new data is visible without re-triggering onFilter.
|
|
327
|
+
const prevDataRef = useRef(data);
|
|
328
|
+
useEffect(() => {
|
|
329
|
+
if (prevDataRef.current !== data) {
|
|
330
|
+
prevDataRef.current = data;
|
|
331
|
+
if (page !== 0) {
|
|
332
|
+
setPage(0);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
}, [data, page, setPage]);
|
|
287
336
|
// Row selection
|
|
288
337
|
const { selectedKeys, isSelected, toggleRow, toggleAll, isAllSelected, isIndeterminate, } = useRowSelection(data, resolvedRowSelection?.keyField || keyField, resolvedRowSelection?.mode || 'none', resolvedRowSelection?.selectedRowKeys, resolvedRowSelection?.getCheckboxProps);
|
|
289
338
|
// Row expansion
|
|
@@ -421,7 +470,9 @@ export const Table = forwardRef(function TableComponent(props, ref) {
|
|
|
421
470
|
shouldCallOnFilter.current = true;
|
|
422
471
|
filterTypeRef.current = 'search';
|
|
423
472
|
onChange?.({ type: 'search', search: value });
|
|
424
|
-
|
|
473
|
+
// Persist to cache
|
|
474
|
+
saveFilterCache({ searchValue: value });
|
|
475
|
+
}, [resetEditingState, onSearch, onChange, saveFilterCache]);
|
|
425
476
|
// Handle sort
|
|
426
477
|
const handleSortClick = useCallback((column) => {
|
|
427
478
|
if (!column.sort)
|
|
@@ -441,7 +492,12 @@ export const Table = forwardRef(function TableComponent(props, ref) {
|
|
|
441
492
|
shouldCallOnFilter.current = true;
|
|
442
493
|
filterTypeRef.current = 'filter';
|
|
443
494
|
onChange?.({ type: 'filter', filters: newFilters });
|
|
444
|
-
|
|
495
|
+
// Persist to cache (including focused field)
|
|
496
|
+
saveFilterCache({
|
|
497
|
+
filters: newFilters,
|
|
498
|
+
focusedField: focusedFilterFieldRef.current,
|
|
499
|
+
});
|
|
500
|
+
}, [filters, setFilter, onFilterChange, onChange, resetEditingState, saveFilterCache]);
|
|
445
501
|
// Handle clear all filters
|
|
446
502
|
const handleClearFilters = useCallback(() => {
|
|
447
503
|
resetEditingState();
|
|
@@ -453,7 +509,10 @@ export const Table = forwardRef(function TableComponent(props, ref) {
|
|
|
453
509
|
onChange?.({ type: 'filter', filters: {} });
|
|
454
510
|
// Reset the tracking ref so subsequent filters can trigger onFilter
|
|
455
511
|
lastOnFilterCallRef.current = null;
|
|
512
|
+
// Clear the cache so remounts also start fresh
|
|
513
|
+
tableFilterCache.delete(id);
|
|
456
514
|
}, [
|
|
515
|
+
id,
|
|
457
516
|
clearFilters,
|
|
458
517
|
onClearFilters,
|
|
459
518
|
onFilterChange,
|
|
@@ -951,6 +1010,7 @@ export const Table = forwardRef(function TableComponent(props, ref) {
|
|
|
951
1010
|
return (_jsxs(Toolbar, { className: classNames.toolbar, style: styles.toolbar, children: [_jsxs(ToolbarGroup, { children: [toolbarLeft, searchable && (_jsxs(SearchInput, { children: [_jsx(SearchIcon, {}), _jsx("input", { type: "text", value: searchValue, onChange: (e) => handleSearchChange(e.target.value), onFocus: () => {
|
|
952
1011
|
// Clear column filter focus when global search is focused
|
|
953
1012
|
focusedFilterFieldRef.current = null;
|
|
1013
|
+
saveFilterCache({ focusedField: null });
|
|
954
1014
|
}, placeholder: searchPlaceholder })] })), searchable && (_jsx(ToolbarButton, { onClick: () => handleSearchChange(''), disabled: !searchValue, style: { opacity: searchValue ? 1 : 0.6 }, children: "Clear" })), _jsx(ToolbarButton, { onClick: handleClearFilters, disabled: !hasFilters, style: { opacity: hasFilters ? 1 : 0.6 }, children: "Clear all filters" }), resolvedExportable && hideExcelSheet !== true && (_jsxs(ToolbarButton, { onClick: handleExport, children: [_jsx(DownloadIcon, {}), exportFormat === 'excel' ? 'Export Excel' : 'Export CSV'] })), showFilterToggle && isFieldSelector && (_jsxs("div", { ref: columnToggleRef, style: { position: 'relative' }, children: [_jsx(Tooltip, { content: "Show/Hide Columns", position: "bottom", children: _jsx(ToolbarButton, { "$active": columnToggleOpen, onClick: () => setColumnToggleOpen(!columnToggleOpen), "aria-label": "Toggle column visibility", style: { padding: '0 8px' }, children: _jsx(FilterIcon, {}) }) }), columnToggleOpen && (_jsxs(ColumnTogglePanel, { children: [_jsxs(ColumnToggleHeader, { children: [_jsx("span", { children: "Show/Hide Columns" }), _jsx("button", { onClick: () => setColumnToggleOpen(false), children: _jsx(CloseIcon, {}) })] }), _jsx(ColumnToggleSearch, { children: _jsx("input", { type: "text", value: columnSearch, onChange: (e) => setColumnSearch(e.target.value), placeholder: "Search columns..." }) }), _jsxs(ColumnToggleList, { children: [_jsxs(ColumnToggleItem, { style: {
|
|
955
1015
|
borderBottom: '1px solid #e5e7eb',
|
|
956
1016
|
paddingBottom: 8,
|
|
@@ -1168,14 +1228,26 @@ export const Table = forwardRef(function TableComponent(props, ref) {
|
|
|
1168
1228
|
column.filter === true ||
|
|
1169
1229
|
column.filterComponent ||
|
|
1170
1230
|
column.filterRenderer;
|
|
1171
|
-
// Get the filter component
|
|
1172
|
-
|
|
1173
|
-
|
|
1231
|
+
// Get the filter component (use cached reference to prevent remounting)
|
|
1232
|
+
let FilterComponent = null;
|
|
1233
|
+
if (hasColumnFilter) {
|
|
1234
|
+
const cacheKey = column.dataField;
|
|
1235
|
+
const resolved = (typeof column.filter === 'function'
|
|
1174
1236
|
? column.filter
|
|
1175
1237
|
: null) ||
|
|
1176
1238
|
column.filterComponent ||
|
|
1177
|
-
getFilterComponent(column.filterType || 'text')
|
|
1178
|
-
|
|
1239
|
+
getFilterComponent(column.filterType || 'text');
|
|
1240
|
+
const cached = filterComponentCacheRef.current.get(cacheKey);
|
|
1241
|
+
if (cached && cached.displayName === resolved.displayName) {
|
|
1242
|
+
FilterComponent = cached;
|
|
1243
|
+
}
|
|
1244
|
+
else {
|
|
1245
|
+
filterComponentCacheRef.current.set(cacheKey, resolved);
|
|
1246
|
+
FilterComponent = resolved;
|
|
1247
|
+
}
|
|
1248
|
+
}
|
|
1249
|
+
// Non-null reference for JSX rendering (guarded by showFilter check below)
|
|
1250
|
+
const ResolvedFilter = FilterComponent;
|
|
1179
1251
|
const onFilter = (value) => handleFilterChange(column.dataField, value);
|
|
1180
1252
|
// Get resized column style
|
|
1181
1253
|
const resizeStyle = resizable
|
|
@@ -1304,7 +1376,10 @@ export const Table = forwardRef(function TableComponent(props, ref) {
|
|
|
1304
1376
|
}, onClick: (e) => e.stopPropagation(), children: column.filterRenderer ? (column.filterRenderer(onFilter, column)) : (_jsx("div", { onFocusCapture: () => {
|
|
1305
1377
|
focusedFilterFieldRef.current =
|
|
1306
1378
|
column.dataField;
|
|
1307
|
-
|
|
1379
|
+
saveFilterCache({
|
|
1380
|
+
focusedField: column.dataField,
|
|
1381
|
+
});
|
|
1382
|
+
}, "data-filter-wrapper": column.dataField, style: { width: '100%' }, children: _jsx(ResolvedFilter, { column: column, value: filters[column.dataField], onChange: onFilter, onClear: () => handleFilterChange(column.dataField, null) }, `filter-${column.dataField}`) })) }), showSort && (_jsx("div", { style: {
|
|
1308
1383
|
minWidth: 40,
|
|
1309
1384
|
minHeight: 24,
|
|
1310
1385
|
display: 'flex',
|