fix(symbol-groups): API + Frontend auf category-Objekt-Format umgestellt – zeigt jetzt alle Kategorien korrekt
Some checks failed
Build and Push Docker Image / build-and-push (push) Has been cancelled

This commit is contained in:
Pepe Ziberi
2026-05-21 15:25:12 +02:00
parent 9cba24aad8
commit 0cbea843ab
3 changed files with 23 additions and 27 deletions

View File

@@ -115,12 +115,12 @@ export async function GET() {
const groups = new Map<string | null, any[]>() const groups = new Map<string | null, any[]>()
for (const sym of flatTenantSymbols) { for (const sym of flatTenantSymbols) {
const key = sym.categoryId || null const key = sym.categoryId || '__none__'
if (!groups.has(key)) groups.set(key, []) if (!groups.has(key)) groups.set(key, [])
groups.get(key)!.push(sym) groups.get(key)!.push(sym)
} }
const catIds = Array.from(groups.keys()).filter(Boolean) as string[] const catIds = Array.from(groups.keys()).filter(k => k !== '__none__') as string[]
let tenantCategories: any[] = [] let tenantCategories: any[] = []
if (catIds.length > 0) { if (catIds.length > 0) {
tenantCategories = await prisma.$queryRawUnsafe( tenantCategories = await prisma.$queryRawUnsafe(
@@ -132,15 +132,12 @@ export async function GET() {
const catMap = new Map(tenantCategories.map((c: any) => [c.id, c])) const catMap = new Map(tenantCategories.map((c: any) => [c.id, c]))
tenantSymbolGroups = Array.from(groups.entries()).map(([catId, symbols]) => { tenantSymbolGroups = Array.from(groups.entries()).map(([catId, symbols]) => {
const cat = catId ? catMap.get(catId) : null const cat = catId !== '__none__' ? catMap.get(catId) : null
return { return {
categoryId: catId, category: cat ? { id: cat.id, name: cat.name } : null,
categoryName: cat ? cat.name || 'Kategorie' : 'Ohne Kategorie',
sortOrder: cat ? cat.sortOrder ?? 999 : 999,
symbols, symbols,
} }
}) })
tenantSymbolGroups.sort((a, b) => a.sortOrder - b.sortOrder)
} }
} catch (err) { } catch (err) {
console.error('Error fetching tenant symbols:', err) console.error('Error fetching tenant symbols:', err)

View File

@@ -84,11 +84,13 @@ export async function GET(req: NextRequest) {
} }
// Group by category // Group by category
const groupedResult: Record<string, any[]> = {} const groupedResult: Record<string, { catId: string | null; catName: string; symbols: any[] }> = {}
for (const sym of mapped) { for (const sym of mapped) {
const catName = sym.categoryName const key = sym.categoryId || '__none__'
if (!groupedResult[catName]) groupedResult[catName] = [] if (!groupedResult[key]) {
groupedResult[catName].push(sym) groupedResult[key] = { catId: sym.categoryId, catName: sym.categoryName, symbols: [] }
}
groupedResult[key].symbols.push(sym)
} }
// Get categories for ordering // Get categories for ordering
@@ -97,16 +99,16 @@ export async function GET(req: NextRequest) {
tenantId tenantId
) )
const ordered: Array<{ categoryId: string | null; categoryName: string; symbols: any[] }> = [] const ordered: Array<{ category: { id: string; name: string } | null; symbols: any[] }> = []
for (const cat of categories) { for (const cat of categories) {
if (groupedResult[cat.name]) { if (groupedResult[cat.id]) {
ordered.push({ categoryId: cat.id, categoryName: cat.name, symbols: groupedResult[cat.name] }) ordered.push({ category: { id: cat.id, name: cat.name }, symbols: groupedResult[cat.id].symbols })
delete groupedResult[cat.name] delete groupedResult[cat.id]
} }
} }
// Append any remaining uncategorized // Append any remaining uncategorized
for (const [catName, symbols] of Object.entries(groupedResult)) { for (const entry of Object.values(groupedResult)) {
ordered.push({ categoryId: null, categoryName: catName, symbols }) ordered.push({ category: null, symbols: entry.symbols })
} }
return NextResponse.json({ categories: ordered }) return NextResponse.json({ categories: ordered })

View File

@@ -25,8 +25,7 @@ interface DisplayCategory {
} }
interface TenantSymbolGroup { interface TenantSymbolGroup {
categoryId: string | null category: { id: string; name: string } | null
categoryName: string
symbols: DisplaySymbol[] symbols: DisplaySymbol[]
} }
@@ -143,8 +142,7 @@ export function RightSidebar({ onSymbolDrop, canEdit, isOpen, onToggle, activeTa
// ─── New tenant symbol groups (Phase 1) ─── // ─── New tenant symbol groups (Phase 1) ───
const groups: TenantSymbolGroup[] = (data.tenantSymbolGroups || []).map((g: any) => ({ const groups: TenantSymbolGroup[] = (data.tenantSymbolGroups || []).map((g: any) => ({
categoryId: g.categoryId, category: g.category,
categoryName: g.categoryName,
symbols: g.symbols.map((s: any) => ({ symbols: g.symbols.map((s: any) => ({
id: s.id, id: s.id,
name: s.name, name: s.name,
@@ -155,8 +153,7 @@ export function RightSidebar({ onSymbolDrop, canEdit, isOpen, onToggle, activeTa
// Merge legacy "Eigene" into tenant groups if present // Merge legacy "Eigene" into tenant groups if present
if (eigene && eigene.symbols.length > 0) { if (eigene && eigene.symbols.length > 0) {
const legacyGroup: TenantSymbolGroup = { const legacyGroup: TenantSymbolGroup = {
categoryId: '__legacy__', category: { id: '__legacy__', name: 'Eigene' },
categoryName: 'Eigene',
symbols: eigene.symbols, symbols: eigene.symbols,
} }
groups.unshift(legacyGroup) groups.unshift(legacyGroup)
@@ -166,7 +163,7 @@ export function RightSidebar({ onSymbolDrop, canEdit, isOpen, onToggle, activeTa
// Auto-expand all tenant groups, auto-collapse library if tenant has symbols // Auto-expand all tenant groups, auto-collapse library if tenant has symbols
if (groups.length > 0 && groups.some(g => g.symbols.length > 0)) { if (groups.length > 0 && groups.some(g => g.symbols.length > 0)) {
setExpandedTenantCats(new Set(groups.map(g => g.categoryId || '__none__'))) setExpandedTenantCats(new Set(groups.map(g => g.category?.id || '__none__')))
setShowLibrarySection(false) setShowLibrarySection(false)
} }
} }
@@ -357,17 +354,17 @@ export function RightSidebar({ onSymbolDrop, canEdit, isOpen, onToggle, activeTa
</div> </div>
) : ( ) : (
filteredTenantGroups.map(g => { filteredTenantGroups.map(g => {
const key = g.categoryId || '__none__' const key = g.category?.id || '__none__'
const expanded = expandedTenantCats.has(key) const expanded = expandedTenantCats.has(key)
return ( return (
<div key={key} className="border rounded-md"> <div key={key} className="border rounded-md">
<button <button
onClick={() => toggleTenantCat(g.categoryId)} onClick={() => toggleTenantCat(g.category?.id || null)}
className="w-full flex items-center justify-between px-2 py-1 text-[11px] font-medium hover:bg-muted/40 transition-colors" className="w-full flex items-center justify-between px-2 py-1 text-[11px] font-medium hover:bg-muted/40 transition-colors"
> >
<span className="flex items-center gap-1.5"> <span className="flex items-center gap-1.5">
<FolderOpen className="w-3 h-3 text-muted-foreground" /> <FolderOpen className="w-3 h-3 text-muted-foreground" />
{g.categoryName} {g.category?.name || 'Ohne Kategorie'}
<span className="text-[10px] text-muted-foreground">({g.symbols.length})</span> <span className="text-[10px] text-muted-foreground">({g.symbols.length})</span>
</span> </span>
<ChevronRight className={`w-3 h-3 transition-transform ${expanded ? 'rotate-90' : ''}`} /> <ChevronRight className={`w-3 h-3 transition-transform ${expanded ? 'rotate-90' : ''}`} />