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: Preview file from offline passed file #326

Merged
merged 9 commits into from
Aug 29, 2017

Conversation

disist
Copy link
Contributor

@disist disist commented Aug 21, 2017

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.

Copy link
Contributor

@tonyjin tonyjin left a 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 into show()
  • Preview should load with your offline file

I'll aim to have the show() modification done today hopefully, within the week at latest.

// Save reference to the file when a well-formed file object is present in options
if (this.previewOptions.file) {
this.updateFileCache(this.previewOptions.file);
}
Copy link
Contributor

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}
     */

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, removed, agree

if (this.previewOptions.file) {
this.loadPreviewWithTokens({});
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this, see above.

Copy link
Contributor

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

Copy link
Contributor Author

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;
}

?

@@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this, see above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, removed

this.logPreviewEvent(this.file.id, this.options);
if (!this.options.skipServerUpdate) {
this.logPreviewEvent(this.file.id, this.options);
}
Copy link
Contributor

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)

Copy link
Contributor

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.

Copy link
Contributor

@priyajeet priyajeet Aug 21, 2017

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)

Copy link
Contributor Author

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.

@tonyjin
Copy link
Contributor

tonyjin commented Aug 21, 2017

FYI, the initial PR for updating show() is in code review: #328

@disist
Copy link
Contributor Author

disist commented Aug 22, 2017

@tonyjin @priyajeet Thanks for the fast response. It's not a problem to wait, it's a life :)
Besides, thanks for the PR with the new signature, I agree with you.

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 original representation on my side? (as it usually did with execution addOriginalRepresentation method in file.js in scope of execution chacheFile)?

Described flow above is correct.

@tonyjin
Copy link
Contributor

tonyjin commented Aug 22, 2017

@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 cacheFile() in loadPreviewWithTokens() like:

// If file object is well-formed, load with it. Otherwise, fetch file information from the server.
if (checkFileValid(this.file)) {
    // Save file in cache. This also adds the 'ORIGINAL' representation.
    cacheFile(this.file);
    this.loadFromCache();
} else {
    this.loadFromServer();
}

if (typeof fileId === 'object') {
this.loadPreviewWithTokens({});
return;
}
Copy link
Contributor

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);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No problem, thanks

@disist
Copy link
Contributor Author

disist commented Aug 23, 2017

@tonyjin Thank you, I have added cacheFile() in loadPreviewWithTokens().
For the first time it's worked it's worked approach for us.

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 show(wellFormedFileObject, null, options)?

@tonyjin
Copy link
Contributor

tonyjin commented Aug 23, 2017

Good thought! We added it to https://github.com/box/box-content-preview/blob/master/src/lib/Preview.js#L503 as part of the show() change. At some point in the future we may be calling load() directly with a file object internally so we thought the validation worked better there.

@disist
Copy link
Contributor Author

disist commented Aug 29, 2017

Hello, Guys! If everything is ok, let's merge this PR.

@tonyjin tonyjin merged commit 8547bc8 into box:master Aug 29, 2017
@tonyjin
Copy link
Contributor

tonyjin commented Aug 29, 2017

@disist done - thanks for your contribution!

@disist disist deleted the display-from-file branch August 29, 2017 19:51
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.

4 participants