import React from 'react'; import { useIntl } from 'react-intl'; import noop from 'lodash/noop'; import type { SelectionMode } from 'react-aria-components'; import { Cell, Column, Row, Table, TableBody, TableHeader, Text } from '@box/blueprint-web'; import { ItemDate, ItemOptions, ItemTypeIcon } from '../item'; import getSize from '../../../utils/size'; import { SORT_ASC, SORT_DESC, TYPE_FOLDER, TYPE_WEBLINK, VIEW_MODE_LIST, VIEW_RECENTS } from '../../../constants'; import { ITEM_ICON_SIZE, ITEM_LIST_COLUMNS, MEDIUM_ITEM_LIST_COLUMNS, SMALL_ITEM_LIST_COLUMNS } from './constants'; import messages from './messages'; import type { BoxItem, SortBy, SortDirection, View } from '../../../common/types/core'; import type { ItemAction, ItemEventHandlers, ItemEventPermissions } from '../item'; import type { ItemListColumn } from './types'; import './ItemList.scss'; export interface ItemListProps extends ItemEventHandlers, ItemEventPermissions { isMedium?: boolean; isSmall?: boolean; isTouch?: boolean; itemActions?: ItemAction[]; items: BoxItem[]; onSortChange?: (sortBy: SortBy, sortDirection: SortDirection) => void; portalElement?: HTMLElement; selectionMode?: SelectionMode; sortBy?: SortBy; sortDirection?: SortDirection; view: View; } const ItemList = ({ canPreview, isMedium, isSmall, isTouch, items, onItemClick = noop, onSortChange = noop, selectionMode, sortBy, sortDirection, view, ...rest }: ItemListProps) => { const { formatMessage } = useIntl(); let defaultColumns: ItemListColumn[] = ITEM_LIST_COLUMNS; if (isSmall) { defaultColumns = SMALL_ITEM_LIST_COLUMNS; } if (isMedium) { defaultColumns = MEDIUM_ITEM_LIST_COLUMNS; } const listColumns = defaultColumns.map(({ messageId, ...column }) => { return { children: formatMessage(messages[messageId]), key: column.id, ...column }; }); // TODO: Refactor ContentExplorer to use SortDirection system from Blueprint const handleSortChange = sortDescriptor => { const { column, direction } = sortDescriptor; onSortChange(column, direction === 'ascending' ? SORT_ASC : SORT_DESC); }; return (