import React from 'react' import AutoSizer from 'react-virtualized-auto-sizer' import { FixedSizeList as List } from 'react-window' import InfiniteLoader from 'react-window-infinite-loader' import { css } from 'styled-components' import * as A from 'fp-ts/lib/Array' import * as O from 'fp-ts/lib/Option' import { pipe } from 'fp-ts/lib/pipeable' import { isNonEmptyString } from '@monorail/sharedHelpers/typeGuards' import { NoData } from '@monorail/visualComponents/dataStates/DataStates' export const TBodyInfiniteVirtualFixedSizeList = (tbodyComponentProps: { children: Array> className: string style: React.CSSProperties rowHeight: number loadMoreItems: () => null continuationToken: string | undefined NoData: JSX.Element | null Loading: JSX.Element }) => { const { rowHeight, children } = tbodyComponentProps return pipe( children, O.fromPredicate(Array.isArray), O.chain(A.head), O.chain(O.fromPredicate(Array.isArray)), O.chain(O.fromPredicate(A.isNonEmpty)), O.fold( () => { return tbodyComponentProps.NoData }, (items: Array) => { const Row = (rowProps: { index: number; style: React.CSSProperties }) => rowProps.index < items.length ? (
{items[rowProps.index]}
) : (
{tbodyComponentProps.Loading}
) const itemCount = isNonEmptyString( tbodyComponentProps.continuationToken, ) ? items.length + 1 : items.length return ( index < items.length} itemCount={itemCount} > {({ ref, onItemsRendered }) => { return (
{({ width, height }) => ( /* prefer FixedSizeList for performance Daniel Laubacher Thu 30 Jul 2020 **/ {Row} )}
) }}
) }, ), ) }