Skip to content

fix(resources): sort folders and resources as one list so pinned items reach the top - #6213

Merged
waleedlatif1 merged 5 commits into
stagingfrom
worktree-resource-sort-no-folder-priority
Aug 3, 2026
Merged

fix(resources): sort folders and resources as one list so pinned items reach the top#6213
waleedlatif1 merged 5 commits into
stagingfrom
worktree-resource-sort-no-folder-priority

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • Folders were sorted separately and concatenated above their sibling resources, so a pinned file/table/knowledge base could never rank above an unpinned folder — pinning only reordered within each partition
  • Files, Tables, and Knowledge now sort folders and items as ONE list via a shared sortResources comparator: pinned → sort key → name
  • Rows with no value for the active column (a folder has no row count or token count) sort last in both directions; the name tiebreak is never inverted by desc
  • Audited every other foldered surface and aligned the ones that contradicted the pages: the mothership resource browse trees (file/table/KB levels partitioned folders-first with items in raw API order), the collapsed sidebar flyout (nested levels partitioned folders-first while its own root interleaved by sortOrder), the sidebar file tree, and the recently-deleted tiebreak
  • Files' sort params were nullable only to encode "folders name/asc, files updated/desc"; with one list that state no longer exists, so they default to updated/desc like Tables and Knowledge
  • Prefetch: all three pages already primed their items + folders, but not pinned ids or workspace members. Pinned ids are the primary sort key now, so painting without them rendered the list in the wrong order and then visibly re-sorted; members back the Owner column. Both now hydrate with the lists

Type of Change

  • Bug fix

Testing

Unit tests for the comparator (interleaving, pinned floats over unpinned folders in both directions, nulls last, direction-independent name tiebreak) and for the browse-tree ordering and the new prefetch keys. Verified each test goes red when the behavior is reverted. tsc, bun run lint, check:client-boundary, check:react-query, check:api-validation all pass. Not yet verified in a running browser.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

Folders and their sibling resources were sorted as two lists and
concatenated folders-first, so a pinned file, table, or knowledge base
could never rank above an unpinned folder — pinning only reordered
within each partition.

Sort them as one list instead: pinned -> sort key -> name, in a shared
`sortResources` comparator. Rows with no value for the active column
(a folder has no row count or token count) sort last in both
directions, and the name tiebreak is never inverted by `desc`.

Also aligns the surfaces that browse the same resources: the mothership
resource trees, the collapsed sidebar flyout (whose nested levels
partitioned folders-first while its own root interleaved), the sidebar
file tree, and the recently-deleted tiebreak.

Files' sort params were nullable only to encode "folders name/asc,
files updated/desc"; with one list that state is gone, so they default
to updated/desc like Tables and Knowledge.
…urce lists

Files, Tables, and Knowledge already prefetched their items and folders,
but not the two lists a complete row needs.

Pinned ids are the list's primary sort key now, so a page that painted
before they arrived rendered the whole list in the wrong order and then
visibly re-sorted. Members back the Owner column, which painted empty
and filled in after.

Both now hydrate alongside the lists via `prefetchResourceListChrome`.
Pinned keys move to `hooks/queries/utils/pinned-item-keys` so the server
prefetch can address them without pulling the contracts barrel and the
optimistic-mutation machinery into the route.
@vercel

vercel Bot commented Aug 3, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Aug 3, 2026 6:25pm

Request Review

@cursor

cursor Bot commented Aug 3, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Touches ordering and URL sort behavior across Files, Tables, Knowledge, sidebar, and prefetch paths—user-visible list order can change and Files clean URLs now encode default sort differently. Logic is well covered by unit tests; main risk is missed surfaces or hydration timing still causing a brief re-sort flash.

Overview
Fixes list ordering where folders were always sorted separately and placed above files/tables/knowledge bases, so a pinned resource could never outrank an unpinned folder. Files, Tables, and Knowledge now merge folders and items into one list and sort with a shared sortResources helper: pinned → active column → name (null column values last; name tiebreak stays A→Z regardless of direction).

Files drops nullable URL sort params and uses the same default updated/desc as the other resource lists, since split folder/file defaults are no longer needed.

Prefetch for Files, Tables, and Knowledge now also hydrates pinned ids (resource + folder pin namespaces) and workspace members so the first paint matches final order and Owner cells don’t flash empty.

Browse and sidebar surfaces are aligned with the pages: mothership buildResourceFolderTree interleaves by name by default; file sidebar / collapsed flyouts interleave folders and files; workflow collapsed folder submenus use interleaveSiblings by sortOrder. Recently deleted adds a name/id tiebreak when sort columns tie.

Removes legacy knowledge card grid pieces (BaseCard, old sort helpers); pinnedItemKeys moves to a small utils module for server prefetch without pulling mutation hooks.

Reviewed by Cursor Bugbot for commit 3e494e2. Configure here.

@greptile-apps

greptile-apps Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR unifies folders and sibling resources under shared ordering so pinned resources can rank above unpinned folders.

  • Adds a shared pinned-first, nulls-last resource comparator.
  • Applies merged ordering across Files, Tables, Knowledge, browse trees, and sidebar surfaces.
  • Prefetches pinned IDs and workspace members alongside resource lists.
  • Removes unused legacy Knowledge card components and aligns sort defaults and URL-state documentation.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
apps/sim/app/workspace/[workspaceId]/components/folders/resource-sort.ts Introduces the shared comparator with deterministic pin, null-key, direction, and name-tiebreak behavior.
apps/sim/app/workspace/[workspaceId]/files/files.tsx Merges visible folders and filtered files into one decorated and sorted row sequence.
apps/sim/app/workspace/[workspaceId]/tables/tables.tsx Applies the shared merged ordering to tables and folders while preserving filtering and rendering behavior.
apps/sim/app/workspace/[workspaceId]/knowledge/knowledge.tsx Applies merged resource ordering to knowledge bases and removes reliance on the former separate sort utility.
apps/sim/app/workspace/[workspaceId]/lib/prefetch-resource-list-chrome.ts Prefetches resource and folder pin state plus workspace members under keys matching the client hooks.
apps/sim/app/workspace/[workspaceId]/home/components/mothership-view/components/add-resource-dropdown/resource-folder-tree.ts Interleaves folders and items deterministically at every tree level by name or explicit sort order.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  Lists[Folders and resources] --> Decorate[Compute pin state, active key, and name]
  Pins[Pinned IDs] --> Decorate
  Members[Workspace members] --> Decorate
  Decorate --> Sort[Sort pinned first, then active key, then name]
  Sort --> Rows[Render one interleaved resource list]
Loading

Reviews (3): Last reviewed commit: "chore(knowledge): delete the dead base-c..." | Re-trigger Greptile

`sortKnowledgeBases` was a second, complete ordering for knowledge bases
(name/createdAt/updatedAt/docCount) left over from the old sort dropdown,
with no consumers since the shared Resource sort menu replaced it — the
kind of duplicate that silently diverges from the page it shadows.

Its `SortOption`/`SortOrder` types and the `SORT_OPTIONS` list that fed
it were dead with it. `utils/sort.ts` now holds only a filter, so it is
renamed to `utils/filter.ts`.
… menu

An owner id that resolves to no workspace member renders an empty cell,
but its sort key was `''`, so those rows floated to the TOP of an
ascending Owner sort while every other valueless cell sorted last. They
now key `null` and follow the same nulls-last rule on all three pages.

The Knowledge sort menu also listed Owner after Last Updated while its
column order — and Tables' menu — put Owner before it.
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cursor review

`BaseCard`/`BaseCardSkeleton`/`BaseCardSkeletonGrid` were the pre-redesign
grid-card knowledge base view, kept alive only by the barrel re-export —
no call sites since the Resource list replaced it.

Removing it orphans `components/constants.ts` entirely (its sort types
went with the dead sort; its three class-name constants had no consumers
left), so that goes too.
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cursor review

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 3e494e2. Configure here.

@waleedlatif1
waleedlatif1 merged commit 6806fc2 into staging Aug 3, 2026
27 checks passed
@waleedlatif1
waleedlatif1 deleted the worktree-resource-sort-no-folder-priority branch August 3, 2026 18:32
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.

1 participant