fix(frontend): dedupe KB list to stop empty render with ≥2 knowledge bases

The "All" scope of the knowledge-base list renders every card with
`:key="kb.id"`. The same knowledge base can appear more than once in the
source data — owned *and* shared back to the caller, or shared into their
view through two different organizations (distinct share_id, identical
knowledge_base.id). Duplicate `v-for` keys corrupt Vue's virtual-DOM
patch and the list renders empty/partial. A single KB never collides, so
the page works with one KB and blanks once there are two or more — the
exact behavior reported in #795.

Extract the merge into a pure, unit-tested helper
(mergeAllScopeKnowledgeBases) that de-duplicates by knowledge-base id —
owned rows win over shared duplicates, and repeated shares of one KB keep
the most-privileged permission — while preserving the existing
pinned → mine → teammate → shared(editable-first) ordering.

Tests use the repo's existing node:test convention; a `test` script is
added so `npm test` discovers them (it also wires up the two previously
orphaned *.test.ts files).

Fixes #795

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Martín Alcalá Rubí
2026-06-05 17:22:55 -03:00
committed by lyingbug
parent 22349055ec
commit bbf7ac29bf
4 changed files with 331 additions and 45 deletions
+2 -1
View File
@@ -9,7 +9,8 @@
"build-with-types": "run-p type-check \"build-only {@}\" --",
"preview": "vite preview",
"build-only": "vite build",
"type-check": "vue-tsc --build"
"type-check": "vue-tsc --build",
"test": "node --test"
},
"dependencies": {
"@microsoft/fetch-event-source": "^2.0.1",