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

feat: Add sortNodes and generic orderBy #961

Merged
merged 2 commits into from
May 23, 2024
Merged

feat: Add sortNodes and generic orderBy #961

merged 2 commits into from
May 23, 2024

Conversation

susnux
Copy link
Contributor

@susnux susnux commented May 22, 2024

Move the functions from the files app to this library to allow reusing them in other places, like for example the FilePicker or Viewer app.

orderBy is a generic natural sorting function which allows to pass a collection, identifiers and associated order and sorts the collection using the browser native Intl.Collator.

sortNodes is a specialized function based on orderBy to sort nodes (files and folders) based on sorting options.

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
Move the functions from the files app to this library to allow
reusing them in other places, like for example the FilePicker or Viewer app.

`orderBy` is a generic natural sorting function which allows to pass
a collection, identifiers and associated order and sorts the
collectiong using the browser native `Intl.Collator`.

`sortNodes` is a specialized function based on `orderBy`
to sort nodes (files and folders) based on sorting options.

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
@susnux susnux added enhancement New feature or request 3. to review labels May 22, 2024
@susnux susnux requested a review from skjnldsv May 22, 2024 14:02
Copy link

codecov bot commented May 22, 2024

Bundle Report

Changes will increase total bundle size by 5.72kB ⬆️

Bundle name Size Change
@nextcloud/files-esm 108.44kB 2.83kB ⬆️
@nextcloud/files-cjs 109.44kB 2.89kB ⬆️

* They key to order the files by
* @default FilesSortingMode.Name
*/
sortingMode?: FilesSortingMode
Copy link
Contributor

Choose a reason for hiding this comment

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

That means we cannot sort by arbitrary values?

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 we allow it? I just wanted to provide a clean interface, but we can of course also accept other values here if you like :)

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 confused myself.
I was thiking about custom columns, but I apparently had planned this already.

You have to provide a sort function if you want your custom column to be sortable, so this piece of code is not relevant, you're right!

https://github.com/nextcloud/server/blob/a8f4b25ae834778e120ea011a3c98aa77ef90c51/apps/files/src/views/FilesList.vue#L311-L315
https://github.com/nextcloud/server/blob/97cd038cf20c5015d9dfecd0e9283367391358d2/apps/files/src/components/FilesListTableHeader.vue#L61-L69

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you ignore types you can even pass every valid property of the Node class^^

@skjnldsv skjnldsv merged commit e6d6537 into main May 23, 2024
16 checks passed
@skjnldsv skjnldsv deleted the feat/files-sorting branch May 23, 2024 07:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3. to review enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Expose sorting methods
2 participants