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

Add VFS context aware sorting #189

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

mahsashadi
Copy link
Contributor

Due to this point, we'd better to improve client-side sorting.

In new code, client will sort only if VFS server adapter does not sort before.

src/utils/vfs.js Outdated
@@ -182,7 +191,10 @@ export const humanFileSize = (bytes, si = false) => {
* @param {string} [options.sortDir='asc'] Sort in this direction
* @return {Object[]}
*/
export const transformReaddir = ({path}, files, options = {}) => {
export const transformReaddir = ({path}, files, capabilityCache, options = {}) => {
Copy link
Member

Choose a reason for hiding this comment

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

Instead of passing capabilities here, maybe an option could be added here instead ?

Like options.serverSorting, which is just passed from capabilityCache.

This way we don't introduce any state checks to utility functions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have committed some changes, although it seems there are still some cognitive complexity.

Copy link
Member

Choose a reason for hiding this comment

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

there are still some cognitive complexity

Feel free to make suggestions on 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.

Sorry, but I did not come up with a better solution.

Copy link
Member

@ajmeese7 ajmeese7 left a comment

Choose a reason for hiding this comment

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

I haven't tested this myself, but if it works then the code looks pretty good to me! 👍🏻

src/vfs.js Outdated
showHiddenFiles: options.showHiddenFiles !== false,
filter: options.filter
filter: options.filter,
serverSorting: capabilityCache[mountPoint(pathToObject(path))] ? capabilityCache[mountPoint(pathToObject(path))].sort : false
Copy link
Member

Choose a reason for hiding this comment

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

I'll defer to Anders' judgement on this, but I think this could stand to be broken up with new lines since it is so long.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll defer to Anders' judgement on this, but I think this could stand to be broken up with new lines since it is so long.

How about below code? @ajmeese7 @andersevenrud

const handleDirectoryList = (path, options) => result =>
  Promise.resolve(result.map(stat => createFileIter(stat)))
    .then(result => {
      let capability = capabilityCache[mountPoint(pathToObject(path))];
      return transformReaddir(pathToObject(path), result, {
        showHiddenFiles: options.showHiddenFiles !== false,
        filter: options.filter,
        serverSorting: capability.sort ? capability.sort : false
      });
    });

Copy link
Member

@ajmeese7 ajmeese7 Aug 27, 2022

Choose a reason for hiding this comment

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

@mahsashadi you can change:

serverSorting: capability.sort ? capability.sort : false

To the following:

serverSorting: capability.sort || false

To reduce the redundancy of it a bit.

Also I recommend changing the variable from a let to a const since there is no mutation of the contents.

@mahsashadi mahsashadi requested review from andersevenrud and ajmeese7 and removed request for andersevenrud and ajmeese7 August 23, 2022 12:18
@mahsashadi mahsashadi requested review from andersevenrud and removed request for ajmeese7 August 28, 2022 11:50
@mahsashadi
Copy link
Contributor Author

Hi again @andersevenrud
Any more changes needed to do in this PR?

@andersevenrud
Copy link
Member

@mahsashadi I'm very sorry, but I got sick last week and was not able to take a look at your stuff. Scheduled another look for this weekend.

@mahsashadi
Copy link
Contributor Author

Hi again after long time.
It will be great if we can approve these changes.
Thanks.
@andersevenrud @ajmeese7

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.

None yet

3 participants