Uh oh!
There was an error while loading. Please reload this page.
fix(files): order file folders in SQL like every other folder list - #6599
Conversation
The list use case defaulted to a name sort whose defaults were written for the new v2 contract, so the internal route — whose contract exposes no sort params — could no longer reach the repository's sortOrder ASC, createdAt ASC ordering. Surfaces that render the payload positionally (the @-mention Folders group, the add-resource search results, Copilot's list_file_folders) silently flipped from newest-first to alphabetical, and the Files browser's SSR prefetch hydrated a different order than its own refetch. Push the sort down to the query like the workflow, knowledge, and table folder lists already do, reusing FOLDER_SORTS. Omitting sortBy keeps the position ordering; v2 always sends one from its contract defaults. A name sort now also uses the database collation and the shared createdAt tiebreak instead of a JS comparator over UTF-16 code units.
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryMedium Risk Overview Omitting Reviewed by Cursor Bugbot for commit 771499a. Configure here. |
Greptile SummaryThis PR moves workspace file-folder sorting from the application layer into the SQL query while preserving positional ordering when no explicit sort is requested.
Confidence Score: 5/5The PR appears safe to merge with no actionable correctness, security, or changed-code quality issues identified. The delegated sort values match the validated API contracts and current callers, the default preserves the prior repository position order, and the shared SQL helper has compatible stable ordering semantics.
|
| Filename | Overview |
|---|---|
| apps/sim/lib/uploads/contexts/workspace/workspace-file-folder-manager.ts | Adds optional SQL sort parameters with position-ascending defaults and uses the established shared folder-ordering helper. |
| apps/sim/lib/workspace-files/application/workspace-file-folders.ts | Forwards validated sorting options to the repository and preserves repository order instead of sorting results in memory. |
| apps/sim/lib/folders/queries.ts | Exports the existing exhaustive folder-sort mapping for reuse without changing its definitions. |
| apps/sim/lib/workspace-files/application/workspace-file-folders.test.ts | Verifies omitted and explicit sort delegation and confirms application code no longer reorders repository results. |
| apps/sim/lib/api/contracts/v2/shared.ts | Updates list-contract documentation to reflect that file-folder sorting now occurs in SQL. |
Reviews (1): Last reviewed commit: "fix(files): order file folders in SQL li..." | Re-trigger Greptile
Summary
executeListWorkspaceFileFoldersdefaulted tosortBy ?? 'name'— defaults written for the new v2 contract — and sorted in JS. The internal contract (workspace-file-folders.ts) exposes onlyscope, so the repository'ssortOrder ASC, createdAt ASCordering became unreachable.sortOrder = minSortOrder - 1, so it is deliberately newest-first, and it is user-modifiable.FOLDER_SORTSmap. OmittingsortBykeepsposition; v2 always sends one from its contract defaults.Impact this fixes
Surfaces that render the payload in arrival order and had flipped newest-first → alphabetical:
@-mention Folders group — no sort,MAX_PER_GROUP = 8, so a workspace with >8 folders showed the 8 alphabetically-first instead of the 8 most recent, making a just-created folder unreachable without typing.list_file_folders.Also removes a real SSR mismatch:
files/prefetch.tshydratesworkspaceFileFolderKeys.list(workspaceId, 'active')by calling the data layer directly (repository order) while the client hook fetches the same key through the route (name-sorted). Its TSDoc asserts a "correctly-ordered first frame" and that a "hydrated entry matches a client fetch" — true again now.Unaffected either way (they re-sort client-side): the Files browser (
files.tsxsorts bysortOrderthenlocaleCompare), Recently Deleted, and the add-resource submenu tree.Secondary correctness win
A
sortBy=namerequest previously compared with raw</>on UTF-16 code units, so"Zebra"sorted before"apple"— a third ordering matching neither the old one nor thelocaleCompareevery client surface uses, with no tiebreak for equal names. It now uses the database collation and the sharedcreatedAttiebreak, consistent with the other folder lists.Type of Change
Testing
sortByleaves it unset. Verified all three fail against the pre-fix code.bunx vitest run lib/ app/api/— 15,141 passing.lint:checkandtype-check(23/23 each), pluscheck:api-validationand monorepo-boundary gates.listActiveFolderRows'?? 'name'is a dead default — its only callers are v2 use cases that always receive a defaultedsortBy.Checklist