@tap-payments/os-micro-frontend-shared 0.1.135-test.2 → 0.1.135-test.2-test.3-test.4
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/build/components/VirtualTables/SheetViewVirtualTable/SheetViewVirtualTable.js +16 -31
- package/build/components/VirtualTables/SheetViewVirtualTable/hooks/usePerformanceOptimizations.d.ts +0 -8
- package/build/components/VirtualTables/SheetViewVirtualTable/hooks/usePerformanceOptimizations.js +69 -51
- package/package.json +2 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { memo, useCallback
|
|
2
|
+
import { memo, useCallback } from 'react';
|
|
3
3
|
import { SHEET_VIEW_TABLE_THRESHOLD } from '../../../constants/index.js';
|
|
4
4
|
import TableFooter from '../components/TableFooter/TableFooter';
|
|
5
5
|
import { SheetViewTableContainer } from '../components/style';
|
|
@@ -8,7 +8,7 @@ import { usePinnedColumns, useSynchronizedScroll, useTableState, useTableData, u
|
|
|
8
8
|
import { PinnedColumn, MainTable, LoadingMainTable, NoDataView, VirtualTable } from './components';
|
|
9
9
|
function SheetViewVirtualTable({ columns, rows, threshold = SHEET_VIEW_TABLE_THRESHOLD, showHeader, headerProps, rowProps, footerProps, rowHeight = 28, isLoading, error, columnsSorting, onColumnSort, loadMoreItems, isFetchingNextPage, triggerDataRefetch, scrollToIndex, areAllRowsLoaded = false, tableBodyStyles, tableTitle, dragControls, onColumnPin, clearBackdropVisibilityTimeout = 100, isPinnable = false, tableMode, overscanCount, }) {
|
|
10
10
|
// Performance optimizations
|
|
11
|
-
const { stableColumns
|
|
11
|
+
const { stableColumns } = usePerformanceOptimizations(columns);
|
|
12
12
|
// Custom hooks for state management
|
|
13
13
|
const { selectedCell, selectedColumn, selectedRow, showBackDrop, setShowBackdrop, handleCellClick, handleColumnClick, handleChipClick, selectedChip, } = useTableState();
|
|
14
14
|
// Table data processing
|
|
@@ -42,33 +42,6 @@ function SheetViewVirtualTable({ columns, rows, threshold = SHEET_VIEW_TABLE_THR
|
|
|
42
42
|
handleCellClick,
|
|
43
43
|
handleChipClick,
|
|
44
44
|
});
|
|
45
|
-
// Memoized header props to prevent unnecessary re-renders when filters change
|
|
46
|
-
const memoizedHeaderProps = useMemo(() => ({
|
|
47
|
-
showHeader,
|
|
48
|
-
columnsSorting,
|
|
49
|
-
onColumnSort,
|
|
50
|
-
headerProps,
|
|
51
|
-
showBackDrop,
|
|
52
|
-
onColumnPin: handleColumnPin,
|
|
53
|
-
isPinnable,
|
|
54
|
-
lastColumnId,
|
|
55
|
-
selectedColumn,
|
|
56
|
-
onColumnClick: handleColumnClick,
|
|
57
|
-
// Force re-render only when filters actually change
|
|
58
|
-
filtersKey: Object.keys(stableFilters).length > 0 ? JSON.stringify(stableFilters) : null,
|
|
59
|
-
}), [
|
|
60
|
-
showHeader,
|
|
61
|
-
columnsSorting,
|
|
62
|
-
onColumnSort,
|
|
63
|
-
headerProps,
|
|
64
|
-
showBackDrop,
|
|
65
|
-
handleColumnPin,
|
|
66
|
-
isPinnable,
|
|
67
|
-
lastColumnId,
|
|
68
|
-
selectedColumn,
|
|
69
|
-
handleColumnClick,
|
|
70
|
-
stableFilters,
|
|
71
|
-
]);
|
|
72
45
|
const onPointerDown = (e) => {
|
|
73
46
|
dragControls === null || dragControls === void 0 ? void 0 : dragControls.start(e);
|
|
74
47
|
};
|
|
@@ -97,7 +70,18 @@ function SheetViewVirtualTable({ columns, rows, threshold = SHEET_VIEW_TABLE_THR
|
|
|
97
70
|
pinnedEndVirtualListRef,
|
|
98
71
|
scrollableVirtualListRef,
|
|
99
72
|
]);
|
|
100
|
-
const baseCommonProps =
|
|
73
|
+
const baseCommonProps = {
|
|
74
|
+
showHeader,
|
|
75
|
+
columnsSorting,
|
|
76
|
+
onColumnSort,
|
|
77
|
+
headerProps,
|
|
78
|
+
showBackDrop,
|
|
79
|
+
onColumnPin: handleColumnPin,
|
|
80
|
+
isPinnable,
|
|
81
|
+
lastColumnId,
|
|
82
|
+
selectedColumn,
|
|
83
|
+
onColumnClick: handleColumnClick,
|
|
84
|
+
tableTitle,
|
|
101
85
|
areAllRowsLoaded,
|
|
102
86
|
isFetchingNextPage,
|
|
103
87
|
scrollToIndex,
|
|
@@ -105,7 +89,8 @@ function SheetViewVirtualTable({ columns, rows, threshold = SHEET_VIEW_TABLE_THR
|
|
|
105
89
|
isError,
|
|
106
90
|
tableMode,
|
|
107
91
|
showNoDataView,
|
|
108
|
-
tableBodyStyles
|
|
92
|
+
tableBodyStyles,
|
|
93
|
+
};
|
|
109
94
|
const commonPropsWithTableStates = Object.assign(Object.assign({}, baseCommonProps), { hasTimeoutError,
|
|
110
95
|
tableLoading });
|
|
111
96
|
return (_jsxs(_Fragment, { children: [_jsx(SheetViewTableContainer, { children: showNoDataView ? (tableLoading ? (
|
package/build/components/VirtualTables/SheetViewVirtualTable/hooks/usePerformanceOptimizations.d.ts
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
1
|
import type { IColumnProps } from '../../../../types/index.js';
|
|
2
|
-
interface StableFilterData {
|
|
3
|
-
type: string;
|
|
4
|
-
data?: unknown;
|
|
5
|
-
options?: unknown;
|
|
6
|
-
apiKey?: string;
|
|
7
|
-
}
|
|
8
2
|
export declare const usePerformanceOptimizations: (columns: readonly IColumnProps[]) => {
|
|
9
3
|
stableColumns: IColumnProps<any>[];
|
|
10
|
-
stableFilters: Record<string, StableFilterData>;
|
|
11
4
|
columnMetrics: {
|
|
12
5
|
visibleColumns: IColumnProps<any>[];
|
|
13
6
|
totalWidth: number;
|
|
@@ -16,4 +9,3 @@ export declare const usePerformanceOptimizations: (columns: readonly IColumnProp
|
|
|
16
9
|
lastColumnId: string | number | symbol;
|
|
17
10
|
};
|
|
18
11
|
};
|
|
19
|
-
export {};
|
package/build/components/VirtualTables/SheetViewVirtualTable/hooks/usePerformanceOptimizations.js
CHANGED
|
@@ -1,14 +1,48 @@
|
|
|
1
1
|
import { useMemo, useRef } from 'react';
|
|
2
|
+
// Deep comparison helper for filter data
|
|
3
|
+
const areFilterDataEqual = (data1, data2) => {
|
|
4
|
+
if (data1 === data2)
|
|
5
|
+
return true;
|
|
6
|
+
if (!data1 || !data2)
|
|
7
|
+
return false;
|
|
8
|
+
const keys1 = Object.keys(data1);
|
|
9
|
+
const keys2 = Object.keys(data2);
|
|
10
|
+
if (keys1.length !== keys2.length)
|
|
11
|
+
return false;
|
|
12
|
+
return keys1.every((key) => {
|
|
13
|
+
const val1 = data1[key];
|
|
14
|
+
const val2 = data2[key];
|
|
15
|
+
if (Array.isArray(val1) && Array.isArray(val2)) {
|
|
16
|
+
return val1.length === val2.length && val1.every((v, i) => v === val2[i]);
|
|
17
|
+
}
|
|
18
|
+
if (typeof val1 === 'object' && typeof val2 === 'object' && val1 && val2) {
|
|
19
|
+
return JSON.stringify(val1) === JSON.stringify(val2);
|
|
20
|
+
}
|
|
21
|
+
return val1 === val2;
|
|
22
|
+
});
|
|
23
|
+
};
|
|
2
24
|
export const usePerformanceOptimizations = (columns) => {
|
|
3
25
|
// Create stable column references to prevent unnecessary re-renders
|
|
4
26
|
const stableColumnsRef = useRef([]);
|
|
5
|
-
|
|
6
|
-
const
|
|
27
|
+
const isFirstRenderRef = useRef(true);
|
|
28
|
+
const filterChangeTrackingRef = useRef(new Map());
|
|
7
29
|
const stableColumns = useMemo(() => {
|
|
8
|
-
//
|
|
9
|
-
|
|
30
|
+
// On first render, just initialize and return columns
|
|
31
|
+
if (isFirstRenderRef.current) {
|
|
32
|
+
isFirstRenderRef.current = false;
|
|
33
|
+
stableColumnsRef.current = [...columns];
|
|
34
|
+
// Initialize filter tracking
|
|
35
|
+
columns.forEach((col) => {
|
|
36
|
+
var _a;
|
|
37
|
+
filterChangeTrackingRef.current.set(col.id, (_a = col.filter) === null || _a === void 0 ? void 0 : _a.data);
|
|
38
|
+
});
|
|
39
|
+
return stableColumnsRef.current;
|
|
40
|
+
}
|
|
41
|
+
// After first render, only update if structural changes or filter changes occurred
|
|
42
|
+
const structurallyChanged = columns.length !== stableColumnsRef.current.length ||
|
|
10
43
|
columns.some((col, index) => {
|
|
11
44
|
const prevCol = stableColumnsRef.current[index];
|
|
45
|
+
console.log({ colFilter: col.filter, prevColFilter: prevCol === null || prevCol === void 0 ? void 0 : prevCol.filter });
|
|
12
46
|
return (!prevCol ||
|
|
13
47
|
col.id !== prevCol.id ||
|
|
14
48
|
col.width !== prevCol.width ||
|
|
@@ -16,56 +50,41 @@ export const usePerformanceOptimizations = (columns) => {
|
|
|
16
50
|
col.hidden !== prevCol.hidden ||
|
|
17
51
|
col.order !== prevCol.order);
|
|
18
52
|
});
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
return stableColumnsRef.current;
|
|
23
|
-
}, [columns]);
|
|
24
|
-
const stableFilters = useMemo(() => {
|
|
25
|
-
// Extract filter-related data from columns for header rendering optimization
|
|
26
|
-
const currentFilters = {};
|
|
53
|
+
// Check for filter-only changes
|
|
54
|
+
const columnsWithFilterChanges = new Set();
|
|
27
55
|
columns.forEach((col) => {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
// Only add apiKey if it exists (for 'list' type filters)
|
|
36
|
-
if (col.filter.type === 'list') {
|
|
37
|
-
filterData.apiKey = col.filter.apiKey;
|
|
38
|
-
}
|
|
39
|
-
currentFilters[columnId] = filterData;
|
|
56
|
+
var _a;
|
|
57
|
+
const colId = col.id;
|
|
58
|
+
const prevFilterData = filterChangeTrackingRef.current.get(colId);
|
|
59
|
+
const currentFilterData = (_a = col.filter) === null || _a === void 0 ? void 0 : _a.data;
|
|
60
|
+
if (!areFilterDataEqual(prevFilterData, currentFilterData)) {
|
|
61
|
+
columnsWithFilterChanges.add(colId);
|
|
62
|
+
filterChangeTrackingRef.current.set(colId, currentFilterData);
|
|
40
63
|
}
|
|
41
64
|
});
|
|
42
|
-
//
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
return
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
});
|
|
64
|
-
};
|
|
65
|
-
if (hasFilterChanged()) {
|
|
66
|
-
stableFiltersRef.current = Object.assign({}, currentFilters);
|
|
65
|
+
// Only update if there are structural changes or filter changes
|
|
66
|
+
if (structurallyChanged || columnsWithFilterChanges.size > 0) {
|
|
67
|
+
// For filter-only changes, update only the affected columns
|
|
68
|
+
if (!structurallyChanged && columnsWithFilterChanges.size > 0) {
|
|
69
|
+
// Create a new array but preserve references for unchanged columns
|
|
70
|
+
const updatedColumns = stableColumnsRef.current.map((stableCol, index) => {
|
|
71
|
+
const newCol = columns[index];
|
|
72
|
+
const colId = newCol === null || newCol === void 0 ? void 0 : newCol.id;
|
|
73
|
+
// Only replace if this column's filter changed
|
|
74
|
+
if (columnsWithFilterChanges.has(colId)) {
|
|
75
|
+
return newCol;
|
|
76
|
+
}
|
|
77
|
+
// Keep the stable reference for unchanged columns
|
|
78
|
+
return stableCol;
|
|
79
|
+
});
|
|
80
|
+
stableColumnsRef.current = updatedColumns;
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
// Full update for structural changes
|
|
84
|
+
stableColumnsRef.current = [...columns];
|
|
85
|
+
}
|
|
67
86
|
}
|
|
68
|
-
return
|
|
87
|
+
return stableColumnsRef.current;
|
|
69
88
|
}, [columns]);
|
|
70
89
|
// Memoize frequently used column calculations
|
|
71
90
|
const columnMetrics = useMemo(() => {
|
|
@@ -83,7 +102,6 @@ export const usePerformanceOptimizations = (columns) => {
|
|
|
83
102
|
}, [stableColumns]);
|
|
84
103
|
return {
|
|
85
104
|
stableColumns,
|
|
86
|
-
stableFilters,
|
|
87
105
|
columnMetrics,
|
|
88
106
|
};
|
|
89
107
|
};
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tap-payments/os-micro-frontend-shared",
|
|
3
3
|
"description": "Shared components and utilities for Tap Payments micro frontends",
|
|
4
|
-
"version": "0.1.135-test.2",
|
|
5
|
-
"testVersion":
|
|
4
|
+
"version": "0.1.135-test.2-test.3-test.4",
|
|
5
|
+
"testVersion": 4,
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "build/index.js",
|
|
8
8
|
"module": "build/index.js",
|