diff --git a/web/src/pages/Categories.jsx b/web/src/pages/Categories.jsx index 2d1bad8..cb24026 100644 --- a/web/src/pages/Categories.jsx +++ b/web/src/pages/Categories.jsx @@ -95,6 +95,19 @@ export default function Categories() { const nameById = Object.fromEntries(categories.map((c) => [c.id, c.name])); const parentOf = Object.fromEntries(categories.map((c) => [c.id, c.parent_id])); const childCount = (id) => categories.filter((c) => c.parent_id === id).length; + // Eigene Unterkategorien (rekursiv) – als Ziel beim Verschieben ausgeschlossen, + // sonst entstünde ein Ring. + function descendantIds(id) { + const result = new Set(); + const stack = [id]; + while (stack.length) { + const cur = stack.pop(); + for (const kid of categories.filter((c) => c.parent_id === cur)) { + if (!result.has(kid.id)) { result.add(kid.id); stack.push(kid.id); } + } + } + return result; + } function versteckt(id) { let p = parentOf[id]; while (p != null) { @@ -135,6 +148,7 @@ export default function Categories() { Kategorie Art + Übergeordnet Artikel @@ -143,6 +157,12 @@ export default function Categories() { {sichtbar.map((c) => { const kinder = childCount(c.id); const zu = collapsed.has(c.id); + // Mögliche neue Elternkategorien: gleicher Typ, nicht sie selbst + // und keine ihrer Unterkategorien. + const desc = descendantIds(c.id); + const parentOptions = tree.filter( + (o) => o.tracking === c.tracking && o.id !== c.id && !desc.has(o.id), + ); return ( @@ -164,9 +184,6 @@ export default function Categories() { {zu && kinder > 0 && ( {kinder} ausgeblendet )} - {c.depth > 0 && c.parent_id && nameById[c.parent_id] && ( - in {nameById[c.parent_id]} - )} @@ -180,6 +197,21 @@ export default function Categories() { {MODUS[c.tracking] || c.tracking} )} + + {isAdmin ? ( + + ) : ( + {c.parent_id ? nameById[c.parent_id] : "–"} + )} + {c.product_count}