Skip to content

Commit faa39dd

Browse files
refactor(content-picker): add Flow type definitions
1 parent 2dce2af commit faa39dd

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/**
2+
* @flow
3+
* @file File picker header and list component
4+
* @author Box
5+
*/
6+
7+
import * as React from 'react';
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 { View, Collection } from '../../common/types/core';
13+
14+
import './Content.scss';
15+
16+
type Props = {
17+
canSetShareAccess: boolean,
18+
currentCollection: Collection,
19+
extensionsWhitelist: string[],
20+
focusedRow: number,
21+
hasHitSelectionLimit: boolean,
22+
isSingleSelect: boolean,
23+
isSmall: boolean,
24+
onFocusChange: Function,
25+
onItemClick: Function,
26+
onItemSelect: Function,
27+
onShareAccessChange: Function,
28+
rootElement?: HTMLElement,
29+
rootId: string,
30+
selectableType: string,
31+
tableRef: Function,
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+
rootElement,
51+
currentCollection,
52+
tableRef,
53+
isSmall,
54+
isSingleSelect,
55+
hasHitSelectionLimit,
56+
canSetShareAccess,
57+
onItemSelect,
58+
onItemClick,
59+
onShareAccessChange,
60+
onFocusChange,
61+
extensionsWhitelist,
62+
}: Props) => (
63+
<div className="bcp-content">
64+
{view === VIEW_ERROR || view === VIEW_SELECTED ? null : (
65+
<ProgressBar percent={currentCollection.percentLoaded} />
66+
)}
67+
{isEmpty(view, currentCollection) ? (
68+
<EmptyView />
69+
) : (
70+
<ItemList
71+
view={view}
72+
rootId={rootId}
73+
rootElement={rootElement}
74+
currentCollection={currentCollection}
75+
tableRef={tableRef}
76+
isSmall={isSmall}
77+
isSingleSelect={isSingleSelect}
78+
hasHitSelectionLimit={hasHitSelectionLimit}
79+
canSetShareAccess={canSetShareAccess}
80+
onItemSelect={onItemSelect}
81+
onItemClick={onItemClick}
82+
onShareAccessChange={onShareAccessChange}
83+
onFocusChange={onFocusChange}
84+
extensionsWhitelist={extensionsWhitelist}
85+
/>
86+
)}
87+
</div>
88+
);
89+
90+
export default Content;

0 commit comments

Comments
 (0)