UNPKG

@websolutespa/payload-plugin-bowl

Version:

Bowl PayloadCms plugin of the BOM Repository

32 lines (31 loc) 1.18 kB
export const ROOT_ITEM = '_root'; export function getNewCategoriesFromChanges(categories, changes) { const newCategories = categories.map((x)=>({ ...x })); const root = changes[ROOT_ITEM]; let order = 0; const parseChildren = (parent)=>{ const parentIndex = parent.index; parent.children?.forEach((childIndex)=>{ order += 10; const category = newCategories.find((x)=>x.id === childIndex); const child = changes[childIndex]; // console.log('RouteService.getNewCategoriesFromChanges', 'parentIndex', parentIndex, 'childIndex', childIndex, child); if (category) { category.category = parentIndex === ROOT_ITEM ? undefined : parentIndex; category.order = order; } if (child) { parseChildren(child); } }); }; if (root) { parseChildren(root); } newCategories.sort((a, b)=>(a.order || 0) - (b.order || 0)); // console.log('RouteService.getNewCategoriesFromChanges', newCategories); return newCategories; } //# sourceMappingURL=category.service.js.map