Skip to content

Commit 794eb6b

Browse files
[DSC-1111] [DURACOM-235] Fixes item cache refresh in comcol-form
1 parent a059c31 commit 794eb6b

3 files changed

Lines changed: 24 additions & 15 deletions

File tree

src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111
</div>
1212
<div class="col-4 d-inline-block">
1313
<div *ngIf="logo" class="float-right">
14-
<button (click)="confirmLogoDeleteWithModal()" data-test="open-delete-modal-button" class="btn btn-danger" type="button">{{'community.edit.logo.delete.title' | translate}}</button>
14+
<button
15+
(click)="confirmLogoDeleteWithModal()"
16+
class="btn btn-danger"
17+
type="button">{{ 'community.edit.logo.delete.title' | translate }}
18+
</button>
1519
</div>
1620
</div>
1721
</div>

src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.ts

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { UntypedFormGroup } from '@angular/forms';
33
import { DynamicFormControlModel, DynamicFormService, DynamicInputModel } from '@ng-dynamic-forms/core';
44
import { TranslateService } from '@ngx-translate/core';
55
import { FileUploader } from 'ng2-file-upload';
6-
import { BehaviorSubject, combineLatest as observableCombineLatest, Observable, Subscription } from 'rxjs';
6+
import { BehaviorSubject, combineLatest as observableCombineLatest, Observable, Subscription, switchMap } from 'rxjs';
77
import { AuthService } from '../../../../core/auth/auth.service';
88
import { ObjectCacheService } from '../../../../core/cache/object-cache.service';
99
import { ComColDataService } from '../../../../core/data/comcol-data.service';
@@ -24,8 +24,7 @@ import { getFirstCompletedRemoteData } from '../../../../core/shared/operators';
2424
import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
2525
import { followLink } from '../../../utils/follow-link-config.model';
2626
import { ConfirmationModalComponent } from '../../../confirmation-modal/confirmation-modal.component';
27-
import { map, take, tap } from 'rxjs/operators';
28-
import { DSpaceObject } from '../../../../core/shared/dspace-object.model';
27+
import { filter, take } from 'rxjs/operators';
2928

3029
/**
3130
* A form for creating and editing Communities or Collections
@@ -124,6 +123,8 @@ export class ComColFormComponent<T extends Collection | Community> implements On
124123

125124
public uploader = new FileUploader(this.uploadFilesOptions);
126125

126+
protected readonly refreshDSO$ = new EventEmitter<void>();
127+
127128
public constructor(protected formService: DynamicFormService,
128129
protected translate: TranslateService,
129130
protected notificationsService: NotificationsService,
@@ -168,6 +169,14 @@ export class ComColFormComponent<T extends Collection | Community> implements On
168169
this.initializedUploaderOptions.next(true);
169170
}
170171
}
172+
173+
this.subs.push(
174+
this.refreshDSO$.pipe(
175+
switchMap(() => this.refreshDsoCache()),
176+
filter(rd => rd.hasSucceeded),
177+
).subscribe(({ payload }) => this.dso = payload)
178+
);
179+
171180
}
172181

173182
/**
@@ -304,7 +313,7 @@ export class ComColFormComponent<T extends Collection | Community> implements On
304313
* @param successMessageKey Translation key for success message
305314
*/
306315
private handleSuccessfulDeletion(successMessageKey: string): void {
307-
this.refreshDsoCache();
316+
this.refreshDSO$.next();
308317
this.notificationsService.success(
309318
this.translate.get(`${successMessageKey}.title`),
310319
this.translate.get(`${successMessageKey}.content`)
@@ -342,15 +351,10 @@ export class ComColFormComponent<T extends Collection | Community> implements On
342351
/**
343352
* Fetches the latest data for the dso
344353
*/
345-
private fetchUpdatedDso(): Observable<DSpaceObject | null> {
354+
private fetchUpdatedDso(): Observable<RemoteData<T>> {
346355
return this.dsoService.findById(this.dso.id, false, true, followLink('logo')).pipe(
347-
tap((rd: RemoteData<T>) => {
348-
if (rd.hasSucceeded) {
349-
this.dso = rd.payload;
350-
}
351-
}),
352-
map((rd: RemoteData<T>) => rd.hasSucceeded ? rd.payload : null)
353-
);
356+
getFirstCompletedRemoteData()
357+
) as Observable<RemoteData<T>>;
354358
}
355359

356360

@@ -360,7 +364,7 @@ export class ComColFormComponent<T extends Collection | Community> implements On
360364
*/
361365
public onCompleteItem() {
362366
if (hasValue(this.dso.id)) {
363-
this.refreshDsoCache();
367+
this.refreshDSO$.next();
364368
}
365369
if (this.isCreation) {
366370
this.finish.emit();
@@ -379,6 +383,7 @@ export class ComColFormComponent<T extends Collection | Community> implements On
379383
* Unsubscribe from open subscriptions
380384
*/
381385
ngOnDestroy(): void {
386+
this.refreshDSO$.complete();
382387
this.subs
383388
.filter((subscription) => hasValue(subscription))
384389
.forEach((subscription) => subscription.unsubscribe());

src/app/shared/comcol/comcol-forms/edit-comcol-page/comcol-metadata/comcol-metadata.component.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
} from '../../../../remote-data.utils';
1818
import { ComcolMetadataComponent } from './comcol-metadata.component';
1919

20-
fdescribe('ComColMetadataComponent', () => {
20+
describe('ComColMetadataComponent', () => {
2121
let comp: ComcolMetadataComponent<any>;
2222
let fixture: ComponentFixture<ComcolMetadataComponent<any>>;
2323
let dsoDataService;

0 commit comments

Comments
 (0)