mirror of
https://dev.azure.com/hugendubel/ISA/_git/ISA-Frontend
synced 2025-12-31 09:37:15 +01:00
Merged PR 389: #1185 Add FromSearch to HistoryState To Identify Origin from Result Page
#1185 Add FromSearch to HistoryState To Identify Origin from Result Page
This commit is contained in:
@@ -56,6 +56,8 @@ fdescribe('ShelfSearchResultComponent', () => {
|
||||
|
||||
describe('fetch', () => {
|
||||
it('should be called onInit with initalFetching set to true', () => {
|
||||
spyOn<any>(component, 'isFromSearchPage').and.returnValue(false);
|
||||
|
||||
spyOn(component, 'fetch').and.callFake(() => {});
|
||||
|
||||
component.ngOnInit();
|
||||
@@ -63,7 +65,18 @@ fdescribe('ShelfSearchResultComponent', () => {
|
||||
expect(component.fetch).toHaveBeenCalledWith(true, true);
|
||||
});
|
||||
|
||||
it('should call fetch without force and initialSearch argument if previous page was search', () => {
|
||||
spyOn<any>(component, 'isFromSearchPage').and.returnValue(true);
|
||||
spyOn(component, 'fetch').and.callFake(() => {});
|
||||
|
||||
component.ngOnInit();
|
||||
|
||||
expect(component.fetch).not.toHaveBeenCalledWith(true, true);
|
||||
});
|
||||
|
||||
it('should call fetchResult on the facade when initializing the component (i.e. OnInit)', async () => {
|
||||
spyOn<any>(component, 'isFromSearchPage').and.returnValue(false);
|
||||
|
||||
component.ngOnInit();
|
||||
|
||||
spyOn(facade, 'fetchResult').and.callThrough();
|
||||
|
||||
@@ -13,7 +13,6 @@ import {
|
||||
ViewChild,
|
||||
ElementRef,
|
||||
ChangeDetectionStrategy,
|
||||
ChangeDetectorRef,
|
||||
} from '@angular/core';
|
||||
import { SearchStateFacade } from 'apps/sales/src/app/store/customer';
|
||||
import { first, takeUntil, map, withLatestFrom } from 'rxjs/operators';
|
||||
@@ -55,7 +54,15 @@ export class ShelfSearchResultsComponent implements OnInit, OnDestroy {
|
||||
ngOnInit() {
|
||||
this.initFacade();
|
||||
this.initScrollContainer();
|
||||
this.fetch(true, true);
|
||||
this.initFetch();
|
||||
}
|
||||
|
||||
initFetch() {
|
||||
if (this.isFromSearchPage()) {
|
||||
this.fetch();
|
||||
} else {
|
||||
this.fetch(true, true);
|
||||
}
|
||||
}
|
||||
|
||||
initFacade() {
|
||||
@@ -122,4 +129,8 @@ export class ShelfSearchResultsComponent implements OnInit, OnDestroy {
|
||||
): boolean {
|
||||
return numberOfFetchedResults < hits;
|
||||
}
|
||||
|
||||
private isFromSearchPage(): boolean {
|
||||
return !!window && !!window.history && !!window.history.state['fromSearch'];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -337,6 +337,7 @@ export class ShelfSearchInputComponent
|
||||
this.shelfNavigationService.navigateToResultList({
|
||||
searchQuery,
|
||||
numberOfHits,
|
||||
fromSearch: true,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -126,14 +126,16 @@ export class ShelfNavigationService {
|
||||
navigateToResultList({
|
||||
searchQuery,
|
||||
numberOfHits,
|
||||
fromSearch,
|
||||
}: {
|
||||
searchQuery: string;
|
||||
numberOfHits: number;
|
||||
fromSearch: boolean;
|
||||
}) {
|
||||
this.createTab();
|
||||
const path = '/shelf/results';
|
||||
const breadcrumb = this.getResultListBreadcrumb(searchQuery, numberOfHits);
|
||||
this.navigateToRoute(path, breadcrumb);
|
||||
this.navigateToRoute(path, breadcrumb, { fromSearch });
|
||||
}
|
||||
|
||||
navigateToHistory(orderitem: OrderItemListItemDTO) {
|
||||
@@ -202,7 +204,8 @@ export class ShelfNavigationService {
|
||||
|
||||
private async navigateToRoute(
|
||||
route: string,
|
||||
breadcrumbName: string
|
||||
breadcrumbName: string,
|
||||
state?: { [key: string]: string | boolean }
|
||||
): Promise<boolean> {
|
||||
this.store.dispatch(
|
||||
new AddBreadcrumb(
|
||||
@@ -214,7 +217,7 @@ export class ShelfNavigationService {
|
||||
)
|
||||
);
|
||||
this.store.dispatch(new ChangeCurrentRoute(route));
|
||||
return this.router.navigate([route]);
|
||||
return this.router.navigate([route], { ...(state ? { state } : {}) });
|
||||
}
|
||||
|
||||
public async navigateBackToDetails(
|
||||
|
||||
Reference in New Issue
Block a user