u
This commit is contained in:
@@ -44,6 +44,8 @@ import {
|
||||
parseCategoryTreeResponse,
|
||||
normalizeCategoryNode,
|
||||
cleanCategorySlugPath,
|
||||
getCategoryChildren,
|
||||
getCategoryDescendantIds,
|
||||
} from '../utils/categoryUtils';
|
||||
|
||||
/**
|
||||
@@ -307,6 +309,35 @@ const actions = {
|
||||
return categoryId;
|
||||
},
|
||||
|
||||
/**
|
||||
* Delete a category and all its descendants recursively.
|
||||
* Calls DELETE /api/category/:id?recursive=true.
|
||||
*
|
||||
* @param {number|string} categoryId
|
||||
*/
|
||||
async deleteCategoryRecursive(categoryId) {
|
||||
const { categories, rootCategoryId } = categoryAutomat.state;
|
||||
|
||||
if (rootCategoryId != null && String(categoryId) === String(rootCategoryId)) {
|
||||
throw new Error('Root-Kategorie kann nicht gelöscht werden');
|
||||
}
|
||||
|
||||
const removedIds = getCategoryDescendantIds(categories, categoryId);
|
||||
|
||||
await categoryApi.delete(categoryId, { recursive: true });
|
||||
|
||||
if (categories) {
|
||||
const next = { ...categories };
|
||||
for (const id of removedIds) {
|
||||
delete next[String(id)];
|
||||
}
|
||||
categoryAutomat.setState({ categories: next });
|
||||
refreshCategoryViewChildren(next);
|
||||
}
|
||||
|
||||
return categoryId;
|
||||
},
|
||||
|
||||
/**
|
||||
* Toggle the POS flag on a category.
|
||||
* @param {{ categoryId: number|string, pos: boolean }} param0
|
||||
|
||||
Reference in New Issue
Block a user