-
Notifications
You must be signed in to change notification settings - Fork 15
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
Added virtualised list to marketplace for quicker model rendering #1978
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
import { Box, Stack, Typography } from '@mui/material' | ||
import { useTheme } from '@mui/material/styles' | ||
import { EntrySearchResult } from 'actions/model' | ||
import { Fragment, useMemo } from 'react' | ||
import { CSSProperties, memo } from 'react' | ||
import { FixedSizeList } from 'react-window' | ||
import ChipSelector from 'src/common/ChipSelector' | ||
import EmptyBlob from 'src/common/EmptyBlob' | ||
import Link from 'src/Link' | ||
|
@@ -22,49 +23,69 @@ export default function EntryList({ | |
}: EntryListProps) { | ||
const theme = useTheme() | ||
|
||
const entriesDisplay = useMemo(() => { | ||
return entries.map((entry, index) => ( | ||
<Fragment key={entry.id}> | ||
<Stack direction='row'> | ||
<Link | ||
sx={{ textDecoration: 'none', whiteSpace: 'nowrap', textOverflow: 'ellipsis', overflow: 'hidden' }} | ||
href={`${entry.kind}/${entry.id}`} | ||
> | ||
<Typography | ||
variant='h5' | ||
sx={{ fontWeight: '500', textDecoration: 'none', color: theme.palette.primary.main }} | ||
const Row = memo(({ data, index, style }: { data: EntrySearchResult[]; index: number; style: CSSProperties }) => { | ||
const entry = data[index] | ||
|
||
return ( | ||
<Box | ||
justifyContent='flex-start' | ||
alignItems='center' | ||
sx={{ backgroundColor: index % 2 ? theme.palette.container.main : 'none', p: 2, margin: 'auto', ...style }} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now that we've got a scroll bar to the right and have also changed how the container for each list item looks, I'd be quite keen to reduce/remove the horizontal padding we have on this list and the tabs above it. |
||
key={entry.id} | ||
> | ||
<Stack> | ||
<Stack direction='row'> | ||
<Link | ||
sx={{ textDecoration: 'none', whiteSpace: 'nowrap', textOverflow: 'ellipsis', overflow: 'hidden' }} | ||
href={`${entry.kind}/${entry.id}`} | ||
> | ||
{entry.name} | ||
</Typography> | ||
</Link> | ||
<Typography | ||
variant='h5' | ||
sx={{ fontWeight: '500', textDecoration: 'none', color: theme.palette.primary.main }} | ||
> | ||
{entry.name} | ||
</Typography> | ||
</Link> | ||
</Stack> | ||
<Typography | ||
variant='body1' | ||
sx={{ marginBottom: 2, whiteSpace: 'nowrap', textOverflow: 'ellipsis', overflow: 'hidden' }} | ||
> | ||
{entry.description} | ||
</Typography> | ||
<div> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this |
||
<ChipSelector | ||
chipTooltipTitle={'Filter by tag'} | ||
options={entry.tags.slice(0, 10)} | ||
expandThreshold={10} | ||
multiple | ||
selectedChips={selectedChips} | ||
onChange={onSelectedChipsChange} | ||
size='small' | ||
ariaLabel='add tag to search filter' | ||
/> | ||
</div> | ||
</Stack> | ||
<Typography | ||
variant='body1' | ||
sx={{ marginBottom: 2, whiteSpace: 'nowrap', textOverflow: 'ellipsis', overflow: 'hidden' }} | ||
> | ||
{entry.description} | ||
</Typography> | ||
<ChipSelector | ||
chipTooltipTitle={'Filter by tag'} | ||
options={entry.tags.slice(0, 10)} | ||
expandThreshold={10} | ||
multiple | ||
selectedChips={selectedChips} | ||
onChange={onSelectedChipsChange} | ||
size='small' | ||
ariaLabel='add tag to search filter' | ||
/> | ||
{index !== entries.length - 1 && <Box sx={{ borderBottom: 1, borderColor: 'divider', marginBottom: 2 }} />} | ||
</Fragment> | ||
)) | ||
}, [entries, onSelectedChipsChange, selectedChips, theme.palette.primary.main]) | ||
</Box> | ||
) | ||
}) | ||
|
||
Row.displayName = 'row' | ||
|
||
if (entriesErrorMessage) return <MessageAlert message={entriesErrorMessage} severity='error' /> | ||
|
||
return ( | ||
<> | ||
{entries.length === 0 && <EmptyBlob data-test='emptyEntryListBlob' text='No entries here' />} | ||
{entriesDisplay} | ||
<FixedSizeList | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From past experience setting |
||
height={window.innerHeight - 300} | ||
itemCount={entries.length} | ||
itemData={entries} | ||
itemSize={130} | ||
width='100%' | ||
> | ||
{Row} | ||
</FixedSizeList> | ||
</> | ||
) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to use
memo()
, which is a HOC (Higher Order Component), you should split this out into its own component.That being said, I don't really see the performance benefit of memoizing something that's going to be unrendered and rerendered as the user scrolls.
IMO this should be pulled out into a new
EntryListRow
component and we can do away with thememo
. I do think it's worth checking that there isn't a degradation of performance if we do this, but I wouldn't expect there to be any noticeable change either way. Therefore I'd vote for simplifying by removing thememo
.