@tap-payments/os-micro-frontend-shared 0.0.283-test.2 → 0.0.283-test.3

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.
@@ -8,7 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
11
- import { useMemo, memo, useState, useCallback } from 'react';
11
+ import { useMemo, memo, useState, useCallback, useRef, useEffect } from 'react';
12
12
  import { useTheme } from '@mui/material/styles';
13
13
  import memoize from 'memoize-one';
14
14
  import InfiniteLoader from 'react-window-infinite-loader';
@@ -51,6 +51,25 @@ function SheetViewVirtualTable({ columns, rows, threshold = TABLE_THRESHOLD, sho
51
51
  const { pinnedStartVirtualListRef, scrollableVirtualListRef, pinnedEndVirtualListRef, handleScroll } = useSynchronizedScroll();
52
52
  const [selectedCell, setSelectedCell] = useState(null);
53
53
  const [selectedColumn, setSelectedColumn] = useState(null);
54
+ const containerHeightRef = useRef(0);
55
+ const lastKnownRowsLengthRef = useRef(0);
56
+ useEffect(() => {
57
+ var _a, _b, _c, _d, _e, _f;
58
+ const hasRowsChanged = lastKnownRowsLengthRef.current !== rows.length;
59
+ const shouldResetCache = hasRowsChanged || areAllRowsLoaded;
60
+ if (shouldResetCache) {
61
+ if (pinnedStartVirtualListRef.current) {
62
+ (_b = (_a = pinnedStartVirtualListRef.current).resetAfterIndex) === null || _b === void 0 ? void 0 : _b.call(_a, 0);
63
+ }
64
+ if (scrollableVirtualListRef.current) {
65
+ (_d = (_c = scrollableVirtualListRef.current).resetAfterIndex) === null || _d === void 0 ? void 0 : _d.call(_c, 0);
66
+ }
67
+ if (pinnedEndVirtualListRef.current) {
68
+ (_f = (_e = pinnedEndVirtualListRef.current).resetAfterIndex) === null || _f === void 0 ? void 0 : _f.call(_e, 0);
69
+ }
70
+ lastKnownRowsLengthRef.current = rows.length;
71
+ }
72
+ }, [rows.length, areAllRowsLoaded, pinnedStartVirtualListRef, scrollableVirtualListRef, pinnedEndVirtualListRef]);
54
73
  const handleCellClick = useCallback((rowIndex, columnId, event) => {
55
74
  event.stopPropagation();
56
75
  const cellKey = `${rowIndex}-${columnId}`;
@@ -93,13 +112,17 @@ function SheetViewVirtualTable({ columns, rows, threshold = TABLE_THRESHOLD, sho
93
112
  };
94
113
  return (_jsx(InfiniteLoader, Object.assign({ isItemLoaded: (index) => index !== lastItemIndex, itemCount: tableItemsCount, loadMoreItems: handleOnLoadMoreItems, threshold: threshold }, { children: ({ onItemsRendered }) => (_jsx(AutoSizer, { children: ({ height, width }) => {
95
114
  var _a;
115
+ containerHeightRef.current = height;
96
116
  const getItemSize = (index) => {
97
- console.log({ All: areAllRowsLoaded, rows, index });
117
+ console.log({ All: areAllRowsLoaded, rows, index, height, containerHeight: containerHeightRef.current });
118
+ const currentHeight = height || containerHeightRef.current || 400;
98
119
  const isLastRow = areAllRowsLoaded && index === rows.length;
99
- if (isLastRow) {
120
+ if (isLastRow && currentHeight > 0) {
100
121
  const usedHeight = rows.length * rowHeight;
101
- const remainingHeight = height - usedHeight;
102
- return Math.max(remainingHeight, rowHeight);
122
+ const remainingHeight = currentHeight - usedHeight;
123
+ const calculatedHeight = Math.max(remainingHeight, rowHeight);
124
+ console.log({ usedHeight, remainingHeight, calculatedHeight, currentHeight });
125
+ return calculatedHeight;
103
126
  }
104
127
  return rowHeight;
105
128
  };
@@ -124,7 +147,7 @@ function SheetViewVirtualTable({ columns, rows, threshold = TABLE_THRESHOLD, sho
124
147
  overflowX: isPinned ? 'hidden' : 'auto',
125
148
  paddingBottom: isPinned ? '25px' : '13px',
126
149
  backgroundColor: isPinned ? 'transparent' : theme.palette.background.default,
127
- } }, { children: ListItemWrapper })));
150
+ } }, { children: ListItemWrapper }), `${containerKey}-${rows.length}-${areAllRowsLoaded}-${height}`));
128
151
  } })) })));
129
152
  }, [
130
153
  itemsCount,
@@ -152,6 +175,7 @@ function SheetViewVirtualTable({ columns, rows, threshold = TABLE_THRESHOLD, sho
152
175
  pinnedStartVirtualListRef,
153
176
  scrollableVirtualListRef,
154
177
  theme.palette.background.default,
178
+ containerHeightRef,
155
179
  ]);
156
180
  const showNoDataView = tableLoading || tableError || tableEmpty || hasTimeoutError;
157
181
  const pinnedStartColumnsWidth = useMemo(() => pinnedStartColumnsData.reduce((acc, col) => {
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.283-test.2",
5
- "testVersion": 2,
4
+ "version": "0.0.283-test.3",
5
+ "testVersion": 3,
6
6
  "type": "module",
7
7
  "main": "build/index.js",
8
8
  "module": "build/index.js",