From dee06c69a6e912324debdcb5c8fa4cf30983de33 Mon Sep 17 00:00:00 2001 From: Kristof De Langhe Date: Mon, 6 Jan 2020 12:57:00 +0100 Subject: [PATCH] 64503: Collection harvester settings refresh cache after submitting changes --- .../collection-source.component.spec.ts | 9 +++++++-- .../collection-source.component.ts | 13 ++++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/app/+collection-page/edit-collection-page/collection-source/collection-source.component.spec.ts b/src/app/+collection-page/edit-collection-page/collection-source/collection-source.component.spec.ts index a44311a1c7..11ec9b1f6a 100644 --- a/src/app/+collection-page/edit-collection-page/collection-source/collection-source.component.spec.ts +++ b/src/app/+collection-page/edit-collection-page/collection-source/collection-source.component.spec.ts @@ -20,6 +20,7 @@ import { By } from '@angular/platform-browser'; import { Collection } from '../../../core/shared/collection.model'; import { RemoteData } from '../../../core/data/remote-data'; import { CollectionDataService } from '../../../core/data/collection-data.service'; +import { RequestService } from '../../../core/data/request.service'; const infoNotification: INotification = new Notification('id', NotificationType.Info, 'info'); const warningNotification: INotification = new Notification('id', NotificationType.Warning, 'warning'); @@ -36,6 +37,7 @@ let formService: DynamicFormService; let router: any; let collection: Collection; let collectionService: CollectionDataService; +let requestService: RequestService; describe('CollectionSourceComponent', () => { let comp: CollectionSourceComponent; @@ -111,8 +113,10 @@ describe('CollectionSourceComponent', () => { }); collectionService = jasmine.createSpyObj('collectionService', { getContentSource: observableOf(contentSource), - updateContentSource: observableOf(contentSource) + updateContentSource: observableOf(contentSource), + getHarvesterEndpoint: observableOf('harvester-endpoint') }); + requestService = jasmine.createSpyObj('requestService', ['removeByHrefSubstring']); TestBed.configureTestingModule({ imports: [TranslateModule.forRoot(), RouterTestingModule], @@ -125,7 +129,8 @@ describe('CollectionSourceComponent', () => { { provide: ActivatedRoute, useValue: { parent: { data: observableOf({ dso: new RemoteData(false, false, true, null, collection) }) } } }, { provide: Router, useValue: router }, { provide: GLOBAL_CONFIG, useValue: { collection: { edit: { undoTimeout: 10 } } } as any }, - { provide: CollectionDataService, useValue: collectionService } + { provide: CollectionDataService, useValue: collectionService }, + { provide: RequestService, useValue: requestService } ], schemas: [NO_ERRORS_SCHEMA] }).compileComponents(); diff --git a/src/app/+collection-page/edit-collection-page/collection-source/collection-source.component.ts b/src/app/+collection-page/edit-collection-page/collection-source/collection-source.component.ts index 8ae8efdfe5..5fcc740663 100644 --- a/src/app/+collection-page/edit-collection-page/collection-source/collection-source.component.ts +++ b/src/app/+collection-page/edit-collection-page/collection-source/collection-source.component.ts @@ -31,6 +31,7 @@ import { CollectionDataService } from '../../../core/data/collection-data.servic import { getSucceededRemoteData } from '../../../core/shared/operators'; import { MetadataConfig } from '../../../core/shared/metadata-config.model'; import { INotification } from '../../../shared/notifications/models/notification.model'; +import { RequestService } from '../../../core/data/request.service'; /** * Component for managing the content source of the collection @@ -236,7 +237,8 @@ export class CollectionSourceComponent extends AbstractTrackableComponent implem protected route: ActivatedRoute, protected router: Router, @Inject(GLOBAL_CONFIG) protected EnvConfig: GlobalConfig, - protected collectionService: CollectionDataService) { + protected collectionService: CollectionDataService, + protected requestService: RequestService) { super(objectUpdatesService, notificationsService, translate); } @@ -373,6 +375,15 @@ export class CollectionSourceComponent extends AbstractTrackableComponent implem * Submit the edited Content Source to the REST API, re-initialize the field update and display a notification */ onSubmit() { + // Remove cached harvester request to allow for latest harvester to be displayed when switching tabs + this.collectionRD$.pipe( + getSucceededRemoteData(), + map((col) => col.payload.uuid), + switchMap((uuid) => this.collectionService.getHarvesterEndpoint(uuid)), + take(1) + ).subscribe((endpoint) => this.requestService.removeByHrefSubstring(endpoint)); + + // Update harvester this.collectionRD$.pipe( getSucceededRemoteData(), map((col) => col.payload.uuid),