mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
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.
This commit is contained in:
@@ -24,6 +24,7 @@ import { FlatNode } from './flat-node.model';
|
|||||||
import { ShowMoreFlatNode } from './show-more-flat-node.model';
|
import { ShowMoreFlatNode } from './show-more-flat-node.model';
|
||||||
import { FindListOptions } from '../core/data/find-list-options.model';
|
import { FindListOptions } from '../core/data/find-list-options.model';
|
||||||
import { AppConfig, APP_CONFIG } from 'src/config/app-config.interface';
|
import { AppConfig, APP_CONFIG } from 'src/config/app-config.interface';
|
||||||
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
|
|
||||||
// Helper method to combine and flatten an array of observables of flatNode arrays
|
// Helper method to combine and flatten an array of observables of flatNode arrays
|
||||||
export const combineAndFlatten = (obsList: Observable<FlatNode[]>[]): Observable<FlatNode[]> =>
|
export const combineAndFlatten = (obsList: Observable<FlatNode[]>[]): Observable<FlatNode[]> =>
|
||||||
@@ -186,7 +187,7 @@ export class CommunityListService {
|
|||||||
return this.transformCommunity(community, level, parent, expandedNodes);
|
return this.transformCommunity(community, level, parent, expandedNodes);
|
||||||
});
|
});
|
||||||
if (currentPage < listOfPaginatedCommunities.totalPages && currentPage === listOfPaginatedCommunities.currentPage) {
|
if (currentPage < listOfPaginatedCommunities.totalPages && currentPage === listOfPaginatedCommunities.currentPage) {
|
||||||
obsList = [...obsList, observableOf([showMoreFlatNode('community', level, parent)])];
|
obsList = [...obsList, observableOf([showMoreFlatNode(`community-${uuidv4()}`, level, parent)])];
|
||||||
}
|
}
|
||||||
|
|
||||||
return combineAndFlatten(obsList);
|
return combineAndFlatten(obsList);
|
||||||
@@ -257,7 +258,7 @@ export class CommunityListService {
|
|||||||
let nodes = rd.payload.page
|
let nodes = rd.payload.page
|
||||||
.map((collection: Collection) => toFlatNode(collection, observableOf(false), level + 1, false, communityFlatNode));
|
.map((collection: Collection) => toFlatNode(collection, observableOf(false), level + 1, false, communityFlatNode));
|
||||||
if (currentCollectionPage < rd.payload.totalPages && currentCollectionPage === rd.payload.currentPage) {
|
if (currentCollectionPage < rd.payload.totalPages && currentCollectionPage === rd.payload.currentPage) {
|
||||||
nodes = [...nodes, showMoreFlatNode('collection', level + 1, communityFlatNode)];
|
nodes = [...nodes, showMoreFlatNode(`collection-${uuidv4()}`, level + 1, communityFlatNode)];
|
||||||
}
|
}
|
||||||
return nodes;
|
return nodes;
|
||||||
} else {
|
} else {
|
||||||
|
@@ -8,7 +8,7 @@
|
|||||||
<span class="fa fa-chevron-right invisible" aria-hidden="true"></span>
|
<span class="fa fa-chevron-right invisible" aria-hidden="true"></span>
|
||||||
</button>
|
</button>
|
||||||
<div class="align-middle pt-2">
|
<div class="align-middle pt-2">
|
||||||
<button *ngIf="node!==loadingNode" (click)="getNextPage(node)"
|
<button *ngIf="!(dataSource.loading$ | async)" (click)="getNextPage(node)"
|
||||||
class="btn btn-outline-primary btn-sm" role="button">
|
class="btn btn-outline-primary btn-sm" role="button">
|
||||||
<i class="fas fa-angle-down"></i> {{ 'communityList.showMore' | translate }}
|
<i class="fas fa-angle-down"></i> {{ 'communityList.showMore' | translate }}
|
||||||
</button>
|
</button>
|
||||||
|
@@ -17,6 +17,7 @@ import { By } from '@angular/platform-browser';
|
|||||||
import { isEmpty, isNotEmpty } from '../../shared/empty.util';
|
import { isEmpty, isNotEmpty } from '../../shared/empty.util';
|
||||||
import { FlatNode } from '../flat-node.model';
|
import { FlatNode } from '../flat-node.model';
|
||||||
import { RouterLinkWithHref } from '@angular/router';
|
import { RouterLinkWithHref } from '@angular/router';
|
||||||
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
|
|
||||||
describe('CommunityListComponent', () => {
|
describe('CommunityListComponent', () => {
|
||||||
let component: CommunityListComponent;
|
let component: CommunityListComponent;
|
||||||
@@ -138,7 +139,7 @@ describe('CommunityListComponent', () => {
|
|||||||
}
|
}
|
||||||
if (expandedNodes === null || isEmpty(expandedNodes)) {
|
if (expandedNodes === null || isEmpty(expandedNodes)) {
|
||||||
if (showMoreTopComNode) {
|
if (showMoreTopComNode) {
|
||||||
return observableOf([...mockTopFlatnodesUnexpanded.slice(0, endPageIndex), showMoreFlatNode('community', 0, null)]);
|
return observableOf([...mockTopFlatnodesUnexpanded.slice(0, endPageIndex), showMoreFlatNode(`community-${uuidv4()}`, 0, null)]);
|
||||||
} else {
|
} else {
|
||||||
return observableOf(mockTopFlatnodesUnexpanded.slice(0, endPageIndex));
|
return observableOf(mockTopFlatnodesUnexpanded.slice(0, endPageIndex));
|
||||||
}
|
}
|
||||||
@@ -165,21 +166,21 @@ describe('CommunityListComponent', () => {
|
|||||||
const endSubComIndex = this.pageSize * expandedParent.currentCommunityPage;
|
const endSubComIndex = this.pageSize * expandedParent.currentCommunityPage;
|
||||||
flatnodes = [...flatnodes, ...subComFlatnodes.slice(0, endSubComIndex)];
|
flatnodes = [...flatnodes, ...subComFlatnodes.slice(0, endSubComIndex)];
|
||||||
if (subComFlatnodes.length > endSubComIndex) {
|
if (subComFlatnodes.length > endSubComIndex) {
|
||||||
flatnodes = [...flatnodes, showMoreFlatNode('community', topNode.level + 1, expandedParent)];
|
flatnodes = [...flatnodes, showMoreFlatNode(`community-${uuidv4()}`, topNode.level + 1, expandedParent)];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isNotEmpty(collFlatnodes)) {
|
if (isNotEmpty(collFlatnodes)) {
|
||||||
const endColIndex = this.pageSize * expandedParent.currentCollectionPage;
|
const endColIndex = this.pageSize * expandedParent.currentCollectionPage;
|
||||||
flatnodes = [...flatnodes, ...collFlatnodes.slice(0, endColIndex)];
|
flatnodes = [...flatnodes, ...collFlatnodes.slice(0, endColIndex)];
|
||||||
if (collFlatnodes.length > endColIndex) {
|
if (collFlatnodes.length > endColIndex) {
|
||||||
flatnodes = [...flatnodes, showMoreFlatNode('collection', topNode.level + 1, expandedParent)];
|
flatnodes = [...flatnodes, showMoreFlatNode(`collection-${uuidv4()}`, topNode.level + 1, expandedParent)];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (showMoreTopComNode) {
|
if (showMoreTopComNode) {
|
||||||
flatnodes = [...flatnodes, showMoreFlatNode('community', 0, null)];
|
flatnodes = [...flatnodes, showMoreFlatNode(`community-${uuidv4()}`, 0, null)];
|
||||||
}
|
}
|
||||||
return observableOf(flatnodes);
|
return observableOf(flatnodes);
|
||||||
}
|
}
|
||||||
|
@@ -111,19 +111,18 @@ export class CommunityListComponent implements OnInit, OnDestroy {
|
|||||||
getNextPage(node: FlatNode): void {
|
getNextPage(node: FlatNode): void {
|
||||||
this.loadingNode = node;
|
this.loadingNode = node;
|
||||||
if (node.parent != null) {
|
if (node.parent != null) {
|
||||||
if (node.id === 'collection') {
|
if (node.id.startsWith('collection')) {
|
||||||
const parentNodeInExpandedNodes = this.expandedNodes.find((node2: FlatNode) => node.parent.id === node2.id);
|
const parentNodeInExpandedNodes = this.expandedNodes.find((node2: FlatNode) => node.parent.id === node2.id);
|
||||||
parentNodeInExpandedNodes.currentCollectionPage++;
|
parentNodeInExpandedNodes.currentCollectionPage++;
|
||||||
}
|
}
|
||||||
if (node.id === 'community') {
|
if (node.id.startsWith('community')) {
|
||||||
const parentNodeInExpandedNodes = this.expandedNodes.find((node2: FlatNode) => node.parent.id === node2.id);
|
const parentNodeInExpandedNodes = this.expandedNodes.find((node2: FlatNode) => node.parent.id === node2.id);
|
||||||
parentNodeInExpandedNodes.currentCommunityPage++;
|
parentNodeInExpandedNodes.currentCommunityPage++;
|
||||||
}
|
}
|
||||||
this.dataSource.loadCommunities(this.paginationConfig, this.expandedNodes);
|
|
||||||
} else {
|
} else {
|
||||||
this.paginationConfig.currentPage++;
|
this.paginationConfig.currentPage++;
|
||||||
this.dataSource.loadCommunities(this.paginationConfig, this.expandedNodes);
|
|
||||||
}
|
}
|
||||||
|
this.dataSource.loadCommunities(this.paginationConfig, this.expandedNodes);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user