Skip to content

Commit

Permalink
chore: fix error in show parent (#29638)
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)






This PR fixes: #29489
  • Loading branch information
nicobytes authored Aug 19, 2024
1 parent 7212cb8 commit 325cd51
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
.category-list {
list-style: none;
margin: 0;
padding: 0 $spacing-3 0 0;
padding: 0;
}

.category-list__item {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
flex: 0 0 25%;
gap: $spacing-1;
padding: $spacing-3;
padding-right: 0;
&.empty {
padding-left: 0;
}
Expand All @@ -69,7 +68,7 @@

.category-field__selected-categories-list {
overflow-y: auto;
scrollbar-gutter: stable;
scrollbar-gutter: auto;
}

:host ::ng-deep .p-sidebar-content {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,16 @@ describe('CategoriesService', () => {
it('can getChildren with inode', () => {
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`,
HttpMethod.GET
);
const url = `${API_URL}/children?inode=${inode}&per_page=${ITEMS_PER_PAGE}&direction=ASC&parentList=true&showChildrenCount=true`;
spectator.expectOne(url, HttpMethod.GET);
});

it('can getChildren with inode & filter', () => {
const inode = 'inode-identifier';
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`,

HttpMethod.GET
);
const url = `${API_URL}/children?inode=${inode}&per_page=${ITEMS_PER_PAGE}&direction=ASC&parentList=true&filter=${filter}&allLevels=true`;
spectator.expectOne(url, HttpMethod.GET);
});

it('can getSelectedHierarchy of selected categories', () => {
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 325cd51

Please sign in to comment.