Skip to content

Commit c640507

Browse files
committed
chore(content-picker): Migrate Content
1 parent a4a7a10 commit c640507

File tree

2 files changed

+95
-8
lines changed

2 files changed

+95
-8
lines changed

src/elements/content-picker/Content.js src/elements/content-picker/Content.js.flow

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
/**
2-
* @flow
3-
* @file File picker header and list component
4-
* @author Box
5-
*/
6-
71
import * as React from 'react';
8-
// $FlowFixMe TypeScript file
92
import EmptyView from '../common/empty-view';
103
import ProgressBar from '../common/progress-bar';
114
import ItemList from './ItemList';
@@ -92,4 +85,4 @@ const Content = ({
9285
</div>
9386
);
9487

95-
export default Content;
88+
export default Content;
+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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

Comments
 (0)