Skip to content

Commit 03d4de2

Browse files
fix(external-import): The import was showing up null input-sources in the live-import page.
Refactor EntityDropdownComponent to streamline service usage and improve pagination handling ref: DSC-1700, DSC-2748
1 parent 06be295 commit 03d4de2

File tree

3 files changed

+40
-55
lines changed

3 files changed

+40
-55
lines changed

src/app/my-dspace-page/my-dspace-new-submission/my-dspace-new-external-dropdown/my-dspace-new-external-dropdown.component.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
@if ((moreThanOne$ | async) !== true) {
1+
@let moreThanOne = moreThanOne$ | async;
2+
@if (moreThanOne !== true) {
23
<div class="add">
34
<button class="btn btn-lg btn-outline-primary mt-1 ms-2"
45
[attr.aria-label]="'mydspace.new-submission-external' | translate" [dsBtnDisabled]="(initialized$ | async) !== true"
@@ -8,7 +9,7 @@
89
</button>
910
</div>
1011
}
11-
@if ((moreThanOne$ | async)) {
12+
@if (moreThanOne === true) {
1213
<div class="add w-100" display="dynamic" placement="bottom-right"
1314
ngbDropdown
1415
>

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

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@ import {
1717
} from '@ngx-translate/core';
1818
import { getTestScheduler } from 'jasmine-marbles';
1919
import { InfiniteScrollDirective } from 'ngx-infinite-scroll';
20-
import { of } from 'rxjs';
2120
import { TestScheduler } from 'rxjs/testing';
2221

2322
import { EntityTypeDataService } from '../../core/data/entity-type-data.service';
24-
import { ItemExportFormatService } from '../../core/itemexportformat/item-export-format.service';
2523
import {
2624
ItemExportFormat,
2725
ItemExportFormatMap,
@@ -110,10 +108,6 @@ describe('EntityDropdownComponent', () => {
110108
getAllAuthorizedRelationshipTypeImport: jasmine.createSpy('getAllAuthorizedRelationshipTypeImport'),
111109
});
112110

113-
const itemExportFormatServiceMock: any = jasmine.createSpyObj('ItemExportFormatService', {
114-
byEntityTypeAndMolteplicity: jasmine.createSpy('byEntityTypeAndMolteplicity'),
115-
});
116-
117111
const translateServiceMock: any = {
118112
instant(name) {
119113
return 'Statistics';
@@ -136,7 +130,6 @@ describe('EntityDropdownComponent', () => {
136130
],
137131
providers: [
138132
{ provide: EntityTypeDataService, useValue: entityTypeServiceMock },
139-
{ provide: ItemExportFormatService, useValue: itemExportFormatServiceMock },
140133
{ provide: TranslateService, useValue: translateServiceMock },
141134
ChangeDetectorRef,
142135
],
@@ -152,7 +145,6 @@ describe('EntityDropdownComponent', () => {
152145
componentAsAny = fixture.componentInstance;
153146
componentAsAny.entityTypeService.getAllAuthorizedRelationshipType.and.returnValue(paginatedEntitiesRD$);
154147
componentAsAny.entityTypeService.getAllAuthorizedRelationshipTypeImport.and.returnValue(paginatedEntitiesRD$);
155-
componentAsAny.itemExportFormatService.byEntityTypeAndMolteplicity.and.returnValue(of(entityFormatList));
156148
component.isSubmission = true;
157149
});
158150

@@ -210,12 +202,4 @@ describe('EntityDropdownComponent', () => {
210202
expect(component.searchListEntity).toEqual([]);
211203
});
212204

213-
it('should invoke the method byEntityTypeAndMolteplicity of EntityTypeService when isSubmission is false', () => {
214-
component.isSubmission = false;
215-
216-
scheduler.schedule(() => fixture.detectChanges());
217-
scheduler.flush();
218-
219-
expect((component as any).itemExportFormatService.byEntityTypeAndMolteplicity).toHaveBeenCalled();
220-
});
221205
});

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

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import {
2525
reduce,
2626
startWith,
2727
switchMap,
28-
take,
2928
tap,
3029
} from 'rxjs/operators';
3130
import { SortPipe } from 'src/app/shared/utils/sort.pipe';
@@ -37,14 +36,12 @@ import {
3736
PaginatedList,
3837
} from '../../core/data/paginated-list.model';
3938
import { RemoteData } from '../../core/data/remote-data';
40-
import {
41-
ItemExportFormatMolteplicity,
42-
ItemExportFormatService,
43-
} from '../../core/itemexportformat/item-export-format.service';
39+
import { ItemExportFormatService } from '../../core/itemexportformat/item-export-format.service';
4440
import { ItemType } from '../../core/shared/item-relationships/item-type.model';
4541
import { getFirstSucceededRemoteWithNotEmptyData } from '../../core/shared/operators';
4642
import {
4743
hasValue,
44+
isEmpty,
4845
isNotNull,
4946
} from '../empty.util';
5047
import { ThemedLoadingComponent } from '../loading/themed-loading.component';
@@ -87,7 +84,8 @@ export class EntityDropdownComponent implements OnInit, OnDestroy {
8784
public searchListEntity: ItemType[] = [];
8885

8986
/**
90-
* TRUE if the parent operation is a 'new submission' operation, FALSE otherwise (eg.: is an 'Import metadata from an external source' operation).
87+
* TRUE if the parent operation is a 'new submission' operation, FALSE otherwise (eg.: is an 'Import metadata from an external source'
88+
* operation).
9189
*/
9290
@Input() isSubmission: boolean;
9391

@@ -129,8 +127,6 @@ export class EntityDropdownComponent implements OnInit, OnDestroy {
129127
constructor(
130128
private changeDetectorRef: ChangeDetectorRef,
131129
private entityTypeService: EntityTypeDataService,
132-
private itemExportFormatService: ItemExportFormatService,
133-
private el: ElementRef,
134130
private translate: TranslateService,
135131
) { }
136132

@@ -193,41 +189,24 @@ export class EntityDropdownComponent implements OnInit, OnDestroy {
193189
*/
194190
public populateEntityList(page: number) {
195191
this.isLoadingList.next(true);
196-
let searchListEntity$;
192+
let searchListEntity$: Observable<RemoteData<PaginatedList<ItemType>>>;
193+
// Set the pagination info
194+
const findOptions: FindListOptions = {
195+
elementsPerPage: 10,
196+
currentPage: page,
197+
};
197198
if (this.isSubmission) {
198-
// Set the pagination info
199-
const findOptions: FindListOptions = {
200-
elementsPerPage: 10,
201-
currentPage: page,
202-
};
203199
searchListEntity$ =
204-
this.entityTypeService.getAllAuthorizedRelationshipType(findOptions)
205-
.pipe(
206-
getFirstSucceededRemoteWithNotEmptyData(),
207-
tap(entityType => {
208-
if ((this.searchListEntity.length + findOptions.elementsPerPage) >= entityType.payload.totalElements) {
209-
this.hasNextPage = false;
210-
}
211-
}),
212-
);
200+
this.entityTypeService.getAllAuthorizedRelationshipType(findOptions);
213201
} else {
214202
searchListEntity$ =
215-
this.itemExportFormatService.byEntityTypeAndMolteplicity(null, ItemExportFormatMolteplicity.MULTIPLE)
216-
.pipe(
217-
take(1),
218-
map((formatTypes: any) => {
219-
const entityList: ItemType[] = Object.keys(formatTypes)
220-
.filter((entityType: string) => isNotNull(entityType) && entityType !== 'null')
221-
.map((entityType: string) => ({
222-
id: entityType,
223-
label: entityType,
224-
} as any));
225-
return createSuccessfulRemoteDataObject(buildPaginatedList(null, entityList));
226-
}),
227-
tap(() => this.hasNextPage = false),
228-
);
203+
this.entityTypeService.getAllAuthorizedRelationshipTypeImport(findOptions);
229204
}
205+
230206
this.searchListEntity$ = searchListEntity$.pipe(
207+
getFirstSucceededRemoteWithNotEmptyData(),
208+
map((formatTypes: RemoteData<PaginatedList<ItemType>>) =>this.parseItemTypesResponse(formatTypes)),
209+
tap((entityTypes) => this.hasNextPages(findOptions, entityTypes)),
231210
switchMap((entityType: RemoteData<PaginatedList<ItemType>>) => entityType.payload.page),
232211
map((item: ItemType) => {
233212
return {
@@ -239,6 +218,7 @@ export class EntityDropdownComponent implements OnInit, OnDestroy {
239218
reduce((acc: any, value: any) => [...acc, value], []),
240219
startWith([]),
241220
);
221+
242222
this.subs.push(
243223
this.searchListEntity$.subscribe({
244224
next: (result: ItemType[]) => {
@@ -249,6 +229,26 @@ export class EntityDropdownComponent implements OnInit, OnDestroy {
249229
);
250230
}
251231

232+
private parseItemTypesResponse(formatTypes: RemoteData<PaginatedList<ItemType>>) {
233+
if (formatTypes.statusCode !== 200) {
234+
return createSuccessfulRemoteDataObject(buildPaginatedList(null, []));
235+
}
236+
const entityList: ItemType[] = (formatTypes?.payload?.page || [])
237+
.filter(itemType => isNotNull(itemType?.id));
238+
return createSuccessfulRemoteDataObject(buildPaginatedList(null, entityList));
239+
}
240+
241+
private hasNextPages<A>(findOptions: FindListOptions, entityType: RemoteData<PaginatedList<A>>) {
242+
if (
243+
findOptions.elementsPerPage > 0 &&
244+
(isEmpty(entityType?.payload?.totalElements) || entityType.payload.totalElements < findOptions.elementsPerPage)
245+
) {
246+
this.hasNextPage = false;
247+
} else {
248+
this.hasNextPage = true;
249+
}
250+
}
251+
252252
/**
253253
* Reset pagination values
254254
*/

0 commit comments

Comments
 (0)