Skip to content

Conversation

@noveens
Copy link
Contributor

@noveens noveens commented Mar 1, 2017

Description

Fixes #15520
Fixes #26318

The filelist is refreshed if and only if the directory is changed and not otherwise.

Related Issue

#15520
#26318

Motivation and Context

How Has This Been Tested?

Tested at all directories.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@mention-bot
Copy link

@noveens, thanks for your PR! By analyzing the history of the files in this pull request, we identified @PVince81, @butonic and @Henni to be potential reviewers.

if (!force && currentDir === targetDir) {
return;
}
if(this._currentDirectory && currentDir === targetDir) {
Copy link
Contributor

Choose a reason for hiding this comment

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

it seems this is what the previous if statement is doing.

Note that there is a force attribute to let callers force a refresh. With your approach this would break.

Did you have a look if it is possible to add this check much earlier, maybe inside app.js ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@PVince81 ,
I had a look, it's not possible to do this at a previous state.

Copy link
Contributor

Choose a reason for hiding this comment

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

Have a look in FileList._onUrlChanged. Try adding the check there instead.

@noveens
Copy link
Contributor Author

noveens commented Mar 1, 2017

@PVince81 ,
updated changes, please review :-)

_onUrlChanged: function(e) {
if (e && _.isString(e.dir)) {
var currentDir = this.getCurrentDirectory();
if(this._currentDirectory && currentDir === e.dir) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, looks better. Does it work ?

Also, why did you add this._currentDirectory in the check ? What's the purpose ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this works now as well.

The this._currentDirectory check is there because we wouldn't want to skip file loading at the root directory ( '/' ).

Copy link
Contributor Author

@noveens noveens Mar 1, 2017

Choose a reason for hiding this comment

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

if we are at root directory OR home page the initialised values of currentDir and e.dir turn out to be same, hence the file-loading doesn't complete at the root page.
To solve this, I introduced the check.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, I see. That makes sense. Please add a comment in the code to clarify this.

So basically this._currentDirectory is null/empty when the file list is first initialized

Copy link
Contributor Author

@noveens noveens Mar 1, 2017

Choose a reason for hiding this comment

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

Exactly.
Adding a comment.

@PVince81
Copy link
Contributor

PVince81 commented Mar 1, 2017

Now curious if some unit test will fail.

Would be good to have a JS unit test for that case too.

@noveens
Copy link
Contributor Author

noveens commented Mar 1, 2017

@PVince81 ,
For which case are you talking about?

@PVince81
Copy link
Contributor

PVince81 commented Mar 1, 2017

For which case are you talking about?

The case you just fixed here. Add the following tests for FileList:

  • if triggering the event for url changed with the same as the current path, the file list is not refreshed (changeDirectory is not called, you can use a stub to check that)
  • if triggering the event for url changed with the root path directly after FileList creation, the file list is refreshed (changeDirectory is called, that's the case you explained in the code comment)

I'll first let you look at the "fileListSpec.js" file to find existing tests you could based this on.
Let me know if you get lost there.

@noveens
Copy link
Contributor Author

noveens commented Mar 1, 2017

@PVince81 ,
On it.

@PVince81 PVince81 added this to the 10.0 milestone Mar 1, 2017
var currentDir = this.getCurrentDirectory();
// this._currentDirectory is NULL when fileList is first initialised
if(this._currentDirectory && currentDir === e.dir) {
if( (this._currentDirectory || this.$el.find('#dir').val()) && currentDir === e.dir) {
Copy link
Contributor

Choose a reason for hiding this comment

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

no, don't use the old crappy '#dir' element. This should be the same value like this.getCurrentDirectory() already.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is neccesary, otherwise the first test fails
in the test, this._currentDirectory remains null for some reason.

Copy link
Contributor

Choose a reason for hiding this comment

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

Then we should rather fix the test instead. Maybe something is missing in the test initialization.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

should I remove this then and look into why it's not initialised?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes please.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On it.


beforeEach(function() {
if (fileList) {
fileList.destroy();
Copy link
Contributor

Choose a reason for hiding this comment

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

You don't need to destroy here, remove this. The afterEach in a higher level at the top of the file already takes care of this.

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 :-)

if (fileList) {
fileList.destroy();
}
fileList = new OCA.Files.FileList($('#app-content-files'), {
Copy link
Contributor

Choose a reason for hiding this comment

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

also no need to create, the very first beforeEach does that already.

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 :-)

fileListStub.restore();
})
it('File list must be refreshed', function() {
console.log(fileList.getCurrentDirectory());
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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh, sorry :p

it('File list must be refreshed', function() {
console.log(fileList.getCurrentDirectory());
$('#app-content-files').trigger(new $.Event('urlChanged', {dir: '/'}));
expect(fileListStub.notCalled).toEqual(false);
Copy link
Contributor

Choose a reason for hiding this comment

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

use fileListStub.calledOnce here, it's better

Copy link
Contributor Author

Choose a reason for hiding this comment

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

should that be called exactly once?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes. Enforcing exactly once is also a good practice.

Just in case future bugs would make it be called multiple times...

testMountType(123, 'external-root', 'external', 'external');
});
});
describe('file list should not refresh if url does not change', function() {
Copy link
Contributor

Choose a reason for hiding this comment

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

You only need one describe block to group your two tests.

describe('file list url refresh tests', function() {
    beforeEach(...);
    afterEach(...);

    it('does not reload the file list if path in url does not change', ...);
    it('refreshes the file list after list creation', ...);
});

@noveens
Copy link
Contributor Author

noveens commented Mar 1, 2017

@PVince81 ,
As per your suggestion of removing the test for homepage refresh,
It turned out that if I remove this.$el.find('#dir').val() , the test for not refreshing when directory hasn't changed seems to fail and not the other way round.
Maybe you can look into this further?

Thanks.

@noveens
Copy link
Contributor Author

noveens commented Mar 1, 2017

@butonic ,
can you please review?

@PVince81
Copy link
Contributor

PVince81 commented Mar 2, 2017

@noveens I looked into it and it seems that it's more complicated than I thought. We can't easily get rid of '#dir' at this point. So I'm willing to accept the PR as it is, with the '#dir' check inside the event handler, for now.

If you also agree, feel free to merge this directly as the tests pass 👍

});
afterEach(function() {
fileListStub.restore();
})
Copy link
Contributor

Choose a reason for hiding this comment

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

one more thing: missing semicolon here.

If you run jshint/jslint on JS files it will tell you that. Maybe your IDE has an option for this.

@noveens
Copy link
Contributor Author

noveens commented Mar 2, 2017

@PVince81 ,
Many thanks for the review :-)
I updated the changes, it would be great if you could merge this instead of me this time :-)

Thanks.

@lock
Copy link

lock bot commented Aug 3, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Aug 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Closing photo preview reloads file list OC.History - don't fire reload if URL hasn't changed any value

4 participants