Skip to content

Commit

Permalink
fix: fix poor scrolling performance
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowusr committed Aug 16, 2024
1 parent 625a211 commit 680ec77
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
--g-text-body-1-line-height: 22px;
--g-text-body-font-weight: normal;

margin-top: 4px;
padding: 4px 0;
font-size: 18px;

Expand Down
48 changes: 26 additions & 22 deletions lib/static/new-ui/features/suites/components/SuitesPage/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, {ChangeEvent, useCallback, useEffect, useState} from 'react';
import {Flex, TextInput} from '@gravity-ui/uikit';
import {Box, Flex, TextInput} from '@gravity-ui/uikit';
import {debounce} from 'lodash';
import classNames from 'classnames';
import {connect} from 'react-redux';
Expand Down Expand Up @@ -55,7 +55,7 @@ function SuitesPageInternal(props: SuitesPageInternalProps): JSX.Element {
}
});

const onItemClick = ({id}: {id: string}): void => {
const onItemClick = useCallback(({id}: {id: string}): void => {
const item = list.structure.itemsById[id];

if (item.type === TreeViewItemType.Suite && list.state.expandedById && id in list.state.expandedById && list.state.setExpanded) {
Expand All @@ -65,7 +65,7 @@ function SuitesPageInternal(props: SuitesPageInternalProps): JSX.Element {

navigate(encodeURIComponent(item.fullTitle));
}
};
}, [list, props.actions, props.treeViewExpandedById]);

const updateTestNameFilter = useCallback(debounce(
(testName) => props.actions.updateTestNameFilter(testName),
Expand All @@ -78,9 +78,9 @@ function SuitesPageInternal(props: SuitesPageInternalProps): JSX.Element {
const virtualizer = useVirtualizer({
count: list.structure.visibleFlattenIds.length,
getScrollElement: () => parentRef.current,
estimateSize: () => 24,
estimateSize: () => 28,
getItemKey: useCallback((index: number) => list.structure.visibleFlattenIds[index], [list]),
overscan: 100
overscan: 200
});

useEffect(() => {
Expand All @@ -103,10 +103,10 @@ function SuitesPageInternal(props: SuitesPageInternalProps): JSX.Element {
}, [props.isInitialized]);

const [testNameFilter, setTestNameFilter] = useState(props.testNameFilter);
const onChange = (event: ChangeEvent<HTMLInputElement>): void => {
const onChange = useCallback((event: ChangeEvent<HTMLInputElement>): void => {
setTestNameFilter(event.target.value);
updateTestNameFilter(event.target.value);
};
}, [setTestNameFilter, updateTestNameFilter]);

const items = virtualizer.getVirtualItems();

Expand Down Expand Up @@ -139,24 +139,28 @@ function SuitesPageInternal(props: SuitesPageInternalProps): JSX.Element {
classes.push(styles['tree-item--browser']);
}

return <ListItemView
return <Box
key={virtualRow.key}
data-index={virtualRow.index}
ref={virtualizer.measureElement}
height={0}
className={classNames(classes)}
{...getItemRenderState({
id: virtualRow.key.toString(),
list,
onItemClick,
mapItemDataToContentProps: (x) => {
return {
startSlot: getIconByStatus(x.status),
title: <TreeViewItemTitle item={x}/>,
subtitle: <TreeViewItemSubtitle item={x}/>
};
}
}).props}/>;
spacing={{pt: 1}}
>
<ListItemView
height={0}
className={classNames(classes)}
{...getItemRenderState({
id: virtualRow.key.toString(),
list,
onItemClick,
mapItemDataToContentProps: (x) => {
return {
startSlot: getIconByStatus(x.status),
title: <TreeViewItemTitle item={x}/>,
subtitle: <TreeViewItemSubtitle item={x}/>
};
}
}).props}/>
</Box>;
})}
</div>
</div>
Expand Down

0 comments on commit 680ec77

Please sign in to comment.