Skip to content

Commit

Permalink
fix(edit-content): show the path in selected items (#29550)
Browse files Browse the repository at this point in the history
### Parent Issue

#29489

### Proposed Changes
* Fix bug in map to show path
* Add query param to get ParentList attr

### Checklist
- [x] Tests
- [x] Translations
- [x] Security Implications Contemplated (add notes if applicable)

### Screenshots
Original             |  Updated
:-------------------------:|:-------------------------:
![Screenshot 2024-08-08 at 10 12
38 AM](https://github.com/user-attachments/assets/d7718d5c-b1ee-4e15-97f5-dd287be527d7)
| ![Screenshot 2024-08-08 at 10 13
00 AM](https://github.com/user-attachments/assets/adc50f51-7d71-4a97-85f9-9c6cc19ffa8c)
  • Loading branch information
nicobytes authored Aug 13, 2024
1 parent f96e156 commit 2e54089
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
});
Expand All @@ -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
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ export interface GetChildrenParams {
showChildrenCount: boolean;
filter?: string;
allLevels?: boolean;
parentList?: boolean;
}

const DEFAULT_PARAMS: Omit<GetChildrenParams, 'inode'> = {
per_page: 7000,
direction: 'ASC',
showChildrenCount: true,
allLevels: false
allLevels: false,
parentList: true
};

/**
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,27 +295,21 @@ export const CategoryFieldStore = signalStore(
return categoryService.getChildren(categoryInode).pipe(
tapResponse({
next: (newCategories) => {
const changes: Partial<CategoryFieldState> = {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand All @@ -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(' / ');
};

/**
Expand Down

0 comments on commit 2e54089

Please sign in to comment.