u
This commit is contained in:
@@ -109,3 +109,27 @@ export function getCategoryBreadcrumbs(categories, currentCategoryId, rootCatego
|
||||
export function normalizeCategoryMap(data, companyRootCategoryId) {
|
||||
return parseCategoryTreeResponse(data, companyRootCategoryId).categories;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array containing the category id and all of its recursive descendant ids.
|
||||
* Useful for preventing cyclic moves.
|
||||
* @param {object} categories - id -> node map
|
||||
* @param {number|string} categoryId - Target category id
|
||||
* @returns {number[]} Array of category ids
|
||||
*/
|
||||
export function getCategoryDescendantIds(categories, categoryId) {
|
||||
const result = [];
|
||||
if (!categories || categoryId == null) return result;
|
||||
const numId = Number(categoryId);
|
||||
result.push(numId);
|
||||
const queue = [numId];
|
||||
while (queue.length > 0) {
|
||||
const currentId = queue.shift();
|
||||
const children = getCategoryChildren(categories, currentId);
|
||||
for (const child of children) {
|
||||
result.push(Number(child.id));
|
||||
queue.push(Number(child.id));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user