-
-
Notifications
You must be signed in to change notification settings - Fork 32
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
base: master
Are you sure you want to change the base?
Add VFS context aware sorting #189
Conversation
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 = {}) => { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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.
There was a problem hiding this 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
});
});
There was a problem hiding this comment.
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.
Hi again @andersevenrud |
@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. |
Hi again after long time. |
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.