@tap-payments/os-micro-frontend-shared 0.1.136-test.4 → 0.1.136-test.5
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/components/SheetViewTableHeaderCell.js
CHANGED
|
@@ -24,20 +24,26 @@ function SheetViewTableHeaderCell({ column: { header, id, align, headerStyle, so
|
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
};
|
|
27
|
-
const onOpenFilterDropdown = () => {
|
|
27
|
+
const onOpenFilterDropdown = useCallback(() => {
|
|
28
28
|
setColumnFilterEl(cellRef.current);
|
|
29
|
-
};
|
|
30
|
-
const handleCellClick = (event) => {
|
|
29
|
+
}, []);
|
|
30
|
+
const handleCellClick = useCallback((event) => {
|
|
31
31
|
// Only fire column click when clicking on the cell itself, not on child elements
|
|
32
32
|
if (event.target === event.currentTarget) {
|
|
33
33
|
onColumnClick === null || onColumnClick === void 0 ? void 0 : onColumnClick(colIndex, event, pinned);
|
|
34
34
|
}
|
|
35
|
-
};
|
|
36
|
-
const handleHeaderInnerClick = (event) => {
|
|
35
|
+
}, [onColumnClick, colIndex, pinned]);
|
|
36
|
+
const handleHeaderInnerClick = useCallback((event) => {
|
|
37
37
|
// Prevent event bubbling to parent cell
|
|
38
38
|
event.stopPropagation();
|
|
39
39
|
onOpenFilterDropdown();
|
|
40
|
-
};
|
|
40
|
+
}, [onOpenFilterDropdown]);
|
|
41
|
+
// Memoize filter props to prevent object recreation on every render
|
|
42
|
+
const memoizedFilterProps = useMemo(() => {
|
|
43
|
+
if (!filter)
|
|
44
|
+
return null;
|
|
45
|
+
return Object.assign(Object.assign({}, filter), { anchorEl: columnFilterEl, setAnchorEl: setColumnFilterEl });
|
|
46
|
+
}, [filter, columnFilterEl]);
|
|
41
47
|
return (_jsx(StyledCell, Object.assign({ "data-id": id, component: "div", "data-testid": "SheetViewVirtualTable_TableHeader_StyledCell", "data-column-id": id, "data-column-width": width, "data-column-width-used": width, "data-column-align": align, "data-column-order": order, "data-column-header": typeof header === 'string' ? header : 'component', "data-column-sortable": !!sortable, "data-column-filterable": !!filter, "data-column-pinned": isPinned, isFirst: isFirst, isLast: isLast, isSheetView: true, ref: cellRef, onClick: handleCellClick, sx: (theme) => (Object.assign({ display: 'flex', gap: theme.spacing(0.5), alignItems: 'center', justifyContent: align === 'right' ? 'flex-end' : 'flex-start', width, textAlign: align, overflow: 'unset', cursor: 'pointer', boxSizing: 'border-box', border: '0.5px solid transparent', borderColor: isSelected ? '#1F88D0' : '#F2F2F2', borderBottom: isSelected ? '0.5px solid transparent' : '0.5px solid #F2F2F2', backgroundColor: isSelected ? '#F2F2F2' : '#FCFCFC', minHeight: '28px', position: 'relative', '&:before': {
|
|
42
48
|
content: '""',
|
|
43
49
|
borderBottom: 'none',
|
|
@@ -46,7 +52,7 @@ function SheetViewTableHeaderCell({ column: { header, id, align, headerStyle, so
|
|
|
46
52
|
right: 0,
|
|
47
53
|
left: 0,
|
|
48
54
|
bottom: 0,
|
|
49
|
-
} }, headerStyle)) }, { children: _jsxs(TableHeaderInner, Object.assign({ onClick: handleHeaderInnerClick }, { children: [typeof header === 'function' ? (header()) : (_jsx(Box, Object.assign({ "data-testid": "SheetViewTableHeader_columns_header", sx: { maxWidth: '100%', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, { children: header && _jsx(HeaderText, Object.assign({ "data-testid": "SheetViewVirtualTable_TableHeader_StyledCell_header_text" }, { children: header })) }))),
|
|
55
|
+
} }, headerStyle)) }, { children: _jsxs(TableHeaderInner, Object.assign({ onClick: handleHeaderInnerClick }, { children: [typeof header === 'function' ? (header()) : (_jsx(Box, Object.assign({ "data-testid": "SheetViewTableHeader_columns_header", sx: { maxWidth: '100%', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, { children: header && _jsx(HeaderText, Object.assign({ "data-testid": "SheetViewVirtualTable_TableHeader_StyledCell_header_text" }, { children: header })) }))), memoizedFilterProps && _jsx(ColumnFilter, Object.assign({}, memoizedFilterProps)), sortable && (_jsx(ColumnSort, { columnId: id, onColumnSort: onColumnSort, columnsSorting: columnsSorting, onClick: (e) => {
|
|
50
56
|
onColumnClick === null || onColumnClick === void 0 ? void 0 : onColumnClick(colIndex, e, pinned);
|
|
51
57
|
} })), isPinnable && pinnable && !isDefaultPinned && !isLast && (_jsx(PinIconContainer, Object.assign({ onClick: (event) => {
|
|
52
58
|
event.stopPropagation();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { memo, useMemo } from 'react';
|
|
2
|
+
import { memo, useCallback, useMemo } from 'react';
|
|
3
3
|
import Box from '@mui/material/Box';
|
|
4
4
|
import Popper from '@mui/material/Popper';
|
|
5
5
|
import { closeIcon, columnIcon, whiteFilterIcon } from '../../../../constants/index.js';
|
|
@@ -9,18 +9,22 @@ import { FilterWrapper } from './style';
|
|
|
9
9
|
import CustomBackdrop from '../../../CustomBackdrop';
|
|
10
10
|
function ColumnFilter(filter) {
|
|
11
11
|
const { anchorEl, setAnchorEl, onClose } = filter;
|
|
12
|
-
const onCloseDropdown = (event) => {
|
|
12
|
+
const onCloseDropdown = useCallback((event) => {
|
|
13
13
|
event.stopPropagation();
|
|
14
14
|
setAnchorEl(null);
|
|
15
15
|
onClose === null || onClose === void 0 ? void 0 : onClose(event);
|
|
16
|
-
};
|
|
17
|
-
const filterData = useMemo(() => { var _a; return ((_a = filter === null || filter === void 0 ? void 0 : filter.options) === null || _a === void 0 ? void 0 : _a.reduce((acc, { apiKey }) => { var _a; return (Object.assign(Object.assign({}, acc), { [apiKey]: (_a = filter === null || filter === void 0 ? void 0 : filter.data) === null || _a === void 0 ? void 0 : _a[apiKey] })); }, {})) || {}; }, [filter]);
|
|
16
|
+
}, [setAnchorEl, onClose]);
|
|
17
|
+
const filterData = useMemo(() => { var _a; return ((_a = filter === null || filter === void 0 ? void 0 : filter.options) === null || _a === void 0 ? void 0 : _a.reduce((acc, { apiKey }) => { var _a; return (Object.assign(Object.assign({}, acc), { [apiKey]: (_a = filter === null || filter === void 0 ? void 0 : filter.data) === null || _a === void 0 ? void 0 : _a[apiKey] })); }, {})) || {}; }, [filter === null || filter === void 0 ? void 0 : filter.options, filter === null || filter === void 0 ? void 0 : filter.data]);
|
|
18
|
+
// Extract derived values for better memoization
|
|
19
|
+
const isListType = filter.type === 'list';
|
|
20
|
+
const listApiKey = isListType ? filter.apiKey : '';
|
|
18
21
|
const listFilterData = useMemo(() => {
|
|
19
22
|
var _a;
|
|
20
|
-
|
|
21
|
-
|
|
23
|
+
if (!isListType)
|
|
24
|
+
return [];
|
|
25
|
+
const rawData = (_a = filter === null || filter === void 0 ? void 0 : filter.data) === null || _a === void 0 ? void 0 : _a[listApiKey];
|
|
22
26
|
return Array.isArray(rawData) ? rawData : [];
|
|
23
|
-
}, [filter]);
|
|
27
|
+
}, [isListType, filter === null || filter === void 0 ? void 0 : filter.data, listApiKey]);
|
|
24
28
|
const showClearIcon = useMemo(() => Object.values(filterData || {}).some((value) => {
|
|
25
29
|
if (typeof value === 'string' || Array.isArray(value))
|
|
26
30
|
return value.length > 0;
|
|
@@ -29,11 +33,16 @@ function ColumnFilter(filter) {
|
|
|
29
33
|
const open = Boolean(anchorEl);
|
|
30
34
|
const filterApiKeys = useMemo(() => {
|
|
31
35
|
var _a;
|
|
32
|
-
if (
|
|
33
|
-
return [
|
|
36
|
+
if (isListType) {
|
|
37
|
+
return [listApiKey];
|
|
34
38
|
}
|
|
35
39
|
return (_a = ((filter === null || filter === void 0 ? void 0 : filter.options) || [])) === null || _a === void 0 ? void 0 : _a.map(({ apiKey }) => apiKey);
|
|
36
|
-
}, [filter]);
|
|
40
|
+
}, [isListType, listApiKey, filter === null || filter === void 0 ? void 0 : filter.options]);
|
|
41
|
+
const clearHandler = useCallback((e) => {
|
|
42
|
+
e.stopPropagation();
|
|
43
|
+
setAnchorEl(null);
|
|
44
|
+
filter.onClear(filterApiKeys);
|
|
45
|
+
}, [setAnchorEl, filter, filterApiKeys]);
|
|
37
46
|
const renderFilter = useMemo(() => {
|
|
38
47
|
if (filter.type === 'list')
|
|
39
48
|
return _jsx(List, { onCloseDropdown: onCloseDropdown, filter: filter });
|
|
@@ -48,11 +57,7 @@ function ColumnFilter(filter) {
|
|
|
48
57
|
return filter.render(componentSharedProps);
|
|
49
58
|
}
|
|
50
59
|
return null;
|
|
51
|
-
}, [
|
|
52
|
-
return (_jsxs(_Fragment, { children: [showClearIcon ? (_jsxs(FilterWrapper, { children: [_jsx(Box, { component: "img", "data-testid": "ColumnFilter_whiteFilterIcon", src: whiteFilterIcon, alt: "filter-icon", sx: { marginInlineEnd: '2px', height: 6 } }), _jsx(Box, { component: "img", "data-testid": "ColumnFilter_closeIcon", src: closeIcon, alt: "close-icon", onClick: (
|
|
53
|
-
e.stopPropagation();
|
|
54
|
-
setAnchorEl(null);
|
|
55
|
-
filter.onClear(filterApiKeys);
|
|
56
|
-
} })] })) : (_jsx(Box, { component: "img", "data-testid": "ColumnFilter_columnIcon", src: columnIcon, alt: "column-icon", sx: { cursor: 'pointer', marginTop: '2px', userSelect: 'none' } })), open && _jsx(CustomBackdrop, { onClick: onCloseDropdown }), _jsx(Popper, Object.assign({ open: open, anchorEl: anchorEl, placement: "bottom-start" }, { children: renderFilter }))] }));
|
|
60
|
+
}, [filter, onCloseDropdown, anchorEl, setAnchorEl]);
|
|
61
|
+
return (_jsxs(_Fragment, { children: [showClearIcon ? (_jsxs(FilterWrapper, { children: [_jsx(Box, { component: "img", "data-testid": "ColumnFilter_whiteFilterIcon", src: whiteFilterIcon, alt: "filter-icon", sx: { marginInlineEnd: '2px', height: 6 } }), _jsx(Box, { component: "img", "data-testid": "ColumnFilter_closeIcon", src: closeIcon, alt: "close-icon", onClick: clearHandler })] })) : (_jsx(Box, { component: "img", "data-testid": "ColumnFilter_columnIcon", src: columnIcon, alt: "column-icon", sx: { cursor: 'pointer', marginTop: '2px', userSelect: 'none' } })), open && _jsx(CustomBackdrop, { onClick: onCloseDropdown }), _jsx(Popper, Object.assign({ open: open, anchorEl: anchorEl, placement: "bottom-start" }, { children: renderFilter }))] }));
|
|
57
62
|
}
|
|
58
63
|
export default memo(ColumnFilter);
|
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.136-test.
|
|
5
|
-
"testVersion":
|
|
4
|
+
"version": "0.1.136-test.5",
|
|
5
|
+
"testVersion": 5,
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "build/index.js",
|
|
8
8
|
"module": "build/index.js",
|