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

Fix: Preview well-formed file in offline (fixes #793) #799

Merged

Conversation

dolgachio
Copy link
Contributor

Hello guys,

This pull request fixes issue - #793
To remind you, it is required to preview well-formed files in offline mode without internet connection.
I am looking forward getting a feedback from you.

Thank you in advance

@boxcla
Copy link

boxcla commented May 22, 2018

Hi @stas-dolgachov, thanks for the pull request. Before we can merge it, we need you to sign our Contributor License Agreement. You can do so electronically here: http://opensource.box.com/cla

Once you have signed, just add a comment to this pull request saying, "CLA signed". Thanks!

@dolgachio
Copy link
Contributor Author

CLA signed

getTokens(this.file.id, this.previewOptions.token)
.then(this.handleTokenResponse)
.catch(this.handleFetchError);
const couldPreviewOfflineWithoutToken = typeof fileIdOrFile === 'object' && this.options.skipServerUpdate;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you rename this to something starting with is? maybe isOfflinePreview

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you, done

@@ -798,6 +803,9 @@ class Preview extends EventEmitter {

// Load from cache if the current file is valid, otherwise load file info from server
if (checkFileValid(this.file)) {
/* Save file in cache. This also adds the 'ORIGINAL' representation.
Copy link
Contributor

Choose a reason for hiding this comment

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

Change comment style to use // instead of /*

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you, done

@@ -1002,6 +1002,15 @@ describe('lib/Preview', () => {
expect(preview.retryTimeout).to.equal(undefined);
});

it('should load preview when a well-formed file object is passed and server update should be skipped', () => {
const previewOptions = { skipServerUpdate: true };
preview.parseOptions(previewOptions);
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we are unit testing load, you shouldn't call parseOptions. Instead set the required fields on the preview object

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you, done.

Copy link
Contributor

@pramodsum pramodsum left a comment

Choose a reason for hiding this comment

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

Thanks so much for fixing this!

@stas-dolgachov: One thing I would note is that if your use case is to allow users to preview files offline, you will probably also need to set the preview option disableEventLog to true. This will disable Preview event logging requests.

skipServerUpdate only prevents the load from server and any server updates.

@pramodsum pramodsum merged commit fac6e9c into box:master May 31, 2018
@dolgachio dolgachio deleted the fix-preview-well-formed-files-in-offline branch June 1, 2018 12:52
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