fix(tree): sort category nodes by name in flattenTree function
This commit is contained in:
@@ -18,7 +18,8 @@ const sortOptions = [
|
||||
|
||||
function flattenTree(nodes: CategoryNode[], depth = 0): { id: number; label: string }[] {
|
||||
const result: { id: number; label: string }[] = [];
|
||||
for (const node of nodes) {
|
||||
const sorted = [...nodes].sort((a, b) => a.name.localeCompare(b.name, 'sv'));
|
||||
for (const node of sorted) {
|
||||
result.push({ id: node.id, label: '\u00a0\u00a0'.repeat(depth) + (depth > 0 ? '↳ ' : '') + node.name });
|
||||
if (node.children?.length) result.push(...flattenTree(node.children, depth + 1));
|
||||
}
|
||||
|
||||
@@ -53,7 +53,8 @@ export default function EditProductForm({ product }: Props) {
|
||||
// Bygg flat lista för select med indragna nivåer
|
||||
function flattenTree(nodes: CategoryNode[], depth = 0): { id: number; name: string; label: string }[] {
|
||||
const result: { id: number; name: string; label: string }[] = [];
|
||||
for (const node of nodes) {
|
||||
const sorted = [...nodes].sort((a, b) => a.name.localeCompare(b.name, 'sv'));
|
||||
for (const node of sorted) {
|
||||
const prefix = depth === 0 ? '' : depth === 1 ? '\u00a0\u00a0\u00a0↳ ' : '\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0↳ ';
|
||||
result.push({ id: node.id, name: node.name, label: prefix + node.name });
|
||||
result.push(...flattenTree(node.children, depth + 1));
|
||||
|
||||
Reference in New Issue
Block a user