@tap-payments/os-micro-frontend-shared 0.1.399 → 0.1.401
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 +3 -1
- package/build/components/VirtualTables/SheetViewVirtualTable/types.d.ts +1 -0
- package/build/components/VirtualTables/VirtualTable/VirtualTable.js +2 -2
- package/build/components/VirtualTables/components/ColumnFilter/ColumnFilter.d.ts +1 -1
- package/build/components/VirtualTables/components/ColumnFilter/ColumnFilter.js +16 -28
- package/build/components/VirtualTables/components/ColumnFilter/type.d.ts +2 -0
- package/build/components/VirtualTables/components/TableHeader/TableHeader.d.ts +1 -1
- package/build/components/VirtualTables/components/TableHeader/TableHeader.js +2 -2
- package/build/components/VirtualTables/components/TableHeader/components/TableCell/TableCell.d.ts +2 -1
- package/build/components/VirtualTables/components/TableHeader/components/TableCell/TableCell.js +4 -2
- package/build/components/VirtualTables/components/TableHeader/type.d.ts +1 -0
- package/build/components/VirtualTables/components/style.d.ts +1 -3
- package/build/components/VirtualTables/components/style.js +17 -2
- package/build/components/VirtualTables/hooks/useColumnFilter.d.ts +10 -0
- package/build/components/VirtualTables/hooks/useColumnFilter.js +22 -0
- package/build/types/merchant.d.ts +1 -0
- package/package.json +1 -1
package/build/components/VirtualTables/SheetViewVirtualTable/components/SheetViewTableHeaderCell.js
CHANGED
|
@@ -8,11 +8,13 @@ import { PinIconContainer, HeaderText } from '../style';
|
|
|
8
8
|
import ColumnSort from '../../components/ColumnSort';
|
|
9
9
|
import { ColumnResize } from '../features/resize';
|
|
10
10
|
import { getColumnId } from '../features/resize/utils/resize';
|
|
11
|
+
import useColumnFilter from '../../../VirtualTables/hooks/useColumnFilter';
|
|
11
12
|
function SheetViewTableHeaderCell({ column: { header, id, tableViewId, align, headerStyle, sortable, filter, pinnable, width, order, pinned }, colIndex, isFirst, isLast, isSelected, isDefaultPinned, onColumnSort, columnsSorting, onColumnPin, isPinnable, lastColumnId, onColumnClick, pinnedColumns, onStartResize, isResizing = false, resizingColumn = null, }) {
|
|
12
13
|
// Use the same unique column ID logic as resize to ensure consistency
|
|
13
14
|
const columnId = getColumnId({ id, tableViewId });
|
|
14
15
|
const [columnFilterEl, setColumnFilterEl] = useState(null);
|
|
15
16
|
const cellRef = useRef(null);
|
|
17
|
+
const { isFilterApplied } = useColumnFilter({ filter });
|
|
16
18
|
const checkIsPanned = useCallback((columnId) => pinnedColumns === null || pinnedColumns === void 0 ? void 0 : pinnedColumns.includes(columnId), [pinnedColumns]);
|
|
17
19
|
const isPinned = useMemo(() => checkIsPanned(id), [id, checkIsPanned]);
|
|
18
20
|
const handlePinClick = (columnId) => {
|
|
@@ -50,7 +52,7 @@ function SheetViewTableHeaderCell({ column: { header, id, tableViewId, align, he
|
|
|
50
52
|
right: 0,
|
|
51
53
|
left: 0,
|
|
52
54
|
bottom: 0,
|
|
53
|
-
} }, 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 })) }))), filter && _jsx(ColumnFilter, Object.assign({}, filter, { anchorEl: columnFilterEl, setAnchorEl: setColumnFilterEl })), sortable && (_jsx(ColumnSort, { columnId: id, onColumnSort: onColumnSort, columnsSorting: columnsSorting, onClick: (e) => {
|
|
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 })) }))), filter && _jsx(ColumnFilter, Object.assign({}, filter, { anchorEl: columnFilterEl, setAnchorEl: setColumnFilterEl, isFilterApplied: isFilterApplied })), sortable && (_jsx(ColumnSort, { columnId: id, onColumnSort: onColumnSort, columnsSorting: columnsSorting, onClick: (e) => {
|
|
54
56
|
onColumnClick === null || onColumnClick === void 0 ? void 0 : onColumnClick(colIndex, e, pinned);
|
|
55
57
|
} })), isPinnable && pinnable && !isDefaultPinned && !isLast && (_jsx(PinIconContainer, Object.assign({ onClick: (event) => {
|
|
56
58
|
event.stopPropagation();
|
|
@@ -27,6 +27,7 @@ export interface SheetViewTableHeaderProps {
|
|
|
27
27
|
onStartResize?: (e: React.MouseEvent, columnId: string) => void;
|
|
28
28
|
isResizing?: boolean;
|
|
29
29
|
resizingColumn?: string | null;
|
|
30
|
+
totalCount?: number;
|
|
30
31
|
}
|
|
31
32
|
export interface VirtualTableContainerProps {
|
|
32
33
|
columnsData: IColumnProps[];
|
|
@@ -35,7 +35,7 @@ const createItemData = memoize((columns, isLoading, rows, rowProps, scrollToInde
|
|
|
35
35
|
isSheetView,
|
|
36
36
|
}));
|
|
37
37
|
function VirtualTable({ columns, rows, threshold = TABLE_THRESHOLD, showHeader, headerProps, rowProps, footerProps, isLoading, error, columnsSorting, onColumnSort, loadMoreItems, isFetchingNextPage, triggerDataRefetch, scrollToIndex, areAllRowsLoaded = false, tableBodyStyles, tableMode, tableTitle, onStartDrag, isSheetView = false, isMinimized, footerComponent, customNoDataComponent, }) {
|
|
38
|
-
var _a;
|
|
38
|
+
var _a, _b;
|
|
39
39
|
const theme = useTheme();
|
|
40
40
|
const onPointerDown = (e) => {
|
|
41
41
|
onStartDrag === null || onStartDrag === void 0 ? void 0 : onStartDrag(e);
|
|
@@ -100,7 +100,7 @@ function VirtualTable({ columns, rows, threshold = TABLE_THRESHOLD, showHeader,
|
|
|
100
100
|
autoSizerKey,
|
|
101
101
|
]);
|
|
102
102
|
const showNoDataView = tableLoading || tableError || tableEmpty || hasTimeoutError;
|
|
103
|
-
return (_jsxs(_Fragment, { children: [_jsxs(TableContainer, { children: [_jsx(StyledTableBox, Object.assign({ as: "main", id: "table-box-container", "aria-labelledby": "table-box-container", "data-testid": "VirtualTable_StyledTableBox", "data-title": tableTitle, "data-direction": theme.direction, "data-are-all-rows-loaded": !!areAllRowsLoaded, "data-is-fetching-next-page": !!isFetchingNextPage, "data-scroll-to-index": scrollToIndex, "data-is-loading": !!isLoading, "data-is-error": !!isError, "data-is-error-timeout": !!hasTimeoutError, "data-table-mode": tableMode, height: "100%", dir: theme.direction, showNoDataView: showNoDataView }, { children: _jsxs(TableWrapper, Object.assign({ "data-testid": "VirtualTable_TableWrapper", showNoDataView: showNoDataView, sx: Object.assign({}, tableBodyStyles) }, { children: [showHeader && (_jsx(TableHeader, { "data-testid": "VirtualTable_TableHeader", columnsSorting: columnsSorting, onColumnSort: onColumnSort, columns: orderedColumns, headerProps: headerProps, showBackDrop: showBackDrop, isSheetView: isSheetView })), showNoDataView ? (customNoDataComponent ? (customNoDataComponent) : (_jsx(TableNoData, { error: error, tableEmpty: tableEmpty, isTimeoutError: hasTimeoutError, tableError: tableError, tableLoading: tableLoading, orderedColumns: orderedColumns, triggerDataRefetch: triggerDataRefetch, footerProps: footerProps }))) : (_jsx(TableWrapper, Object.assign({ "data-testid": "VirtualTable_TableWrapper", sx: {
|
|
103
|
+
return (_jsxs(_Fragment, { children: [_jsxs(TableContainer, { children: [_jsx(StyledTableBox, Object.assign({ as: "main", id: "table-box-container", "aria-labelledby": "table-box-container", "data-testid": "VirtualTable_StyledTableBox", "data-title": tableTitle, "data-direction": theme.direction, "data-are-all-rows-loaded": !!areAllRowsLoaded, "data-is-fetching-next-page": !!isFetchingNextPage, "data-scroll-to-index": scrollToIndex, "data-is-loading": !!isLoading, "data-is-error": !!isError, "data-is-error-timeout": !!hasTimeoutError, "data-table-mode": tableMode, height: "100%", dir: theme.direction, showNoDataView: showNoDataView }, { children: _jsxs(TableWrapper, Object.assign({ "data-testid": "VirtualTable_TableWrapper", showNoDataView: showNoDataView, sx: Object.assign({}, tableBodyStyles) }, { children: [showHeader && (_jsx(TableHeader, { "data-testid": "VirtualTable_TableHeader", columnsSorting: columnsSorting, onColumnSort: onColumnSort, columns: orderedColumns, headerProps: headerProps, showBackDrop: showBackDrop, isSheetView: isSheetView, totalCount: (_b = footerProps === null || footerProps === void 0 ? void 0 : footerProps.totalCount) !== null && _b !== void 0 ? _b : 0 })), showNoDataView ? (customNoDataComponent ? (customNoDataComponent) : (_jsx(TableNoData, { error: error, tableEmpty: tableEmpty, isTimeoutError: hasTimeoutError, tableError: tableError, tableLoading: tableLoading, orderedColumns: orderedColumns, triggerDataRefetch: triggerDataRefetch, footerProps: footerProps }))) : (_jsx(TableWrapper, Object.assign({ "data-testid": "VirtualTable_TableWrapper", sx: {
|
|
104
104
|
width: '100%',
|
|
105
105
|
minWidth: 'fit-content',
|
|
106
106
|
} }, { children: _jsx(StyledBox, Object.assign({ "data-testid": "VirtualTable_StyledBox", hidePadding: true, className: "list-wrapper" }, { children: renderTableContainer })) })))] })) })), !showNoDataView && areTotalRowsNotFillingHeight && !isFetchingNextPage && (_jsx(TableLastItem
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { ColumnFilterProps } from './type';
|
|
3
|
-
declare function ColumnFilter(
|
|
3
|
+
declare function ColumnFilter(props: ColumnFilterProps): import("react/jsx-runtime").JSX.Element;
|
|
4
4
|
declare const _default: import("react").MemoExoticComponent<typeof ColumnFilter>;
|
|
5
5
|
export default _default;
|
|
@@ -7,52 +7,40 @@ import { closeIcon, columnIcon, whiteFilterIcon } from '../../../../constants/in
|
|
|
7
7
|
import Inputs from './Inputs';
|
|
8
8
|
import List from './List';
|
|
9
9
|
import { FilterWrapper } from './style';
|
|
10
|
-
function ColumnFilter(
|
|
11
|
-
const { anchorEl, setAnchorEl, onClose } =
|
|
10
|
+
function ColumnFilter(props) {
|
|
11
|
+
const { anchorEl, setAnchorEl, onClose, isFilterApplied, disabled } = props;
|
|
12
12
|
const onCloseDropdown = (event) => {
|
|
13
13
|
event.stopPropagation();
|
|
14
14
|
setAnchorEl(null);
|
|
15
15
|
onClose === null || onClose === void 0 ? void 0 : onClose(event);
|
|
16
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]);
|
|
18
|
-
const listFilterData = useMemo(() => {
|
|
19
|
-
var _a;
|
|
20
|
-
const listFilter = filter;
|
|
21
|
-
const rawData = (_a = listFilter === null || listFilter === void 0 ? void 0 : listFilter.data) === null || _a === void 0 ? void 0 : _a[listFilter.apiKey];
|
|
22
|
-
return Array.isArray(rawData) ? rawData : [];
|
|
23
|
-
}, [filter]);
|
|
24
|
-
const showClearIcon = useMemo(() => Object.values(filterData || {}).some((value) => {
|
|
25
|
-
if (typeof value === 'string' || Array.isArray(value))
|
|
26
|
-
return value.length > 0;
|
|
27
|
-
return value != null;
|
|
28
|
-
}) || listFilterData.length > 0, [filterData, listFilterData]);
|
|
29
17
|
const open = Boolean(anchorEl);
|
|
30
18
|
const filterApiKeys = useMemo(() => {
|
|
31
19
|
var _a;
|
|
32
|
-
if (
|
|
33
|
-
return [
|
|
20
|
+
if (props.type === 'list') {
|
|
21
|
+
return [props.apiKey];
|
|
34
22
|
}
|
|
35
|
-
return (_a = ((
|
|
36
|
-
}, [
|
|
23
|
+
return (_a = ((props === null || props === void 0 ? void 0 : props.options) || [])) === null || _a === void 0 ? void 0 : _a.map(({ apiKey }) => apiKey);
|
|
24
|
+
}, [props]);
|
|
37
25
|
const renderFilter = useMemo(() => {
|
|
38
|
-
if (
|
|
39
|
-
return _jsx(List, { onCloseDropdown: onCloseDropdown, filter:
|
|
40
|
-
if (
|
|
41
|
-
return _jsx(Inputs, { onCloseDropdown: onCloseDropdown, filter:
|
|
42
|
-
if (
|
|
26
|
+
if (props.type === 'list')
|
|
27
|
+
return _jsx(List, { onCloseDropdown: onCloseDropdown, filter: props });
|
|
28
|
+
if (props.type === 'inputs')
|
|
29
|
+
return _jsx(Inputs, { onCloseDropdown: onCloseDropdown, filter: props });
|
|
30
|
+
if (props.type === 'custom') {
|
|
43
31
|
const componentSharedProps = {
|
|
44
32
|
anchorEl,
|
|
45
33
|
setAnchorEl,
|
|
46
34
|
onCloseDropdown,
|
|
47
35
|
};
|
|
48
|
-
return
|
|
36
|
+
return props.render(componentSharedProps);
|
|
49
37
|
}
|
|
50
38
|
return null;
|
|
51
|
-
}, [open,
|
|
52
|
-
return (_jsxs(_Fragment, { children: [
|
|
39
|
+
}, [open, props, onCloseDropdown]);
|
|
40
|
+
return (_jsxs(_Fragment, { children: [isFilterApplied ? (_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: (e) => {
|
|
53
41
|
e.stopPropagation();
|
|
54
42
|
setAnchorEl(null);
|
|
55
|
-
|
|
56
|
-
} })] })) : (_jsx(Box, { component: "img", "data-testid": "ColumnFilter_columnIcon", src: columnIcon, alt: "column-icon", sx: {
|
|
43
|
+
props.onClear(filterApiKeys);
|
|
44
|
+
} })] })) : (_jsx(Box, { component: "img", "data-testid": "ColumnFilter_columnIcon", src: columnIcon, alt: "column-icon", sx: { marginTop: '2px', userSelect: 'none', opacity: disabled ? 0.5 : 1 } })), open && _jsx(CustomBackdrop, { onClick: onCloseDropdown }), _jsx(Popper, Object.assign({ open: open, anchorEl: anchorEl, placement: "bottom-start" }, { children: renderFilter }))] }));
|
|
57
45
|
}
|
|
58
46
|
export default memo(ColumnFilter);
|
|
@@ -4,6 +4,8 @@ export type ColumnFilterProps = IColumnFilter & {
|
|
|
4
4
|
anchorEl: HTMLElement | null;
|
|
5
5
|
setAnchorEl: (el: HTMLElement | null) => void;
|
|
6
6
|
onClose?: (e: MouseEvent<HTMLElement>) => void;
|
|
7
|
+
isFilterApplied: boolean;
|
|
8
|
+
disabled?: boolean;
|
|
7
9
|
};
|
|
8
10
|
export interface CustomColumnFilterProps extends Pick<ColumnFilterProps, 'anchorEl' | 'setAnchorEl'> {
|
|
9
11
|
onCloseDropdown: (e: MouseEvent<HTMLElement>) => void;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { TableHeaderProps } from './type';
|
|
3
|
-
declare function TableHeader({ columns, headerProps, showBackDrop, onColumnSort, columnsSorting, isSheetView }: TableHeaderProps): import("react/jsx-runtime").JSX.Element;
|
|
3
|
+
declare function TableHeader({ columns, headerProps, showBackDrop, onColumnSort, columnsSorting, isSheetView, totalCount }: TableHeaderProps): import("react/jsx-runtime").JSX.Element;
|
|
4
4
|
declare const _default: import("react").MemoExoticComponent<typeof TableHeader>;
|
|
5
5
|
export default _default;
|
|
@@ -2,9 +2,9 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { memo } from 'react';
|
|
3
3
|
import { TableCell } from './components';
|
|
4
4
|
import { StyledHeader, StyledMUITableRow } from './style';
|
|
5
|
-
function TableHeader({ columns, headerProps, showBackDrop, onColumnSort, columnsSorting, isSheetView }) {
|
|
5
|
+
function TableHeader({ columns, headerProps, showBackDrop, onColumnSort, columnsSorting, isSheetView, totalCount }) {
|
|
6
6
|
return (_jsx(StyledHeader, Object.assign({ component: "nav", "data-testid": "VirtualTable_TableHeader_StyledHeader", showBackDrop: showBackDrop }, headerProps, { children: _jsx(StyledMUITableRow, Object.assign({ component: "section", "data-testid": "VirtualTable_TableHeader_StyledMUITableRow", isSheetView: isSheetView }, { children: columns.map((column, colIndex) => {
|
|
7
|
-
return (_jsx(TableCell, { column: column, isFirst: column.id === columns[0].id, isLast: column.id === columns[columns.length - 1].id, onColumnSort: onColumnSort, columnsSorting: columnsSorting, isSheetView: isSheetView }, `${column.id}-${colIndex}`));
|
|
7
|
+
return (_jsx(TableCell, { column: column, isFirst: column.id === columns[0].id, isLast: column.id === columns[columns.length - 1].id, onColumnSort: onColumnSort, columnsSorting: columnsSorting, isSheetView: isSheetView, totalCount: totalCount }, `${column.id}-${colIndex}`));
|
|
8
8
|
}) })) })));
|
|
9
9
|
}
|
|
10
10
|
export default memo(TableHeader);
|
package/build/components/VirtualTables/components/TableHeader/components/TableCell/TableCell.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ interface TableCellProps extends Pick<TableHeaderProps, 'onColumnSort' | 'isShee
|
|
|
4
4
|
column: IColumnProps;
|
|
5
5
|
isFirst: boolean;
|
|
6
6
|
isLast: boolean;
|
|
7
|
+
totalCount?: number;
|
|
7
8
|
}
|
|
8
|
-
export declare function TableCell({ column: { header, id, align, headerStyle, sortable, filter, width, order }, isFirst, isLast, isSheetView, onColumnSort, columnsSorting, }: TableCellProps): import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
export declare function TableCell({ column: { header, id, align, headerStyle, sortable, filter, width, order }, isFirst, isLast, isSheetView, onColumnSort, columnsSorting, totalCount, }: TableCellProps): import("react/jsx-runtime").JSX.Element;
|
|
9
10
|
export {};
|
package/build/components/VirtualTables/components/TableHeader/components/TableCell/TableCell.js
CHANGED
|
@@ -4,11 +4,13 @@ import Box from '@mui/material/Box';
|
|
|
4
4
|
import ColumnFilter from '../../../../../VirtualTables/components/ColumnFilter';
|
|
5
5
|
import ColumnSort from '../../../../../VirtualTables/components/ColumnSort';
|
|
6
6
|
import { StyledCell, TableHeaderInner } from '../../../../../VirtualTables/components/style';
|
|
7
|
-
|
|
7
|
+
import useColumnFilter from '../../../../../VirtualTables/hooks/useColumnFilter';
|
|
8
|
+
export function TableCell({ column: { header, id, align, headerStyle, sortable, filter, width, order }, isFirst, isLast, isSheetView, onColumnSort, columnsSorting, totalCount, }) {
|
|
8
9
|
const [columnFilterEl, setColumnFilterEl] = useState(null);
|
|
9
10
|
const cellRef = useRef(null);
|
|
11
|
+
const { isFilterApplied, filterDisabled } = useColumnFilter({ filter, totalCount });
|
|
10
12
|
const onOpenFilterDropdown = () => {
|
|
11
13
|
setColumnFilterEl(cellRef.current);
|
|
12
14
|
};
|
|
13
|
-
return (_jsx(StyledCell, Object.assign({ "data-id": id, component: "div", "data-testid": "VirtualTable_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, isFirst: isFirst, isLast: isLast, ref: cellRef, sx: (theme) => (Object.assign({ paddingInline: '0.6875rem', paddingLeft: isFirst ? '0' : '0.6875rem', paddingRight: isLast ? '0' : '0.6875rem', display: 'flex', gap: theme.spacing(0.5), alignItems: 'center', justifyContent: align === 'right' ? 'flex-end' : 'flex-start', width: width, textAlign: align, overflow: 'unset', fontWeight: 600 }, headerStyle)), isSheetView: isSheetView }, { children: _jsxs(TableHeaderInner, Object.assign({ onClick: onOpenFilterDropdown }, { children: [typeof header === 'function' ? (header()) : (_jsx(Box, Object.assign({ "data-testid": "TableHeader_columns_header", sx: { maxWidth: '100%', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, { children: header && (_jsx("span", Object.assign({ style: { textOverflow: 'ellipsis', width: '80%', overflow: 'hidden' }, "data-testid": "VirtualTable_TableHeader_StyledCell_header_text" }, { children: header }))) }))), filter && _jsx(ColumnFilter, Object.assign({}, filter, { anchorEl: columnFilterEl, setAnchorEl: setColumnFilterEl })), sortable && _jsx(ColumnSort, { onColumnSort: onColumnSort, columnsSorting: columnsSorting, columnId: id })] })) })));
|
|
15
|
+
return (_jsx(StyledCell, Object.assign({ "data-id": id, component: "div", "data-testid": "VirtualTable_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, isFirst: isFirst, isLast: isLast, ref: cellRef, sx: (theme) => (Object.assign(Object.assign({ paddingInline: '0.6875rem', paddingLeft: isFirst ? '0' : '0.6875rem', paddingRight: isLast ? '0' : '0.6875rem', display: 'flex', gap: theme.spacing(0.5), alignItems: 'center', justifyContent: align === 'right' ? 'flex-end' : 'flex-start', width: width, textAlign: align, overflow: 'unset', fontWeight: 600 }, (filterDisabled && { cursor: 'not-allowed' })), headerStyle)), isSheetView: isSheetView }, { children: _jsxs(TableHeaderInner, Object.assign({ disabled: filterDisabled, onClick: onOpenFilterDropdown }, { children: [typeof header === 'function' ? (header()) : (_jsx(Box, Object.assign({ "data-testid": "TableHeader_columns_header", sx: { maxWidth: '100%', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, { children: header && (_jsx("span", Object.assign({ style: { textOverflow: 'ellipsis', width: '80%', overflow: 'hidden' }, "data-testid": "VirtualTable_TableHeader_StyledCell_header_text" }, { children: header }))) }))), filter && (_jsx(ColumnFilter, Object.assign({}, filter, { anchorEl: columnFilterEl, setAnchorEl: setColumnFilterEl, isFilterApplied: isFilterApplied, disabled: filterDisabled }))), sortable && _jsx(ColumnSort, { onColumnSort: onColumnSort, columnsSorting: columnsSorting, columnId: id })] })) })));
|
|
14
16
|
}
|
|
@@ -20,9 +20,7 @@ export declare const StyledCell: import("@emotion/styled").StyledComponent<impor
|
|
|
20
20
|
isSheetView?: boolean | undefined;
|
|
21
21
|
isSelected?: boolean | undefined;
|
|
22
22
|
}, {}, {}>;
|
|
23
|
-
export declare const TableHeaderInner: import("@emotion/styled").StyledComponent<import("@mui/system").
|
|
24
|
-
ref?: ((instance: HTMLDivElement | null) => void) | import("react").RefObject<HTMLDivElement> | null | undefined;
|
|
25
|
-
}, keyof import("@mui/system").BoxOwnProps<import("@mui/material").Theme>> & import("@mui/system").MUIStyledCommonProps<import("@mui/material").Theme>, {}, {}>;
|
|
23
|
+
export declare const TableHeaderInner: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material").Theme>, import("react").DetailedHTMLProps<import("react").ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, {}>;
|
|
26
24
|
interface StyledVirtualListProps {
|
|
27
25
|
areTotalRowsNotFillingHeight: boolean;
|
|
28
26
|
isSheetView?: boolean;
|
|
@@ -51,12 +51,27 @@ export const StyledCell = styled(TableCell, {
|
|
|
51
51
|
},
|
|
52
52
|
}));
|
|
53
53
|
});
|
|
54
|
-
export const TableHeaderInner = styled(
|
|
54
|
+
export const TableHeaderInner = styled('button')(({ theme }) => ({
|
|
55
55
|
zIndex: 1,
|
|
56
56
|
display: 'flex',
|
|
57
57
|
gap: theme.spacing(0.5),
|
|
58
58
|
alignItems: 'center',
|
|
59
|
-
overflow: 'hidden
|
|
59
|
+
overflow: 'hidden',
|
|
60
|
+
maxWidth: '100%',
|
|
61
|
+
textOverflow: 'ellipsis',
|
|
62
|
+
whiteSpace: 'nowrap',
|
|
63
|
+
backgroundColor: 'transparent',
|
|
64
|
+
border: 'none',
|
|
65
|
+
cursor: 'pointer',
|
|
66
|
+
padding: 0,
|
|
67
|
+
margin: 0,
|
|
68
|
+
color: 'inherit',
|
|
69
|
+
fontSize: 'inherit',
|
|
70
|
+
fontWeight: 'inherit',
|
|
71
|
+
boxSizing: 'border-box',
|
|
72
|
+
':disabled': {
|
|
73
|
+
cursor: 'not-allowed',
|
|
74
|
+
},
|
|
60
75
|
}));
|
|
61
76
|
export const StyledVirtualList = styled(VirtualScrollList, {
|
|
62
77
|
shouldForwardProp: (prop) => !['areTotalRowsNotFillingHeight', 'isSheetView'].includes(prop),
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { IColumnFilter } from '../../../types/index.js';
|
|
2
|
+
type UseColumnFilterParams = {
|
|
3
|
+
filter?: IColumnFilter;
|
|
4
|
+
totalCount?: number;
|
|
5
|
+
};
|
|
6
|
+
declare const useColumnFilter: (params: UseColumnFilterParams) => {
|
|
7
|
+
isFilterApplied: boolean;
|
|
8
|
+
filterDisabled: boolean;
|
|
9
|
+
};
|
|
10
|
+
export default useColumnFilter;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
const useColumnFilter = (params) => {
|
|
3
|
+
const { filter, totalCount } = params;
|
|
4
|
+
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]);
|
|
5
|
+
const listFilterData = useMemo(() => {
|
|
6
|
+
var _a;
|
|
7
|
+
const listFilter = filter;
|
|
8
|
+
const rawData = (_a = listFilter === null || listFilter === void 0 ? void 0 : listFilter.data) === null || _a === void 0 ? void 0 : _a[listFilter.apiKey];
|
|
9
|
+
return Array.isArray(rawData) ? rawData : [];
|
|
10
|
+
}, [filter]);
|
|
11
|
+
const isFilterApplied = useMemo(() => Object.values(filterData || {}).some((value) => {
|
|
12
|
+
if (typeof value === 'string' || Array.isArray(value))
|
|
13
|
+
return value.length > 0;
|
|
14
|
+
return value != null;
|
|
15
|
+
}) || listFilterData.length > 0, [filterData, listFilterData]);
|
|
16
|
+
const filterDisabled = !isFilterApplied && totalCount === 0;
|
|
17
|
+
return {
|
|
18
|
+
isFilterApplied,
|
|
19
|
+
filterDisabled,
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
export default useColumnFilter;
|
package/package.json
CHANGED