Implement Skill Tree Selection Components and Update API Calls
Deploy Development / deploy (push) Successful in 44s
Test Suite / pytest-backend (push) Successful in 37s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 12s
Test Suite / k6 /health Baseline (push) Successful in 33s
Test Suite / playwright-tests (push) Successful in 1m15s
Deploy Development / deploy (push) Successful in 44s
Test Suite / pytest-backend (push) Successful in 37s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 12s
Test Suite / k6 /health Baseline (push) Successful in 33s
Test Suite / playwright-tests (push) Successful in 1m15s
- Introduced new `SkillTreeSelect` and `SkillTreeMultiSelect` components for enhanced skill selection in various modals and forms. - Updated API calls to use `listSkillsCatalog` instead of `listSkills` for improved data retrieval. - Enhanced CSS styles for skill selection components to improve user experience and visual consistency across the application.
This commit is contained in:
1 parent
728b37ad5f
commit
3067b2e6a8
12 files changed
+793
-46
No files matched your search
@@ -0,0 +1,163 @@
|
||||
/**
|
||||
* Hierarchie Fähigkeiten-Katalog: Hauptgruppe → Kategorie → Fähigkeit.
|
||||
* Datenbasis: GET /api/skills/catalog (catalog_* Felder).
|
||||
*/
|
||||
|
||||
export function bySortThenName(a, b) {
|
||||
const sa = a.sort_order != null ? Number(a.sort_order) : 99999
|
||||
const sb = b.sort_order != null ? Number(b.sort_order) : 99999
|
||||
if (sa !== sb) return sa - sb
|
||||
return String(a.name || a.label || '').localeCompare(String(b.name || b.label || ''), 'de')
|
||||
}
|
||||
|
||||
/** @param {object} skill */
|
||||
export function skillCatalogPathLabel(skill) {
|
||||
if (!skill || typeof skill !== 'object') return ''
|
||||
const parts = []
|
||||
const main = (skill.catalog_main_category_name || '').trim()
|
||||
const cat = (skill.catalog_category_name || '').trim()
|
||||
if (main) parts.push(main)
|
||||
if (cat) parts.push(cat)
|
||||
parts.push((skill.name || '').trim() || `#${skill.id}`)
|
||||
return parts.join(' › ')
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {object[]} skills
|
||||
* @returns {Array<{ key: string, type: string, label: string, skillId?: number, skill?: object, children?: object[] }>}
|
||||
*/
|
||||
export function buildSkillCatalogTree(skills) {
|
||||
if (!Array.isArray(skills) || skills.length === 0) return []
|
||||
|
||||
/** @type {Map<string, { key: string, type: string, label: string, sortOrder: number, children: Map<string, object> }>} */
|
||||
const mainMap = new Map()
|
||||
|
||||
for (const skill of skills) {
|
||||
const mainId = skill.main_category_id ?? null
|
||||
const mainKey = mainId != null ? `m-${mainId}` : 'm-none'
|
||||
const mainLabel = (skill.catalog_main_category_name || '').trim() || 'Ohne Hauptgruppe'
|
||||
const mainSort = Number(skill.catalog_main_sort ?? 99999)
|
||||
|
||||
if (!mainMap.has(mainKey)) {
|
||||
mainMap.set(mainKey, {
|
||||
key: mainKey,
|
||||
type: 'main',
|
||||
label: mainLabel,
|
||||
sortOrder: mainSort,
|
||||
children: new Map(),
|
||||
})
|
||||
}
|
||||
const mainNode = mainMap.get(mainKey)
|
||||
|
||||
const catId = skill.category_id ?? null
|
||||
const catKey = catId != null ? `c-${catId}` : 'c-none'
|
||||
const catLabel = (skill.catalog_category_name || '').trim() || 'Ohne Kategorie'
|
||||
const catSort = Number(skill.catalog_category_sort ?? 99999)
|
||||
|
||||
if (!mainNode.children.has(catKey)) {
|
||||
mainNode.children.set(catKey, {
|
||||
key: `${mainKey}-${catKey}`,
|
||||
type: 'category',
|
||||
label: catLabel,
|
||||
sortOrder: catSort,
|
||||
skills: [],
|
||||
})
|
||||
}
|
||||
mainNode.children.get(catKey).skills.push(skill)
|
||||
}
|
||||
|
||||
return [...mainMap.values()]
|
||||
.sort((a, b) => {
|
||||
if (a.sortOrder !== b.sortOrder) return a.sortOrder - b.sortOrder
|
||||
return a.label.localeCompare(b.label, 'de')
|
||||
})
|
||||
.map((main) => ({
|
||||
key: main.key,
|
||||
type: main.type,
|
||||
label: main.label,
|
||||
children: [...main.children.values()]
|
||||
.sort((a, b) => {
|
||||
if (a.sortOrder !== b.sortOrder) return a.sortOrder - b.sortOrder
|
||||
return a.label.localeCompare(b.label, 'de')
|
||||
})
|
||||
.map((cat) => ({
|
||||
key: cat.key,
|
||||
type: cat.type,
|
||||
label: cat.label,
|
||||
children: [...cat.skills].sort(bySortThenName).map((skill) => ({
|
||||
key: `s-${skill.id}`,
|
||||
type: 'skill',
|
||||
label: (skill.name || '').trim() || `#${skill.id}`,
|
||||
skillId: Number(skill.id),
|
||||
skill,
|
||||
})),
|
||||
})),
|
||||
}))
|
||||
}
|
||||
|
||||
/**
|
||||
* Alle wählbaren Blätter mit Pfad-Label (für Suche / Chips).
|
||||
* @param {ReturnType<typeof buildSkillCatalogTree>} tree
|
||||
* @param {Set<number>|number[]} [excludeIds]
|
||||
*/
|
||||
export function collectSkillLeavesFromTree(tree, excludeIds) {
|
||||
const exclude = new Set(
|
||||
(excludeIds instanceof Set ? [...excludeIds] : excludeIds || [])
|
||||
.map((x) => Number(x))
|
||||
.filter((n) => Number.isFinite(n))
|
||||
)
|
||||
/** @type {Array<{ id: number, label: string, pathLabel: string, skill: object }>} */
|
||||
const out = []
|
||||
|
||||
const walk = (nodes, pathParts) => {
|
||||
for (const n of nodes) {
|
||||
if (n.type === 'skill' && n.skillId != null) {
|
||||
if (!exclude.has(n.skillId)) {
|
||||
const pathLabel = [...pathParts, n.label].join(' › ')
|
||||
out.push({ id: n.skillId, label: n.label, pathLabel, skill: n.skill })
|
||||
}
|
||||
} else if (n.children?.length) {
|
||||
walk(n.children, [...pathParts, n.label])
|
||||
}
|
||||
}
|
||||
}
|
||||
walk(tree, [])
|
||||
return out
|
||||
}
|
||||
|
||||
/** @param {ReturnType<typeof buildSkillCatalogTree>} tree */
|
||||
export function filterSkillTreeByQuery(tree, query) {
|
||||
const q = String(query || '').trim().toLowerCase()
|
||||
if (!q) return tree
|
||||
|
||||
const filterNodes = (nodes) => {
|
||||
/** @type {typeof nodes} */
|
||||
const result = []
|
||||
for (const n of nodes) {
|
||||
if (n.type === 'skill') {
|
||||
const hay = `${n.label} ${skillCatalogPathLabel(n.skill)}`.toLowerCase()
|
||||
if (hay.includes(q)) result.push(n)
|
||||
} else {
|
||||
const kids = filterNodes(n.children || [])
|
||||
if (kids.length) result.push({ ...n, children: kids })
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
return filterNodes(tree)
|
||||
}
|
||||
|
||||
/** @param {ReturnType<typeof buildSkillCatalogTree>} tree */
|
||||
export function allExpandableKeys(tree) {
|
||||
const keys = []
|
||||
const walk = (nodes) => {
|
||||
for (const n of nodes) {
|
||||
if (n.type !== 'skill' && n.children?.length) {
|
||||
keys.push(n.key)
|
||||
walk(n.children)
|
||||
}
|
||||
}
|
||||
}
|
||||
walk(tree)
|
||||
return keys
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import {
|
||||
buildSkillCatalogTree,
|
||||
collectSkillLeavesFromTree,
|
||||
filterSkillTreeByQuery,
|
||||
skillCatalogPathLabel,
|
||||
} from './skillCatalogTree.js'
|
||||
|
||||
const sample = [
|
||||
{
|
||||
id: 1,
|
||||
name: 'Dachi Waza',
|
||||
main_category_id: 10,
|
||||
category_id: 20,
|
||||
catalog_main_category_name: 'Karate',
|
||||
catalog_main_sort: 1,
|
||||
catalog_category_name: 'Kihon',
|
||||
catalog_category_sort: 2,
|
||||
sort_order: 1,
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: 'Kata Ablauf',
|
||||
main_category_id: 10,
|
||||
category_id: 21,
|
||||
catalog_main_category_name: 'Karate',
|
||||
catalog_main_sort: 1,
|
||||
catalog_category_name: 'Kata',
|
||||
catalog_category_sort: 1,
|
||||
sort_order: 1,
|
||||
},
|
||||
]
|
||||
|
||||
describe('skillCatalogTree', () => {
|
||||
it('buildSkillCatalogTree groups by main and category', () => {
|
||||
const tree = buildSkillCatalogTree(sample)
|
||||
expect(tree).toHaveLength(1)
|
||||
expect(tree[0].label).toBe('Karate')
|
||||
expect(tree[0].children).toHaveLength(2)
|
||||
expect(tree[0].children[0].label).toBe('Kata')
|
||||
expect(tree[0].children[0].children[0].skillId).toBe(2)
|
||||
})
|
||||
|
||||
it('skillCatalogPathLabel', () => {
|
||||
expect(skillCatalogPathLabel(sample[0])).toBe('Karate › Kihon › Dachi Waza')
|
||||
})
|
||||
|
||||
it('collectSkillLeavesFromTree respects exclude', () => {
|
||||
const tree = buildSkillCatalogTree(sample)
|
||||
const leaves = collectSkillLeavesFromTree(tree, [1])
|
||||
expect(leaves).toHaveLength(1)
|
||||
expect(leaves[0].id).toBe(2)
|
||||
})
|
||||
|
||||
it('filterSkillTreeByQuery', () => {
|
||||
const tree = buildSkillCatalogTree(sample)
|
||||
const filtered = filterSkillTreeByQuery(tree, 'dachi')
|
||||
expect(filtered[0].children.some((c) => c.children?.some((s) => s.skillId === 1))).toBe(true)
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user