Skip to content

Commit

Permalink
feat: dynamic breadcrumb for quote-edit and quote-request-edit
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian-Haehnlein committed Mar 3, 2020
1 parent c95c31f commit 5769cba
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 5 deletions.
5 changes: 4 additions & 1 deletion src/app/extensions/quoting/pages/quoting-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
],
},
},
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -66,6 +67,7 @@ describe('Quote Request Effects', () => {
{ path: 'login', component: DummyComponent },
{ path: 'foobar', component: DummyComponent },
]),
TranslateModule.forRoot(),
ngrxTesting({
reducers: {
quoting: combineReducers(quotingReducers),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -14,6 +15,7 @@ import {
mapTo,
mergeMap,
switchMap,
switchMapTo,
tap,
withLatestFrom,
} from 'rxjs/operators';
Expand All @@ -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';
Expand All @@ -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';
Expand All @@ -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
) {}

/**
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions src/app/extensions/quoting/store/quote/quote.effects.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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),
Expand Down
30 changes: 27 additions & 3 deletions src/app/extensions/quoting/store/quote/quote.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,25 @@ 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';
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 {
Expand All @@ -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
) {}

/**
Expand Down Expand Up @@ -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}` },
],
})
)
);
}

0 comments on commit 5769cba

Please sign in to comment.