[CSTPER-66] moved refreshCache function to common ComColDataService, tests have been moved accordingly.

Used HalEndpointService to discover communities search top endpoint
This commit is contained in:
Corrado Lombardi
2020-11-17 09:29:01 +01:00
parent 9658da4fc0
commit c40f31279f
6 changed files with 125 additions and 191 deletions

View File

@@ -15,6 +15,7 @@ import {
} from '../../../core/shared/operators';
import {Community} from '../../../core/shared/community.model';
import {Collection} from '../../../core/shared/collection.model';
import {ComColDataService} from '../../../core/data/comcol-data.service';
/**
* Component representing the delete page for communities and collections
@@ -34,7 +35,7 @@ export class DeleteComColPageComponent<TDomain extends DSpaceObject> implements
public dsoRD$: Observable<RemoteData<TDomain>>;
public constructor(
protected dsoDataService: DataService<TDomain>,
protected dsoDataService: ComColDataService<TDomain>,
protected router: Router,
protected route: ActivatedRoute,
protected notifications: NotificationsService,
@@ -58,7 +59,7 @@ export class DeleteComColPageComponent<TDomain extends DSpaceObject> implements
if (response.isSuccessful) {
const successMessage = this.translate.instant((dso as any).type + '.delete.notification.success');
this.notifications.success(successMessage)
this.refreshCache(dso);
this.dsoDataService.refreshCache(dso);
} else {
const errorMessage = this.translate.instant((dso as any).type + '.delete.notification.fail');
this.notifications.error(errorMessage)
@@ -74,23 +75,4 @@ export class DeleteComColPageComponent<TDomain extends DSpaceObject> implements
onCancel(dso: TDomain) {
this.router.navigate([this.frontendURL + '/' + dso.uuid + '/edit']);
}
private refreshCache(dso: TDomain) {
const parentCommunityUrl = this.parentCommunityUrl(dso as any);
if (!hasValue(parentCommunityUrl)) {
return;
}
this.dsoDataService.findByHref(parentCommunityUrl).pipe(
getSucceededOrNoContentResponse(),
take(1),
).subscribe((rd: RemoteData<TDomain>) => {
const href = rd.hasSucceeded && !isEmpty(rd.payload.id) ? rd.payload.id : 'communities/search/top';
this.requestService.removeByHrefSubstring(href)
});
}
private parentCommunityUrl(dso: Collection | Community): string {
const parentCommunity = dso._links.parentCommunity;
return isNotEmpty(parentCommunity) ? parentCommunity.href : null;
}
}