/** * @flow * @file Item list component * @author Box */ import React from 'react'; import classNames from 'classnames'; import { injectIntl } from 'react-intl'; import type { InjectIntlProvidedProps } from 'react-intl'; import { Table, Column } from 'react-virtualized/dist/es/Table'; import AutoSizer from 'react-virtualized/dist/es/AutoSizer'; import KeyBinder from '../common/KeyBinder'; import nameCellRenderer from '../common/item/nameCellRenderer'; import iconCellRenderer from '../common/item/iconCellRenderer'; import { focus } from '../../utils/dom'; import messages from '../common/messages'; import headerCellRenderer from './headerCellRenderer'; import sizeCellRenderer from './sizeCellRenderer'; import dateCellRenderer from './dateCellRenderer'; import moreOptionsCellRenderer from './moreOptionsCellRenderer'; import { FIELD_DATE, FIELD_ID, FIELD_NAME, FIELD_SIZE, VIEW_FOLDER, VIEW_RECENTS } from '../../constants'; import type { View, Collection } from '../../common/types/core'; import 'react-virtualized/styles.css'; import './ItemList.scss'; type Props = { canDelete: boolean, canDownload: boolean, canPreview: boolean, canRename: boolean, canShare: boolean, currentCollection: Collection, focusedRow: number, isMedium: boolean, isSmall: boolean, isTouch: boolean, onItemClick: Function, onItemDelete: Function, onItemDownload: Function, onItemPreview: Function, onItemRename: Function, onItemSelect: Function, onItemShare: Function, onSortChange: Function, rootElement: HTMLElement, rootId: string, tableRef: Function, view: View, } & InjectIntlProvidedProps; const ItemList = ({ view, isSmall, isMedium, isTouch, rootId, rootElement, canShare, canDownload, canDelete, canPreview, canRename, onItemClick, onItemSelect, onItemDelete, onItemDownload, onItemRename, onItemShare, onItemPreview, onSortChange, currentCollection, tableRef, focusedRow, intl, }: Props) => { const nameCell = nameCellRenderer( rootId, view, onItemClick, onItemSelect, canPreview, isSmall, // shows details if false isTouch, ); const iconCell = iconCellRenderer(); const dateCell = dateCellRenderer(); const sizeAccessCell = sizeCellRenderer(); const moreOptionsCell = moreOptionsCellRenderer( canPreview, canShare, canDownload, canDelete, canRename, onItemSelect, onItemDelete, onItemDownload, onItemRename, onItemShare, onItemPreview, isSmall, ); const isRecents: boolean = view === VIEW_RECENTS; const hasSort: boolean = view === VIEW_FOLDER; const { id, items = [], sortBy, sortDirection }: Collection = currentCollection; const rowCount: number = items.length; const rowClassName = ({ index }) => { if (index === -1) { return 'bce-item-header-row'; } const { selected } = items[index]; return classNames(`bce-item-row bce-item-row-${index}`, { 'bce-item-row-selected': selected, }); }; const sort = ({ sortBy: by, sortDirection: direction }) => { onSortChange(by, direction); }; return ( focus(rootElement, `.bce-item-row-${scrollToRow}`)} > {({ onSectionRendered, scrollToRow, focusOnRender }) => ( {({ width, height }) => ( items[index]} ref={tableRef} rowClassName={rowClassName} scrollToIndex={scrollToRow} sort={sort} sortBy={sortBy} sortDirection={sortDirection} onRowClick={({ rowData }) => onItemSelect(rowData)} onRowsRendered={({ startIndex, stopIndex }) => { onSectionRendered({ rowStartIndex: startIndex, rowStopIndex: stopIndex, }); if (focusOnRender) { focus(rootElement, `.bce-item-row-${scrollToRow}`); } }} > {isSmall ? null : ( )} {isSmall || isMedium ? null : ( )}
)}
)}
); }; export default injectIntl(ItemList);