Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New: Support well-formed file object in show() #328

Merged
merged 1 commit into from
Aug 22, 2017

Conversation

tonyjin
Copy link
Contributor

@tonyjin tonyjin commented Aug 21, 2017

// a breaking change and should be done with care. Clients that leverage functionality dependent on this format
// (e.g. Box.Preview.updateFileCache()) will need to be updated if this list is modified.
const FILE_FIELDS = [
'id',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normally, id is returned with any get files API call. Now, since we also use this list for simple validation of a passed in file object, I'm explicitly adding this so developers cannot pass in a file object without an ID.

// load the preview
this.load(fileId);
// Check if passed in file is a well-formed Box File object
if (typeof fileIdOrFile === 'object' && !checkFileValid(fileIdOrFile)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should move the === object check inside checkFileValid() since it already has a similar null check

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, move the checkFileValid check below

if (typeof fileIdOrFile === 'string') {
// Use cached file data if available, otherwise create empty file object
this.file = this.cache.get(fileIdOrFile) || { id: fileIdOrFile };
} else {
Copy link
Contributor

@priyajeet priyajeet Aug 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this else if checkValidFile() else throw the error. So that load() function is guarded. Because we use load() function for all internal calls, which eventually may also send a file object eventually.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestions, thanks. Updated.

- Partially reverts changes from box#24.
- Adds 'id' to FILE_FIELDS since we use that to validate the file object passed in
@tonyjin tonyjin merged commit 540a011 into box:master Aug 22, 2017
@tonyjin tonyjin deleted the file-show branch August 22, 2017 19:53
pramodsum added a commit to JustinHoldstock/box-content-preview that referenced this pull request Jan 25, 2019
https://github.com/box/box-annotations/releases/tag/v3.7.1

* Update Translations (box#328) ([39805b8](box/box-annotations@39805b8)), closes [box#328](box/box-annotations#328)
* Chore: Add escape hotkey on AnnotationPopover (box#327) ([e92ec85](box/box-annotations@e92ec85)), closes [box#327](box/box-annotations#327)
* Fix: Highlight selection on Surface (box#326) ([6a3b83a](box/box-annotations@6a3b83a)), closes [box#326](box/box-annotations#326)
* Fix: Import correct styling for flyout component (box#325) ([14d65f6](box/box-annotations@14d65f6)), closes [box#325](box/box-annotations#325)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants