Skip to content

Commit 9503390

Browse files
alisaismailatiSimone-Ramundi
authored andcommitted
[DSC-1932] Porting of "CST-16493"
1 parent dd06969 commit 9503390

4 files changed

Lines changed: 45 additions & 5 deletions

File tree

src/app/shared/entity-dropdown/entity-dropdown.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
<button class="dropdown-item disabled" *ngIf="searchListEntity?.length == 0 && !(isLoadingList | async)">
1313
{{'submission.sections.general.no-entity' | translate}}
1414
</button>
15-
<button *ngFor="let listItem of searchListEntity"
15+
<button *ngFor="let listItem of searchListEntity | dsSort: 'label'"
1616
class="dropdown-item entity-item"
1717
title="{{ listItem.label }}"
1818
(click)="onSelect(listItem)">
1919
<ul class="list-unstyled mb-0">
20-
<li class="list-item text-truncate text-primary font-weight-bold">{{ listItem.label.toLowerCase() + '.listelement.badge' | translate }}</li>
20+
<li class="list-item text-truncate text-primary font-weight-bold">{{ listItem.label }}</li>
2121
</ul>
2222
</button>
2323
<button class="dropdown-item disabled" *ngIf="(isLoadingList | async)" >

src/app/shared/entity-dropdown/entity-dropdown.component.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
} from '../../core/itemexportformat/item-export-format.service';
2424
import { createSuccessfulRemoteDataObject } from '../remote-data.utils';
2525
import { FindListOptions } from '../../core/data/find-list-options.model';
26+
import { TranslateService } from '@ngx-translate/core';
2627

2728
@Component({
2829
selector: 'ds-entity-dropdown',
@@ -91,12 +92,14 @@ export class EntityDropdownComponent implements OnInit, OnDestroy {
9192
* @param {EntityTypeDataService} entityTypeService
9293
* @param {ItemExportFormatService} itemExportFormatService
9394
* @param {ElementRef} el
95+
* @param {TranslateService} translate
9496
*/
9597
constructor(
9698
private changeDetectorRef: ChangeDetectorRef,
9799
private entityTypeService: EntityTypeDataService,
98100
private itemExportFormatService: ItemExportFormatService,
99-
private el: ElementRef
101+
private el: ElementRef,
102+
private translate: TranslateService
100103
) { }
101104

102105
/**
@@ -194,12 +197,21 @@ export class EntityDropdownComponent implements OnInit, OnDestroy {
194197
}
195198
this.searchListEntity$ = searchListEntity$.pipe(
196199
switchMap((entityType: RemoteData<PaginatedList<ItemType>>) => entityType.payload.page),
200+
map((item: ItemType) => {
201+
return {
202+
...item,
203+
label: this.translate.instant(`${item.label?.toLowerCase()}.listelement.badge`)
204+
};
205+
}
206+
),
197207
reduce((acc: any, value: any) => [...acc, value], []),
198208
startWith([])
199209
);
200210
this.subs.push(
201211
this.searchListEntity$.subscribe({
202-
next: (result: ItemType[]) => { this.searchListEntity.push(...result); },
212+
next: (result: ItemType[]) => {
213+
this.searchListEntity = [...this.searchListEntity, ...result];
214+
},
203215
complete: () => { this.hideShowLoader(false); this.changeDetectorRef.detectChanges(); }
204216
})
205217
);

src/app/shared/shared.module.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ import { MetadataLinkViewPopoverComponent } from './metadata-link-view/metadata-
358358
import { MetadataLinkViewAvatarPopoverComponent } from './metadata-link-view/metadata-link-view-avatar-popover/metadata-link-view-avatar-popover.component';
359359
import { MetadataLinkViewOrcidComponent } from './metadata-link-view/metadata-link-view-orcid/metadata-link-view-orcid.component';
360360
import {StickyPopoverDirective} from './metadata-link-view/sticky-popover.directive';
361+
import { SortPipe } from './utils/sort.pipe';
361362

362363
const MODULES = [
363364
CommonModule,
@@ -404,7 +405,8 @@ const PIPES = [
404405
ConsolePipe,
405406
ObjNgFor,
406407
BrowserOnlyPipe,
407-
ShortNumberPipe
408+
ShortNumberPipe,
409+
SortPipe,
408410
];
409411

410412
const COMPONENTS = [

src/app/shared/utils/sort.pipe.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { Pipe, PipeTransform } from '@angular/core';
2+
import orderBy from 'lodash/orderBy';
3+
4+
@Pipe({
5+
name: 'dsSort'
6+
})
7+
export class SortPipe implements PipeTransform {
8+
9+
transform(value: any[], column: string = '', order: 'asc' | 'desc' = 'asc'): any[] {
10+
if (!value || !order) {
11+
return value;
12+
}
13+
if (!column || column === '') {
14+
if (order === 'asc') {
15+
return value.sort();
16+
} else {
17+
return value.sort().reverse();
18+
}
19+
}
20+
if (value.length <= 1) {
21+
return value;
22+
}
23+
24+
return orderBy(value, [column], [order]);
25+
}
26+
}

0 commit comments

Comments
 (0)