@daffodil/search-product 0.0.0-PLACEHOLDER
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +52 -0
- package/README.md +11 -0
- package/driver/in-memory/ng-package.json +8 -0
- package/driver/in-memory/package.json +3 -0
- package/driver/in-memory/src/backend/search.service.spec.ts +72 -0
- package/driver/in-memory/src/backend/search.service.ts +77 -0
- package/driver/in-memory/src/in-memory.module.ts +32 -0
- package/driver/in-memory/src/index.ts +1 -0
- package/driver/in-memory/src/public_api.ts +1 -0
- package/driver/magento/ng-package.json +8 -0
- package/driver/magento/package.json +3 -0
- package/driver/magento/src/core.module.ts +26 -0
- package/driver/magento/src/driver.module.ts +33 -0
- package/driver/magento/src/errors/map.ts +12 -0
- package/driver/magento/src/errors/transform.spec.ts +27 -0
- package/driver/magento/src/errors/transform.ts +46 -0
- package/driver/magento/src/federated-driver.module.ts +53 -0
- package/driver/magento/src/index.ts +1 -0
- package/driver/magento/src/models/get-product-response.interface.ts +18 -0
- package/driver/magento/src/models/public_api.ts +1 -0
- package/driver/magento/src/product-search.service.spec.ts +180 -0
- package/driver/magento/src/product-search.service.ts +124 -0
- package/driver/magento/src/public_api.ts +6 -0
- package/driver/magento/src/queries/fragments/product-result.ts +30 -0
- package/driver/magento/src/queries/product-search.ts +47 -0
- package/driver/ng-package.json +8 -0
- package/driver/package.json +3 -0
- package/driver/src/index.ts +1 -0
- package/driver/src/interfaces/options.interface.ts +4 -0
- package/driver/src/interfaces/public_api.ts +3 -0
- package/driver/src/interfaces/response.interface.ts +7 -0
- package/driver/src/interfaces/search-product-service.interface.ts +23 -0
- package/driver/src/public_api.ts +1 -0
- package/driver/testing/ng-package.json +8 -0
- package/driver/testing/package.json +3 -0
- package/driver/testing/src/index.ts +1 -0
- package/driver/testing/src/public_api.ts +1 -0
- package/driver/testing/src/testing.module.ts +31 -0
- package/karma.conf.js +10 -0
- package/ng-package.json +8 -0
- package/ng-package.prod.json +7 -0
- package/package.json +48 -0
- package/routing/ng-package.json +8 -0
- package/routing/package.json +3 -0
- package/routing/src/effects/collection-route.effects.ts +35 -0
- package/routing/src/index.ts +1 -0
- package/routing/src/module.ts +40 -0
- package/routing/src/public_api.ts +1 -0
- package/src/constants/public_api.ts +1 -0
- package/src/constants/search-result-kind.ts +6 -0
- package/src/index.ts +1 -0
- package/src/models/product-search-result.type.ts +11 -0
- package/src/models/public_api.ts +1 -0
- package/src/public_api.ts +3 -0
- package/src/transforms/products-to-result.spec.ts +34 -0
- package/src/transforms/products-to-result.ts +13 -0
- package/src/transforms/public_api.ts +1 -0
- package/state/ng-package.json +8 -0
- package/state/package.json +3 -0
- package/state/src/actions/product-collection.actions.ts +115 -0
- package/state/src/core.module.ts +37 -0
- package/state/src/effects/collection.effects.spec.ts +363 -0
- package/state/src/effects/collection.effects.ts +90 -0
- package/state/src/facades/collection/facade.ts +24 -0
- package/state/src/facades/public_api.ts +5 -0
- package/state/src/facades/search/incremental.facade.ts +23 -0
- package/state/src/facades/search/page.facade.ts +23 -0
- package/state/src/facades/search/search-facade.interface.ts +15 -0
- package/state/src/facades/search/search.facade.spec.ts +103 -0
- package/state/src/facades/search/search.facade.ts +34 -0
- package/state/src/index.ts +1 -0
- package/state/src/page.module.ts +18 -0
- package/state/src/public_api.ts +7 -0
- package/state/src/reducers/collection/public_api.ts +3 -0
- package/state/src/reducers/collection/reducer.ts +64 -0
- package/state/src/reducers/collection/search-reducers.ts +11 -0
- package/state/src/reducers/collection/search.reducer.spec.ts +156 -0
- package/state/src/reducers/collection/search.reducer.ts +35 -0
- package/state/src/reducers/product/entities.reducer.spec.ts +62 -0
- package/state/src/reducers/product/entities.reducer.ts +33 -0
- package/state/src/reducers/product/public_api.ts +2 -0
- package/state/src/reducers/product/reducers.spec.ts +16 -0
- package/state/src/reducers/product/reducers.ts +13 -0
- package/state/src/reducers/public_api.ts +9 -0
- package/state/src/reducers/reducers.interface.ts +19 -0
- package/state/src/reducers/reducers.spec.ts +10 -0
- package/state/src/reducers/reducers.ts +11 -0
- package/state/src/reducers/store-feature-key.ts +4 -0
- package/state/src/selectors/collection/selectors.ts +24 -0
- package/state/src/selectors/incremental/selectors.ts +10 -0
- package/state/src/selectors/page/selectors.ts +10 -0
- package/state/src/selectors/public_api.ts +5 -0
- package/state/src/selectors/search-feature.selector.ts +25 -0
- package/state/src/selectors/search.selector.spec.ts +113 -0
- package/state/src/selectors/search.selector.ts +52 -0
- package/state/src/state.module.ts +14 -0
- package/state/testing/ng-package.json +8 -0
- package/state/testing/package.json +3 -0
- package/state/testing/src/index.ts +1 -0
- package/state/testing/src/mock-search-facade.ts +21 -0
- package/state/testing/src/public_api.ts +2 -0
- package/state/testing/src/testing.module.ts +22 -0
- package/test.ts +24 -0
- package/testing/ng-package.json +8 -0
- package/testing/package.json +3 -0
- package/testing/src/factories/product-search-result.factory.spec.ts +43 -0
- package/testing/src/factories/product-search-result.factory.ts +26 -0
- package/testing/src/factories/public_api.ts +1 -0
- package/testing/src/index.ts +1 -0
- package/testing/src/public_api.ts +2 -0
- package/testing/src/testing.module.ts +19 -0
- package/tsconfig.json +38 -0
- package/tsconfig.lib.json +28 -0
- package/tsconfig.lib.prod.json +9 -0
- package/tsconfig.spec.json +19 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Injectable,
|
|
3
|
+
Inject,
|
|
4
|
+
} from '@angular/core';
|
|
5
|
+
import {
|
|
6
|
+
Actions,
|
|
7
|
+
createEffect,
|
|
8
|
+
ofType,
|
|
9
|
+
} from '@ngrx/effects';
|
|
10
|
+
import {
|
|
11
|
+
asyncScheduler,
|
|
12
|
+
of,
|
|
13
|
+
} from 'rxjs';
|
|
14
|
+
import {
|
|
15
|
+
switchMap,
|
|
16
|
+
map,
|
|
17
|
+
catchError,
|
|
18
|
+
throttleTime,
|
|
19
|
+
withLatestFrom,
|
|
20
|
+
} from 'rxjs/operators';
|
|
21
|
+
|
|
22
|
+
import { DaffError } from '@daffodil/core';
|
|
23
|
+
import {
|
|
24
|
+
DaffCollectionRequest,
|
|
25
|
+
daffCollectionBuildRequestFromMetadata,
|
|
26
|
+
} from '@daffodil/core';
|
|
27
|
+
import { ErrorTransformer } from '@daffodil/core/state';
|
|
28
|
+
import { DAFF_SEARCH_ERROR_MATCHER } from '@daffodil/search';
|
|
29
|
+
import { DaffSearchProductResult } from '@daffodil/search-product';
|
|
30
|
+
import { DaffSearchProductDriverInterface } from '@daffodil/search-product/driver';
|
|
31
|
+
import { DaffSearchDriver } from '@daffodil/search/driver';
|
|
32
|
+
import {
|
|
33
|
+
DaffSearchPageFacade,
|
|
34
|
+
DaffSearchLoadFailure,
|
|
35
|
+
DaffSearchLoadSuccess,
|
|
36
|
+
} from '@daffodil/search/state';
|
|
37
|
+
|
|
38
|
+
import { DaffSearchProductCollectionActionTypes } from '../actions/product-collection.actions';
|
|
39
|
+
import { DaffSearchProductCollectionFacade } from '../facades/public_api';
|
|
40
|
+
|
|
41
|
+
export const DAFF_SEARCH_PRODUCT_COLLECTION_ACTION_TYPES = [
|
|
42
|
+
DaffSearchProductCollectionActionTypes.SearchProductApplyFiltersAction,
|
|
43
|
+
DaffSearchProductCollectionActionTypes.SearchProductRemoveFiltersAction,
|
|
44
|
+
DaffSearchProductCollectionActionTypes.SearchProductReplaceFiltersAction,
|
|
45
|
+
DaffSearchProductCollectionActionTypes.SearchProductToggleFiltersAction,
|
|
46
|
+
DaffSearchProductCollectionActionTypes.SearchProductChangeCurrentPageAction,
|
|
47
|
+
DaffSearchProductCollectionActionTypes.SearchProductChangePageSizeAction,
|
|
48
|
+
DaffSearchProductCollectionActionTypes.SearchProductChangeSortingOptionAction,
|
|
49
|
+
DaffSearchProductCollectionActionTypes.SearchProductClearFiltersAction,
|
|
50
|
+
];
|
|
51
|
+
|
|
52
|
+
@Injectable()
|
|
53
|
+
export class DaffSearchProductCollectionEffects<
|
|
54
|
+
T extends DaffSearchProductResult = DaffSearchProductResult,
|
|
55
|
+
> {
|
|
56
|
+
constructor(
|
|
57
|
+
private actions$: Actions,
|
|
58
|
+
private collectionFacade: DaffSearchProductCollectionFacade,
|
|
59
|
+
private searchFacade: DaffSearchPageFacade,
|
|
60
|
+
// TODO: should we reference the product kind driver here?
|
|
61
|
+
@Inject(DaffSearchDriver) private driver: DaffSearchProductDriverInterface<T>,
|
|
62
|
+
@Inject(DAFF_SEARCH_ERROR_MATCHER) private errorMatcher: ErrorTransformer,
|
|
63
|
+
) {}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Updates the product collection according to the action.
|
|
67
|
+
* It will take the request metedata, including currently
|
|
68
|
+
* applied filters, from state, form them into a request,
|
|
69
|
+
* and pass that into the {@link DaffProductCollectionDriverCall} provided to this class.
|
|
70
|
+
*
|
|
71
|
+
* @param throttleWindow the amount of time to delay when apply/removing filters
|
|
72
|
+
* in a sequence.
|
|
73
|
+
*/
|
|
74
|
+
update$ = createEffect(() => (throttleWindow = 300, scheduler = asyncScheduler) => this.actions$.pipe(
|
|
75
|
+
ofType(...DAFF_SEARCH_PRODUCT_COLLECTION_ACTION_TYPES),
|
|
76
|
+
withLatestFrom(
|
|
77
|
+
this.collectionFacade.metadata$,
|
|
78
|
+
this.searchFacade.recent$,
|
|
79
|
+
),
|
|
80
|
+
map(([action, metadata, recent]): [string, DaffCollectionRequest] => [
|
|
81
|
+
recent[0],
|
|
82
|
+
daffCollectionBuildRequestFromMetadata(metadata),
|
|
83
|
+
]),
|
|
84
|
+
throttleTime(throttleWindow, scheduler, { leading: true, trailing: true }),
|
|
85
|
+
switchMap(([recent, request]) => this.driver.search(recent, request).pipe(
|
|
86
|
+
map(resp => new DaffSearchLoadSuccess<T>(resp)),
|
|
87
|
+
catchError((error: DaffError) => of(new DaffSearchLoadFailure(this.errorMatcher(error)))),
|
|
88
|
+
)),
|
|
89
|
+
));
|
|
90
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Injectable } from '@angular/core';
|
|
2
|
+
import { Store } from '@ngrx/store';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
DaffCollectionFacade,
|
|
6
|
+
DaffCollectionFacadeInterface,
|
|
7
|
+
} from '@daffodil/core/state';
|
|
8
|
+
|
|
9
|
+
import { DaffSearchProductStateRootSlice } from '../../reducers/public_api';
|
|
10
|
+
import { getSearchProductCollectionSelectors } from '../../selectors/public_api';
|
|
11
|
+
|
|
12
|
+
@Injectable({
|
|
13
|
+
providedIn: 'root',
|
|
14
|
+
})
|
|
15
|
+
export class DaffSearchProductCollectionFacade extends DaffCollectionFacade<DaffSearchProductStateRootSlice> implements DaffCollectionFacadeInterface {
|
|
16
|
+
constructor(
|
|
17
|
+
store: Store<DaffSearchProductStateRootSlice>,
|
|
18
|
+
) {
|
|
19
|
+
super(
|
|
20
|
+
store,
|
|
21
|
+
getSearchProductCollectionSelectors(),
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { DaffSearchProductFacadeInterface } from './search/search-facade.interface';
|
|
2
|
+
export { DaffSearchProductFacade } from './search/search.facade';
|
|
3
|
+
export { DaffSearchProductPageFacade } from './search/page.facade';
|
|
4
|
+
export { DaffSearchProductIncrementalFacade } from './search/incremental.facade';
|
|
5
|
+
export { DaffSearchProductCollectionFacade } from './collection/facade';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Injectable } from '@angular/core';
|
|
2
|
+
import { Store } from '@ngrx/store';
|
|
3
|
+
|
|
4
|
+
import { DaffSearchProductStateRootSlice } from '../../reducers/public_api';
|
|
5
|
+
import { daffSearchProductGetIncrementalSelectors } from '../../selectors/public_api';
|
|
6
|
+
import { DaffSearchProductFacadeInterface } from './search-facade.interface';
|
|
7
|
+
import { DaffSearchProductFacade } from './search.facade';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @inheritdoc
|
|
11
|
+
*
|
|
12
|
+
* A facade for the normal search state.
|
|
13
|
+
*/
|
|
14
|
+
@Injectable({
|
|
15
|
+
providedIn: 'root',
|
|
16
|
+
})
|
|
17
|
+
export class DaffSearchProductIncrementalFacade extends DaffSearchProductFacade implements DaffSearchProductFacadeInterface {
|
|
18
|
+
constructor(
|
|
19
|
+
store: Store<DaffSearchProductStateRootSlice>,
|
|
20
|
+
) {
|
|
21
|
+
super(store, daffSearchProductGetIncrementalSelectors());
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Injectable } from '@angular/core';
|
|
2
|
+
import { Store } from '@ngrx/store';
|
|
3
|
+
|
|
4
|
+
import { DaffSearchProductStateRootSlice } from '../../reducers/public_api';
|
|
5
|
+
import { daffSearchProductGetPageSelectors } from '../../selectors/public_api';
|
|
6
|
+
import { DaffSearchProductFacadeInterface } from './search-facade.interface';
|
|
7
|
+
import { DaffSearchProductFacade } from './search.facade';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @inheritdoc
|
|
11
|
+
*
|
|
12
|
+
* A facade for the normal search state.
|
|
13
|
+
*/
|
|
14
|
+
@Injectable({
|
|
15
|
+
providedIn: 'root',
|
|
16
|
+
})
|
|
17
|
+
export class DaffSearchProductPageFacade extends DaffSearchProductFacade implements DaffSearchProductFacadeInterface {
|
|
18
|
+
constructor(
|
|
19
|
+
store: Store<DaffSearchProductStateRootSlice>,
|
|
20
|
+
) {
|
|
21
|
+
super(store, daffSearchProductGetPageSelectors());
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Action } from '@ngrx/store';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
|
|
4
|
+
import { DaffStoreFacade } from '@daffodil/core/state';
|
|
5
|
+
import { DaffProduct } from '@daffodil/product';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Exposes the search state selectors.
|
|
9
|
+
*/
|
|
10
|
+
export interface DaffSearchProductFacadeInterface extends DaffStoreFacade<Action> {
|
|
11
|
+
/**
|
|
12
|
+
* The products returned in the most recent search.
|
|
13
|
+
*/
|
|
14
|
+
productResults$: Observable<DaffProduct[]>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { Injectable } from '@angular/core';
|
|
2
|
+
import { TestBed } from '@angular/core/testing';
|
|
3
|
+
import {
|
|
4
|
+
StoreModule,
|
|
5
|
+
combineReducers,
|
|
6
|
+
Store,
|
|
7
|
+
} from '@ngrx/store';
|
|
8
|
+
import { cold } from 'jasmine-marbles';
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
DAFF_PRODUCT_STORE_FEATURE_KEY,
|
|
12
|
+
daffProductReducers,
|
|
13
|
+
DaffProductGridLoadSuccess,
|
|
14
|
+
} from '@daffodil/product/state';
|
|
15
|
+
import { DaffProductTestingModule } from '@daffodil/product/testing';
|
|
16
|
+
import { daffSearchTransformResultsToCollection } from '@daffodil/search';
|
|
17
|
+
import { DaffSearchProductResult } from '@daffodil/search-product';
|
|
18
|
+
import {
|
|
19
|
+
daffSearchProductGetPageSelectors,
|
|
20
|
+
daffSearchProductReducers,
|
|
21
|
+
DaffSearchProductStateRootSlice,
|
|
22
|
+
DAFF_SEARCH_PRODUCT_STORE_FEATURE_KEY,
|
|
23
|
+
} from '@daffodil/search-product/state';
|
|
24
|
+
import { DaffSearchProductResultFactory } from '@daffodil/search-product/testing';
|
|
25
|
+
import { DaffSearchDriverResponse } from '@daffodil/search/driver';
|
|
26
|
+
import {
|
|
27
|
+
DaffSearchLoadSuccess,
|
|
28
|
+
daffSearchReducers,
|
|
29
|
+
DAFF_SEARCH_STORE_FEATURE_KEY,
|
|
30
|
+
} from '@daffodil/search/state';
|
|
31
|
+
|
|
32
|
+
import { DaffSearchProductFacade } from './search.facade';
|
|
33
|
+
|
|
34
|
+
@Injectable()
|
|
35
|
+
export class TestFacade extends DaffSearchProductFacade {
|
|
36
|
+
constructor(
|
|
37
|
+
store: Store<DaffSearchProductStateRootSlice>,
|
|
38
|
+
) {
|
|
39
|
+
super(store, daffSearchProductGetPageSelectors());
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
describe('@daffodil/search-product/state | DaffSearchProductFacade', () => {
|
|
44
|
+
let store: Store<DaffSearchProductStateRootSlice>;
|
|
45
|
+
let facade: TestFacade;
|
|
46
|
+
let searchResultFactory: DaffSearchProductResultFactory;
|
|
47
|
+
|
|
48
|
+
let mockSearchResult: DaffSearchProductResult;
|
|
49
|
+
let mockSearchResultResponse: DaffSearchDriverResponse;
|
|
50
|
+
|
|
51
|
+
beforeEach(() => {
|
|
52
|
+
TestBed.configureTestingModule({
|
|
53
|
+
imports: [
|
|
54
|
+
StoreModule.forRoot({
|
|
55
|
+
[DAFF_SEARCH_STORE_FEATURE_KEY]: combineReducers(daffSearchReducers),
|
|
56
|
+
[DAFF_PRODUCT_STORE_FEATURE_KEY]: combineReducers(daffProductReducers),
|
|
57
|
+
[DAFF_SEARCH_PRODUCT_STORE_FEATURE_KEY]: combineReducers(daffSearchProductReducers),
|
|
58
|
+
}),
|
|
59
|
+
DaffProductTestingModule,
|
|
60
|
+
],
|
|
61
|
+
providers: [
|
|
62
|
+
TestFacade,
|
|
63
|
+
],
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
store = TestBed.inject(Store);
|
|
67
|
+
facade = TestBed.inject(TestFacade);
|
|
68
|
+
searchResultFactory = TestBed.inject(DaffSearchProductResultFactory);
|
|
69
|
+
|
|
70
|
+
mockSearchResult = searchResultFactory.create();
|
|
71
|
+
mockSearchResultResponse = {
|
|
72
|
+
collection: daffSearchTransformResultsToCollection([mockSearchResult]),
|
|
73
|
+
metadata: {},
|
|
74
|
+
};
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('should be created', () => {
|
|
78
|
+
expect(facade).toBeTruthy();
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('should be able to dispatch an action to the store', () => {
|
|
82
|
+
spyOn(store, 'dispatch');
|
|
83
|
+
const action = { type: 'SOME_TYPE' };
|
|
84
|
+
|
|
85
|
+
facade.dispatch(action);
|
|
86
|
+
expect(store.dispatch).toHaveBeenCalledWith(action);
|
|
87
|
+
expect(store.dispatch).toHaveBeenCalledTimes(1);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
describe('productResults$', () => {
|
|
91
|
+
it('should initially be an empty array', () => {
|
|
92
|
+
const expected = cold('a', { a: []});
|
|
93
|
+
expect(facade.productResults$).toBeObservable(expected);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('should be the productResults upon a successful load', () => {
|
|
97
|
+
const expected = cold('a', { a: [mockSearchResult]});
|
|
98
|
+
store.dispatch(new DaffSearchLoadSuccess(mockSearchResultResponse));
|
|
99
|
+
store.dispatch(new DaffProductGridLoadSuccess([mockSearchResult]));
|
|
100
|
+
expect(facade.productResults$).toBeObservable(expected);
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Action,
|
|
3
|
+
Store,
|
|
4
|
+
select,
|
|
5
|
+
} from '@ngrx/store';
|
|
6
|
+
import { Observable } from 'rxjs';
|
|
7
|
+
|
|
8
|
+
import { DaffProduct } from '@daffodil/product';
|
|
9
|
+
|
|
10
|
+
import { DaffSearchProductStateRootSlice } from '../../reducers/public_api';
|
|
11
|
+
import { DaffSearchProductSelectors } from '../../selectors/public_api';
|
|
12
|
+
import { DaffSearchProductFacadeInterface } from './search-facade.interface';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @inheritdoc
|
|
16
|
+
*/
|
|
17
|
+
export abstract class DaffSearchProductFacade implements DaffSearchProductFacadeInterface {
|
|
18
|
+
productResults$: Observable<DaffProduct[]>;
|
|
19
|
+
|
|
20
|
+
constructor(
|
|
21
|
+
private store: Store<DaffSearchProductStateRootSlice>,
|
|
22
|
+
selectors: DaffSearchProductSelectors,
|
|
23
|
+
) {
|
|
24
|
+
const {
|
|
25
|
+
selectProductResults,
|
|
26
|
+
} = selectors;
|
|
27
|
+
|
|
28
|
+
this.productResults$ = this.store.pipe(select(selectProductResults));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
dispatch(action: Action) {
|
|
32
|
+
this.store.dispatch(action);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './public_api';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { NgModule } from '@angular/core';
|
|
2
|
+
import { EffectsModule } from '@ngrx/effects';
|
|
3
|
+
|
|
4
|
+
import { DaffSearchPageStateModule } from '@daffodil/search/state';
|
|
5
|
+
|
|
6
|
+
import { DaffSearchProductStateCoreModule } from './core.module';
|
|
7
|
+
import { DaffSearchProductCollectionEffects } from './effects/collection.effects';
|
|
8
|
+
|
|
9
|
+
@NgModule({
|
|
10
|
+
imports: [
|
|
11
|
+
DaffSearchProductStateCoreModule,
|
|
12
|
+
DaffSearchPageStateModule,
|
|
13
|
+
EffectsModule.forFeature([
|
|
14
|
+
DaffSearchProductCollectionEffects,
|
|
15
|
+
]),
|
|
16
|
+
],
|
|
17
|
+
})
|
|
18
|
+
export class DaffSearchProductPageStateModule {}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from './reducers/public_api';
|
|
2
|
+
export * from './selectors/public_api';
|
|
3
|
+
export * from './facades/public_api';
|
|
4
|
+
export * from './actions/product-collection.actions';
|
|
5
|
+
|
|
6
|
+
export { DaffSearchProductStateModule } from './state.module';
|
|
7
|
+
export { DaffSearchProductPageStateModule } from './page.module';
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import {
|
|
2
|
+
daffApplyRequestsToFilters,
|
|
3
|
+
daffClearFilters,
|
|
4
|
+
DaffCollectionMetadata,
|
|
5
|
+
DaffCollectionRequest,
|
|
6
|
+
daffRemoveRequestsFromFilters,
|
|
7
|
+
daffToggleRequestOnFilters,
|
|
8
|
+
} from '@daffodil/core';
|
|
9
|
+
import {
|
|
10
|
+
daffCollectionReducerInitialState,
|
|
11
|
+
getCollectionStateAdapter,
|
|
12
|
+
} from '@daffodil/core/state';
|
|
13
|
+
import {
|
|
14
|
+
DaffSearchActions,
|
|
15
|
+
DaffSearchActionTypes,
|
|
16
|
+
} from '@daffodil/search/state';
|
|
17
|
+
|
|
18
|
+
import {
|
|
19
|
+
DaffSearchProductCollectionActions,
|
|
20
|
+
DaffSearchProductCollectionActionTypes,
|
|
21
|
+
} from '../../actions/product-collection.actions';
|
|
22
|
+
|
|
23
|
+
export const daffSearchProductCollectionReducer = (
|
|
24
|
+
state: DaffCollectionMetadata = daffCollectionReducerInitialState,
|
|
25
|
+
action: DaffSearchActions | DaffSearchProductCollectionActions,
|
|
26
|
+
): DaffCollectionMetadata => {
|
|
27
|
+
switch (action.type) {
|
|
28
|
+
case DaffSearchActionTypes.SearchLoadAction:
|
|
29
|
+
return getCollectionStateAdapter().storeRequest(<DaffCollectionRequest>action.options, state);
|
|
30
|
+
|
|
31
|
+
case DaffSearchActionTypes.SearchLoadSuccessAction:
|
|
32
|
+
return getCollectionStateAdapter().setMetadata(<DaffCollectionMetadata>action.payload.metadata, state);
|
|
33
|
+
|
|
34
|
+
case DaffSearchProductCollectionActionTypes.SearchProductChangePageSizeAction:
|
|
35
|
+
return getCollectionStateAdapter().setPageSize(action.pageSize, state);
|
|
36
|
+
|
|
37
|
+
case DaffSearchProductCollectionActionTypes.SearchProductChangeCurrentPageAction:
|
|
38
|
+
return getCollectionStateAdapter().setCurrentPage(action.currentPage, state);
|
|
39
|
+
|
|
40
|
+
case DaffSearchProductCollectionActionTypes.SearchProductChangeSortingOptionAction:
|
|
41
|
+
return getCollectionStateAdapter().setSort(action.sort.option, action.sort.direction, state);
|
|
42
|
+
|
|
43
|
+
case DaffSearchProductCollectionActionTypes.SearchProductReplaceFiltersAction:
|
|
44
|
+
return getCollectionStateAdapter().setFilters(daffApplyRequestsToFilters(action.filters, daffClearFilters(state.filters)), state);
|
|
45
|
+
|
|
46
|
+
case DaffSearchProductCollectionActionTypes.SearchProductApplyFiltersAction:
|
|
47
|
+
return getCollectionStateAdapter().setFilters(daffApplyRequestsToFilters(action.filters, state.filters), state);
|
|
48
|
+
|
|
49
|
+
case DaffSearchProductCollectionActionTypes.SearchProductClearFiltersAction:
|
|
50
|
+
return getCollectionStateAdapter().setFilters(daffClearFilters(state.filters), state);
|
|
51
|
+
|
|
52
|
+
case DaffSearchProductCollectionActionTypes.SearchProductRemoveFiltersAction:
|
|
53
|
+
return getCollectionStateAdapter().setFilters(daffRemoveRequestsFromFilters(action.filters, state.filters), state);
|
|
54
|
+
|
|
55
|
+
case DaffSearchProductCollectionActionTypes.SearchProductToggleFiltersAction:
|
|
56
|
+
return getCollectionStateAdapter().setFilters(daffToggleRequestOnFilters(action.filter, state.filters), state);
|
|
57
|
+
|
|
58
|
+
case DaffSearchActionTypes.SearchLoadFailureAction:
|
|
59
|
+
return daffCollectionReducerInitialState;
|
|
60
|
+
|
|
61
|
+
default:
|
|
62
|
+
return state;
|
|
63
|
+
}
|
|
64
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ActionReducerMap } from '@ngrx/store';
|
|
2
|
+
|
|
3
|
+
import { daffIdentityReducer } from '@daffodil/core/state';
|
|
4
|
+
import { DaffSearchReducersState } from '@daffodil/search/state';
|
|
5
|
+
|
|
6
|
+
import { daffSearchProductCollectionSearchReducer } from './search.reducer';
|
|
7
|
+
|
|
8
|
+
export const daffSearchProductCollectionSearchReducers: ActionReducerMap<DaffSearchReducersState> = {
|
|
9
|
+
search: daffSearchProductCollectionSearchReducer,
|
|
10
|
+
incremental: daffIdentityReducer,
|
|
11
|
+
};
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DaffSearchProductCollectionApplyFilters,
|
|
3
|
+
DaffSearchProductCollectionReplaceFilters,
|
|
4
|
+
DaffSearchProductCollectionRemoveFilters,
|
|
5
|
+
DaffSearchProductCollectionClearFilters,
|
|
6
|
+
DaffSearchProductCollectionToggleFilter,
|
|
7
|
+
DaffSearchProductCollectionChangeCurrentPage,
|
|
8
|
+
DaffSearchProductCollectionChangePageSize,
|
|
9
|
+
DaffSearchProductCollectionChangeSortingOption,
|
|
10
|
+
} from '@daffodil/search-product/state';
|
|
11
|
+
import {
|
|
12
|
+
daffSearchInitialState as initialState,
|
|
13
|
+
DaffSearchReducerState,
|
|
14
|
+
} from '@daffodil/search/state';
|
|
15
|
+
|
|
16
|
+
import { daffSearchProductCollectionSearchReducer as reducer } from './search.reducer';
|
|
17
|
+
|
|
18
|
+
describe('@daffodil/search-product-product/state | daffSearchProductCollectionSearchReducer', () => {
|
|
19
|
+
describe('when an unknown action is triggered', () => {
|
|
20
|
+
it('should return the current state', () => {
|
|
21
|
+
const action = <any>{};
|
|
22
|
+
|
|
23
|
+
const result = reducer(initialState, action);
|
|
24
|
+
|
|
25
|
+
expect(result).toBe(initialState);
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
describe('when SearchProductCollectionApplyFiltersAction is triggered', () => {
|
|
30
|
+
let result: DaffSearchReducerState;
|
|
31
|
+
|
|
32
|
+
beforeEach(() => {
|
|
33
|
+
const searchResultLoadAction = new DaffSearchProductCollectionApplyFilters([]);
|
|
34
|
+
|
|
35
|
+
result = reducer({
|
|
36
|
+
...initialState,
|
|
37
|
+
}, searchResultLoadAction);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('sets loading state to true', () => {
|
|
41
|
+
expect(result.loading).toEqual(true);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
describe('when SearchProductCollectionReplaceFiltersAction is triggered', () => {
|
|
46
|
+
let result: DaffSearchReducerState;
|
|
47
|
+
|
|
48
|
+
beforeEach(() => {
|
|
49
|
+
const searchResultLoadAction = new DaffSearchProductCollectionReplaceFilters([]);
|
|
50
|
+
|
|
51
|
+
result = reducer({
|
|
52
|
+
...initialState,
|
|
53
|
+
}, searchResultLoadAction);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('sets loading state to true', () => {
|
|
57
|
+
expect(result.loading).toEqual(true);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe('when SearchProductCollectionRemoveFiltersAction is triggered', () => {
|
|
62
|
+
let result: DaffSearchReducerState;
|
|
63
|
+
|
|
64
|
+
beforeEach(() => {
|
|
65
|
+
const searchResultLoadAction = new DaffSearchProductCollectionRemoveFilters([]);
|
|
66
|
+
|
|
67
|
+
result = reducer({
|
|
68
|
+
...initialState,
|
|
69
|
+
}, searchResultLoadAction);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('sets loading state to true', () => {
|
|
73
|
+
expect(result.loading).toEqual(true);
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
describe('when SearchProductCollectionClearFiltersAction is triggered', () => {
|
|
78
|
+
let result: DaffSearchReducerState;
|
|
79
|
+
|
|
80
|
+
beforeEach(() => {
|
|
81
|
+
const searchResultLoadAction = new DaffSearchProductCollectionClearFilters();
|
|
82
|
+
|
|
83
|
+
result = reducer({
|
|
84
|
+
...initialState,
|
|
85
|
+
}, searchResultLoadAction);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('sets loading state to true', () => {
|
|
89
|
+
expect(result.loading).toEqual(true);
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
describe('when SearchProductCollectionToggleFilterAction is triggered', () => {
|
|
94
|
+
let result: DaffSearchReducerState;
|
|
95
|
+
|
|
96
|
+
beforeEach(() => {
|
|
97
|
+
const searchResultLoadAction = new DaffSearchProductCollectionToggleFilter(null);
|
|
98
|
+
|
|
99
|
+
result = reducer({
|
|
100
|
+
...initialState,
|
|
101
|
+
}, searchResultLoadAction);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('sets loading state to true', () => {
|
|
105
|
+
expect(result.loading).toEqual(true);
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
describe('when SearchProductCollectionChangeCurrentPageAction is triggered', () => {
|
|
110
|
+
let result: DaffSearchReducerState;
|
|
111
|
+
|
|
112
|
+
beforeEach(() => {
|
|
113
|
+
const searchResultLoadAction = new DaffSearchProductCollectionChangeCurrentPage(5);
|
|
114
|
+
|
|
115
|
+
result = reducer({
|
|
116
|
+
...initialState,
|
|
117
|
+
}, searchResultLoadAction);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('sets loading state to true', () => {
|
|
121
|
+
expect(result.loading).toEqual(true);
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
describe('when SearchProductCollectionChangePageSizeAction is triggered', () => {
|
|
126
|
+
let result: DaffSearchReducerState;
|
|
127
|
+
|
|
128
|
+
beforeEach(() => {
|
|
129
|
+
const searchResultLoadAction = new DaffSearchProductCollectionChangePageSize(5);
|
|
130
|
+
|
|
131
|
+
result = reducer({
|
|
132
|
+
...initialState,
|
|
133
|
+
}, searchResultLoadAction);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it('sets loading state to true', () => {
|
|
137
|
+
expect(result.loading).toEqual(true);
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
describe('when SearchProductCollectionChangeSortingOptionAction is triggered', () => {
|
|
142
|
+
let result: DaffSearchReducerState;
|
|
143
|
+
|
|
144
|
+
beforeEach(() => {
|
|
145
|
+
const searchResultLoadAction = new DaffSearchProductCollectionChangeSortingOption(null);
|
|
146
|
+
|
|
147
|
+
result = reducer({
|
|
148
|
+
...initialState,
|
|
149
|
+
}, searchResultLoadAction);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it('sets loading state to true', () => {
|
|
153
|
+
expect(result.loading).toEqual(true);
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import {
|
|
2
|
+
daffSearchInitialState,
|
|
3
|
+
DaffSearchReducerState,
|
|
4
|
+
} from '@daffodil/search/state';
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
DaffSearchProductCollectionActions,
|
|
8
|
+
DaffSearchProductCollectionActionTypes,
|
|
9
|
+
} from '../../actions/product-collection.actions';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The reducer for handling apply product filters actions in the main search state.
|
|
13
|
+
*/
|
|
14
|
+
export function daffSearchProductCollectionSearchReducer(
|
|
15
|
+
state = daffSearchInitialState,
|
|
16
|
+
action: DaffSearchProductCollectionActions,
|
|
17
|
+
): DaffSearchReducerState {
|
|
18
|
+
switch (action.type) {
|
|
19
|
+
case DaffSearchProductCollectionActionTypes.SearchProductApplyFiltersAction:
|
|
20
|
+
case DaffSearchProductCollectionActionTypes.SearchProductReplaceFiltersAction:
|
|
21
|
+
case DaffSearchProductCollectionActionTypes.SearchProductRemoveFiltersAction:
|
|
22
|
+
case DaffSearchProductCollectionActionTypes.SearchProductClearFiltersAction:
|
|
23
|
+
case DaffSearchProductCollectionActionTypes.SearchProductToggleFiltersAction:
|
|
24
|
+
case DaffSearchProductCollectionActionTypes.SearchProductChangeCurrentPageAction:
|
|
25
|
+
case DaffSearchProductCollectionActionTypes.SearchProductChangePageSizeAction:
|
|
26
|
+
case DaffSearchProductCollectionActionTypes.SearchProductChangeSortingOptionAction:
|
|
27
|
+
return {
|
|
28
|
+
...state,
|
|
29
|
+
loading: true,
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
default:
|
|
33
|
+
return state;
|
|
34
|
+
}
|
|
35
|
+
}
|