Skip to content

Commit 1d0ca04

Browse files
tamu-sad-iiigithub-actions[bot]
authored andcommitted
Update condition to render show more node
`loadingNode` ends up being the current `node` after clicking it preventing it from rendering when more pages available. Update community list component spec Make the show more flat node id unique The nodes with same id are conflicting when added to the tree. Clicking on the second with same id places the show more button under the wrong branch and expands the wrong page. (cherry picked from commit 11d3771)
1 parent 34b91a7 commit 1d0ca04

4 files changed

Lines changed: 12 additions & 11 deletions

File tree

src/app/community-list-page/community-list-service.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { FlatNode } from './flat-node.model';
2424
import { ShowMoreFlatNode } from './show-more-flat-node.model';
2525
import { FindListOptions } from '../core/data/find-list-options.model';
2626
import { AppConfig, APP_CONFIG } from 'src/config/app-config.interface';
27+
import { v4 as uuidv4 } from 'uuid';
2728

2829
// Helper method to combine and flatten an array of observables of flatNode arrays
2930
export const combineAndFlatten = (obsList: Observable<FlatNode[]>[]): Observable<FlatNode[]> =>
@@ -186,7 +187,7 @@ export class CommunityListService {
186187
return this.transformCommunity(community, level, parent, expandedNodes);
187188
});
188189
if (currentPage < listOfPaginatedCommunities.totalPages && currentPage === listOfPaginatedCommunities.currentPage) {
189-
obsList = [...obsList, observableOf([showMoreFlatNode('community', level, parent)])];
190+
obsList = [...obsList, observableOf([showMoreFlatNode(`community-${uuidv4()}`, level, parent)])];
190191
}
191192

192193
return combineAndFlatten(obsList);
@@ -257,7 +258,7 @@ export class CommunityListService {
257258
let nodes = rd.payload.page
258259
.map((collection: Collection) => toFlatNode(collection, observableOf(false), level + 1, false, communityFlatNode));
259260
if (currentCollectionPage < rd.payload.totalPages && currentCollectionPage === rd.payload.currentPage) {
260-
nodes = [...nodes, showMoreFlatNode('collection', level + 1, communityFlatNode)];
261+
nodes = [...nodes, showMoreFlatNode(`collection-${uuidv4()}`, level + 1, communityFlatNode)];
261262
}
262263
return nodes;
263264
} else {

src/app/community-list-page/community-list/community-list.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<span class="fa fa-chevron-right invisible" aria-hidden="true"></span>
99
</button>
1010
<div class="align-middle pt-2">
11-
<button *ngIf="node!==loadingNode" (click)="getNextPage(node)"
11+
<button *ngIf="!(dataSource.loading$ | async)" (click)="getNextPage(node)"
1212
class="btn btn-outline-primary btn-sm" role="button">
1313
<i class="fas fa-angle-down"></i> {{ 'communityList.showMore' | translate }}
1414
</button>

src/app/community-list-page/community-list/community-list.component.spec.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { By } from '@angular/platform-browser';
1717
import { isEmpty, isNotEmpty } from '../../shared/empty.util';
1818
import { FlatNode } from '../flat-node.model';
1919
import { RouterLinkWithHref } from '@angular/router';
20+
import { v4 as uuidv4 } from 'uuid';
2021

2122
describe('CommunityListComponent', () => {
2223
let component: CommunityListComponent;
@@ -138,7 +139,7 @@ describe('CommunityListComponent', () => {
138139
}
139140
if (expandedNodes === null || isEmpty(expandedNodes)) {
140141
if (showMoreTopComNode) {
141-
return observableOf([...mockTopFlatnodesUnexpanded.slice(0, endPageIndex), showMoreFlatNode('community', 0, null)]);
142+
return observableOf([...mockTopFlatnodesUnexpanded.slice(0, endPageIndex), showMoreFlatNode(`community-${uuidv4()}`, 0, null)]);
142143
} else {
143144
return observableOf(mockTopFlatnodesUnexpanded.slice(0, endPageIndex));
144145
}
@@ -165,21 +166,21 @@ describe('CommunityListComponent', () => {
165166
const endSubComIndex = this.pageSize * expandedParent.currentCommunityPage;
166167
flatnodes = [...flatnodes, ...subComFlatnodes.slice(0, endSubComIndex)];
167168
if (subComFlatnodes.length > endSubComIndex) {
168-
flatnodes = [...flatnodes, showMoreFlatNode('community', topNode.level + 1, expandedParent)];
169+
flatnodes = [...flatnodes, showMoreFlatNode(`community-${uuidv4()}`, topNode.level + 1, expandedParent)];
169170
}
170171
}
171172
if (isNotEmpty(collFlatnodes)) {
172173
const endColIndex = this.pageSize * expandedParent.currentCollectionPage;
173174
flatnodes = [...flatnodes, ...collFlatnodes.slice(0, endColIndex)];
174175
if (collFlatnodes.length > endColIndex) {
175-
flatnodes = [...flatnodes, showMoreFlatNode('collection', topNode.level + 1, expandedParent)];
176+
flatnodes = [...flatnodes, showMoreFlatNode(`collection-${uuidv4()}`, topNode.level + 1, expandedParent)];
176177
}
177178
}
178179
}
179180
}
180181
});
181182
if (showMoreTopComNode) {
182-
flatnodes = [...flatnodes, showMoreFlatNode('community', 0, null)];
183+
flatnodes = [...flatnodes, showMoreFlatNode(`community-${uuidv4()}`, 0, null)];
183184
}
184185
return observableOf(flatnodes);
185186
}

src/app/community-list-page/community-list/community-list.component.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,19 +111,18 @@ export class CommunityListComponent implements OnInit, OnDestroy {
111111
getNextPage(node: FlatNode): void {
112112
this.loadingNode = node;
113113
if (node.parent != null) {
114-
if (node.id === 'collection') {
114+
if (node.id.startsWith('collection')) {
115115
const parentNodeInExpandedNodes = this.expandedNodes.find((node2: FlatNode) => node.parent.id === node2.id);
116116
parentNodeInExpandedNodes.currentCollectionPage++;
117117
}
118-
if (node.id === 'community') {
118+
if (node.id.startsWith('community')) {
119119
const parentNodeInExpandedNodes = this.expandedNodes.find((node2: FlatNode) => node.parent.id === node2.id);
120120
parentNodeInExpandedNodes.currentCommunityPage++;
121121
}
122-
this.dataSource.loadCommunities(this.paginationConfig, this.expandedNodes);
123122
} else {
124123
this.paginationConfig.currentPage++;
125-
this.dataSource.loadCommunities(this.paginationConfig, this.expandedNodes);
126124
}
125+
this.dataSource.loadCommunities(this.paginationConfig, this.expandedNodes);
127126
}
128127

129128
}

0 commit comments

Comments
 (0)