diff --git a/src/app/extensions/quoting/pages/quoting-routing.module.ts b/src/app/extensions/quoting/pages/quoting-routing.module.ts index afa2c599d7..93e3a4dbcb 100644 --- a/src/app/extensions/quoting/pages/quoting-routing.module.ts +++ b/src/app/extensions/quoting/pages/quoting-routing.module.ts @@ -27,7 +27,10 @@ const routes: Routes = [ canActivate: [FeatureToggleGuard, AuthGuard], data: { feature: 'quoting', - breadcrumbData: [{ key: 'quote.quotes.link', link: '/account/quotes' }, { key: 'quote.quote_details.link' }], + breadcrumbData: [ + { key: 'quote.quotes.link', link: '/account/quotes' }, + { key: 'quote.edit.unsubmitted.quote_request_details.text' }, + ], }, }, ]; diff --git a/src/app/extensions/quoting/store/quote-request/quote-request.effects.spec.ts b/src/app/extensions/quoting/store/quote-request/quote-request.effects.spec.ts index 140421c507..da8ed7def4 100644 --- a/src/app/extensions/quoting/store/quote-request/quote-request.effects.spec.ts +++ b/src/app/extensions/quoting/store/quote-request/quote-request.effects.spec.ts @@ -5,6 +5,7 @@ import { Router } from '@angular/router'; import { RouterTestingModule } from '@angular/router/testing'; import { provideMockActions } from '@ngrx/effects/testing'; import { Store, combineReducers } from '@ngrx/store'; +import { TranslateModule } from '@ngx-translate/core'; import { cold, hot } from 'jest-marbles'; import { RouteNavigation } from 'ngrx-router'; import { noop, of, throwError } from 'rxjs'; @@ -66,6 +67,7 @@ describe('Quote Request Effects', () => { { path: 'login', component: DummyComponent }, { path: 'foobar', component: DummyComponent }, ]), + TranslateModule.forRoot(), ngrxTesting({ reducers: { quoting: combineReducers(quotingReducers), diff --git a/src/app/extensions/quoting/store/quote-request/quote-request.effects.ts b/src/app/extensions/quoting/store/quote-request/quote-request.effects.ts index e6c799c2f3..081e09c0a8 100644 --- a/src/app/extensions/quoting/store/quote-request/quote-request.effects.ts +++ b/src/app/extensions/quoting/store/quote-request/quote-request.effects.ts @@ -2,6 +2,7 @@ import { Injectable } from '@angular/core'; import { Router } from '@angular/router'; import { Actions, Effect, ofType } from '@ngrx/effects'; import { Store, select } from '@ngrx/store'; +import { TranslateService } from '@ngx-translate/core'; import { mapToParam, ofRoute } from 'ngrx-router'; import { combineLatest, concat, forkJoin } from 'rxjs'; import { @@ -14,6 +15,7 @@ import { mapTo, mergeMap, switchMap, + switchMapTo, tap, withLatestFrom, } from 'rxjs/operators'; @@ -28,6 +30,7 @@ import { ProductCompletenessLevel } from 'ish-core/models/product/product.model' import { getCurrentBasket } from 'ish-core/store/checkout/basket'; import { LoadProductIfNotLoaded } from 'ish-core/store/shopping/products'; import { UserActionTypes, getUserAuthorized } from 'ish-core/store/user'; +import { SetBreadcrumbData } from 'ish-core/store/viewconf'; import { mapErrorToAction, mapToPayload, mapToPayloadProperty, whenFalsy, whenTruthy } from 'ish-core/utils/operators'; import { QuoteRequest } from '../../models/quote-request/quote-request.model'; @@ -37,6 +40,7 @@ import { QuoteActionTypes } from '../quote/quote.actions'; import * as actions from './quote-request.actions'; import { getCurrentQuoteRequests, + getSelectedQuoteRequest, getSelectedQuoteRequestId, getSelectedQuoteRequestWithProducts, } from './quote-request.selectors'; @@ -48,7 +52,8 @@ export class QuoteRequestEffects { private featureToggleService: FeatureToggleService, private quoteRequestService: QuoteRequestService, private router: Router, - private store: Store<{}> + private store: Store<{}>, + private translateService: TranslateService ) {} /** @@ -394,6 +399,25 @@ export class QuoteRequestEffects { mapTo(new actions.LoadQuoteRequests()) ); + @Effect() + setQuoteRequestBreadcrumb$ = this.actions$.pipe( + ofRoute(), + mapToParam('quoteRequestId'), + whenTruthy(), + switchMapTo(this.store.pipe(select(getSelectedQuoteRequest))), + whenTruthy(), + withLatestFrom(this.translateService.get('quote.edit.unsubmitted.quote_request_details.text')), + map( + ([quoteRequest, x]) => + new SetBreadcrumbData({ + breadcrumbData: [ + { key: 'quote.quotes.link', link: '/account/quotes' }, + { text: `${x} - ${quoteRequest.displayName}` }, + ], + }) + ) + ); + /** * Filter for itemId and update pairs with actual quantity or sku changes. * @param payloadItems The items of the action payload, containing items to update. diff --git a/src/app/extensions/quoting/store/quote/quote.effects.spec.ts b/src/app/extensions/quoting/store/quote/quote.effects.spec.ts index 05b0ebc596..837cf1f445 100644 --- a/src/app/extensions/quoting/store/quote/quote.effects.spec.ts +++ b/src/app/extensions/quoting/store/quote/quote.effects.spec.ts @@ -4,6 +4,7 @@ import { TestBed, async, fakeAsync, tick } from '@angular/core/testing'; import { RouterTestingModule } from '@angular/router/testing'; import { provideMockActions } from '@ngrx/effects/testing'; import { Store, combineReducers } from '@ngrx/store'; +import { TranslateModule } from '@ngx-translate/core'; import { cold, hot } from 'jest-marbles'; import { noop, of, throwError } from 'rxjs'; import { anyString, anything, instance, mock, verify, when } from 'ts-mockito'; @@ -59,6 +60,7 @@ describe('Quote Effects', () => { { path: 'account/quotes/request/:quoteRequestId', component: DummyComponent }, { path: 'basket', component: DummyComponent }, ]), + TranslateModule.forRoot(), ngrxTesting({ reducers: { quoting: combineReducers(quotingReducers), diff --git a/src/app/extensions/quoting/store/quote/quote.effects.ts b/src/app/extensions/quoting/store/quote/quote.effects.ts index 08f53b5e1d..973f41e6a6 100644 --- a/src/app/extensions/quoting/store/quote/quote.effects.ts +++ b/src/app/extensions/quoting/store/quote/quote.effects.ts @@ -2,9 +2,10 @@ import { Injectable } from '@angular/core'; import { Router } from '@angular/router'; import { Actions, Effect, ofType } from '@ngrx/effects'; import { Store, select } from '@ngrx/store'; +import { TranslateService } from '@ngx-translate/core'; import { mapToParam, ofRoute } from 'ngrx-router'; import { combineLatest } from 'rxjs'; -import { concatMap, filter, map, mapTo, mergeMap, tap, withLatestFrom } from 'rxjs/operators'; +import { concatMap, filter, map, mapTo, mergeMap, switchMapTo, tap, withLatestFrom } from 'rxjs/operators'; import { FeatureToggleService } from 'ish-core/feature-toggle.module'; import { ProductCompletenessLevel } from 'ish-core/models/product/product.model'; @@ -12,13 +13,14 @@ import { BasketService } from 'ish-core/services/basket/basket.service'; import { UpdateBasket, getCurrentBasketId } from 'ish-core/store/checkout/basket'; import { LoadProductIfNotLoaded } from 'ish-core/store/shopping/products'; import { UserActionTypes } from 'ish-core/store/user'; +import { SetBreadcrumbData } from 'ish-core/store/viewconf'; import { mapErrorToAction, mapToPayload, mapToPayloadProperty, whenTruthy } from 'ish-core/utils/operators'; import { QuoteService } from '../../services/quote/quote.service'; import { QuoteRequestActionTypes } from '../quote-request'; import * as actions from './quote.actions'; -import { getSelectedQuoteId, getSelectedQuoteWithProducts } from './quote.selectors'; +import { getSelectedQuote, getSelectedQuoteId, getSelectedQuoteWithProducts } from './quote.selectors'; @Injectable() export class QuoteEffects { @@ -28,7 +30,8 @@ export class QuoteEffects { private quoteService: QuoteService, private basketService: BasketService, private router: Router, - private store: Store<{}> + private store: Store<{}>, + private translateService: TranslateService ) {} /** @@ -199,4 +202,25 @@ export class QuoteEffects { this.router.navigate(['/basket']); }) ); + + @Effect() + setQuoteRequestBreadcrumb$ = this.actions$.pipe( + ofRoute(), + mapToParam('quoteId'), + whenTruthy(), + switchMapTo(this.store.pipe(select(getSelectedQuote))), + whenTruthy(), + withLatestFrom(this.translateService.get('quote.edit.responded.quote_details.text')), + withLatestFrom(this.translateService.get('quote.edit.unsubmitted.quote_request_details.text')), + map(([[quote, x], y]) => [quote, quote.state === 'Responded' ? x : y]), + map( + ([quote, x]) => + new SetBreadcrumbData({ + breadcrumbData: [ + { key: 'quote.quotes.link', link: '/account/quotes' }, + { text: `${x} - ${quote.displayName}` }, + ], + }) + ) + ); }