@tap-payments/os-micro-frontend-shared 0.0.70-sheet-view-table-row-v2 → 0.0.70-sheet-view-table-row-v3

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 } from 'react';
11
+ import { useMemo, memo, useState, useRef, useEffect } from 'react';
12
12
  import { useTheme } from '@mui/material/styles';
13
13
  import memoize from 'memoize-one';
14
14
  import AutoSizer from 'react-virtualized-auto-sizer';
@@ -57,6 +57,12 @@ function VirtualTable({ columns, rows, threshold = TABLE_THRESHOLD, showHeader,
57
57
  const itemsCount = isDelayedFetchingNextPage || (areAllRowsLoaded && !areTotalRowsNotFillingHeight) ? rows.length + 1 : rows.length;
58
58
  const itemData = createItemData(orderedColumns, isDelayedFetchingNextPage, rows, rowProps, scrollToIndex, lastItemIndex, (_a = footerProps === null || footerProps === void 0 ? void 0 : footerProps.totalCount) !== null && _a !== void 0 ? _a : 0, isError, areAllRowsLoaded && !areTotalRowsNotFillingHeight, isSheetView);
59
59
  const tableRowHeight = isSheetView ? SHEET_VIEW_TABLE_ROW_HEIGHT : TABLE_ROW_HEIGHT;
60
+ const listRef = useRef(null);
61
+ useEffect(() => {
62
+ if (listRef.current && typeof listRef.current.resetAfterIndex === 'function') {
63
+ listRef.current.resetAfterIndex(0, true);
64
+ }
65
+ }, [isSheetView, tableRowHeight]);
60
66
  const renderTableContainer = useMemo(() => {
61
67
  const setBackdropVisibility = (isVisible) => {
62
68
  setShowBackdrop(isVisible);
@@ -66,7 +72,7 @@ function VirtualTable({ columns, rows, threshold = TABLE_THRESHOLD, showHeader,
66
72
  return;
67
73
  yield (loadMoreItems === null || loadMoreItems === void 0 ? void 0 : loadMoreItems());
68
74
  });
69
- return (_jsx(InfiniteLoader, Object.assign({ "data-testid": "VirtualTable_InfiniteLoader", isItemLoaded: (index) => index !== lastItemIndex, itemCount: itemsCount, loadMoreItems: handleOnLoadMoreItems, threshold: threshold }, { children: ({ onItemsRendered, ref }) => (_jsx(AutoSizer, Object.assign({ ref: ref, "data-testid": "VirtualTable_AutoSizer" }, { children: ({ height, width }) => (_jsx(StyledVirtualList, Object.assign({ "data-testid": "VirtualTable_VirtualList", useIsScrolling: true, className: "list", itemData: itemData, height: height || 0, width: width || 0, itemCount: itemsCount, itemSize: () => tableRowHeight, onItemsRendered: onItemsRendered, setBackdropVisibility: setBackdropVisibility, areTotalRowsNotFillingHeight: areTotalRowsNotFillingHeight, scrollToIndex: scrollToIndex, overscanCount: TABLE_LIST_OVER_SCAN, isSheetView: isSheetView }, { children: ListItemWrapper }))) }))) })));
75
+ return (_jsx(InfiniteLoader, Object.assign({ "data-testid": "VirtualTable_InfiniteLoader", isItemLoaded: (index) => index !== lastItemIndex, itemCount: itemsCount, loadMoreItems: handleOnLoadMoreItems, threshold: threshold }, { children: ({ onItemsRendered, ref }) => (_jsx(AutoSizer, Object.assign({ ref: ref, "data-testid": "VirtualTable_AutoSizer" }, { children: ({ height, width }) => (_jsx(StyledVirtualList, Object.assign({ "data-testid": "VirtualTable_VirtualList", useIsScrolling: true, className: "list", itemData: itemData, height: height || 0, width: width || 0, itemCount: itemsCount, itemSize: () => tableRowHeight, onItemsRendered: onItemsRendered, setBackdropVisibility: setBackdropVisibility, areTotalRowsNotFillingHeight: areTotalRowsNotFillingHeight, scrollToIndex: scrollToIndex, overscanCount: TABLE_LIST_OVER_SCAN, isSheetView: isSheetView, listRef: listRef }, { children: ListItemWrapper }))) }))) })));
70
76
  }, [
71
77
  lastItemIndex,
72
78
  loadMoreItems,
@@ -1,7 +1,9 @@
1
- import { VariableSizeListProps } from 'react-window';
1
+ import React from 'react';
2
+ import { VariableSizeList, VariableSizeListProps } from 'react-window';
2
3
  type ExtendedVariableSizeListProps = VariableSizeListProps & {
3
4
  setBackdropVisibility: (isVisible: boolean) => void;
4
5
  scrollToIndex?: number;
6
+ listRef?: React.RefObject<VariableSizeList>;
5
7
  };
6
- declare function VirtualScrollList({ itemData, children, setBackdropVisibility, scrollToIndex, ...restProps }: ExtendedVariableSizeListProps): import("react/jsx-runtime").JSX.Element;
8
+ declare function VirtualScrollList({ itemData, children, setBackdropVisibility, scrollToIndex, listRef: externalListRef, ...restProps }: ExtendedVariableSizeListProps): import("react/jsx-runtime").JSX.Element;
7
9
  export default VirtualScrollList;
@@ -17,14 +17,15 @@ import VirtualScrollOuter from './VirtualScrollOuter';
17
17
  import useScrollBackShadow from '../../hooks/useScrollBackShadow';
18
18
  import { VirtualScrollOuterProvider } from '../../context';
19
19
  function VirtualScrollList(_a) {
20
- var { itemData, children, setBackdropVisibility, scrollToIndex } = _a, restProps = __rest(_a, ["itemData", "children", "setBackdropVisibility", "scrollToIndex"]);
20
+ var { itemData, children, setBackdropVisibility, scrollToIndex, listRef: externalListRef } = _a, restProps = __rest(_a, ["itemData", "children", "setBackdropVisibility", "scrollToIndex", "listRef"]);
21
21
  const { handleBackDropVisibility, clearBackdropVisibility, clearTimer } = useScrollBackShadow({
22
22
  setBackdropVisibility,
23
23
  });
24
24
  const renderedScrollTopRef = useRef(0);
25
25
  const scrollTopRef = useRef(undefined);
26
26
  const scrollLocked = useRef(false);
27
- const listRef = useRef(null);
27
+ const internalListRef = useRef(null);
28
+ const listRef = externalListRef || internalListRef;
28
29
  const scrollTo = useCallback(() => {
29
30
  var _a, _b;
30
31
  clearTimer();
@@ -38,7 +39,7 @@ function VirtualScrollList(_a) {
38
39
  }
39
40
  clearBackdropVisibility();
40
41
  return false;
41
- }, []);
42
+ }, [clearBackdropVisibility, clearTimer, handleBackDropVisibility, listRef]);
42
43
  const handleScroll = React.useCallback((event) => {
43
44
  scrollTopRef.current = event.currentTarget.scrollTop;
44
45
  if (!scrollLocked.current) {
@@ -51,7 +52,7 @@ function VirtualScrollList(_a) {
51
52
  if ((scrollToIndex || 0) >= 0 && !Number.isNaN(scrollToIndex) && scrollToIndex !== undefined && ((_a = listRef.current) === null || _a === void 0 ? void 0 : _a.scrollTo)) {
52
53
  (_b = listRef.current) === null || _b === void 0 ? void 0 : _b.scrollToItem(scrollToIndex, 'center');
53
54
  }
54
- }, [scrollToIndex]);
55
+ }, [scrollToIndex, listRef]);
55
56
  const itemDataInternal = React.useMemo(() => (Object.assign(Object.assign({}, itemData), { renderedScrollTopRef })), [itemData]);
56
57
  const handleOnScroll = React.useCallback(() => {
57
58
  scrollLocked.current = scrollTo();
@@ -26,6 +26,7 @@ interface StyledVirtualListProps {
26
26
  export declare const StyledVirtualList: import("@emotion/styled").StyledComponent<import("react-window").VariableSizeListProps<any> & {
27
27
  setBackdropVisibility: (isVisible: boolean) => void;
28
28
  scrollToIndex?: number | undefined;
29
+ listRef?: import("react").RefObject<import("react-window").VariableSizeList<any>> | undefined;
29
30
  } & import("@mui/system").MUIStyledCommonProps<import("@mui/material").Theme> & StyledVirtualListProps, {}, {}>;
30
31
  export declare const StyledTableRow: import("@emotion/styled").StyledComponent<import("@mui/material").TableRowOwnProps & import("@mui/material/OverridableComponent").CommonProps & Omit<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLTableRowElement>, HTMLTableRowElement>, "ref"> & {
31
32
  ref?: ((instance: HTMLTableRowElement | null) => void) | import("react").RefObject<HTMLTableRowElement> | null | undefined;
@@ -0,0 +1 @@
1
+ export declare const VTDemo: () => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,58 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState } from 'react';
3
+ import { Button, VirtualTable } from '../components/index.js';
4
+ import { Box } from '@mui/material';
5
+ export const VTDemo = () => {
6
+ const [isSheetView, setIsSheetView] = useState(false);
7
+ const toggleView = () => {
8
+ setIsSheetView((prev) => !prev);
9
+ };
10
+ return (_jsx(Box, Object.assign({ sx: {
11
+ width: '100%',
12
+ height: '100vh',
13
+ overflow: 'auto',
14
+ flexDirection: 'row',
15
+ display: 'flex',
16
+ justifyContent: 'center',
17
+ p: 3,
18
+ backgroundColor: 'gray',
19
+ } }, { children: _jsxs(Box, Object.assign({ "data-testid": "ChargesList", sx: {
20
+ position: 'relative',
21
+ display: 'flex',
22
+ flexDirection: 'column',
23
+ width: '80%',
24
+ height: '100%',
25
+ } }, { children: [_jsx(Button, Object.assign({ onClick: toggleView }, { children: "Toggle" })), _jsx(VirtualTable, { showHeader: true, showFooter: true, footerProps: {
26
+ totalCount: 4,
27
+ sandboxMode: false,
28
+ maximized: false,
29
+ }, loadMoreItems: () => Promise.resolve(), isLoading: false, isFetchingNextPage: false, rows: [
30
+ { index: '1', date: 'date', order: 'order' },
31
+ { index: '2', date: 'date', order: 'order' },
32
+ { index: '3', date: 'date', order: 'order' },
33
+ ], areAllRowsLoaded: true, columnsSorting: { id: 'asc' }, onColumnSort: () => { }, columns: [
34
+ { id: 'index', header: '', width: '28px' },
35
+ {
36
+ id: 'date',
37
+ header: 'Date',
38
+ width: '170px',
39
+ },
40
+ {
41
+ id: 'order',
42
+ header: 'Order',
43
+ width: '170px',
44
+ filter: {
45
+ onConfirm: undefined,
46
+ onClear: () => { },
47
+ type: 'inputs',
48
+ options: [
49
+ {
50
+ placeholder: 'Order',
51
+ apiKey: 'orderID',
52
+ },
53
+ ],
54
+ data: {},
55
+ },
56
+ },
57
+ ], error: null, triggerDataRefetch: () => Promise.resolve(), showBackgroundColor: false, tableTitle: "Acceptance-Charges", tableMode: 'sheet', dragControls: undefined, isSheetView: isSheetView })] })) })));
58
+ };
@@ -0,0 +1 @@
1
+ export { VTDemo } from './VTDemo';
@@ -0,0 +1 @@
1
+ export { VTDemo } from './VTDemo';
package/package.json CHANGED
@@ -1,7 +1,7 @@
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.70-sheet-view-table-row-v2",
4
+ "version": "0.0.70-sheet-view-table-row-v3",
5
5
  "type": "module",
6
6
  "main": "build/index.js",
7
7
  "module": "build/index.js",