Skip to content

Commit 94c5d08

Browse files
authored
Update: Only request applicable API fields (#54)
Only content explorer should be requesting preview related api fields. Likewise only content explorer should get preview sidebar related fields only if it is there. Adds new colors to timeline component which now shows random colors for each time line. Some UI changes.
1 parent 8b19970 commit 94c5d08

26 files changed

Lines changed: 573 additions & 160 deletions

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@
150150
"prettier": "^1.5.3",
151151
"prettier-eslint-cli": "^4.1.1",
152152
"properties-parser": "^0.3.1",
153+
"randomcolor": "^0.5.3",
153154
"react": "^15.6.1",
154155
"react-addons-test-utils": "^15.6.0",
155156
"react-dom": "^15.6.1",

src/api/File.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,9 @@
55
*/
66

77
import Item from './Item';
8-
import {
9-
FIELD_DOWNLOAD_URL,
10-
CACHE_PREFIX_FILE,
11-
FIELDS_TO_FETCH,
12-
X_REP_HINTS,
13-
TYPED_ID_FILE_PREFIX
14-
} from '../constants';
158
import Cache from '../util/Cache';
9+
import getFields from '../util/fields';
10+
import { FIELD_DOWNLOAD_URL, CACHE_PREFIX_FILE, X_REP_HINTS, TYPED_ID_FILE_PREFIX } from '../constants';
1611
import type { BoxItem } from '../flowTypes';
1712

1813
class File extends Item {
@@ -71,13 +66,20 @@ class File extends Item {
7166
/**
7267
* Gets a box file
7368
*
74-
* @param {string} id File id
75-
* @param {Function} successCallback Function to call with results
76-
* @param {Function} errorCallback Function to call with errors
77-
* @param {boolean} forceFetch Bypasses the cache
69+
* @param {string} id - File id
70+
* @param {Function} successCallback - Function to call with results
71+
* @param {Function} errorCallback - Function to call with errors
72+
* @param {boolean|void} [forceFetch] - Bypasses the cache
73+
* @param {boolean|void} [includePreviewSidebar] - Optionally include preview sidebar fields
7874
* @return {Promise}
7975
*/
80-
file(id: string, successCallback: Function, errorCallback: Function, forceFetch: boolean = false): Promise<void> {
76+
file(
77+
id: string,
78+
successCallback: Function,
79+
errorCallback: Function,
80+
forceFetch: boolean = false,
81+
includePreviewSidebarFields: boolean = false
82+
): Promise<void> {
8183
if (this.isDestroyed()) {
8284
return Promise.reject();
8385
}
@@ -104,7 +106,7 @@ class File extends Item {
104106
id: this.getTypedFileId(id),
105107
url: this.getUrl(id),
106108
params: {
107-
fields: FIELDS_TO_FETCH
109+
fields: getFields(true, includePreviewSidebarFields)
108110
},
109111
headers: { 'X-Rep-Hints': X_REP_HINTS }
110112
})

src/api/Folder.js

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import sort from '../util/sorter';
1111
import FileAPI from '../api/File';
1212
import WebLinkAPI from '../api/WebLink';
1313
import Cache from '../util/Cache';
14-
import { FIELDS_TO_FETCH, CACHE_PREFIX_FOLDER, X_REP_HINTS } from '../constants';
14+
import getFields from '../util/fields';
15+
import { CACHE_PREFIX_FOLDER, X_REP_HINTS } from '../constants';
1516
import getBadItemError from '../util/error';
1617
import type {
1718
BoxItem,
@@ -66,6 +67,16 @@ class Folder extends Item {
6667
*/
6768
errorCallback: Function;
6869

70+
/**
71+
* @property {boolean}
72+
*/
73+
includePreviewFields: boolean;
74+
75+
/**
76+
* @property {boolean}
77+
*/
78+
includePreviewSidebarFields: boolean;
79+
6980
/**
7081
* Creates a key for the cache
7182
*
@@ -217,7 +228,7 @@ class Folder extends Item {
217228
params: {
218229
offset: this.offset,
219230
limit: LIMIT_ITEM_FETCH,
220-
fields: FIELDS_TO_FETCH
231+
fields: getFields(this.includePreviewFields, this.includePreviewSidebarFields)
221232
},
222233
headers: { 'X-Rep-Hints': X_REP_HINTS }
223234
})
@@ -228,12 +239,14 @@ class Folder extends Item {
228239
/**
229240
* Gets a box folder and its items
230241
*
231-
* @param {string} id Folder id
232-
* @param {string} sortBy sort by field
233-
* @param {string} sortDirection sort direction
234-
* @param {Function} successCallback Function to call with results
235-
* @param {Function} errorCallback Function to call with errors
236-
* @param {boolean} forceFetch Bypasses the cache
242+
* @param {string} id - Folder id
243+
* @param {string} sortBy - sort by field
244+
* @param {string} sortDirection - sort direction
245+
* @param {Function} successCallback - Function to call with results
246+
* @param {Function} errorCallback - Function to call with errors
247+
* @param {boolean|void} [forceFetch] - Bypasses the cache
248+
* @param {boolean|void} [includePreview] - Optionally include preview fields
249+
* @param {boolean|void} [includePreviewSidebar] - Optionally include preview sidebar fields
237250
* @return {void}
238251
*/
239252
folder(
@@ -242,7 +255,9 @@ class Folder extends Item {
242255
sortDirection: SortDirection,
243256
successCallback: Function,
244257
errorCallback: Function,
245-
forceFetch: boolean = false
258+
forceFetch: boolean = false,
259+
includePreviewFields: boolean = false,
260+
includePreviewSidebarFields: boolean = false
246261
): void {
247262
if (this.isDestroyed()) {
248263
return;
@@ -256,6 +271,8 @@ class Folder extends Item {
256271
this.errorCallback = errorCallback;
257272
this.sortBy = sortBy;
258273
this.sortDirection = sortDirection;
274+
this.includePreviewFields = includePreviewFields;
275+
this.includePreviewSidebarFields = includePreviewSidebarFields; // implies preview
259276

260277
// Clear the cache if needed
261278
if (forceFetch) {
@@ -316,7 +333,7 @@ class Folder extends Item {
316333
return Promise.reject();
317334
}
318335

319-
const url = `${this.getUrl()}?fields=${FIELDS_TO_FETCH}`;
336+
const url = `${this.getUrl()}?fields=${getFields()}`;
320337
return this.xhr
321338
.post({
322339
url,

src/api/Metadata.js

Lines changed: 115 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ class Metadata extends Item {
163163
{
164164
id: uniqueid('time_'),
165165
start: 20,
166-
end: 30
166+
end: 80
167167
},
168168
{
169169
id: uniqueid('time_'),
@@ -182,14 +182,127 @@ class Metadata extends Item {
182182
}
183183
]
184184
},
185+
{
186+
id: uniqueid('cardentry_'),
187+
type: 'text',
188+
text: 'Games',
189+
appears: [
190+
{
191+
id: uniqueid('time_'),
192+
start: 100,
193+
end: 810
194+
},
195+
{
196+
id: uniqueid('time_'),
197+
start: 1500,
198+
end: 1800
199+
},
200+
{
201+
id: uniqueid('time_'),
202+
start: 1950,
203+
end: 2310
204+
}
205+
]
206+
},
185207
{
186208
id: uniqueid('cardentry_'),
187209
type: 'image',
188210
url: 'http://www.globalo.com/content/uploads/2015/12/darth-vader.jpg',
189211
appears: [
190212
{
191213
id: uniqueid('time_'),
192-
start: 2530,
214+
start: 0,
215+
end: 150
216+
},
217+
{
218+
id: uniqueid('time_'),
219+
start: 200,
220+
end: 400
221+
},
222+
{
223+
id: uniqueid('time_'),
224+
start: 800,
225+
end: 1200
226+
},
227+
{
228+
id: uniqueid('time_'),
229+
start: 2000,
230+
end: 2560
231+
}
232+
]
233+
},
234+
{
235+
id: uniqueid('cardentry_'),
236+
type: 'image',
237+
url: 'http://www.globalo.com/content/uploads/2015/12/darth-vader.jpg',
238+
appears: [
239+
{
240+
id: uniqueid('time_'),
241+
start: 300,
242+
end: 600
243+
},
244+
{
245+
id: uniqueid('time_'),
246+
start: 1000,
247+
end: 1400
248+
},
249+
{
250+
id: uniqueid('time_'),
251+
start: 1500,
252+
end: 1800
253+
},
254+
{
255+
id: uniqueid('time_'),
256+
start: 2200,
257+
end: 2560
258+
}
259+
]
260+
},
261+
{
262+
id: uniqueid('cardentry_'),
263+
type: 'text',
264+
text: 'Books',
265+
appears: [
266+
{
267+
id: uniqueid('time_'),
268+
start: 20,
269+
end: 300
270+
},
271+
{
272+
id: uniqueid('time_'),
273+
start: 1000,
274+
end: 2100
275+
},
276+
{
277+
id: uniqueid('time_'),
278+
start: 2500,
279+
end: 3300
280+
}
281+
]
282+
},
283+
{
284+
id: uniqueid('cardentry_'),
285+
type: 'image',
286+
url: 'http://www.globalo.com/content/uploads/2015/12/darth-vader.jpg',
287+
appears: [
288+
{
289+
id: uniqueid('time_'),
290+
start: 100,
291+
end: 200
292+
},
293+
{
294+
id: uniqueid('time_'),
295+
start: 300,
296+
end: 800
297+
},
298+
{
299+
id: uniqueid('time_'),
300+
start: 1000,
301+
end: 1200
302+
},
303+
{
304+
id: uniqueid('time_'),
305+
start: 2200,
193306
end: 2560
194307
}
195308
]

src/api/Recents.js

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,8 @@ import Cache from '../util/Cache';
1212
import flatten from '../util/flatten';
1313
import sort from '../util/sorter';
1414
import getBadItemError from '../util/error';
15-
import {
16-
FIELDS_TO_FETCH,
17-
DEFAULT_ROOT,
18-
CACHE_PREFIX_RECENTS,
19-
SORT_DESC,
20-
FIELD_INTERACTED_AT,
21-
X_REP_HINTS
22-
} from '../constants';
15+
import getFields from '../util/fields';
16+
import { DEFAULT_ROOT, CACHE_PREFIX_RECENTS, SORT_DESC, FIELD_INTERACTED_AT, X_REP_HINTS } from '../constants';
2317
import type {
2418
Crumb,
2519
BoxItem,
@@ -63,6 +57,16 @@ class Recents extends Base {
6357
*/
6458
sortDirection: SortDirection;
6559

60+
/**
61+
* @property {boolean}
62+
*/
63+
includePreviewFields: boolean;
64+
65+
/**
66+
* @property {boolean}
67+
*/
68+
includePreviewSidebarFields: boolean;
69+
6670
/**
6771
* Creates a key for the cache
6872
*
@@ -187,7 +191,7 @@ class Recents extends Base {
187191
.get({
188192
url: this.getUrl(),
189193
params: {
190-
fields: FIELDS_TO_FETCH
194+
fields: getFields(this.includePreviewFields, this.includePreviewSidebarFields)
191195
},
192196
headers: { 'X-Rep-Hints': X_REP_HINTS }
193197
})
@@ -199,11 +203,13 @@ class Recents extends Base {
199203
* Gets recent files
200204
*
201205
* @param {string} id - parent folder id
202-
* @param {string} sortBy sort by field
203-
* @param {string} sortDirection sort direction
206+
* @param {string} sortBy - sort by field
207+
* @param {string} sortDirection - sort direction
204208
* @param {Function} successCallback - Function to call with results
205209
* @param {Function} errorCallback - Function to call with errors
206-
* @param {boolean} forceUpdate Bypasses the cache
210+
* @param {boolean|void} [forceFetch] - Bypasses the cache
211+
* @param {boolean|void} [includePreview] - Optionally include preview fields
212+
* @param {boolean|void} [includePreviewSidebar] - Optionally include preview sidebar fields
207213
* @return {void}
208214
*/
209215
recents(
@@ -212,7 +218,9 @@ class Recents extends Base {
212218
sortDirection: SortDirection,
213219
successCallback: Function,
214220
errorCallback: Function,
215-
forceFetch: boolean = false
221+
forceFetch: boolean = false,
222+
includePreviewFields: boolean = false,
223+
includePreviewSidebarFields: boolean = false
216224
): void {
217225
if (this.isDestroyed()) {
218226
return;
@@ -224,6 +232,8 @@ class Recents extends Base {
224232
this.errorCallback = errorCallback;
225233
this.sortBy = sortBy;
226234
this.sortDirection = sortDirection;
235+
this.includePreviewFields = includePreviewFields;
236+
this.includePreviewSidebarFields = includePreviewSidebarFields;
227237

228238
const cache: Cache = this.getCache();
229239
this.key = this.getCacheKey(this.id);

0 commit comments

Comments
 (0)