fix(player): fix virtualization

This commit is contained in:
nick-delirium 2023-04-27 14:22:19 +02:00
parent 1d9c8f4b93
commit f71f104fee
6 changed files with 20 additions and 22 deletions

View file

@ -29,7 +29,7 @@ interface IProps {
function EventsBlock(props: IProps) {
const [mouseOver, setMouseOver] = React.useState(true)
const scroller = React.useRef<List>(null)
const cache = useCellMeasurerCache(undefined, {
const cache = useCellMeasurerCache( {
fixedWidth: true,
defaultHeight: 300
});

View file

@ -29,7 +29,7 @@ interface IProps {
function EventsBlock(props: IProps) {
const [mouseOver, setMouseOver] = React.useState(true);
const scroller = React.useRef<List>(null);
const cache = useCellMeasurerCache(undefined, {
const cache = useCellMeasurerCache( {
fixedWidth: true,
defaultHeight: 300,
});

View file

@ -112,7 +112,7 @@ function ConsolePanel({ isLive }: { isLive: boolean }) {
}
}, [activeIndex]);
const cache = useCellMeasurerCache(filteredList)
const cache = useCellMeasurerCache()
const showDetails = (log: any) => {
setIsDetailsModalActive(true);
@ -135,19 +135,17 @@ function ConsolePanel({ isLive }: { isLive: boolean }) {
return (
// @ts-ignore
<CellMeasurer cache={cache} columnIndex={0} key={key} rowIndex={index} parent={parent}>
{() => (
<ConsoleRow
style={style}
log={item}
jump={jump}
iconProps={getIconProps(item.level)}
renderWithNL={renderWithNL}
onClick={() => showDetails(item)}
recalcHeight={() => {
(_list as any).current.recomputeRowHeights(index);
cache.clear(index, 0)
}}
/>
{({ measure, registerChild }) => (
<div ref={registerChild} style={style}>
<ConsoleRow
log={item}
jump={jump}
iconProps={getIconProps(item.level)}
renderWithNL={renderWithNL}
onClick={() => showDetails(item)}
recalcHeight={measure}
/>
</div>
)}
</CellMeasurer>
)

View file

@ -19,9 +19,12 @@ function ConsoleRow(props: Props) {
const canExpand = lines.length > 1;
const clickable = canExpand || !!log.errorId;
React.useEffect(() => {
recalcHeight?.();
}, [expanded])
const toggleExpand = () => {
setExpanded(!expanded);
setTimeout(() => recalcHeight?.(), 0);
};
return (
<div

View file

@ -58,7 +58,7 @@ function StackEventPanel() {
timeoutStartAutoscroll()
}
const cache = useCellMeasurerCache(filteredList)
const cache = useCellMeasurerCache()
const showDetails = (item: any) => {
setIsDetailsModalActive(true)

View file

@ -1,12 +1,9 @@
import { useMemo } from 'react'
import { CellMeasurerCache, CellMeasurerCacheParams } from 'react-virtualized';
import useLatestRef from 'App/hooks/useLatestRef'
export default function useCellMeasurerCache(itemList?: any[], options?: CellMeasurerCacheParams) {
const filteredListRef = itemList ? useLatestRef(itemList) : undefined
export default function useCellMeasurerCache(options?: CellMeasurerCacheParams) {
return useMemo(() => new CellMeasurerCache({
fixedWidth: true,
keyMapper: filteredListRef ? (index) => filteredListRef.current[index] : undefined,
...options
}), [])
}