Skip to content

Conversation

alikhere
Copy link
Contributor

@alikhere alikhere commented Sep 6, 2025

Summary

Implements a new sorting feature for the Files section that allows users to sort files with pinned items appearing first, while maintaining default sorting behaviour.

Features Added

  • Sort Dropdown: Clean dropdown UI with two options:
    • "Name (A–Z)" - Default(current) behavior (folders first, then files, alphabetically)
    • "Pinned first" - Pinned items at top,
  • Persistence: Both sort preference and view mode (list/grid) are saved to localStorage
  • Auto-sorting: When "Pinned first" is selected, newly pinned items automatically move to top
  • Backwards Compatible For those who prefer current behavior

Implementation

  • Enhanced sortFiles function with pinned-first logic
  • Added BY_PINNED sort option to existing sorting system
  • Implemented localStorage persistence for user preferences
  • Added TypeScript type support for new sort option
  • Created accessible dropdown component following existing UI patterns

Before

pinned-before

After

pinned-after

Fixes: #2407

@alikhere alikhere requested a review from a team as a code owner September 6, 2025 13:38
@alikhere alikhere changed the title Feat/sorting files feat: add pinned-first sorting option to files section Sep 6, 2025
@alikhere
Copy link
Contributor Author

alikhere commented Sep 8, 2025

Hey @SgtPooki @lidel Could you please review the PR.

@lidel lidel self-assigned this Sep 17, 2025
changed doFilesCopyCidProvide to doFilesCidProvide to match the actual prop name from the redux store
- add early return for empty or single-item arrays
- skip pinned checking when no pins exist
extract duplicate re-sorting logic into resortIfPinnedSorting helper function to reduce code duplication
- validate saved sorting values against allowed SORTING enum
- clear corrupted localStorage data on parse errors
- remove keyboard navigation complexity from SortDropdown
- changed console.warn to console.error for save failures
- replace two separate list/grid buttons with single toggle button
- show current view icon (list icon when in list mode, grid icon when in grid mode)
- add toggleViewMode function for cleaner code
- update tooltips to "Click to switch to..." for clarity
- remove unused viewList/viewGrid locale keys
- view preference already persisted to localStorage
- removed unused filelist-view and filegrid-view classes
- ascending: pinned items first
- descending: unpinned items first
- previously always showed pinned first regardless of direction
- add BY_ORIGINAL sorting mode to preserve ipfs.ls order
- column headers now cycle: ascending → descending → original
- no arrow indicator shown when in original order state
- add "Original order" option to sort dropdown
- make sortFiles non-mutating to preserve original order
- store originalContent to preserve true ipfs.ls order

refactor: improve sorting implementation
- extract getSortedContent helper to reduce code duplication
- make resortContent generic instead of pinned-specific
- optimize pin checking with Set for O(1) lookup performance
- remove unnecessary array spread for BY_ORIGINAL
- style column headers with charcoal-muted for consistency
- expand dropdown to show all sort directions (asc/desc)
- add Size sorting options to dropdown
- show separate options for each sort type and direction:
  - Name (A → Z) / Name (Z → A)
  - Size (smallest first) / Size (largest first)
  - Pinned first / Unpinned first
  - Original order
- update selection logic to match both sort type and direction
- clearer labels for what each option does
- fix eslint multiline-ternary formatting
more accurate label that conveys this is the unmodified UnixFS DAG traversal order
prevent long labels from breaking dropdown layout
remove extra space before comment
Copy link
Member

@lidel lidel left a comment

Choose a reason for hiding this comment

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

Thank you @alikhere, applied some changes, but lgtm.

Realized we already had partially implemented sorting UI in the list mode, when you clicked on column names.

What I did I've wired up sorting by pin there:

2025-09-17_05-23

..and then added option to sort by size to the dropdown, and then adding asc/desc version of each. I also added option to disable sorting and show original order as it is in the UnixFS DAG:

2025-09-17_05-34

Once i get CI to be green,
I'm merging as-is but feel free to refine / improve in a follow-up PR.

- update test selectors for new button titles
- handle single toggle button for view switching
- clear localStorage in test setup
- fix React act() warnings in async tests
@lidel lidel merged commit c9251eb into ipfs:main Sep 17, 2025
20 checks passed
@lidel lidel changed the title feat: add pinned-first sorting option to files section feat(files): advanced sorting options Sep 17, 2025
@alikhere
Copy link
Contributor Author

alikhere commented Sep 17, 2025

Thank you @alikhere, applied some changes, but lgtm.

Realized we already had partially implemented sorting UI in the list mode, when you clicked on column names.

What I did I've wired up sorting by pin there:

2025-09-17_05-23

..and then added option to sort by size to the dropdown, and then adding asc/desc version of each. I also added option to disable sorting and show original order as it is in the UnixFS DAG:

2025-09-17_05-34

Once i get CI to be green, I'm merging as-is but feel free to refine / improve in a follow-up PR.

Looks great!

@alikhere alikhere deleted the feat/sorting-files branch September 17, 2025 06:37
ipfs-gui-bot pushed a commit that referenced this pull request Sep 17, 2025
## [4.9.0](v4.8.0...v4.9.0) (2025-09-17)

 CID `bafybeietkqxghs3hm56e3w64s4papqlvvzqzjigs4eyuy24plkpz652fee`

 ---

### Features

* add Agent Version column to peers table ([#2433](#2433)) ([614f30d](614f30d)), closes [ipfs/kubo#9465](ipfs/kubo#9465) [ipfs/js-kubo-rpc-client#342](ipfs/js-kubo-rpc-client#342) [ipfs/kubo#9465](ipfs/kubo#9465)
* add close button to file viewer for improved navigation ([#2401](#2401)) ([84969a5](84969a5))
* add diagnostics screen ([#2392](#2392)) ([f3a8179](f3a8179)), closes [#2424](#2424) [ipfs-check#102](ipfs/ipfs-check#102) [/github.com/ipfs/ipfs-check/pull/102#pullrequestreview-3214396503](https://github.com/ipfs//github.com/ipfs/ipfs-check/pull/102/issues/pullrequestreview-3214396503) [#2434](#2434)
* **files:** advanced sorting options ([#2421](#2421)) ([c9251eb](c9251eb))
* migrate Tooltip from Javascript to Typescript ([#2381](#2381)) ([dc9e9ac](dc9e9ac))

### Bug Fixes

* create redux-bundler migration helpers ([#2388](#2388)) ([d1fdb87](d1fdb87))
* display UX friendly error for missing files ([#2346](#2346)) ([d4e7fca](d4e7fca))
* **files:** rename in Grid View ([#2422](#2422)) ([e39bce6](e39bce6))
* **i18n:** prevent English replacements in translation sync workflow ([#2418](#2418)) ([323c59e](323c59e))
* macos input focus issue in draggable regions ([#2416](#2416)) ([5382688](5382688))
* migrate error boundary to typescript ([#2402](#2402)) ([b33775a](b33775a))
* **navbar:**  highlighting on browser back ([#2425](#2425)) ([cec6dfd](cec6dfd))
* Prevent layout breaks with long filenames in file preview ([#2415](#2415)) ([f82efcd](f82efcd))
* reference to `global` in browser environment ([#2408](#2408)) ([03b2e92](03b2e92))
* shared max for bandwidth chart ([#2426](#2426)) ([cd17032](cd17032))
* typecheck more files ([#2409](#2409)) ([fb967ee](fb967ee))

### Tests

* fix bring-your-own kubo node functionality ([#2396](#2396)) ([0883cfa](0883cfa))
* make e2e tests more robust ([#2438](#2438)) ([3de544b](3de544b))

### Trivial Changes

* **readme:** update links ([dc6f8f4](dc6f8f4))
* remove selectApiUrl selector ([#2412](#2412)) ([d4710e8](d4710e8))
@ipfs-gui-bot
Copy link
Collaborator

🎉 This PR is included in version 4.9.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat(files): sort option to move pinned items to the top
3 participants