Skip to content

Commit ee57ad9

Browse files
authored
Update: Add onNavigate to explorer (#7)
Also fixes upload not working in explorer and picker Fixes some style issues
1 parent 3ab1c6b commit ee57ad9

21 files changed

Lines changed: 116 additions & 76 deletions

File tree

README.md

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,23 @@
99
The Box UI Elements are currently in beta and may contain bugs. Their interfaces may also update as needed. Please email [box-ui-kit-feedback@box.com](mailto:box-ui-kit-feedback@box.com) to report issues or provide feedback.
1010

1111
## Usage
12-
If you are not building a React based app, please follow the [documentation link](https://developer.box.com/docs/box-ui-elements) to use the Box UI Elements as simple library includes. Continue reading below to import the components into your React based app.
12+
If you are not building a [React](https://facebook.github.io/react) based app, please follow the [documentation on our developer docs](https://developer.box.com/docs/box-ui-elements), which shows how to use the Box UI Elements via script includes. Continue reading below to import the components into your React based app.
1313

1414
## Installation
1515
`yarn add box-ui-elements`
1616

1717
## Authentication
18-
We have designed the Box UI Elements in an authentication-type agnostic way so whether you are using them for users who have Box accounts (Managed Users) or non-Box accounts (App Users), they should just work out of the box. They only expect a **token** to be passed in for authentication. Please refer to the documentation links to learn more about authentication and generating access tokens.
18+
We have designed the Box UI Elements in an authentication-type agnostic way. Whether you are using them for users who have Box accounts (Managed Users) or non-Box accounts (App Users), they should just work out of the box. They only expect an **access token** to be passed in for authentication. Please refer to the documentation links to learn more about authentication and generating access tokens.
1919

2020
## CSS
21-
The Box UI Elements require their corresponding CSS stylesheet to render properly. If you import the CSS as shown in the examples below, you will require setting up webpack's style-loader / css-loader plugins to properly process the CSS. Alternatively, you can just include the CSS file in your apps's HTML without importing it into javascript.
21+
The Box UI Elements require their corresponding CSS stylesheet to render properly. If you import the CSS as shown in the examples below, you will require setting up webpack's style-loader / css-loader plugins to properly process the CSS. Alternatively, you can just include the CSS file (hosted versions can be found in the documentation links) in your apps's HTML without importing it into javascript.
2222

2323
## Components
24-
You can import the `ContentExplorer`, `ContentPicker`, `ContentUploader`, `ContentPreview` or `ContentTree`. Likewise, you can also import the `ContentPickerPopup`, `ContentUploaderPopup` or `ContentTreePopup` which are popup versions for the picker, uploader and content tree respectively.
24+
You can import the `ContentExplorer`, `ContentPicker`, `ContentUploader`, `ContentPreview` or `ContentTree`. Likewise, you can also import the `ContentPickerPopup`, `ContentUploaderPopup` or `ContentTreePopup` which are popup versions for the content picker, content uploader and content tree respectively.
2525

2626
## Content Explorer ([Documentation](https://developer.box.com/docs/box-content-explorer))
2727

28-
<img src="https://user-images.githubusercontent.com/1075325/27419186-596c98ba-56d4-11e7-818e-f5050d5a29fd.png" width="75%"/>
28+
<img src="https://user-images.githubusercontent.com/1075325/27887154-092a232a-6194-11e7-82f4-697331ac5cbe.png" width="75%"/>
2929

3030
```js
3131
import React from 'react';
@@ -51,24 +51,25 @@ render(
5151
| Attribute | Type | Default | Description |
5252
| --- | --- | --- | --- |
5353
| token* | string | | *See the [developer docs](https://developer.box.com/docs/box-content-explorer#section-options).* |
54-
| getLocalizedMessage* | function | | Function to get localized strings. |
54+
| getLocalizedMessage* | function(string, { [string]: string }) | | Function to get localized strings. |
5555
| rootFolderId | string | `0` | The root folder for the content explorer. |
5656
| currentFolderId | string | | The current folder shown for the content explorer. This should be a sub folder to the root folder. |
5757
| sortBy | string | `name` | *See the [developer docs](https://developer.box.com/docs/box-content-explorer#section-options).* |
58-
| sortDirection | SortDirection | `asc` | *See the [developer docs](https://developer.box.com/docs/box-content-explorer#section-options).* |
58+
| sortDirection | string | `asc` | *See the [developer docs](https://developer.box.com/docs/box-content-explorer#section-options).* |
5959
| canPreview | boolean | `true` | *See the [developer docs](https://developer.box.com/docs/box-content-explorer#section-options).* |
6060
| canDownload | boolean | `true` | *See the [developer docs](https://developer.box.com/docs/box-content-explorer#section-options).* |
6161
| canDelete | boolean | `true` | *See the [developer docs](https://developer.box.com/docs/box-content-explorer#section-options).* |
6262
| canUpload | boolean | `true` | *See the [developer docs](https://developer.box.com/docs/box-content-explorer#section-options).* |
6363
| canRename | boolean | `true` | *See the [developer docs](https://developer.box.com/docs/box-content-explorer#section-options).* |
6464
| canShare | boolean | `true` | *See the [developer docs](https://developer.box.com/docs/box-content-explorer#section-options).* |
6565
| canSetShareAccess | boolean | `true` | *See the [developer docs](https://developer.box.com/docs/box-content-explorer#section-options).* |
66-
| onDelete | function | | Callback function for when item(s) are deleted. |
67-
| onDownload | function | | Callback function for when item(s) are downloaded. |
68-
| onPreview | function | | Callback function for when an item is previewed. |
69-
| onRename | function | | Callback function for when an item is renamed. |
70-
| onSelect | function | | Callback function for when item(s) are selected. |
71-
| onUpload | function | | Callback function for when item(s) are uploaded. |
66+
| onDelete | function(Array&lt;[File](https://developer.box.com/reference#file-object)&gt;) | | Callback function for when item(s) are deleted. |
67+
| onDownload | function(Array&lt;[File](https://developer.box.com/reference#file-object)&gt;) | | Callback function for when item(s) are downloaded. |
68+
| onPreview | function([File](https://developer.box.com/reference#file-object)) | | Callback function for when an item is previewed. |
69+
| onRename | function([File](https://developer.box.com/reference#file-object)) | | Callback function for when an item is renamed. |
70+
| onSelect | function(Array&lt;[Folder](https://developer.box.com/reference#folder-object)&#124;[File](https://developer.box.com/reference#file-object)&#124;[Web Link](https://developer.box.com/reference#web-link-object)&gt;) | | Callback function for when item(s) are selected. |
71+
| onUpload | function(Array&lt;[File](https://developer.box.com/reference#file-object)&gt;) | | Callback function for when item(s) are uploaded. |
72+
| onNavigate | function([File](https://developer.box.com/reference#file-object)) | | Callback function for when navigating into a folder. |
7273
| isTouch | boolean | | *See the [developer docs](https://developer.box.com/docs/box-content-explorer#section-options).* |
7374
| logoUrl | string | | *See the [developer docs](https://developer.box.com/docs/box-content-explorer#section-options).* |
7475
| sharedLink | string | | *See the [developer docs](https://developer.box.com/docs/box-content-explorer#section-options).* |
@@ -77,7 +78,7 @@ render(
7778

7879
## Content Picker ([Documentation](https://developer.box.com/docs/box-content-picker))
7980

80-
<img src="https://user-images.githubusercontent.com/1075325/27419182-59696758-56d4-11e7-89d5-a462d0ea742c.png" width="75%"/>
81+
<img src="https://user-images.githubusercontent.com/1075325/27887156-0940ee3e-6194-11e7-8e22-961139e82dfe.png" width="75%"/>
8182

8283
```js
8384
import React from 'react';
@@ -103,12 +104,12 @@ render(
103104
| Attribute | Type | Default | Description |
104105
| --- | --- | --- | --- |
105106
| token* | string | | *See the [developer docs](https://developer.box.com/docs/box-content-picker#section-options).* |
106-
| getLocalizedMessage* | function | | Function to get localized strings. |
107+
| getLocalizedMessage* | function(string, { [string]: string }) | | Function to get localized strings. |
107108
| rootFolderId | string | `0` | The root folder for the content picker. |
108109
| type | string | `file, web_link` | Indicates which type of items can be picked. Should be a comma seperated combination of `file`, `folder` or `web_link`. |
109110
| sortBy | string | `name` | *See the [developer docs](https://developer.box.com/docs/box-content-picker#section-options).* |
110-
| sortDirection | SortDirection | `asc` | *See the [developer docs](https://developer.box.com/docs/box-content-picker#section-options).* |
111-
| extensions | string[] | `[]` | *See the [developer docs](https://developer.box.com/docs/box-content-picker#section-options).* |
111+
| sortDirection | string | `asc` | *See the [developer docs](https://developer.box.com/docs/box-content-picker#section-options).* |
112+
| extensions | Array&lt;string&gt; | `[]` | *See the [developer docs](https://developer.box.com/docs/box-content-picker#section-options).* |
112113
| maxSelectable | number | `Infinity` | *See the [developer docs](https://developer.box.com/docs/box-content-picker#section-options).* |
113114
| canUpload | boolean | `true` | *See the [developer docs](https://developer.box.com/docs/box-content-picker#section-options).* |
114115
| canSetShareAccess | boolean | `true` | *See the [developer docs](https://developer.box.com/docs/box-content-picker#section-options).* |
@@ -120,7 +121,7 @@ render(
120121
| sharedLinkPassword | string | | *See the [developer docs](https://developer.box.com/docs/box-content-picker#section-options).* |
121122

122123
## Content Uploader ([Documentation](https://developer.box.com/docs/box-content-uploader))
123-
<img src="https://user-images.githubusercontent.com/1075325/27419181-596712b4-56d4-11e7-911e-d230a02efd5e.png" width="75%"/>
124+
<img src="https://user-images.githubusercontent.com/1075325/27887153-09243762-6194-11e7-8d2d-cf654d9364bc.png" width="75%"/>
124125

125126
```js
126127
import React from 'react';
@@ -146,10 +147,10 @@ render(
146147
| Attribute | Type | Default | Description |
147148
| --- | --- | --- | --- |
148149
| token* | string | | *See the [developer docs](https://developer.box.com/docs/box-content-uploader#section-options).* |
149-
| getLocalizedMessage* | function | | Function to get localized strings. |
150+
| getLocalizedMessage* | function(string, { [string]: string }) | | Function to get localized strings. |
150151
| rootFolderId | string | `0` | The root folder for the content uploader. |
151152
| onClose | function | | Callback function for when the close button is pressed. |
152-
| onComplete | function | | Callback function for when uploads are complete. |
153+
| onComplete | function(Array&lt;[File](https://developer.box.com/reference#file-object)&gt;) | | Callback function for when uploads are complete. |
153154
| isTouch | boolean | | *See the [developer docs](https://developer.box.com/docs/box-content-uploader#section-options).* |
154155
| logoUrl | string | | *See the [developer docs](https://developer.box.com/docs/box-content-uploader#section-options).* |
155156
| sharedLink | string | | *See the [developer docs](https://developer.box.com/docs/box-content-uploader#section-options).* |
@@ -158,7 +159,7 @@ render(
158159

159160
## Content Tree ([Documentation](https://developer.box.com/docs/box-content-tree))
160161

161-
<img src="https://user-images.githubusercontent.com/1075325/27419183-5969c446-56d4-11e7-8dd1-432cd63aa40b.png" width="75%"/>
162+
<img src="https://user-images.githubusercontent.com/1075325/27887155-092e7362-6194-11e7-877d-157726789bef.png" width="75%"/>
162163

163164
```js
164165
import React from 'react';
@@ -184,10 +185,10 @@ render(
184185
| Attribute | Type | Default | Description |
185186
| --- | --- | --- | --- |
186187
| token* | string | | *See the [developer docs](https://developer.box.com/docs/box-content-tree#section-options).* |
187-
| getLocalizedMessage* | function | | Function to get localized strings. |
188+
| getLocalizedMessage* | function(string, { [string]: string }) | | Function to get localized strings. |
188189
| rootFolderId | string | `0` | The root folder for the content tree. |
189190
| type | string | `file, web_link, folder` | Indicates which type of items show up in the tree. Should be a comma seperated combination of `file`, `folder` or `web_link`. |
190-
| onClick | function | | Callback function for when an item is clicked. |
191+
| onClick | function([Folder](https://developer.box.com/reference#folder-object)&#124;[File](https://developer.box.com/reference#file-object)&#124;[Web Link](https://developer.box.com/reference#web-link-object)) | | Callback function for when an item is clicked. |
191192
| isTouch | boolean | | *See the [developer docs](https://developer.box.com/docs/box-content-tree#section-options).* |
192193
| logoUrl | string | | *See the [developer docs](https://developer.box.com/docs/box-content-tree#section-options).* |
193194
| sharedLink | string | | *See the [developer docs](https://developer.box.com/docs/box-content-tree#section-options).* |
@@ -224,7 +225,7 @@ render(
224225
| fileId* | string | | The id of the file to preview. |
225226
| locale | string | `en-US` | Locale for this component. |
226227
| onLoad | function | | Callback function for when a file preview loads. |
227-
| collection | string[] | `[]` | *See the [developer docs](https://developer.box.com/docs/box-content-preview#section-initialization-and-options).* |
228+
| collection | Array&lt;string&gt; | `[]` | *See the [developer docs](https://developer.box.com/docs/box-content-preview#section-initialization-and-options).* |
228229
| header | string | `light` | *See the [developer docs](https://developer.box.com/docs/box-content-preview#section-initialization-and-options).* |
229230
| logoUrl | string | | *See the [developer docs](https://developer.box.com/docs/box-content-preview#section-initialization-and-options).* |
230231
| sharedLink | string | | *See the [developer docs](https://developer.box.com/docs/box-content-preview#section-initialization-and-options).* |

src/api/Folder.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ import type {
1818
FlattenedBoxItem,
1919
FlattenedBoxItemCollection,
2020
SortBy,
21-
SortDirection
21+
SortDirection,
22+
Collection
2223
} from '../flowTypes';
2324

2425
const LIMIT_ITEM_FETCH = 1000;
@@ -122,16 +123,18 @@ class Folder extends Item {
122123
}
123124

124125
const percentLoaded: number = total_count === 0 ? 100 : entries.length * 100 / total_count;
125-
this.successCallback({
126+
const collection: Collection = {
126127
id,
127128
name,
128129
percentLoaded,
129130
permissions,
131+
boxItem: sortedFolder,
130132
breadcrumbs: path_collection.entries,
131133
sortBy: this.sortBy,
132134
sortDirection: this.sortDirection,
133135
items: entries.map((key: string) => this.getCache().get(key))
134-
});
136+
};
137+
this.successCallback(collection);
135138
}
136139

137140
/**

src/api/Search.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import type {
1717
FlattenedBoxItem,
1818
FlattenedBoxItemCollection,
1919
SortBy,
20-
SortDirection
20+
SortDirection,
21+
Collection
2122
} from '../flowTypes';
2223

2324
const LIMIT_ITEM_FETCH = 200;
@@ -136,13 +137,14 @@ class Search extends Base {
136137
}
137138

138139
const percentLoaded: number = total_count === 0 ? 100 : entries.length * 100 / total_count;
139-
this.successCallback({
140+
const collection: Collection = {
140141
percentLoaded,
141142
id: this.id,
142143
sortBy: this.sortBy,
143144
sortDirection: this.sortDirection,
144145
items: entries.map((key: string) => this.getCache().get(key))
145-
});
146+
};
147+
this.successCallback(collection);
146148
}
147149

148150
/**

src/components/Button/Button.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ type Props = {
2323
type: ButtonType
2424
};
2525

26-
type DefaultProps = {
26+
type DefaultProps = {|
2727
type: ButtonType
28-
};
28+
|};
2929

3030
class Button extends PureComponent<DefaultProps, Props, void> {
3131
props: Props;

src/components/Button/Button.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@
99
font-size: 13px;
1010
line-height: 16px;
1111
margin: 0;
12+
max-width: 100%;
13+
overflow: hidden;
1214
padding: 8px 16px;
1315
position: relative;
1416
text-align: center;
1517
text-decoration: none;
18+
text-overflow: ellipsis;
1619
text-shadow: none;
1720
transition: background-color .05s ease-in-out, border-color .05s ease-in-out;
1821
white-space: nowrap;

src/components/ContentExplorer/ContentExplorer.js

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ type Props = {
7979
onRename: Function,
8080
onSelect: Function,
8181
onUpload: Function,
82+
onNavigate: Function,
8283
logoUrl?: string,
8384
sharedLink?: string,
8485
sharedLinkPassword?: string
@@ -101,7 +102,7 @@ type State = {
101102
errorCode: string
102103
};
103104

104-
type DefaultProps = {
105+
type DefaultProps = {|
105106
rootFolderId: string,
106107
sortBy: SortBy,
107108
sortDirection: SortDirection,
@@ -120,8 +121,9 @@ type DefaultProps = {
120121
onPreview: Function,
121122
onRename: Function,
122123
onSelect: Function,
123-
onUpload: Function
124-
};
124+
onUpload: Function,
125+
onNavigate: Function
126+
|};
125127

126128
class ContentExplorer extends Component<DefaultProps, Props, State> {
127129
id: string;
@@ -151,7 +153,8 @@ class ContentExplorer extends Component<DefaultProps, Props, State> {
151153
onPreview: noop,
152154
onRename: noop,
153155
onSelect: noop,
154-
onUpload: noop
156+
onUpload: noop,
157+
onNavigate: noop
155158
};
156159

157160
/**
@@ -300,6 +303,25 @@ class ContentExplorer extends Component<DefaultProps, Props, State> {
300303
/* eslint-enable no-console */
301304
};
302305

306+
/**
307+
* Focuses the grid and fires navigate event
308+
*
309+
* @private
310+
* @return {void}
311+
*/
312+
finishNavigation() {
313+
const { onNavigate }: Props = this.props;
314+
const { currentCollection: { percentLoaded, boxItem } }: State = this.state;
315+
onNavigate(cloneDeep(boxItem));
316+
317+
// Don't focus the grid until its loaded and user is not already on an interactable element
318+
if (percentLoaded !== 100 || !this.table || !this.table.Grid || isActionableElement(document.activeElement)) {
319+
return;
320+
}
321+
const grid: any = findDOMNode(this.table.Grid);
322+
grid.focus();
323+
}
324+
303325
/**
304326
* Folder fetch success callback
305327
*
@@ -325,13 +347,7 @@ class ContentExplorer extends Component<DefaultProps, Props, State> {
325347
this.closeModals();
326348

327349
// Set the new state and focus the grid for tabbing
328-
this.setState(newState, () => {
329-
if (!this.table || !this.table.Grid || isActionableElement(document.activeElement)) {
330-
return;
331-
}
332-
const grid: any = findDOMNode(this.table.Grid);
333-
grid.focus();
334-
});
350+
this.setState(newState, this.finishNavigation);
335351
};
336352

337353
/**
@@ -993,7 +1009,7 @@ class ContentExplorer extends Component<DefaultProps, Props, State> {
9931009
{canUpload && !!this.appElement
9941010
? <UploadDialog
9951011
isOpen={isUploadModalOpen}
996-
root={id}
1012+
rootFolderId={id}
9971013
token={token}
9981014
sharedLink={sharedLink}
9991015
sharedLinkPassword={sharedLinkPassword}

src/components/ContentPicker/ContentPicker.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ type State = {
8787
isUploadModalOpen: boolean
8888
};
8989

90-
type DefaultProps = {
90+
type DefaultProps = {|
9191
type: string,
9292
rootFolderId: string,
9393
onChoose: Function,
@@ -102,7 +102,7 @@ type DefaultProps = {
102102
uploadHost: string,
103103
clientName: string,
104104
className: string
105-
};
105+
|};
106106

107107
class ContentPicker extends Component<DefaultProps, Props, State> {
108108
id: string;
@@ -717,7 +717,7 @@ class ContentPicker extends Component<DefaultProps, Props, State> {
717717
{canUpload && !!this.appElement
718718
? <UploadDialog
719719
isOpen={isUploadModalOpen}
720-
root={id}
720+
rootFolderId={id}
721721
token={token}
722722
sharedLink={sharedLink}
723723
sharedLinkPassword={sharedLinkPassword}

src/components/ContentPreview/ContentPreview.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ import {
1414
DEFAULT_PREVIEW_LOCALE
1515
} from '../../constants';
1616

17-
type DefaultProps = {
17+
type DefaultProps = {|
1818
apiHost: string,
1919
staticHost: string,
2020
locale: string,
2121
version: string,
2222
className: string
23-
};
23+
|};
2424

2525
type Props = {
2626
fileId: string,

0 commit comments

Comments
 (0)