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: Return a file element even if the rendered list does not contained one #45121

Merged
merged 1 commit into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions apps/files/js/filelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -1357,8 +1357,18 @@
* @return {Object} jQuery object of the matching row
*/
findFileEl: function(fileName){
// use filterAttr to avoid escaping issues
return this.$fileList.find('tr').filterAttr('data-file', fileName);
var fileRow = this.$fileList.find('tr').filterAttr('data-file', fileName);
if (fileRow.length) {
return fileRow;
}

// The row we try to get might not have been rendered due to pagination,
// so in case we find the file in the file list return the rendered row instead
var fileData = this.files.find(function (el){
return el.name === fileName;
});

return fileData ? this._renderRow(fileData, {updateSummary: false, silent: true}) : fileRow;
},

/**
Expand Down
4 changes: 2 additions & 2 deletions apps/files/tests/js/filelistSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,7 @@ describe('OCA.Files.FileList tests', function() {
// element is renamed before the request finishes
$tr = fileList.findFileEl('Tu_after_three.txt');
expect($tr.length).toEqual(1);
expect(fileList.findFileEl('One.txt').length).toEqual(0);
expect($('.files-fileList tr').find('[data-name="One.txt"]').length).toEqual(0);
// file actions are hidden
expect($tr.hasClass('busy')).toEqual(true);

Expand Down Expand Up @@ -1426,7 +1426,7 @@ describe('OCA.Files.FileList tests', function() {
name: 'File with index 28b.txt'
});
expect($('.files-fileList tr').length).toEqual(20);
expect(fileList.findFileEl('File with index 28b.txt').length).toEqual(0);
expect($('.files-fileList tr').find('[data-name="File with index 28b.txt"]').length).toEqual(0);
fileList._nextPage(true);
expect($('.files-fileList tr').length).toEqual(40);
expect(fileList.findFileEl('File with index 28b.txt').index()).toEqual(29);
Expand Down
Loading