Skip to content

Commit

Permalink
Fix #25251 Pages reload listing when deactivating router outlet (#25516)
Browse files Browse the repository at this point in the history
  • Loading branch information
zJaaal authored and manuelrojas committed Jul 20, 2023
1 parent 4354bd6 commit 3c1da3c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,4 @@
</ng-template>
</div>

<router-outlet
(activate)="subscribeToShutdown($event)"
(deactivate)="unsubscribeToShutdown()"
></router-outlet>
<router-outlet (deactivate)="loadPagesOnDeactivation()"></router-outlet>
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { of } from 'rxjs/internal/observable/of';

import { DotIframeService } from '@components/_common/iframe/service/dot-iframe/dot-iframe.service';
import { IframeOverlayService } from '@components/_common/iframe/service/iframe-overlay.service';
import { DotCreateContentletComponent } from '@components/dot-contentlet-editor/components/dot-create-contentlet/dot-create-contentlet.component';
import { DotContentletEditorService } from '@components/dot-contentlet-editor/services/dot-contentlet-editor.service';
import { DotMessageDisplayServiceMock } from '@components/dot-message-display/dot-message-display.component.spec';
import { DotMessageSeverity, DotMessageType } from '@components/dot-message-display/model';
Expand Down Expand Up @@ -394,30 +393,14 @@ describe('DotPagesComponent', () => {
});
});

it('should get pages after closing DotCreateContentletComponent', () => {
const dialogComponentFixture = TestBed.createComponent(DotCreateContentletComponent);
fixture.detectChanges();

const dialogComponent = dialogComponentFixture.componentInstance;

it('should trigger getPages when deactivating the router-outlet', () => {
const routerOutlet = de.query(By.css('router-outlet'));

routerOutlet.triggerEventHandler('activate', dialogComponent);
fixture.detectChanges();

dialogComponent.shutdown.emit();
fixture.detectChanges();
expect(store.getPages).toHaveBeenCalled();
});
it('should trigger unsubscribeToShutdown when deactivating the router-outlet', () => {
const routerOutlet = de.query(By.css('router-outlet'));
spyOn(component, 'unsubscribeToShutdown');

routerOutlet.triggerEventHandler('activate');
fixture.detectChanges();
routerOutlet.triggerEventHandler('deactivate');
fixture.detectChanges();

expect(component.unsubscribeToShutdown).toHaveBeenCalled();
expect(store.getPages).toHaveBeenCalled();
});
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Subject, Subscription } from 'rxjs';
import { Subject } from 'rxjs';

import { HttpErrorResponse, HttpResponse } from '@angular/common/http';
import {
Expand All @@ -15,7 +15,6 @@ import { Menu } from 'primeng/menu';
import { Observable } from 'rxjs/internal/Observable';
import { filter, take, takeUntil } from 'rxjs/operators';

import { DotCreateContentletComponent } from '@components/dot-contentlet-editor/components/dot-create-contentlet/dot-create-contentlet.component';
import { DotMessageSeverity, DotMessageType } from '@components/dot-message-display/model';
import { DotMessageDisplayService } from '@components/dot-message-display/services';
import { DotHttpErrorManagerService } from '@dotcms/app/api/services/dot-http-error-manager/dot-http-error-manager.service';
Expand Down Expand Up @@ -48,7 +47,6 @@ export class DotPagesComponent implements AfterViewInit, OnDestroy {

private domIdMenuAttached = '';
private destroy$: Subject<boolean> = new Subject<boolean>();
private contentletDialogShutdown: Subscription;

constructor(
private store: DotPageStore,
Expand Down Expand Up @@ -200,28 +198,13 @@ export class DotPagesComponent implements AfterViewInit, OnDestroy {
}

/**
* Subscribe to the shutdown event of the contentlet dialog
* Load pages on deactivation
*
* @param {*} componentRef
* @return {*}
* @memberof DotPagesComponent
*/
subscribeToShutdown(componentRef: Component): void {
if (!(componentRef instanceof DotCreateContentletComponent)) return;

this.contentletDialogShutdown = componentRef.shutdown.subscribe(() => {
this.store.getPages({
offset: 0
});
loadPagesOnDeactivation() {
this.store.getPages({
offset: 0
});
}

/**
* Unsubscribe to the shutdown event of the contentlet dialog
*
* @memberof DotPagesComponent
*/
unsubscribeToShutdown() {
if (this.contentletDialogShutdown) this.contentletDialogShutdown.unsubscribe();
}
}

0 comments on commit 3c1da3c

Please sign in to comment.