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