Skip to content

Commit

Permalink
Add fix for search field not working on back button click (#1291)
Browse files Browse the repository at this point in the history
  • Loading branch information
teodor-ritense authored Nov 27, 2024
1 parent facbfb3 commit bca8d5e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ import {
switchMap,
take,
tap,
Subscription,
} from 'rxjs';
import {
DOSSIER_DETAIL_DEFAULT_DISPLAY_SIZE,
Expand Down Expand Up @@ -275,7 +276,7 @@ export class DossierDetailComponent
private _pendingTab: TabImpl;
private _observer!: ResizeObserver;
private _tabsInit = false;
private _prevQueryParams: Params | undefined | null;
private readonly _subscriptions = new Subscription();

constructor(
private readonly breadcrumbService: BreadcrumbService,
Expand Down Expand Up @@ -314,13 +315,14 @@ export class DossierDetailComponent
this.pageTitleService.disableReset();
this.iconService.registerAll([ChevronDown16]);
this.setDocumentStyle();
this.handleBackNavigation();
this.enableResetOnBackNavigation();
}

public ngOnDestroy(): void {
this.breadcrumbService.clearSecondBreadcrumb();
this.pageTitleService.enableReset();
this.removeDocumentStyle();
this._subscriptions.unsubscribe();
}

public getAllAssociatedProcessDefinitions(): void {
Expand Down Expand Up @@ -580,25 +582,18 @@ export class DossierDetailComponent
this.renderer.removeClass(this.htmlDocument.getElementsByTagName('html')[0], 'html--fixed');
}

private handleBackNavigation(): void {
this._prevQueryParams =
this.router.lastSuccessfulNavigation?.previousNavigation?.extras.queryParams;

this.router.events
.pipe(
filter(event => event instanceof NavigationStart && event.navigationTrigger === 'popstate'),
take(1)
)
.subscribe(() => {
this.pageTitleService.enableReset();

if (!this._prevQueryParams) return;

this.router.navigate([`dossiers/${this.documentDefinitionName}`], {
queryParams: this._prevQueryParams,
replaceUrl: true,
});
});
private enableResetOnBackNavigation(): void {
this._subscriptions.add(
this.router.events
.pipe(
filter(
event => event instanceof NavigationStart && event.navigationTrigger === 'popstate'
)
)
.subscribe(() => {
this.pageTitleService.enableReset();
})
);
}

private handleNoTaskProcessLink(isAdmin: boolean): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -504,9 +504,7 @@ export class DossierListComponent implements OnInit, OnDestroy {
`/dossiers/${documentDefinitionName}`,
this.route.snapshot.queryParams
);
this.router.navigate([`/dossiers/${documentDefinitionName}/document/${item.id}`], {
replaceUrl: true,
});
this.router.navigate([`/dossiers/${documentDefinitionName}/document/${item.id}`]);
});
}

Expand Down
2 changes: 1 addition & 1 deletion projects/valtimo/dossier/src/lib/models/tabs.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ export class TabLoaderImpl implements TabLoader<TabImpl> {
this._router.navigate([`${urlBeforeDocumentId}${currentDocumentId}/${nextTab.name}`], {
...(nextTab.name === 'documents' && {
queryParams,
replaceUrl: true,
}),
replaceUrl: true,
});
});
}
Expand Down

0 comments on commit bca8d5e

Please sign in to comment.