|
| 1 | +/** |
| 2 | + * @file File picker header and list component |
| 3 | + * @author Box |
| 4 | + */ |
| 5 | + |
| 6 | +import * as React from 'react'; |
| 7 | +import { Table } from '@box/react-virtualized/dist/es/Table'; |
| 8 | +import EmptyView from '../common/empty-view'; |
| 9 | +import ProgressBar from '../common/progress-bar'; |
| 10 | +import ItemList from './ItemList'; |
| 11 | +import { VIEW_ERROR, VIEW_SELECTED } from '../../constants'; |
| 12 | +import type { BoxItem, Collection, View } from '../../common/types/core'; |
| 13 | + |
| 14 | +import './Content.scss'; |
| 15 | + |
| 16 | +export interface ContentProps { |
| 17 | + canSetShareAccess: boolean; |
| 18 | + currentCollection: Collection; |
| 19 | + extensionsWhitelist: string[]; |
| 20 | + focusedRow: number; |
| 21 | + hasHitSelectionLimit: boolean; |
| 22 | + isSingleSelect: boolean; |
| 23 | + isSmall: boolean; |
| 24 | + onFocusChange: (focusedRow: number) => void; |
| 25 | + onItemClick: (item: string | null) => void; |
| 26 | + onItemSelect: (item: BoxItem) => void; |
| 27 | + onShareAccessChange: (access: string, item: BoxItem) => void; |
| 28 | + rootElement?: HTMLElement; |
| 29 | + rootId: string; |
| 30 | + selectableType: string; |
| 31 | + tableRef: (ref: Table) => void; |
| 32 | + view: View; |
| 33 | +} |
| 34 | + |
| 35 | +/** |
| 36 | + * Determines if we should show the empty state |
| 37 | + * |
| 38 | + * @param {string} view the current view |
| 39 | + * @param {Object} currentCollection the current collection |
| 40 | + * @return {boolean} empty or not |
| 41 | + */ |
| 42 | +function isEmpty(view: View, currentCollection: Collection): boolean { |
| 43 | + const { items = [] } = currentCollection; |
| 44 | + return view === VIEW_ERROR || items.length === 0; |
| 45 | +} |
| 46 | + |
| 47 | +const Content = ({ |
| 48 | + view, |
| 49 | + rootId, |
| 50 | + isSmall, |
| 51 | + rootElement, |
| 52 | + focusedRow, |
| 53 | + hasHitSelectionLimit, |
| 54 | + selectableType, |
| 55 | + currentCollection, |
| 56 | + tableRef, |
| 57 | + canSetShareAccess, |
| 58 | + isSingleSelect, |
| 59 | + onItemClick, |
| 60 | + onItemSelect, |
| 61 | + onShareAccessChange, |
| 62 | + onFocusChange, |
| 63 | + extensionsWhitelist, |
| 64 | +}: ContentProps) => ( |
| 65 | + <div className="bcp-content"> |
| 66 | + {view === VIEW_ERROR || view === VIEW_SELECTED ? null : ( |
| 67 | + <ProgressBar percent={currentCollection.percentLoaded} /> |
| 68 | + )} |
| 69 | + {isEmpty(view, currentCollection) ? ( |
| 70 | + <EmptyView view={view} isLoading={currentCollection.percentLoaded !== 100} /> |
| 71 | + ) : ( |
| 72 | + <ItemList |
| 73 | + view={view} |
| 74 | + rootId={rootId} |
| 75 | + isSmall={isSmall} |
| 76 | + rootElement={rootElement} |
| 77 | + focusedRow={focusedRow} |
| 78 | + currentCollection={currentCollection} |
| 79 | + tableRef={tableRef} |
| 80 | + canSetShareAccess={canSetShareAccess} |
| 81 | + hasHitSelectionLimit={hasHitSelectionLimit} |
| 82 | + isSingleSelect={isSingleSelect} |
| 83 | + selectableType={selectableType} |
| 84 | + onItemSelect={onItemSelect} |
| 85 | + onItemClick={onItemClick} |
| 86 | + onFocusChange={onFocusChange} |
| 87 | + onShareAccessChange={onShareAccessChange} |
| 88 | + extensionsWhitelist={extensionsWhitelist} |
| 89 | + /> |
| 90 | + )} |
| 91 | + </div> |
| 92 | +); |
| 93 | + |
| 94 | +export default Content; |
0 commit comments