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:
Sebastian Neumair
2020-10-23 12:00:03 +00:00
4 changed files with 33 additions and 5 deletions

View File

@@ -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();

View File

@@ -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'];
}
}

View File

@@ -337,6 +337,7 @@ export class ShelfSearchInputComponent
this.shelfNavigationService.navigateToResultList({
searchQuery,
numberOfHits,
fromSearch: true,
});
}

View File

@@ -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(