diff --git a/core-web/libs/edit-content/src/lib/fields/dot-edit-content-category-field/services/categories.service.spec.ts b/core-web/libs/edit-content/src/lib/fields/dot-edit-content-category-field/services/categories.service.spec.ts index 0fcc7589b82c..0b04fd7260ed 100644 --- a/core-web/libs/edit-content/src/lib/fields/dot-edit-content-category-field/services/categories.service.spec.ts +++ b/core-web/libs/edit-content/src/lib/fields/dot-edit-content-category-field/services/categories.service.spec.ts @@ -13,7 +13,7 @@ describe('CategoriesService', () => { const inode = 'inode-identifier'; spectator.service.getChildren(inode).subscribe(); spectator.expectOne( - `${API_URL}/children?inode=${inode}&per_page=${ITEMS_PER_PAGE}&direction=ASC&showChildrenCount=true`, + `${API_URL}/children?inode=${inode}&per_page=${ITEMS_PER_PAGE}&direction=ASC&parentList=true&showChildrenCount=true`, HttpMethod.GET ); }); @@ -23,7 +23,7 @@ describe('CategoriesService', () => { const filter = 'query'; spectator.service.getChildren(inode, { filter }).subscribe(); spectator.expectOne( - `${API_URL}/children?inode=${inode}&per_page=${ITEMS_PER_PAGE}&direction=ASC&filter=${filter}&allLevels=true`, + `${API_URL}/children?inode=${inode}&per_page=${ITEMS_PER_PAGE}&direction=ASC&parentList=true&filter=${filter}&allLevels=true`, HttpMethod.GET ); diff --git a/core-web/libs/edit-content/src/lib/fields/dot-edit-content-category-field/services/categories.service.ts b/core-web/libs/edit-content/src/lib/fields/dot-edit-content-category-field/services/categories.service.ts index a3a3b2964925..2d1163f95342 100644 --- a/core-web/libs/edit-content/src/lib/fields/dot-edit-content-category-field/services/categories.service.ts +++ b/core-web/libs/edit-content/src/lib/fields/dot-edit-content-category-field/services/categories.service.ts @@ -21,13 +21,15 @@ export interface GetChildrenParams { showChildrenCount: boolean; filter?: string; allLevels?: boolean; + parentList?: boolean; } const DEFAULT_PARAMS: Omit = { per_page: 7000, direction: 'ASC', showChildrenCount: true, - allLevels: false + allLevels: false, + parentList: true }; /** @@ -90,7 +92,8 @@ export class CategoriesService { let httpParams = new HttpParams() .set('inode', params.inode) .set('per_page', params.per_page.toString()) - .set('direction', params.direction); + .set('direction', params.direction) + .set('parentList', params.parentList); if (!params.filter) { // No add showChildrenCount when we use filter diff --git a/core-web/libs/edit-content/src/lib/fields/dot-edit-content-category-field/store/content-category-field.store.ts b/core-web/libs/edit-content/src/lib/fields/dot-edit-content-category-field/store/content-category-field.store.ts index 7517ce64d67f..4b2363429754 100644 --- a/core-web/libs/edit-content/src/lib/fields/dot-edit-content-category-field/store/content-category-field.store.ts +++ b/core-web/libs/edit-content/src/lib/fields/dot-edit-content-category-field/store/content-category-field.store.ts @@ -295,27 +295,21 @@ export const CategoryFieldStore = signalStore( return categoryService.getChildren(categoryInode).pipe( tapResponse({ next: (newCategories) => { + const changes: Partial = { + categories: removeEmptyArrays([ + ...store.categories(), + newCategories + ]), + state: ComponentStatus.LOADED + }; if (event) { - patchState(store, { - categories: removeEmptyArrays([ - ...store.categories(), - newCategories - ]), - state: ComponentStatus.LOADED, - keyParentPath: [ - ...store.keyParentPath(), - event.item.key - ] - }); - } else { - patchState(store, { - categories: removeEmptyArrays([ - ...store.categories(), - newCategories - ]), - state: ComponentStatus.LOADED - }); + changes.keyParentPath = [ + ...store.keyParentPath(), + event.item.key + ]; } + + patchState(store, changes); }, error: () => { // TODO: Add Error Handler diff --git a/core-web/libs/edit-content/src/lib/fields/dot-edit-content-category-field/utils/category-field.utils.spec.ts b/core-web/libs/edit-content/src/lib/fields/dot-edit-content-category-field/utils/category-field.utils.spec.ts index 911fc813c050..4460829b522e 100644 --- a/core-web/libs/edit-content/src/lib/fields/dot-edit-content-category-field/utils/category-field.utils.spec.ts +++ b/core-web/libs/edit-content/src/lib/fields/dot-edit-content-category-field/utils/category-field.utils.spec.ts @@ -179,7 +179,8 @@ describe('CategoryFieldUtils', () => { const item: DotCategoryFieldKeyValueObj = { key: CATEGORY_LEVEL_1[1].key, value: CATEGORY_LEVEL_1[1].categoryName, - inode: CATEGORY_LEVEL_1[1].inode + inode: CATEGORY_LEVEL_1[1].inode, + path: '' }; const expected: DotCategoryFieldKeyValueObj[] = [...storedSelected, item]; diff --git a/core-web/libs/edit-content/src/lib/fields/dot-edit-content-category-field/utils/category-field.utils.ts b/core-web/libs/edit-content/src/lib/fields/dot-edit-content-category-field/utils/category-field.utils.ts index 2ce08ea45e23..6b96244a3643 100644 --- a/core-web/libs/edit-content/src/lib/fields/dot-edit-content-category-field/utils/category-field.utils.ts +++ b/core-web/libs/edit-content/src/lib/fields/dot-edit-content-category-field/utils/category-field.utils.ts @@ -69,7 +69,7 @@ const transformCategory = ( const { key, inode, categoryName, childrenCount } = category; const hasChildren = childrenCount > 0; - const path = category.parentList ? getParentPath(category.parentList) : ''; + const path = getParentPath(category.parentList ?? []); return { key, @@ -181,7 +181,7 @@ export const updateChecked = ( if (!currentChecked.some((entry) => entry.key === item.key)) { currentChecked = [ ...currentChecked, - { key: item.key, value: item.value, inode: item.inode } + { key: item.key, value: item.value, inode: item.inode, path: item?.path ?? '' } ]; } } else { @@ -199,14 +199,14 @@ export const updateChecked = ( * @param parentList */ export const getParentPath = (parentList: DotCategoryParent[]): string => { - if (parentList) { - return parentList - .slice(1) - .map((parent) => parent.name) - .join(' / '); + if (parentList.length === 0) { + return ''; } - return ''; + return parentList + .slice(1) + .map((parent) => parent.name) + .join(' / '); }; /**