From ab612a53350a74a2ab4abb8766802527f2d54069 Mon Sep 17 00:00:00 2001 From: Lars Date: Wed, 20 May 2026 11:21:18 +0200 Subject: [PATCH] Update Skill Tree Picker and Catalog Functions for Clarity - Modified comments in `SkillTreePickerPanel` and `skillCatalogTree.js` to accurately reflect the default expansion behavior, specifying that only main groups are open by default. - Refactored `defaultExpandedKeysForSkillTree` to simplify the logic, ensuring only main groups are returned as expanded. - Adjusted tests in `skillCatalogTree.test.js` to validate the updated behavior, confirming that only main groups are opened in the skill tree. --- frontend/src/components/SkillTreePickerPanel.jsx | 2 +- frontend/src/utils/skillCatalogTree.js | 15 +++------------ frontend/src/utils/skillCatalogTree.test.js | 6 +++--- 3 files changed, 7 insertions(+), 16 deletions(-) diff --git a/frontend/src/components/SkillTreePickerPanel.jsx b/frontend/src/components/SkillTreePickerPanel.jsx index e127a1a..6b947a1 100644 --- a/frontend/src/components/SkillTreePickerPanel.jsx +++ b/frontend/src/components/SkillTreePickerPanel.jsx @@ -78,7 +78,7 @@ function SkillTreeNodes({ nodes, depth, expanded, exclude, onToggle, onPickSkill } /** - * Ausklappbare Baumliste: Hauptgruppe → Kategorie → Fähigkeit (Hauptgruppe und Kategorie standard offen). + * Ausklappbare Baumliste: Hauptgruppe → Kategorie → Fähigkeit (nur Hauptgruppe standard offen). */ export default function SkillTreePickerPanel({ skills = [], diff --git a/frontend/src/utils/skillCatalogTree.js b/frontend/src/utils/skillCatalogTree.js index 64de7bb..37f27ba 100644 --- a/frontend/src/utils/skillCatalogTree.js +++ b/frontend/src/utils/skillCatalogTree.js @@ -162,19 +162,10 @@ export function allExpandableKeys(tree) { return keys } -/** Standard: Hauptgruppe und Kategorie aufgeklappt (Fähigkeiten direkt darunter sichtbar). */ +/** Standard: nur Hauptgruppe aufgeklappt; Kategorien und Fähigkeiten zugeklappt. */ export function defaultExpandedKeysForSkillTree(tree) { - const keys = [] - const walk = (nodes) => { - for (const n of nodes) { - if (n.type === 'main' || n.type === 'category') { - keys.push(n.key) - walk(n.children || []) - } - } - } - walk(tree) - return keys + if (!Array.isArray(tree)) return [] + return tree.filter((n) => n.type === 'main').map((n) => n.key) } /** Sentinel für Katalog-Admin: keine Hauptgruppe gewählt. */ diff --git a/frontend/src/utils/skillCatalogTree.test.js b/frontend/src/utils/skillCatalogTree.test.js index bbd06fd..f320a63 100644 --- a/frontend/src/utils/skillCatalogTree.test.js +++ b/frontend/src/utils/skillCatalogTree.test.js @@ -49,11 +49,11 @@ describe('skillCatalogTree', () => { expect(kataSkill.skillId).toBe(2) }) - it('defaultExpandedKeysForSkillTree opens main and category only', () => { + it('defaultExpandedKeysForSkillTree opens main groups only', () => { const tree = buildSkillCatalogTree(sample) const keys = defaultExpandedKeysForSkillTree(tree) - expect(keys).toContain('m-10') - expect(keys.some((k) => k.includes('c-21'))).toBe(true) + expect(keys).toEqual(['m-10']) + expect(keys.some((k) => k.includes('c-'))).toBe(false) expect(keys.some((k) => k.startsWith('s-'))).toBe(false) })