Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/app/modules/library/library/library.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export abstract class LibraryComponent implements OnInit {
return project;
})
.filter((project) => project.visible)
.sort((a, b) => b.id - a.id);
.sort(this.sortUnits);
this.emitNumberOfProjectsVisible(this.countVisibleProjects(this.filteredProjects));
this.pageIndex = 0;
this.setPagination();
Expand All @@ -83,4 +83,18 @@ export abstract class LibraryComponent implements OnInit {
protected countVisibleProjects(projects: LibraryProject[]): number {
return projects.filter((project) => project.visible).length;
}

// Sort units from newest -> oldest in each of these categories
// WISE Tested (Platform) -> WISE Tested (Other) -> Community (Platform) -> Community (Other)
private sortUnits(a: LibraryProject, b: LibraryProject): number {
const unitTypes = [
'wiseTestedPlatform',
'wiseTestedOther',
'communityBuiltPlatform',
'communityBuiltOther'
];
const unitTypeIndexA = unitTypes.indexOf(a.metadata.publicUnitType + a.metadata.unitType);
const unitTypeIndexB = unitTypes.indexOf(b.metadata.publicUnitType + b.metadata.unitType);
return unitTypeIndexA === unitTypeIndexB ? b.id - a.id : unitTypeIndexA - unitTypeIndexB;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ describe('PublicLibraryComponent', () => {
providers: [
MockProvider(LibraryService, {
communityLibraryProjectsSource$: of([
{ id: 1, name: 'P1' },
{ id: 2, name: 'P2' }
{ id: 1, metadata: { publicUnitType: 'wiseTested', unitType: 'Platform' } },
{ id: 2, metadata: { publicUnitType: 'wiseTested', unitType: 'Platform' } }
] as LibraryProject[]),
officialLibraryProjectsSource$: of([
{ id: 1, name: 'P1' },
{ id: 3, name: 'P3' }
{ id: 1, metadata: { publicUnitType: 'wiseTested', unitType: 'Platform' } },
{ id: 3, metadata: { publicUnitType: 'communityBuilt', unitType: 'Platform' } }
] as LibraryProject[])
}),
ProjectFilterValues
Expand All @@ -33,7 +33,7 @@ describe('PublicLibraryComponent', () => {
fixture.detectChanges();
});

it('should remove duplicate units', () => {
expect(component['projects'].length).toBe(3);
it('should remove duplicates and order units', () => {
expect(component['filteredProjects'].map((p) => p.id)).toEqual([2, 1, 3]);
});
});
Loading