[DSC-1111] [DURACOM-235] Fixes item cache refresh in comcol-form

This commit is contained in:
Vincenzo Mecca
2024-03-01 18:49:18 +01:00
parent a059c31bad
commit 794eb6bc59
3 changed files with 24 additions and 15 deletions

View File

@@ -11,7 +11,11 @@
</div> </div>
<div class="col-4 d-inline-block"> <div class="col-4 d-inline-block">
<div *ngIf="logo" class="float-right"> <div *ngIf="logo" class="float-right">
<button (click)="confirmLogoDeleteWithModal()" data-test="open-delete-modal-button" class="btn btn-danger" type="button">{{'community.edit.logo.delete.title' | translate}}</button> <button
(click)="confirmLogoDeleteWithModal()"
class="btn btn-danger"
type="button">{{ 'community.edit.logo.delete.title' | translate }}
</button>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -3,7 +3,7 @@ import { UntypedFormGroup } from '@angular/forms';
import { DynamicFormControlModel, DynamicFormService, DynamicInputModel } from '@ng-dynamic-forms/core'; import { DynamicFormControlModel, DynamicFormService, DynamicInputModel } from '@ng-dynamic-forms/core';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import { FileUploader } from 'ng2-file-upload'; import { FileUploader } from 'ng2-file-upload';
import { BehaviorSubject, combineLatest as observableCombineLatest, Observable, Subscription } from 'rxjs'; import { BehaviorSubject, combineLatest as observableCombineLatest, Observable, Subscription, switchMap } from 'rxjs';
import { AuthService } from '../../../../core/auth/auth.service'; import { AuthService } from '../../../../core/auth/auth.service';
import { ObjectCacheService } from '../../../../core/cache/object-cache.service'; import { ObjectCacheService } from '../../../../core/cache/object-cache.service';
import { ComColDataService } from '../../../../core/data/comcol-data.service'; import { ComColDataService } from '../../../../core/data/comcol-data.service';
@@ -24,8 +24,7 @@ import { getFirstCompletedRemoteData } from '../../../../core/shared/operators';
import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap'; import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
import { followLink } from '../../../utils/follow-link-config.model'; import { followLink } from '../../../utils/follow-link-config.model';
import { ConfirmationModalComponent } from '../../../confirmation-modal/confirmation-modal.component'; import { ConfirmationModalComponent } from '../../../confirmation-modal/confirmation-modal.component';
import { map, take, tap } from 'rxjs/operators'; import { filter, take } from 'rxjs/operators';
import { DSpaceObject } from '../../../../core/shared/dspace-object.model';
/** /**
* A form for creating and editing Communities or Collections * A form for creating and editing Communities or Collections
@@ -124,6 +123,8 @@ export class ComColFormComponent<T extends Collection | Community> implements On
public uploader = new FileUploader(this.uploadFilesOptions); public uploader = new FileUploader(this.uploadFilesOptions);
protected readonly refreshDSO$ = new EventEmitter<void>();
public constructor(protected formService: DynamicFormService, public constructor(protected formService: DynamicFormService,
protected translate: TranslateService, protected translate: TranslateService,
protected notificationsService: NotificationsService, protected notificationsService: NotificationsService,
@@ -168,6 +169,14 @@ export class ComColFormComponent<T extends Collection | Community> implements On
this.initializedUploaderOptions.next(true); this.initializedUploaderOptions.next(true);
} }
} }
this.subs.push(
this.refreshDSO$.pipe(
switchMap(() => this.refreshDsoCache()),
filter(rd => rd.hasSucceeded),
).subscribe(({ payload }) => this.dso = payload)
);
} }
/** /**
@@ -304,7 +313,7 @@ export class ComColFormComponent<T extends Collection | Community> implements On
* @param successMessageKey Translation key for success message * @param successMessageKey Translation key for success message
*/ */
private handleSuccessfulDeletion(successMessageKey: string): void { private handleSuccessfulDeletion(successMessageKey: string): void {
this.refreshDsoCache(); this.refreshDSO$.next();
this.notificationsService.success( this.notificationsService.success(
this.translate.get(`${successMessageKey}.title`), this.translate.get(`${successMessageKey}.title`),
this.translate.get(`${successMessageKey}.content`) this.translate.get(`${successMessageKey}.content`)
@@ -342,15 +351,10 @@ export class ComColFormComponent<T extends Collection | Community> implements On
/** /**
* Fetches the latest data for the dso * Fetches the latest data for the dso
*/ */
private fetchUpdatedDso(): Observable<DSpaceObject | null> { private fetchUpdatedDso(): Observable<RemoteData<T>> {
return this.dsoService.findById(this.dso.id, false, true, followLink('logo')).pipe( return this.dsoService.findById(this.dso.id, false, true, followLink('logo')).pipe(
tap((rd: RemoteData<T>) => { getFirstCompletedRemoteData()
if (rd.hasSucceeded) { ) as Observable<RemoteData<T>>;
this.dso = rd.payload;
}
}),
map((rd: RemoteData<T>) => rd.hasSucceeded ? rd.payload : null)
);
} }
@@ -360,7 +364,7 @@ export class ComColFormComponent<T extends Collection | Community> implements On
*/ */
public onCompleteItem() { public onCompleteItem() {
if (hasValue(this.dso.id)) { if (hasValue(this.dso.id)) {
this.refreshDsoCache(); this.refreshDSO$.next();
} }
if (this.isCreation) { if (this.isCreation) {
this.finish.emit(); this.finish.emit();
@@ -379,6 +383,7 @@ export class ComColFormComponent<T extends Collection | Community> implements On
* Unsubscribe from open subscriptions * Unsubscribe from open subscriptions
*/ */
ngOnDestroy(): void { ngOnDestroy(): void {
this.refreshDSO$.complete();
this.subs this.subs
.filter((subscription) => hasValue(subscription)) .filter((subscription) => hasValue(subscription))
.forEach((subscription) => subscription.unsubscribe()); .forEach((subscription) => subscription.unsubscribe());

View File

@@ -17,7 +17,7 @@ import {
} from '../../../../remote-data.utils'; } from '../../../../remote-data.utils';
import { ComcolMetadataComponent } from './comcol-metadata.component'; import { ComcolMetadataComponent } from './comcol-metadata.component';
fdescribe('ComColMetadataComponent', () => { describe('ComColMetadataComponent', () => {
let comp: ComcolMetadataComponent<any>; let comp: ComcolMetadataComponent<any>;
let fixture: ComponentFixture<ComcolMetadataComponent<any>>; let fixture: ComponentFixture<ComcolMetadataComponent<any>>;
let dsoDataService; let dsoDataService;