Skip to content

Commit

Permalink
fix(files): Fix legacy files list sorting
Browse files Browse the repository at this point in the history
The sorting was not saved since files2vue changes in Nextcloud 27, as a new API endpoint
was introduced and the old one was dropped without adjusting the legacy file list to use it.

Signed-off-by: Ferdinand Thiessen <[email protected]>
  • Loading branch information
susnux committed Aug 16, 2023
1 parent f85e751 commit a1699a3
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 8 deletions.
21 changes: 16 additions & 5 deletions apps/files/js/filelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -2185,11 +2185,22 @@
}

if (persist && OC.getCurrentUser().uid) {
$.post(OC.generateUrl('/apps/files/api/v1/sorting'), {
// Compatibility with new files-to-vue API
mode: sort === 'name' ? 'basename' : sort,
direction: direction,
view: 'files'
$.ajax({
type: 'PUT',
url: OC.generateUrl('apps/files/api/v1/views/files/sorting_mode'),
contentType: 'application/json',
data: JSON.stringify({
// Compatibility with new files-to-vue API
value: sort === 'name' ? 'basename' : sort,
})
});
$.ajax({
type: 'PUT',
url: OC.generateUrl('apps/files/api/v1/views/files/sorting_direction'),
contentType: 'application/json',
data: JSON.stringify({
value: direction,
})
});
}
},
Expand Down
6 changes: 3 additions & 3 deletions apps/files/lib/Controller/ViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public function index($dir = '', $view = '', $fileid = null, $fileNotFound = fal
$this->initialState->provideInitialState('favoriteFolders', $favElements['folders'] ?? []);

// File sorting user config
$filesSortingConfig = json_decode($this->config->getUserValue($userId, 'files', 'files_sorting_configs', '{}'), true);
$filesSortingConfig = $this->viewConfig->getConfigs();
$this->initialState->provideInitialState('filesSortingConfig', $filesSortingConfig);

// render the container content for every navigation item
Expand Down Expand Up @@ -274,8 +274,8 @@ public function index($dir = '', $view = '', $fileid = null, $fileNotFound = fal
$params['ownerDisplayName'] = $storageInfo['ownerDisplayName'] ?? '';
$params['isPublic'] = false;
$params['allowShareWithLink'] = $this->shareManager->shareApiAllowLinks() ? 'yes' : 'no';
$params['defaultFileSorting'] = $filesSortingConfig['files']['mode'] ?? 'basename';
$params['defaultFileSortingDirection'] = $filesSortingConfig['files']['direction'] ?? 'asc';
$params['defaultFileSorting'] = $filesSortingConfig['files']['sorting_mode'] ?? 'basename';
$params['defaultFileSortingDirection'] = $filesSortingConfig['files']['sorting_direction'] ?? 'asc';
$params['showgridview'] = $this->config->getUserValue($userId, 'files', 'show_grid', false);
$showHidden = (bool) $this->config->getUserValue($userId, 'files', 'show_hidden', false);
$params['showHiddenFiles'] = $showHidden ? 1 : 0;
Expand Down
20 changes: 20 additions & 0 deletions cypress/e2e/files.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,24 @@ describe('Login with a new user and open the files app', function() {
cy.visit('/apps/files')
cy.get('.files-fileList tr').should('contain', 'welcome.txt')
})

it('should save the last file list sorting', function() {
cy.intercept('PUT', /api\/v1\/views\/files\/sorting_direction$/).as('sorting_direction')

cy.visit('/apps/files')
// default to sorting by name
cy.get('.files-filestable th.column-name .sort-indicator').should('be.visible')
// change to size
cy.get('.files-filestable th').contains('Size').click()
// size sorting should be active
cy.get('.files-filestable th.column-name .sort-indicator').should('not.be.visible')
cy.get('.files-filestable th.column-size .sort-indicator').should('be.visible')
cy.wait('@sorting_direction')

// Re-visit
cy.visit('/apps/files')
// now sorting by name should be disabled and sorting by size should be enabled
cy.get('.files-filestable th.column-name .sort-indicator').should('not.be.visible')
cy.get('.files-filestable th.column-size .sort-indicator').should('be.visible')
})
})

0 comments on commit a1699a3

Please sign in to comment.