Skip to content

Commit ab31183

Browse files
committed
[DSC-1700] fix(entity-dropdown): add support for importing from external sources
1 parent 5a58505 commit ab31183

4 files changed

Lines changed: 40 additions & 13 deletions

File tree

cypress/e2e/my-dspace.cy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ describe('My DSpace page', () => {
119119
// Open the New Import dropdown
120120
cy.get('button[data-test="import-dropdown"]').click();
121121
// Click on the "Item" type in that dropdown
122-
cy.get('#importControlsDropdownMenu button[title="Equipment"]').click();
122+
cy.get('#importControlsDropdownMenu button[title="Funding"]').click();
123123

124124
// New URL should include /import-external, as we've moved to the import page
125125
cy.url().should('include', '/import-external');

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@
2121
class="dropdown-menu p-0"
2222
id="importControlsDropdownMenu"
2323
aria-labelledby="dropdownImport">
24-
<ds-entity-dropdown [isSubmission]="false" (selectionChange)="openPage($event)"></ds-entity-dropdown>
24+
<ds-entity-dropdown [isSubmission]="false" [isImportFromExternalSource]="true" (selectionChange)="openPage($event)"></ds-entity-dropdown>
2525
</div>
2626
</div>

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,24 @@ describe('EntityDropdownComponent', () => {
136136
expect((component as any).entityTypeService.getAllAuthorizedRelationshipType).toHaveBeenCalled();
137137
});
138138

139+
it('should init component with entities list when isImportFromExternalSource is true', () => {
140+
component.isSubmission = false;
141+
component.isImportFromExternalSource = true;
142+
spyOn(component.subs, 'push');
143+
spyOn(component, 'resetPagination');
144+
spyOn(component, 'populateEntityList').and.callThrough();
145+
146+
scheduler.schedule(() => fixture.detectChanges());
147+
scheduler.flush();
148+
const elements = fixture.debugElement.queryAll(By.css('.entity-item'));
149+
150+
expect(elements.length).toEqual(5);
151+
expect(component.subs.push).toHaveBeenCalled();
152+
expect(component.resetPagination).toHaveBeenCalled();
153+
expect(component.populateEntityList).toHaveBeenCalled();
154+
expect((component as any).entityTypeService.getAllAuthorizedRelationshipTypeImport).toHaveBeenCalled();
155+
});
156+
139157
it('should trigger onSelect method when select a new entity from list', () => {
140158
scheduler.schedule(() => fixture.detectChanges());
141159
scheduler.flush();

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

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ export class EntityDropdownComponent implements OnInit, OnDestroy {
5959
*/
6060
@Input() isSubmission: boolean;
6161

62+
/**
63+
* TRUE if the main operation is "Import metadata from an external source", FALSE otherwise.
64+
* Used to determine which list type to populate.
65+
*/
66+
@Input() isImportFromExternalSource: boolean;
67+
6268
/**
6369
* The entity to output to the parent component
6470
*/
@@ -161,23 +167,26 @@ export class EntityDropdownComponent implements OnInit, OnDestroy {
161167
*/
162168
public populateEntityList(page: number) {
163169
this.isLoadingList.next(true);
164-
let searchListEntity$;
165-
if (this.isSubmission) {
170+
let searchListEntity$: Observable<RemoteData<PaginatedList<ItemType>>>;
171+
if (this.isSubmission || this.isImportFromExternalSource) {
166172
// Set the pagination info
167173
const findOptions: FindListOptions = {
168174
elementsPerPage: 10,
169175
currentPage: page
170176
};
171-
searchListEntity$ =
172-
this.entityTypeService.getAllAuthorizedRelationshipType(findOptions)
173-
.pipe(
174-
getFirstSucceededRemoteWithNotEmptyData(),
175-
tap(entityType => {
176-
if ((this.searchListEntity.length + findOptions.elementsPerPage) >= entityType.payload.totalElements) {
177-
this.hasNextPage = false;
178-
}
177+
178+
searchListEntity$ = this.isSubmission ?
179+
this.entityTypeService.getAllAuthorizedRelationshipType(findOptions) :
180+
this.entityTypeService.getAllAuthorizedRelationshipTypeImport(findOptions);
181+
182+
searchListEntity$ = searchListEntity$.pipe(
183+
getFirstSucceededRemoteWithNotEmptyData(),
184+
tap(entityType => {
185+
if ((this.searchListEntity.length + findOptions.elementsPerPage) >= entityType.payload.totalElements) {
186+
this.hasNextPage = false;
187+
}
179188
})
180-
);
189+
);
181190
} else {
182191
searchListEntity$ =
183192
this.itemExportFormatService.byEntityTypeAndMolteplicity(null, ItemExportFormatMolteplicity.MULTIPLE)

0 commit comments

Comments
 (0)