Skip to content

Commit 96d9631

Browse files
atarix83vins01-4science
authored andcommitted
Merged in task/dspace-cris-2024_02_x/DSC-1700 (pull request DSpace#4131)
[DSC-1700] fix(entity-dropdown): add support for importing from external sources Approved-by: Vincenzo Mecca
2 parents d293c75 + 992f149 commit 96d9631

File tree

4 files changed

+41
-14
lines changed

4 files changed

+41
-14
lines changed

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
@@ -173,6 +173,24 @@ describe('EntityDropdownComponent', () => {
173173
expect((component as any).entityTypeService.getAllAuthorizedRelationshipType).toHaveBeenCalled();
174174
});
175175

176+
it('should init component with entities list when isImportFromExternalSource is true', () => {
177+
component.isSubmission = false;
178+
component.isImportFromExternalSource = true;
179+
spyOn(component.subs, 'push');
180+
spyOn(component, 'resetPagination');
181+
spyOn(component, 'populateEntityList').and.callThrough();
182+
183+
scheduler.schedule(() => fixture.detectChanges());
184+
scheduler.flush();
185+
const elements = fixture.debugElement.queryAll(By.css('.entity-item'));
186+
187+
expect(elements.length).toEqual(5);
188+
expect(component.subs.push).toHaveBeenCalled();
189+
expect(component.resetPagination).toHaveBeenCalled();
190+
expect(component.populateEntityList).toHaveBeenCalled();
191+
expect((component as any).entityTypeService.getAllAuthorizedRelationshipTypeImport).toHaveBeenCalled();
192+
});
193+
176194
it('should trigger onSelect method when select a new entity from list', () => {
177195
scheduler.schedule(() => fixture.detectChanges());
178196
scheduler.flush();

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

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ export class EntityDropdownComponent implements OnInit, OnDestroy {
9090
*/
9191
@Input() isSubmission: boolean;
9292

93+
/**
94+
* TRUE if the main operation is "Import metadata from an external source", FALSE otherwise.
95+
* Used to determine which list type to populate.
96+
*/
97+
@Input() isImportFromExternalSource: boolean;
98+
9399
/**
94100
* The entity to output to the parent component
95101
*/
@@ -192,23 +198,26 @@ export class EntityDropdownComponent implements OnInit, OnDestroy {
192198
*/
193199
public populateEntityList(page: number) {
194200
this.isLoadingList.next(true);
195-
let searchListEntity$;
196-
if (this.isSubmission) {
201+
let searchListEntity$: Observable<RemoteData<PaginatedList<ItemType>>>;
202+
if (this.isSubmission || this.isImportFromExternalSource) {
197203
// Set the pagination info
198204
const findOptions: FindListOptions = {
199205
elementsPerPage: 10,
200206
currentPage: page,
201207
};
202-
searchListEntity$ =
203-
this.entityTypeService.getAllAuthorizedRelationshipType(findOptions)
204-
.pipe(
205-
getFirstSucceededRemoteWithNotEmptyData(),
206-
tap(entityType => {
207-
if ((this.searchListEntity.length + findOptions.elementsPerPage) >= entityType.payload.totalElements) {
208-
this.hasNextPage = false;
209-
}
210-
}),
211-
);
208+
209+
searchListEntity$ = this.isSubmission ?
210+
this.entityTypeService.getAllAuthorizedRelationshipType(findOptions) :
211+
this.entityTypeService.getAllAuthorizedRelationshipTypeImport(findOptions);
212+
213+
searchListEntity$ = searchListEntity$.pipe(
214+
getFirstSucceededRemoteWithNotEmptyData(),
215+
tap(entityType => {
216+
if ((this.searchListEntity.length + findOptions.elementsPerPage) >= entityType.payload.totalElements) {
217+
this.hasNextPage = false;
218+
}
219+
}),
220+
);
212221
} else {
213222
searchListEntity$ =
214223
this.itemExportFormatService.byEntityTypeAndMolteplicity(null, ItemExportFormatMolteplicity.MULTIPLE)

0 commit comments

Comments
 (0)