Skip to content

feat(frontend): remember the chosen sort in resource lists - #5866

Open
ignity21 wants to merge 2 commits into
Tencent:mainfrom
ignity21:feat-remember-resource-sort
Open

ignity21 wants to merge 2 commits into
Tencent:mainfrom
ignity21:feat-remember-resource-sort

Conversation

@ignity21

@ignity21 ignity21 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Description

The knowledge base, agent and space lists always open sorted by "Recently updated". Users who prefer another order (for example by name) have to pick it again every time they open the list. This PR remembers the chosen sort per workspace and restores it on the next visit.

  • New frontend/src/utils/resourceSortPreference.ts loads and saves the choice through the existing preferenceStorage helpers, with the same user and workspace scoping that useResourcePins uses for recents: WeKnora_${userId}_t${tenantId}_resource_sort_${list}.
  • KnowledgeBaseList.vue, AgentList.vue and OrganizationList.vue initialise selectedResourceSort from the stored value for authStore.effectiveTenantId and save it when it changes (two lines each). Switching workspace reloads the page, so the list picks up that workspace's choice.

Behaviour:

  • Each list remembers its own choice (knowledge_bases, agents, organizations), so sorting knowledge bases by name does not change the agent list.
  • The choice is per user and per workspace: each workspace keeps its own sort, because the lists differ between workspaces. Two accounts sharing a browser do not inherit each other's choice.
  • Until the workspace id is known nothing is read or written, so no key is shared across workspaces.
  • A missing or unknown stored value (for example an option removed later) falls back to DEFAULT_RESOURCE_SORT, so the default for first-time users is unchanged.
  • If localStorage is unavailable, the list behaves as before (default sort, nothing saved); preferenceStorage already swallows those errors.
  • Only the sort is stored. The fixed group order (pinned / mine / shared) is unchanged, as before the choice only orders items within each group.

Type of Change

  • 🐛 Bug fix
  • ✨ New feature
  • 💥 Breaking change
  • 📚 Documentation update
  • 🎨 Refactor
  • ⚡ Performance improvement
  • 🧪 Test
  • 🔧 Configuration / Build / CI

Related Issue

None.

Testing

The first version remembered one sort per user for all workspaces. Testing on our deployment showed that a sort chosen in one workspace then applied in every other workspace, which is not what users expected, so the second commit scopes it per workspace.

Added resourceSortPreference.test.ts (8 tests): default when nothing is stored, round trip, unknown stored values fall back to the default, workspaces are independent, nothing is read or written without a workspace id, lists are independent, accounts on the same browser are isolated, and unavailable storage neither throws nor leaks a value. It fails against main (module missing) and passes with this change; resourceSorting.test.ts still passes.

npx tsx --test src/utils/resourceSortPreference.test.ts src/utils/resourceSorting.test.ts
ℹ tests 13
ℹ pass 13

I also compiled the three changed SFCs with @vue/compiler-sfc 3.5 and type-checked the new module with tsc --strict. I could not run type-check, build or the full test suite locally, because npm ci is blocked here by a policy on remote tarballs (xlsx from cdn.sheetjs.com), so those are left to CI.

git diff --check is clean.

Checklist

  • git diff --check origin/main...HEAD passes
  • Changed source files are formatted
  • Targeted tests for the changed packages/components pass
  • Diff-scoped lint passes where applicable (not run locally)
  • Full-repository checks were run, or any unrelated/environment-dependent failures are documented above (documented above)
  • Self-reviewed the code
  • Added/updated tests covering the change
  • Updated related documentation (README, website-docs/, Swagger annotations, etc.) (not needed)
  • Breaking changes are clearly called out in the description above (none)

Screenshots / Recordings

No visual change: the sort control looks the same, it just opens with the previously chosen option. I will add a short recording once it has been checked on our deployment.

The knowledge base, agent and space lists always open with "Recently
updated", so users who prefer another order have to pick it again on
every visit.

Store the chosen sort as a per-user UI preference through
preferenceStorage (WeKnora_${userId}_resource_sort_${list}) and restore
it when the list opens. Each list keeps its own choice, the choice
follows the user across spaces in the same browser, and accounts that
share a browser do not inherit each other's choice. Unknown stored
values fall back to the default sort.
Remembering one sort per user carried a choice made in one workspace
into every other workspace. Scope the stored preference by workspace as
well, the same way useResourcePins scopes recents
(WeKnora_${userId}_t${tenantId}_resource_sort_${list}), and read or
write nothing until the workspace id is known so no choice is shared
across workspaces.

This branch has not been deployed

No deployments
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