-
Notifications
You must be signed in to change notification settings - Fork 116
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
Conversation
tonyjin
commented
Aug 21, 2017
- Partially reverts changes from Chore: Preview.js cleanup and slight refactor #24 and will enable New: Preview file from offline passed file #326
- Adds 'id' to FILE_FIELDS since we use that to validate the file object passed in
// 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', |
There was a problem hiding this comment.
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.
f0a6932
to
3c0a73c
Compare
src/lib/Preview.js
Outdated
// load the preview | ||
this.load(fileId); | ||
// Check if passed in file is a well-formed Box File object | ||
if (typeof fileIdOrFile === 'object' && !checkFileValid(fileIdOrFile)) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
src/lib/Preview.js
Outdated
if (typeof fileIdOrFile === 'string') { | ||
// Use cached file data if available, otherwise create empty file object | ||
this.file = this.cache.get(fileIdOrFile) || { id: fileIdOrFile }; | ||
} else { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
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)