-
Notifications
You must be signed in to change notification settings - Fork 113
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: Preview file from offline passed file #326
Conversation
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.
Hey Dmitry, thanks for the PR and apologies for the lack of communication from our end. Both hiring and preparation for our annual developer conference have started ramping up so we've both been a bit busy.
I left comments on the areas you shouldn't need to add from your end since I'll make a new patch updating the function signature for show()
.
This should be the flow, please check if I'm wrong:
- You make the fetch file info call from your end, generate your offline link, and prepare a well-formed file object that substitutes the PDF url_template with your offline link
- We modify
show()
from our end to accept a file object OR a file ID as the first parameter - You pass in your file object and the
skipServerCheck
option intoshow()
- Preview should load with your offline file
I'll aim to have the show()
modification done today hopefully, within the week at latest.
src/lib/Preview.js
Outdated
// Save reference to the file when a well-formed file object is present in options | ||
if (this.previewOptions.file) { | ||
this.updateFileCache(this.previewOptions.file); | ||
} |
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.
Remove this. I'll try and get a different PR in this week for allowing the file object to be directly sent into preview.show() as the first param.
The signature will be like:
/**
* Primary function for showing a preview of a file.
*
* @param {string|Object} fileIdOrFile - Box File ID or well-formed Box File object
* @param {string|Function} token - Access token string or generator function
* @param {Object} [options] - Optional preview options
* @return {void}
*/
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.
Okay, removed, agree
src/lib/Preview.js
Outdated
if (this.previewOptions.file) { | ||
this.loadPreviewWithTokens({}); | ||
return; | ||
} |
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.
Remove this, see above.
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.
Will need a guard for the line below
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.
So, when we pass well-formed file object, we need to call this.loadPreviewWithTokens
but we don't pass the token and in lines below, we call this.loadPreviewWithTokens
after executing getTokens
, so as a proposal with according to your pull request #328, can I use guard here:
if (typeof fileIdOrFile === 'object') {
this.loadPreviewWithTokens({});
return;
}
?
src/lib/Preview.js
Outdated
@@ -613,6 +623,12 @@ class Preview extends EventEmitter { | |||
// Save the reference to any additional custom options for viewers | |||
this.options.viewers = options.viewers || {}; | |||
|
|||
// Save the reference to file object | |||
this.options.file = options.file || null; |
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.
Remove this, see above.
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.
Okay, removed
src/lib/Preview.js
Outdated
this.logPreviewEvent(this.file.id, this.options); | ||
if (!this.options.skipServerUpdate) { | ||
this.logPreviewEvent(this.file.id, this.options); | ||
} |
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.
I have conflicting thoughts about this. On one hand I see that your offline use case wouldn't require this logging call but on the other hand there could be generic use case where we don't want to refresh from the server but the developer is not using an offline use case.
I don't think we need a separate option for this, and I'd err on the side of having this logging call fail in your offline use case (ie remove the if 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.
Yeah lets remove this if
check. And just let the request fail it was offline.
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.
Might still have to do something about line 924 below this.prefetchNextFiles();
Likely add a guard in line 1086 if (this.collection.length < 2 || this.options.skipServerUpdate)
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.
Guys, agree, let the request fail it was offline.
@priyajeet Thanks for good catch about this.prefetchNextFiles()
. I've added the guard.
FYI, the initial PR for updating |
@tonyjin @priyajeet Thanks for the fast response. It's not a problem to wait, it's a life :) After your comments I have one question regarding one comment on 513 line in Previewer, could you please look here. And one question regarding you PR #328, should I add Described flow above is correct. |
@disist good catch. Faking the 'original' representation is a construct on Preview's end and isn't something we should expect the API to return. To account for other use cases, I think you should add a
|
src/lib/Preview.js
Outdated
if (typeof fileId === 'object') { | ||
this.loadPreviewWithTokens({}); | ||
return; | ||
} |
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 point. How about this formatting?
if (typeof fileId === 'object') {
// Load without token if using well-formed file object
this.loadPreviewWithTokens({});
} else {
// Fetch tokens before proceeding
getTokens(this.file.id, this.previewOptions.token)
.then(this.loadPreviewWithTokens)
.catch(this.triggerFetchError);
}
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.
No problem, thanks
@tonyjin Thank you, I have added And also one question, should we add check on the well-formed file object when I pass file object and not pass token, I mean in |
Good thought! We added it to https://github.com/box/box-content-preview/blob/master/src/lib/Preview.js#L503 as part of the |
Hello, Guys! If everything is ok, let's merge this PR. |
@disist done - thanks for your contribution! |
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)
Hello guys,
It continues of the pull request #254
I have created a new (clean) pull request with our latest agreements
Guys, @tonyjin, @priyajeet Are you ok with this implementation?
To remind our goal: learn previewer to show files from offline storage when we have no internet.