Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(AnalyticalTable): update @tanstack/react-virtual to 3.0.0-beta.61 #4899

Merged
merged 27 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
4ef21c6
update tanstack/virtual to beta 54
MarcusNotheis Jul 18, 2023
7503890
migrate column virtualizer
MarcusNotheis Jul 18, 2023
9a69af2
migrate row virtualizer
MarcusNotheis Jul 18, 2023
dd265d3
Update VirtualTableBody.tsx
MarcusNotheis Jul 18, 2023
0e166e7
update react-virtual to beta.57
MarcusNotheis Aug 30, 2023
6960227
refactor dnd hook
MarcusNotheis Aug 31, 2023
68c07b7
fix weird dnd behaviour
MarcusNotheis Aug 31, 2023
0fe86c6
fix dnd hook errors and remove custom measureElement
MarcusNotheis Aug 31, 2023
05ea649
prevent scrollbars
MarcusNotheis Aug 31, 2023
6eedf42
chore: update react-virtual to beta.58
MarcusNotheis Sep 5, 2023
4aaeb22
update to beta.59
MarcusNotheis Sep 6, 2023
84377cc
use `data-row-index`
MarcusNotheis Sep 6, 2023
cbe7629
fix alternate row colors
MarcusNotheis Sep 6, 2023
bebdac7
adjust keyboard navigation test
MarcusNotheis Sep 6, 2023
1367daf
fix horizontal scrollbar
Lukas742 Sep 7, 2023
69b5acb
use data attribute for horizontal virtualizer only
Lukas742 Sep 7, 2023
00ccf4d
update to beta.60
Lukas742 Sep 14, 2023
c8ab160
Merge branch 'main' into fix/tanstack-virtual-3-beta.54
Lukas742 Sep 14, 2023
e681b15
Revert "use data attribute for horizontal virtualizer only"
Lukas742 Sep 14, 2023
2fd1be1
Revert "fix horizontal scrollbar"
Lukas742 Sep 14, 2023
5dc1548
fix horizontal scrollbar (again)
Lukas742 Sep 14, 2023
9b13af3
remove `scaleXFactor` internally
Lukas742 Sep 14, 2023
b9aac0b
chore: update to beta.61
MarcusNotheis Sep 27, 2023
a3fef43
Update index.tsx
MarcusNotheis Sep 27, 2023
18565a6
Merge branch 'main' into fix/tanstack-virtual-3-beta.54
MarcusNotheis Sep 27, 2023
95f3477
Merge branch 'main' into fix/tanstack-virtual-3-beta.54
MarcusNotheis Sep 27, 2023
4978bef
Update AnalyticalTable.cy.tsx
MarcusNotheis Sep 27, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/main/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"watch:css": "postcss --watch --dir ../../temp src/**/*.css"
},
"dependencies": {
"@tanstack/react-virtual": "3.0.0-beta.18",
"@tanstack/react-virtual": "3.0.0-beta.59",
"@ui5/webcomponents-react-base": "workspace:~",
"clsx": "2.0.0",
"react-jss": "^10.10.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2290,7 +2290,7 @@ describe('AnalyticalTable', () => {
// last currently rendered row
cy.focused().should('have.attr', 'data-row-index', '22').should('have.attr', 'data-column-index', '0');
cy.realPress('PageDown');
cy.focused().should('have.attr', 'data-row-index', '36').should('have.attr', 'data-column-index', '0');
cy.focused().should('have.attr', 'data-row-index', '37').should('have.attr', 'data-column-index', '0');
cy.realPress('PageDown');
cy.focused().should('have.attr', 'data-row-index', '50').should('have.attr', 'data-column-index', '0');
cy.realPress('PageUp');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ const styles = {
overflowY: 'auto',
scrollbarWidth: 'none',
borderBlockEnd: `1px solid ${ThemingParameters.sapList_TableFooterBorder}`,
boxSizing: 'border-box',
'-ms-overflow-style': 'none',
'&::-webkit-scrollbar': {
width: '0 !important',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { VirtualItem, Virtualizer } from '@tanstack/react-virtual';
import type { Virtualizer } from '@tanstack/react-virtual';
import { ThemingParameters } from '@ui5/webcomponents-react-base';
import React, { forwardRef, Fragment } from 'react';
import { createUseStyles } from 'react-jss';
Expand All @@ -23,20 +23,14 @@ const styles = {

interface ColumnHeaderContainerProps {
headerProps: Record<string, unknown>;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
headerGroup: Record<string, any>;
onSort: (e: CustomEvent<{ column: unknown; sortDirection: string }>) => void;
onGroupByChanged: (e: CustomEvent<{ column?: Record<string, unknown>; isGrouped?: boolean }>) => void;
onDragStart: any;
onDragOver: any;
onDrop: any;
onDragEnter: any;
onDragEnd: any;
dragOver: any;
resizeInfo: Record<string, unknown>;
isRtl: boolean;
portalContainer: Element;
columnVirtualizer: Virtualizer<DivWithCustomScrollProp>;
scaleXFactor?: number;
columnVirtualizer: Virtualizer<DivWithCustomScrollProp, Element>;
uniqueId: string;
showVerticalEndBorder: boolean;
}
Expand All @@ -49,17 +43,10 @@ export const ColumnHeaderContainer = forwardRef<HTMLDivElement, ColumnHeaderCont
headerGroup,
onSort,
onGroupByChanged,
onDragStart,
onDragOver,
onDrop,
onDragEnter,
onDragEnd,
dragOver,
resizeInfo,
isRtl,
portalContainer,
columnVirtualizer,
scaleXFactor,
uniqueId,
showVerticalEndBorder
} = props;
Expand All @@ -73,7 +60,7 @@ export const ColumnHeaderContainer = forwardRef<HTMLDivElement, ColumnHeaderCont
ref={ref}
data-component-name="AnalyticalTableHeaderRow"
>
{columnVirtualizer.getVirtualItems().map((virtualColumn: VirtualItem<Record<string, unknown>>, index) => {
{columnVirtualizer.getVirtualItems().map((virtualColumn, index) => {
const column = headerGroup.headers[virtualColumn.index];
if (!column) {
return null;
Expand Down Expand Up @@ -106,21 +93,14 @@ export const ColumnHeaderContainer = forwardRef<HTMLDivElement, ColumnHeaderCont
id={`${uniqueId}${rest?.id ?? ''}`}
columnId={rest.id}
visibleColumnIndex={index}
columnIndex={virtualColumn.index}
onSort={onSort}
onGroupBy={onGroupByChanged}
onDragStart={onDragStart}
onDragOver={onDragOver}
onDrop={onDrop}
onDragEnter={onDragEnter}
onDragEnd={onDragEnd}
dragOver={column.id === dragOver}
headerTooltip={column.headerTooltip}
isDraggable={(column.canReorder || !column.disableDragAndDrop) && !resizeInfo.isResizingColumn}
virtualColumn={virtualColumn}
columnVirtualizer={columnVirtualizer}
isRtl={isRtl}
portalContainer={portalContainer}
scaleXFactor={scaleXFactor}
>
{column.render('Header')}
</ColumnHeader>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { VirtualItem } from '@tanstack/react-virtual';
import type { VirtualItem, Virtualizer } from '@tanstack/react-virtual';
import iconFilter from '@ui5/webcomponents-icons/dist/filter.js';
import iconGroup from '@ui5/webcomponents-icons/dist/group-2.js';
import iconSortAscending from '@ui5/webcomponents-icons/dist/sort-ascending.js';
Expand All @@ -18,12 +18,12 @@ import { createUseStyles } from 'react-jss';
import { CustomThemingParameters } from '../../../themes/CustomVariables.js';
import { Icon } from '../../../webComponents/Icon/index.js';
import { Text } from '../../Text/index.js';
import type { DivWithCustomScrollProp } from '../index.js';
import type { ColumnType } from '../types/ColumnType.js';
import { ColumnHeaderModal } from './ColumnHeaderModal.js';

export interface ColumnHeaderProps {
visibleColumnIndex: number;
columnIndex: number;
onSort?: (e: CustomEvent<{ column: unknown; sortDirection: string }>) => void;
onGroupBy?: (e: CustomEvent<{ column: unknown; isGrouped: boolean }>) => void;
onDragStart: DragEventHandler<HTMLDivElement>;
Expand All @@ -34,11 +34,11 @@ export interface ColumnHeaderProps {
dragOver: boolean;
isDraggable: boolean;
headerTooltip: string;
virtualColumn: VirtualItem<Record<string, any>>;
virtualColumn: VirtualItem;
columnVirtualizer: Virtualizer<DivWithCustomScrollProp, Element>;
isRtl: boolean;
children: ReactNode | ReactNode[];
portalContainer: Element;
scaleXFactor?: number;
columnId?: string;
showVerticalEndBorder: boolean;

Expand Down Expand Up @@ -134,19 +134,20 @@ export const ColumnHeader = (props: ColumnHeaderProps) => {
dragOver,
role,
virtualColumn,
columnVirtualizer,
isRtl,
columnIndex,
visibleColumnIndex,
onClick,
onKeyDown,
portalContainer,
scaleXFactor,
isFiltered,
'aria-label': ariaLabel,
'aria-sort': ariaSort,
showVerticalEndBorder
} = props;

const columnIndex = virtualColumn.index;

const [popoverOpen, setPopoverOpen] = useState(false);
const columnHeaderRef = useRef<HTMLDivElement>(null);

Expand Down Expand Up @@ -215,26 +216,20 @@ export const ColumnHeader = (props: ColumnHeaderProps) => {
if (!column) return null;
return (
<div
ref={columnHeaderRef}
ref={(node) => {
columnHeaderRef.current = node;
columnVirtualizer.measureElement(node);
}}
className={clsx(classes.thContainer, showVerticalEndBorder && classes.verticalEndBorder)}
style={{
position: 'absolute',
top: 0,
width: `${virtualColumn.size}px`,
...directionStyles
}}
data-column-index-virtual={columnIndex}
>
<div
ref={(node) => {
const clientRect = node?.getBoundingClientRect();
if (clientRect && scaleXFactor > 0) {
const scaledGetBoundingClientRect = () => ({ ...clientRect, width: clientRect.width / scaleXFactor });
const updatedNode = { ...node, getBoundingClientRect: scaledGetBoundingClientRect };
virtualColumn.measureElement(updatedNode);
} else {
virtualColumn.measureElement(node);
}
}}
data-visible-column-index={visibleColumnIndex}
data-visible-row-index={0}
data-row-index={0}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const EmptyRow = ({
className,
children
}: {
virtualRow: VirtualItem<any>;
virtualRow: VirtualItem;
className: string;
children?: ReactNode;
}) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const useStyles = createUseStyles(styles, { name: 'RowSubComponent' });

interface RowSubComponent {
subComponentsHeight: Record<string, { rowId: string; subComponentHeight?: number }>;
virtualRow: VirtualItem<Record<string, unknown>>;
virtualRow: VirtualItem;
dispatch: (e: { type: string; payload?: Record<string, unknown> }) => void;
row: Record<string, unknown>;
rowHeight: number;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import type { Virtualizer } from '@tanstack/react-virtual';
import { useVirtualizer } from '@tanstack/react-virtual';
import { clsx } from 'clsx';
import type { MutableRefObject, ReactNode } from 'react';
import React, { useCallback, useMemo, useRef } from 'react';
import type { AnalyticalTablePropTypes } from '../index.js';
import type { AnalyticalTablePropTypes, DivWithCustomScrollProp } from '../index.js';
import type { ScrollToRefType } from '../interfaces.js';
import { getSubRowsByString } from '../util/index.js';
import { EmptyRow } from './EmptyRow.js';
Expand All @@ -28,13 +29,15 @@ interface VirtualTableBodyProps {
alwaysShowSubComponent: boolean;
dispatch?: (e: { type: string; payload?: Record<string, unknown> }) => void;
subComponentsHeight?: Record<string, { rowId: string; subComponentHeight?: number }>;
columnVirtualizer: Record<string, any>;
columnVirtualizer: Virtualizer<DivWithCustomScrollProp, Element>;
manualGroupBy?: boolean;
subRowsKey: string;
scrollContainerRef?: MutableRefObject<HTMLDivElement>;
}

const measureElement = (el) => el.offsetHeight;
const measureElement = (el: HTMLElement) => {
return el.offsetHeight;
};

export const VirtualTableBody = (props: VirtualTableBodyProps) => {
const {
Expand Down Expand Up @@ -85,7 +88,8 @@ export const VirtualTableBody = (props: VirtualTableBodyProps) => {
[rowHeight, rows, renderRowSubComponent, alwaysShowSubComponent, subComponentsHeight]
),
overscan,
measureElement
measureElement,
indexAttribute: 'data-virtual-row-index'
});
scrollToRef.current = {
...scrollToRef.current,
Expand Down Expand Up @@ -161,7 +165,10 @@ export const VirtualTableBody = (props: VirtualTableBodyProps) => {
lastNonEmptyRow.current = row;
}
prepareRow(row);
const rowProps = row.getRowProps({ 'aria-rowindex': virtualRow.index });
const rowProps = row.getRowProps({
'aria-rowindex': virtualRow.index + 1,
'data-virtual-row-index': virtualRow.index
});
const isNavigatedCell = markNavigatedRow(row);
const RowSubComponent = typeof renderRowSubComponent === 'function' ? renderRowSubComponent(row) : undefined;

Expand All @@ -182,21 +189,19 @@ export const VirtualTableBody = (props: VirtualTableBodyProps) => {
) {
updatedHeight += subComponentsHeight?.[virtualRow.index]?.subComponentHeight ?? 0;
}

return (
// eslint-disable-next-line react/jsx-key
<div
{...rowProps}
ref={rowVirtualizer.measureElement}
style={{
...(rowProps.style ?? {}),
transform: `translateY(${virtualRow.start}px)`,
position: 'absolute',
boxSizing: 'border-box',
height: `${updatedHeight}px`
}}
ref={(node) => {
virtualRow.measureElement(node);
}}
aria-rowindex={rowProps['aria-rowindex'] + 1}
>
{RowSubComponent && (row.isExpanded || alwaysShowSubComponent) && (
<SubComponent
Expand All @@ -217,9 +222,9 @@ export const VirtualTableBody = (props: VirtualTableBodyProps) => {
const directionStyles = isRtl
? {
transform: `translateX(-${virtualColumn.start}px)`,
right: 0
insertInlineStart: 0
}
: { transform: `translateX(${virtualColumn.start}px)`, left: 0 };
: { transform: `translateX(${virtualColumn.start}px)`, insertInlineStart: 0 };
if (!cell) {
return null;
}
Expand Down
Loading
Loading