@tap-payments/os-micro-frontend-shared 0.0.258-test.3 → 0.0.258-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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2025 Tap Payments
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Tap Payments
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,12 +1,12 @@
1
- # os-micro-frontend-shared
2
-
3
- ## Publishing Workflow
4
-
5
- 1. Update version in package.json
6
- 2. Commit changes
7
- 3. Create and push a tag:
8
-
9
- ```bash
10
- npm version patch # or minor, major
11
- git push origin main --tags
12
- ```
1
+ # os-micro-frontend-shared
2
+
3
+ ## Publishing Workflow
4
+
5
+ 1. Update version in package.json
6
+ 2. Commit changes
7
+ 3. Create and push a tag:
8
+
9
+ ```bash
10
+ npm version patch # or minor, major
11
+ git push origin main --tags
12
+ ```
@@ -13,11 +13,7 @@ interface SheetViewTableHeaderProps {
13
13
  lastColumnId?: string | null;
14
14
  selectedColumn?: string | null;
15
15
  onColumnClick?: (columnId: string, event: React.MouseEvent) => void;
16
- openFilterColumnId?: string | null;
17
- filterAnchorEl?: HTMLElement | null;
18
- onFilterOpen?: (columnId: string, anchorEl: HTMLElement) => void;
19
- onFilterClose?: () => void;
20
16
  }
21
- declare function SheetViewTableHeader({ columns, headerProps, showBackDrop, onColumnSort, columnsSorting, pinnedColumns, onColumnPin, isPinnable, lastColumnId, selectedColumn, onColumnClick, openFilterColumnId: externalOpenFilterColumnId, filterAnchorEl: externalFilterAnchorEl, onFilterOpen: externalOnFilterOpen, onFilterClose: externalOnFilterClose, }: SheetViewTableHeaderProps): import("react/jsx-runtime").JSX.Element;
17
+ declare function SheetViewTableHeader({ columns, headerProps, showBackDrop, onColumnSort, columnsSorting, pinnedColumns, onColumnPin, isPinnable, lastColumnId, selectedColumn, onColumnClick, }: SheetViewTableHeaderProps): import("react/jsx-runtime").JSX.Element;
22
18
  declare const _default: import("react").MemoExoticComponent<typeof SheetViewTableHeader>;
23
19
  export default _default;
@@ -6,44 +6,22 @@ import { columnIcon, pinIcon, sortAzIcon, sortZaIcon, unpinIcon } from '../../..
6
6
  import ColumnFilter from '../components/ColumnFilter';
7
7
  import { StyledCell } from '../style';
8
8
  import { ActionIcon, ColumnIcon, PinIconContainer, StyledHeader, StyledMUITableRow, HeaderText } from './style';
9
- function SheetViewTableHeader({ columns, headerProps, showBackDrop, onColumnSort, columnsSorting, pinnedColumns = [], onColumnPin, isPinnable = false, lastColumnId, selectedColumn = null, onColumnClick, openFilterColumnId: externalOpenFilterColumnId, filterAnchorEl: externalFilterAnchorEl, onFilterOpen: externalOnFilterOpen, onFilterClose: externalOnFilterClose, }) {
10
- const [sortAnchorEl, setSortAnchorEl] = useState(null);
11
- const sortOpen = Boolean(sortAnchorEl);
12
- const [internalOpenFilterColumnId, setInternalOpenFilterColumnId] = useState(null);
13
- const [internalFilterAnchorEl, setInternalFilterAnchorEl] = useState(null);
14
- const openFilterColumnId = externalOpenFilterColumnId !== undefined ? externalOpenFilterColumnId : internalOpenFilterColumnId;
15
- const filterAnchorEl = externalFilterAnchorEl !== undefined ? externalFilterAnchorEl : internalFilterAnchorEl;
9
+ function SheetViewTableHeader({ columns, headerProps, showBackDrop, onColumnSort, columnsSorting, pinnedColumns = [], onColumnPin, isPinnable = false, lastColumnId, selectedColumn = null, onColumnClick, }) {
10
+ const [anchorEl, setAnchorEl] = useState(null);
11
+ const open = Boolean(anchorEl);
16
12
  const theme = useTheme();
17
- const handleSortClick = (event) => {
18
- setSortAnchorEl(event.currentTarget);
13
+ const handleClick = (event) => {
14
+ setAnchorEl(event.currentTarget);
19
15
  };
20
- const handleSortClose = () => {
21
- setSortAnchorEl(null);
22
- };
23
- const handleFilterOpen = (columnId) => (event) => {
24
- if (externalOnFilterOpen) {
25
- externalOnFilterOpen(columnId, event.currentTarget);
26
- }
27
- else {
28
- setInternalOpenFilterColumnId(columnId);
29
- setInternalFilterAnchorEl(event.currentTarget);
30
- }
31
- };
32
- const handleFilterClose = () => {
33
- if (externalOnFilterClose) {
34
- externalOnFilterClose();
35
- }
36
- else {
37
- setInternalOpenFilterColumnId(null);
38
- setInternalFilterAnchorEl(null);
39
- }
16
+ const handleClose = () => {
17
+ setAnchorEl(null);
40
18
  };
41
19
  const handleSortingOption = (columnId, order) => {
42
20
  if (columnId) {
43
21
  onColumnSort === null || onColumnSort === void 0 ? void 0 : onColumnSort({
44
22
  [columnId]: order,
45
23
  });
46
- handleSortClose();
24
+ handleClose();
47
25
  }
48
26
  };
49
27
  const handlePinClick = (columnId) => {
@@ -67,32 +45,27 @@ function SheetViewTableHeader({ columns, headerProps, showBackDrop, onColumnSort
67
45
  const isPinned = pinnedColumns.includes(id);
68
46
  const isDefaultPinned = !!column.isDefaultPinned;
69
47
  const isSelected = selectedColumn === id;
70
- return (_jsxs(StyledCell, Object.assign({ "data-id": id, component: "div", "data-testid": "SheetViewVirtualTable_TableHeader_StyledCell", "data-column-id": column.id, "data-column-width": column.width, "data-column-width-used": column.width, "data-column-align": column.align, "data-column-order": column.order, "data-column-header": typeof column.header === 'string' ? column.header : 'component', "data-column-sortable": !!column.sortable, "data-column-filterable": !!column.filter, "data-column-pinned": isPinned, isFirst: isFirst, isLast: isLast, isSheetView: true, onClick: (event) => onColumnClick === null || onColumnClick === void 0 ? void 0 : onColumnClick(id, event), sx: Object.assign({ display: 'flex', gap: theme.spacing(0.5), alignItems: 'center', justifyContent: align === 'right' ? 'flex-end' : 'flex-start', width: column.width, textAlign: align, overflow: 'unset', cursor: 'pointer', boxSizing: 'border-box', border: isSelected ? '2px solid #1F88D0' : '1px solid #F2F2F2', backgroundColor: isSelected ? '#F2F2F2' : '#FCFCFC', height: isSelected ? '100%' : 'auto', minHeight: isSelected ? '28px' : 'auto' }, headerStyle) }, { 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, { externalAnchorEl: openFilterColumnId === id ? filterAnchorEl : null, externalOpen: openFilterColumnId === id, onExternalOpen: handleFilterOpen(id), onExternalClose: handleFilterClose }))), sortable && (_jsx(ColumnIcon, { onClick: sortable
71
- ? (event) => {
72
- event.stopPropagation();
73
- handleSortClick(event);
74
- }
75
- : undefined, src: columnIcon, alt: "column-icon", "data-id": id })), isPinnable && pinnable && !isDefaultPinned && !isLast && (_jsx(PinIconContainer, Object.assign({ onClick: (event) => {
48
+ return (_jsxs(StyledCell, Object.assign({ "data-id": id, component: "div", "data-testid": "SheetViewVirtualTable_TableHeader_StyledCell", "data-column-id": column.id, "data-column-width": column.width, "data-column-width-used": column.width, "data-column-align": column.align, "data-column-order": column.order, "data-column-header": typeof column.header === 'string' ? column.header : 'component', "data-column-sortable": !!column.sortable, "data-column-filterable": !!column.filter, "data-column-pinned": isPinned, isFirst: isFirst, isLast: isLast, isSheetView: true, onClick: (event) => onColumnClick === null || onColumnClick === void 0 ? void 0 : onColumnClick(id, event), sx: Object.assign({ display: 'flex', gap: theme.spacing(0.5), alignItems: 'center', justifyContent: align === 'right' ? 'flex-end' : 'flex-start', width: column.width, textAlign: align, overflow: 'unset', cursor: 'pointer', boxSizing: 'border-box', border: isSelected ? '2px solid #1F88D0' : '1px solid #F2F2F2', backgroundColor: isSelected ? '#F2F2F2' : '#FCFCFC', height: isSelected ? '100%' : 'auto', minHeight: isSelected ? '28px' : 'auto' }, headerStyle) }, { 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)), sortable && _jsx(ColumnIcon, { onClick: sortable ? handleClick : undefined, src: columnIcon, alt: "column-icon", "data-id": id }), isPinnable && pinnable && !isDefaultPinned && !isLast && (_jsx(PinIconContainer, Object.assign({ onClick: (event) => {
76
49
  event.stopPropagation();
77
50
  handlePinClick(id);
78
51
  }, title: isPinned ? 'Unpin column' : 'Pin column' }, { children: _jsx("img", { src: isPinned ? unpinIcon : pinIcon, alt: "pin-icon" }) })))] }), `${id}-${colIndex}`));
79
- }) })), _jsx(Dropdown, { open: sortOpen, onClose: handleSortClose, anchorEl: sortAnchorEl, menuItems: [
52
+ }) })), _jsx(Dropdown, { open: open, onClose: handleClose, anchorEl: anchorEl, menuItems: [
80
53
  {
81
54
  label: 'Sort A-Z',
82
55
  name: 'asc',
83
56
  icon: _jsx(ActionIcon, { src: sortAzIcon, alt: "sort-icon" }),
84
- selected: (columnsSorting === null || columnsSorting === void 0 ? void 0 : columnsSorting[(sortAnchorEl === null || sortAnchorEl === void 0 ? void 0 : sortAnchorEl.dataset.id) || '']) === 'asc',
57
+ selected: (columnsSorting === null || columnsSorting === void 0 ? void 0 : columnsSorting[(anchorEl === null || anchorEl === void 0 ? void 0 : anchorEl.dataset.id) || '']) === 'asc',
85
58
  onClick: () => {
86
- handleSortingOption(sortAnchorEl === null || sortAnchorEl === void 0 ? void 0 : sortAnchorEl.dataset.id, 'asc');
59
+ handleSortingOption(anchorEl === null || anchorEl === void 0 ? void 0 : anchorEl.dataset.id, 'asc');
87
60
  },
88
61
  },
89
62
  {
90
63
  label: 'Sort Z-A',
91
64
  name: 'desc',
92
65
  icon: _jsx(ActionIcon, { src: sortZaIcon, alt: "sort-icon" }),
93
- selected: (columnsSorting === null || columnsSorting === void 0 ? void 0 : columnsSorting[(sortAnchorEl === null || sortAnchorEl === void 0 ? void 0 : sortAnchorEl.dataset.id) || '']) === 'desc',
66
+ selected: (columnsSorting === null || columnsSorting === void 0 ? void 0 : columnsSorting[(anchorEl === null || anchorEl === void 0 ? void 0 : anchorEl.dataset.id) || '']) === 'desc',
94
67
  onClick: () => {
95
- handleSortingOption(sortAnchorEl === null || sortAnchorEl === void 0 ? void 0 : sortAnchorEl.dataset.id, 'desc');
68
+ handleSortingOption(anchorEl === null || anchorEl === void 0 ? void 0 : anchorEl.dataset.id, 'desc');
96
69
  },
97
70
  },
98
71
  ] })] })));
@@ -50,31 +50,20 @@ function SheetViewVirtualTable({ columns, rows, threshold = TABLE_THRESHOLD, sho
50
50
  const { pinnedStartVirtualListRef, scrollableVirtualListRef, pinnedEndVirtualListRef, handleScroll } = useSynchronizedScroll();
51
51
  const [selectedCell, setSelectedCell] = useState(null);
52
52
  const [selectedColumn, setSelectedColumn] = useState(null);
53
- const [openFilterColumnId, setOpenFilterColumnId] = useState(null);
54
- const [filterAnchorEl, setFilterAnchorEl] = useState(null);
55
53
  const handleCellClick = useCallback((rowIndex, columnId, event) => {
56
54
  event.stopPropagation();
57
55
  const cellKey = `${rowIndex}-${columnId}`;
58
56
  setSelectedCell((prev) => (prev === cellKey ? null : cellKey));
59
57
  setSelectedColumn(null);
60
58
  }, []);
61
- const handleFilterOpen = useCallback((columnId, anchorEl) => {
62
- setOpenFilterColumnId(columnId);
63
- setFilterAnchorEl(anchorEl);
64
- }, []);
65
- const handleFilterClose = useCallback(() => {
66
- setOpenFilterColumnId(null);
67
- setFilterAnchorEl(null);
68
- }, []);
69
59
  const handleColumnClick = useCallback((columnId, event) => {
70
60
  event.stopPropagation();
71
- const column = orderedColumns.find((col) => col.id === columnId);
72
- if (column === null || column === void 0 ? void 0 : column.filter) {
73
- handleFilterOpen(columnId, event.currentTarget);
61
+ if (event.target !== event.currentTarget) {
62
+ return;
74
63
  }
75
64
  setSelectedColumn((prev) => (prev === columnId ? null : columnId));
76
65
  setSelectedCell(null);
77
- }, [orderedColumns, handleFilterOpen]);
66
+ }, []);
78
67
  const onPointerDown = (e) => {
79
68
  dragControls === null || dragControls === void 0 ? void 0 : dragControls.start(e);
80
69
  };
@@ -142,13 +131,13 @@ function SheetViewVirtualTable({ columns, rows, threshold = TABLE_THRESHOLD, sho
142
131
  const containerKey = position === 'start' ? 'pinnedStart' : 'pinnedEnd';
143
132
  if (columnsData.length === 0)
144
133
  return null;
145
- return (_jsx(Wrapper, { children: _jsxs(StyledTableBox, Object.assign({ as: "main", id: "sheet-table-box-container", "aria-labelledby": "sheet-table-box-container", "data-testid": "SheetViewVirtualTable_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-show-background-color": !!showBackgroundColor, "data-table-mode": tableMode, height: "100%", dir: theme.direction, showBackgroundColor: showBackgroundColor, showNoDataView: showNoDataView }, { children: [showHeader && (_jsx(SheetViewTableHeader, { "data-testid": "SheetViewVirtualTable_PinnedTableHeader", columnsSorting: columnsSorting, onColumnSort: onColumnSort, columns: columnsData, headerProps: headerProps, showBackDrop: showBackDrop, pinnedColumns: pinnedColumnsList, onColumnPin: handleColumnPin, isPinnable: isPinnable, lastColumnId: lastColumnId, selectedColumn: selectedColumn, onColumnClick: handleColumnClick, openFilterColumnId: openFilterColumnId, filterAnchorEl: filterAnchorEl, onFilterOpen: handleFilterOpen, onFilterClose: handleFilterClose })), _jsx(TableWrapper, Object.assign({ "data-testid": "VirtualTable_TableWrapper", sx: {
134
+ return (_jsx(Wrapper, { children: _jsxs(StyledTableBox, Object.assign({ as: "main", id: "sheet-table-box-container", "aria-labelledby": "sheet-table-box-container", "data-testid": "SheetViewVirtualTable_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-show-background-color": !!showBackgroundColor, "data-table-mode": tableMode, height: "100%", dir: theme.direction, showBackgroundColor: showBackgroundColor, showNoDataView: showNoDataView }, { children: [showHeader && (_jsx(SheetViewTableHeader, { "data-testid": "SheetViewVirtualTable_PinnedTableHeader", columnsSorting: columnsSorting, onColumnSort: onColumnSort, columns: columnsData, headerProps: headerProps, showBackDrop: showBackDrop, pinnedColumns: pinnedColumnsList, onColumnPin: handleColumnPin, isPinnable: isPinnable, lastColumnId: lastColumnId, selectedColumn: selectedColumn, onColumnClick: handleColumnClick })), _jsx(TableWrapper, Object.assign({ "data-testid": "VirtualTable_TableWrapper", sx: {
146
135
  width: '100%',
147
136
  minWidth: 'fit-content',
148
137
  overflowX: 'hidden',
149
138
  } }, { children: _jsx(StyledBox, Object.assign({ "data-testid": "SheetViewVirtualTable_PinnedStyledBox", hidePadding: true, className: "list-wrapper" }, { children: createVirtualTableContainer(columnsData, containerKey, true, columnsWidth) })) }))] })) }));
150
139
  };
151
- return (_jsxs(_Fragment, { children: [_jsxs(TableContainer, { children: [showNoDataView ? (_jsx(StyledTableBox, Object.assign({ as: "main", id: "sheet-table-box-container", "aria-labelledby": "sheet-table-box-container", "data-testid": "SheetViewVirtualTable_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-show-background-color": !!showBackgroundColor, "data-table-mode": tableMode, height: "100%", dir: theme.direction, showBackgroundColor: showBackgroundColor, showNoDataView: showNoDataView }, { children: _jsx(TableWrapper, Object.assign({ isSheetView: true, "data-testid": "SheetViewVirtualTable_TableWrapper", showNoDataView: showNoDataView, sx: tableBodyStyles }, { children: _jsx(TableNoData, { error: error, tableEmpty: tableEmpty, isTimeoutError: hasTimeoutError, tableError: tableError, tableLoading: tableLoading, orderedColumns: orderedColumns, triggerDataRefetch: triggerDataRefetch, footerProps: footerProps }) })) }))) : (_jsxs(SheetViewVirtualTableWrapper, { children: [renderPinnedColumn('start', pinnedStartColumnsData, pinnedStartColumnsWidth, pinnedStartColumns), _jsx(MainTableWrapper, Object.assign({ hasPinnedStart: pinnedStartColumnsData.length > 0, hasPinnedEnd: pinnedEndColumnsData.length > 0 }, { children: _jsx(StyledTableBox, Object.assign({ as: "main", id: "sheet-table-box-container", "aria-labelledby": "sheet-table-box-container", "data-testid": "SheetViewVirtualTable_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-show-background-color": !!showBackgroundColor, "data-table-mode": tableMode, height: "100%", dir: theme.direction, showBackgroundColor: showBackgroundColor, showNoDataView: showNoDataView, scrollable: true }, { children: _jsxs(TableWrapper, Object.assign({ "data-testid": "SheetViewVirtualTable_TableWrapper", showNoDataView: showNoDataView, sx: Object.assign(Object.assign({}, tableBodyStyles), { display: 'flex', flexDirection: 'column', height: '100%' }) }, { children: [showHeader && (_jsx(UnpinnedTableHeaderWrapper, { children: _jsx(SheetViewTableHeader, { "data-testid": "SheetViewVirtualTable_UnpinnedTableHeader", columnsSorting: columnsSorting, onColumnSort: onColumnSort, columns: unpinnedColumnsData, headerProps: headerProps, showBackDrop: showBackDrop, pinnedColumns: [...pinnedStartColumns, ...pinnedEndColumns], onColumnPin: handleColumnPin, isPinnable: isPinnable, lastColumnId: lastColumnId, selectedColumn: selectedColumn, onColumnClick: handleColumnClick, openFilterColumnId: openFilterColumnId, filterAnchorEl: filterAnchorEl, onFilterOpen: handleFilterOpen, onFilterClose: handleFilterClose }) })), _jsx(TableWrapper, Object.assign({ "data-testid": "VirtualTable_TableWrapper", sx: {
140
+ return (_jsxs(_Fragment, { children: [_jsxs(TableContainer, { children: [showNoDataView ? (_jsx(StyledTableBox, Object.assign({ as: "main", id: "sheet-table-box-container", "aria-labelledby": "sheet-table-box-container", "data-testid": "SheetViewVirtualTable_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-show-background-color": !!showBackgroundColor, "data-table-mode": tableMode, height: "100%", dir: theme.direction, showBackgroundColor: showBackgroundColor, showNoDataView: showNoDataView }, { children: _jsx(TableWrapper, Object.assign({ isSheetView: true, "data-testid": "SheetViewVirtualTable_TableWrapper", showNoDataView: showNoDataView, sx: tableBodyStyles }, { children: _jsx(TableNoData, { error: error, tableEmpty: tableEmpty, isTimeoutError: hasTimeoutError, tableError: tableError, tableLoading: tableLoading, orderedColumns: orderedColumns, triggerDataRefetch: triggerDataRefetch, footerProps: footerProps }) })) }))) : (_jsxs(SheetViewVirtualTableWrapper, { children: [renderPinnedColumn('start', pinnedStartColumnsData, pinnedStartColumnsWidth, pinnedStartColumns), _jsx(MainTableWrapper, Object.assign({ hasPinnedStart: pinnedStartColumnsData.length > 0, hasPinnedEnd: pinnedEndColumnsData.length > 0 }, { children: _jsx(StyledTableBox, Object.assign({ as: "main", id: "sheet-table-box-container", "aria-labelledby": "sheet-table-box-container", "data-testid": "SheetViewVirtualTable_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-show-background-color": !!showBackgroundColor, "data-table-mode": tableMode, height: "100%", dir: theme.direction, showBackgroundColor: showBackgroundColor, showNoDataView: showNoDataView, scrollable: true }, { children: _jsxs(TableWrapper, Object.assign({ "data-testid": "SheetViewVirtualTable_TableWrapper", showNoDataView: showNoDataView, sx: Object.assign(Object.assign({}, tableBodyStyles), { display: 'flex', flexDirection: 'column', height: '100%' }) }, { children: [showHeader && (_jsx(UnpinnedTableHeaderWrapper, { children: _jsx(SheetViewTableHeader, { "data-testid": "SheetViewVirtualTable_UnpinnedTableHeader", columnsSorting: columnsSorting, onColumnSort: onColumnSort, columns: unpinnedColumnsData, headerProps: headerProps, showBackDrop: showBackDrop, pinnedColumns: [...pinnedStartColumns, ...pinnedEndColumns], onColumnPin: handleColumnPin, isPinnable: isPinnable, lastColumnId: lastColumnId, selectedColumn: selectedColumn, onColumnClick: handleColumnClick }) })), _jsx(TableWrapper, Object.assign({ "data-testid": "VirtualTable_TableWrapper", sx: {
152
141
  width: '100%',
153
142
  minWidth: 'fit-content',
154
143
  } }, { children: _jsx(StyledBox, Object.assign({ "data-testid": "SheetViewVirtualTable_ScrollableStyledBox", hidePadding: true, className: "list-wrapper" }, { children: createVirtualTableContainer(unpinnedColumnsData, 'scrollable', false) })) }))] })) })) })), renderPinnedColumn('end', pinnedEndColumnsData, pinnedEndColumnsWidth, [...pinnedStartColumns, ...pinnedEndColumns])] })), !showNoDataView && areTotalRowsNotFillingHeight && !isFetchingNextPage && (_jsx(TableLastItem, { height: (itemsCount + 1) * TABLE_ROW_HEIGHT, sandboxMode: footerProps === null || footerProps === void 0 ? void 0 : footerProps.sandboxMode, "data-testid": "SheetViewVirtualTable_TableLastItem" }))] }), _jsx(TableFooter, Object.assign({ "data-testid": "SheetViewVirtualTable_TableFooter", showSeparator: true, showBackDrop: showBackDrop, onPointerDown: onPointerDown }, footerProps))] }));
@@ -1,11 +1,5 @@
1
- import { MouseEvent } from 'react';
1
+ /// <reference types="react" />
2
2
  import { IColumnFilter } from '../../../../types/index.js';
3
- type ColumnFilterProps = IColumnFilter & {
4
- externalAnchorEl?: HTMLElement | null;
5
- externalOpen?: boolean;
6
- onExternalOpen?: (event: MouseEvent<HTMLElement>) => void;
7
- onExternalClose?: () => void;
8
- };
9
- declare function ColumnFilter(props: ColumnFilterProps): import("react/jsx-runtime").JSX.Element;
3
+ declare function ColumnFilter(filter: IColumnFilter): import("react/jsx-runtime").JSX.Element;
10
4
  declare const _default: import("react").MemoExoticComponent<typeof ColumnFilter>;
11
5
  export default _default;
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { memo, useMemo, useState, useCallback } from 'react';
2
+ import { memo, useMemo, useState } from 'react';
3
3
  import Box from '@mui/material/Box';
4
4
  import ClickAwayListener from '@mui/material/ClickAwayListener';
5
5
  import Popper from '@mui/material/Popper';
@@ -8,62 +8,50 @@ import Inputs from './Inputs';
8
8
  import List from './List';
9
9
  import { FilterWrapper } from './style';
10
10
  import CustomBackdrop from '../../../CustomBackdrop';
11
- function ColumnFilter(props) {
12
- const { externalAnchorEl, externalOpen, onExternalOpen, onExternalClose } = props;
13
- const [internalAnchorEl, setInternalAnchorEl] = useState(null);
14
- const anchorEl = externalAnchorEl !== undefined ? externalAnchorEl : internalAnchorEl;
15
- const open = externalOpen !== undefined ? externalOpen : Boolean(internalAnchorEl);
11
+ function ColumnFilter(filter) {
12
+ const [anchorEl, setAnchorEl] = useState(null);
16
13
  const openDropdown = (event) => {
17
- if (onExternalOpen) {
18
- onExternalOpen(event);
19
- }
20
- else {
21
- setInternalAnchorEl(event.currentTarget);
22
- }
14
+ setAnchorEl(event.currentTarget);
23
15
  };
24
- const onCloseDropdown = useCallback(() => {
25
- if (onExternalClose) {
26
- onExternalClose();
27
- }
28
- else {
29
- setInternalAnchorEl(null);
30
- }
31
- }, [onExternalClose]);
32
- const filterData = useMemo(() => { var _a; return ((_a = props === null || props === void 0 ? void 0 : props.options) === null || _a === void 0 ? void 0 : _a.reduce((acc, { apiKey }) => { var _a; return (Object.assign(Object.assign({}, acc), { [apiKey]: (_a = props === null || props === void 0 ? void 0 : props.data) === null || _a === void 0 ? void 0 : _a[apiKey] })); }, {})) || {}; }, [props]);
16
+ const onCloseDropdown = () => {
17
+ setAnchorEl(null);
18
+ };
19
+ 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]);
33
20
  const listFilterData = useMemo(() => {
34
21
  var _a;
35
- const listFilter = props;
22
+ const listFilter = filter;
36
23
  const rawData = (_a = listFilter === null || listFilter === void 0 ? void 0 : listFilter.data) === null || _a === void 0 ? void 0 : _a[listFilter.apiKey];
37
24
  return Array.isArray(rawData) ? rawData : [];
38
- }, [props]);
25
+ }, [filter]);
39
26
  const showClearIcon = useMemo(() => Object.values(filterData || {}).some((value) => {
40
27
  if (typeof value === 'string' || Array.isArray(value))
41
28
  return value.length > 0;
42
29
  return Boolean(value);
43
30
  }) || listFilterData.length > 0, [filterData, listFilterData]);
31
+ const open = Boolean(anchorEl);
44
32
  const filterApiKeys = useMemo(() => {
45
33
  var _a;
46
- if (props.type === 'list') {
47
- return [props.apiKey];
34
+ if (filter.type === 'list') {
35
+ return [filter.apiKey];
48
36
  }
49
- return (_a = ((props === null || props === void 0 ? void 0 : props.options) || [])) === null || _a === void 0 ? void 0 : _a.map(({ apiKey }) => apiKey);
50
- }, [props]);
37
+ return (_a = ((filter === null || filter === void 0 ? void 0 : filter.options) || [])) === null || _a === void 0 ? void 0 : _a.map(({ apiKey }) => apiKey);
38
+ }, [filter]);
51
39
  const renderFilter = useMemo(() => {
52
- if (props.type === 'list')
53
- return _jsx(List, { onCloseDropdown: onCloseDropdown, filter: props });
54
- if (props.type === 'inputs')
55
- return _jsx(Inputs, { onCloseDropdown: onCloseDropdown, filter: props });
56
- if (props.type === 'custom') {
40
+ if (filter.type === 'list')
41
+ return _jsx(List, { onCloseDropdown: onCloseDropdown, filter: filter });
42
+ if (filter.type === 'inputs')
43
+ return _jsx(Inputs, { onCloseDropdown: onCloseDropdown, filter: filter });
44
+ if (filter.type === 'custom') {
57
45
  const componentSharedProps = {
58
46
  anchorEl,
59
- setAnchorEl: externalAnchorEl !== undefined ? undefined : setInternalAnchorEl,
47
+ setAnchorEl,
60
48
  };
61
- return props.render(componentSharedProps);
49
+ return filter.render(componentSharedProps);
62
50
  }
63
51
  return null;
64
- }, [props, anchorEl, externalAnchorEl, setInternalAnchorEl, onCloseDropdown]);
52
+ }, [open, filter, anchorEl, setAnchorEl]);
65
53
  return (_jsx(ClickAwayListener, Object.assign({ onClickAway: onCloseDropdown }, { children: _jsxs(Box, Object.assign({ component: "section", "data-testid": "ColumnFilter", sx: { position: 'relative', display: 'flex', alignItems: 'center' } }, { children: [showClearIcon ? (_jsxs(FilterWrapper, { children: [_jsx(Box, { component: "img", "data-testid": "ColumnFilter_whiteFilterIcon", src: whiteFilterIcon, alt: "filter-icon", sx: { marginInlineEnd: '2px', height: 6 }, onClick: openDropdown }), _jsx(Box, { component: "img", "data-testid": "ColumnFilter_closeIcon", src: closeIcon, alt: "close-icon", onClick: () => {
66
- props.onClear(filterApiKeys);
54
+ filter.onClear(filterApiKeys);
67
55
  } })] })) : (_jsx(Box, { component: "img", "data-testid": "ColumnFilter_columnIcon", src: columnIcon, alt: "column-icon", sx: { cursor: 'pointer', marginTop: '2px' }, onClick: openDropdown })), open && _jsx(CustomBackdrop, { onClick: onCloseDropdown }), _jsx(Popper, Object.assign({ open: open, anchorEl: anchorEl, placement: "bottom-start", sx: {
68
56
  zIndex: 9999,
69
57
  } }, { children: renderFilter }))] })) })));
@@ -41,70 +41,45 @@ const StyledMUITableRow = styled(MUITableRow, {
41
41
  paddingBlock: 0,
42
42
  }))));
43
43
  function TableHeader({ columns, headerProps, showBackDrop, onColumnSort, columnsSorting, isSheetView }) {
44
- const [sortAnchorEl, setSortAnchorEl] = useState(null);
45
- const sortOpen = Boolean(sortAnchorEl);
46
- const [openFilterColumnId, setOpenFilterColumnId] = useState(null);
47
- const [filterAnchorEl, setFilterAnchorEl] = useState(null);
44
+ const [anchorEl, setAnchorEl] = useState(null);
45
+ const open = Boolean(anchorEl);
48
46
  const theme = useTheme();
49
- const handleSortClick = (event) => {
50
- setSortAnchorEl(event.currentTarget);
47
+ const handleClick = (event) => {
48
+ setAnchorEl(event.currentTarget);
51
49
  };
52
- const handleColumnHeaderClick = (event, column) => {
53
- if (column.filter) {
54
- setOpenFilterColumnId(column.id);
55
- setFilterAnchorEl(event.currentTarget);
56
- return;
57
- }
58
- if (column.sortable) {
59
- setSortAnchorEl(event.currentTarget);
60
- }
61
- };
62
- const handleFilterOpen = (columnId) => (event) => {
63
- setOpenFilterColumnId(columnId);
64
- setFilterAnchorEl(event.currentTarget);
65
- };
66
- const handleFilterClose = () => {
67
- setOpenFilterColumnId(null);
68
- setFilterAnchorEl(null);
69
- };
70
- const handleSortClose = () => {
71
- setSortAnchorEl(null);
50
+ const handleClose = () => {
51
+ setAnchorEl(null);
72
52
  };
73
53
  const handleSortingOption = (columnId, order) => {
74
54
  if (columnId) {
75
55
  onColumnSort === null || onColumnSort === void 0 ? void 0 : onColumnSort({
76
56
  [columnId]: order,
77
57
  });
78
- handleSortClose();
58
+ handleClose();
79
59
  }
80
60
  };
81
61
  return (_jsxs(StyledHeader, Object.assign({ component: "nav", "data-testid": "VirtualTable_TableHeader_StyledHeader", showBackDrop: showBackDrop }, headerProps, { sx: Object.assign({ width: '100%', minWidth: 'auto', overflowX: 'scroll' }, headerProps === null || headerProps === void 0 ? void 0 : headerProps.sx) }, { children: [_jsx(StyledMUITableRow, Object.assign({ component: "section", "data-testid": "VirtualTable_TableHeader_StyledMUITableRow", isSheetView: isSheetView }, { children: columns.map((column, colIndex) => {
82
62
  const { header, id, align, headerStyle, sortable, filter } = column;
83
63
  const isFirst = id === columns[0].id;
84
64
  const isLast = id === columns[columns.length - 1].id;
85
- return (_jsxs(StyledCell, Object.assign({ "data-id": id, component: "div", "data-testid": "VirtualTable_TableHeader_StyledCell", "data-column-id": column.id, "data-column-width": column.width, "data-column-width-used": column.width, "data-column-align": column.align, "data-column-order": column.order, "data-column-header": typeof column.header === 'string' ? column.header : 'component', "data-column-sortable": !!column.sortable, "data-column-filterable": !!column.filter, isFirst: isFirst, isLast: isLast, onClick: (event) => handleColumnHeaderClick(event, column), sx: 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: column.width, textAlign: align, overflow: 'unset', fontWeight: 600, cursor: column.filter || column.sortable ? 'pointer' : 'default' }, headerStyle), isSheetView: isSheetView }, { 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, { externalAnchorEl: openFilterColumnId === id ? filterAnchorEl : null, externalOpen: openFilterColumnId === id, onExternalOpen: handleFilterOpen(id), onExternalClose: handleFilterClose }))), sortable && (_jsx(ColumnIcon, { onClick: sortable
86
- ? (event) => {
87
- event.stopPropagation();
88
- handleSortClick(event);
89
- }
90
- : undefined, src: columnIcon, alt: "column-icon", "data-id": id }))] }), `${id}-${colIndex}`));
91
- }) })), _jsx(Dropdown, { open: sortOpen, onClose: handleSortClose, anchorEl: sortAnchorEl, menuItems: [
65
+ return (_jsxs(StyledCell, Object.assign({ "data-id": id, component: "div", "data-testid": "VirtualTable_TableHeader_StyledCell", "data-column-id": column.id, "data-column-width": column.width, "data-column-width-used": column.width, "data-column-align": column.align, "data-column-order": column.order, "data-column-header": typeof column.header === 'string' ? column.header : 'component', "data-column-sortable": !!column.sortable, "data-column-filterable": !!column.filter, isFirst: isFirst, isLast: isLast, sx: 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: column.width, textAlign: align, overflow: 'unset', fontWeight: 600 }, headerStyle), isSheetView: isSheetView }, { 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)), sortable && _jsx(ColumnIcon, { onClick: sortable ? handleClick : undefined, src: columnIcon, alt: "column-icon", "data-id": id })] }), `${id}-${colIndex}`));
66
+ }) })), _jsx(Dropdown, { open: open, onClose: handleClose, anchorEl: anchorEl, menuItems: [
92
67
  {
93
68
  label: 'Sort A-Z',
94
69
  name: 'asc',
95
70
  icon: _jsx(ActionIcon, { src: sortAzIcon, alt: "sort-icon" }),
96
- selected: (columnsSorting === null || columnsSorting === void 0 ? void 0 : columnsSorting[(sortAnchorEl === null || sortAnchorEl === void 0 ? void 0 : sortAnchorEl.dataset.id) || '']) === 'asc',
71
+ selected: (columnsSorting === null || columnsSorting === void 0 ? void 0 : columnsSorting[(anchorEl === null || anchorEl === void 0 ? void 0 : anchorEl.dataset.id) || '']) === 'asc',
97
72
  onClick: () => {
98
- handleSortingOption(sortAnchorEl === null || sortAnchorEl === void 0 ? void 0 : sortAnchorEl.dataset.id, 'asc');
73
+ handleSortingOption(anchorEl === null || anchorEl === void 0 ? void 0 : anchorEl.dataset.id, 'asc');
99
74
  },
100
75
  },
101
76
  {
102
77
  label: 'Sort Z-A',
103
78
  name: 'desc',
104
79
  icon: _jsx(ActionIcon, { src: sortZaIcon, alt: "sort-icon" }),
105
- selected: (columnsSorting === null || columnsSorting === void 0 ? void 0 : columnsSorting[(sortAnchorEl === null || sortAnchorEl === void 0 ? void 0 : sortAnchorEl.dataset.id) || '']) === 'desc',
80
+ selected: (columnsSorting === null || columnsSorting === void 0 ? void 0 : columnsSorting[(anchorEl === null || anchorEl === void 0 ? void 0 : anchorEl.dataset.id) || '']) === 'desc',
106
81
  onClick: () => {
107
- handleSortingOption(sortAnchorEl === null || sortAnchorEl === void 0 ? void 0 : sortAnchorEl.dataset.id, 'desc');
82
+ handleSortingOption(anchorEl === null || anchorEl === void 0 ? void 0 : anchorEl.dataset.id, 'desc');
108
83
  },
109
84
  },
110
85
  ] })] })));
@@ -76,7 +76,7 @@ export const getLoggedInUserSegment = () => {
76
76
  const userData = getLoggedInUserData();
77
77
  if (!userData)
78
78
  return null;
79
- return getSegmentData(userData === null || userData === void 0 ? void 0 : userData.segments, userData === null || userData === void 0 ? void 0 : userData.active_segment_id);
79
+ return getSegmentData(userData === null || userData === void 0 ? void 0 : userData.segments, userData === null || userData === void 0 ? void 0 : userData.active_segment_id, userData === null || userData === void 0 ? void 0 : userData.active_segments);
80
80
  };
81
81
  export const getLoggedInUserActiveSegment = () => {
82
82
  const userData = getLoggedInUserData();
@@ -1,2 +1,2 @@
1
1
  import { Segment, SegmentData } from '../types/index.js';
2
- export declare const getSegmentData: (segments: Segment[], activeSegmentId: string) => SegmentData;
2
+ export declare const getSegmentData: (segments: Segment[], activeSegmentId: string, activeSegments: Segment[]) => SegmentData;
@@ -1,9 +1,12 @@
1
1
  import { getDefaultEntityCountry } from './entity';
2
- export const getSegmentData = (segments, activeSegmentId) => {
3
- var _a, _b;
2
+ export const getSegmentData = (segments, activeSegmentId, activeSegments) => {
3
+ var _a, _b, _c;
4
4
  const newSegment = (_a = segments.find((segment) => segment.id === activeSegmentId)) !== null && _a !== void 0 ? _a : {};
5
- const defaultCountry = getDefaultEntityCountry(newSegment === null || newSegment === void 0 ? void 0 : newSegment.countries);
6
- const defaultEntity = (_b = defaultCountry === null || defaultCountry === void 0 ? void 0 : defaultCountry.entities) === null || _b === void 0 ? void 0 : _b.find((entity) => entity.default);
5
+ const activeSegment = (_b = activeSegments.find((segment) => segment.id === activeSegmentId)) !== null && _b !== void 0 ? _b : {};
6
+ const defaultCountry = activeSegment.countries.length === 1
7
+ ? newSegment.countries.find((country) => { var _a; return country.id === ((_a = activeSegment.countries) === null || _a === void 0 ? void 0 : _a[0].id); })
8
+ : getDefaultEntityCountry(newSegment === null || newSegment === void 0 ? void 0 : newSegment.countries);
9
+ const defaultEntity = (_c = defaultCountry === null || defaultCountry === void 0 ? void 0 : defaultCountry.entities) === null || _c === void 0 ? void 0 : _c.find((entity) => entity.default);
7
10
  return Object.assign(Object.assign({}, newSegment), { defaultCountry,
8
11
  defaultEntity });
9
12
  };
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.0.258-test.3",
5
- "testVersion": 3,
4
+ "version": "0.0.258-test.4",
5
+ "testVersion": 4,
6
6
  "type": "module",
7
7
  "main": "build/index.js",
8
8
  "module": "build/index.js",