-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(showcase): update generic-search actions style
- Loading branch information
1 parent
6c3f35a
commit 7dd7c09
Showing
11 changed files
with
84 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 13 additions & 48 deletions
61
showcase/src/app/demo-ui/pages/generic-search/actions/demo-generic-search.actions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,14 @@ | ||
import { Action } from "@ngrx/store"; | ||
import { createAction, props, union } from "@ngrx/store"; | ||
import { HeroMovieSearchCriteria } from "../entities"; | ||
|
||
export enum DemoGenericActionTypes { | ||
SET_DEMO_GENERIC_SEARCH_CRITERIA = "[DemoGenericSearch] Set criteria", | ||
REMOVE_DEMO_GENERIC_SEARCH_CRITERIA = "[DemoGenericSearch] Remove criteria", | ||
DEMO_GENERIC_HAS_SEARCHED = "[DemoGenericSearch] Has searched", | ||
DEMO_GENERIC_HAS_SEARCHED_RESET = "[DemoGenericSearch] Has searched reset" | ||
} | ||
|
||
export class DemoGenericSearchSetCriteria implements Action { | ||
/** | ||
* The type of action | ||
*/ | ||
public readonly type: DemoGenericActionTypes.SET_DEMO_GENERIC_SEARCH_CRITERIA = DemoGenericActionTypes.SET_DEMO_GENERIC_SEARCH_CRITERIA; | ||
/** | ||
* Class constructor | ||
* @param criteria - Criteria to be set | ||
*/ | ||
public constructor(public criteria: HeroMovieSearchCriteria) {} | ||
} | ||
|
||
export class DemoGenericSearchRemoveCriteria implements Action { | ||
/** | ||
* The type of action | ||
*/ | ||
public readonly type: DemoGenericActionTypes.REMOVE_DEMO_GENERIC_SEARCH_CRITERIA = | ||
DemoGenericActionTypes.REMOVE_DEMO_GENERIC_SEARCH_CRITERIA; | ||
} | ||
|
||
export class DemoGenericSearchHasSearched implements Action { | ||
/** | ||
* The type of action | ||
*/ | ||
public readonly type: DemoGenericActionTypes.DEMO_GENERIC_HAS_SEARCHED = DemoGenericActionTypes.DEMO_GENERIC_HAS_SEARCHED; | ||
} | ||
|
||
export class DemoGenericSearchHasSearchedReset implements Action { | ||
/** | ||
* The type of action | ||
*/ | ||
public readonly type: DemoGenericActionTypes.DEMO_GENERIC_HAS_SEARCHED_RESET = DemoGenericActionTypes.DEMO_GENERIC_HAS_SEARCHED_RESET; | ||
} | ||
|
||
export type DemoGenericSearchActions = | ||
| DemoGenericSearchRemoveCriteria | ||
| DemoGenericSearchHasSearchedReset | ||
| DemoGenericSearchHasSearched | ||
| DemoGenericSearchSetCriteria; | ||
import { demoGenericSearchStoreKey } from "../constants"; | ||
|
||
export const setCriteria = createAction(`[${demoGenericSearchStoreKey}] Set criteria`, props<{ criteria: HeroMovieSearchCriteria }>()); | ||
export const removeCriteria = createAction(`[${demoGenericSearchStoreKey}] Remove criteria`); | ||
export const hasSearched = createAction(`[${demoGenericSearchStoreKey}] Has searched`); | ||
export const hasSearchedReset = createAction(`[${demoGenericSearchStoreKey}] Has searched reset`); | ||
|
||
/** | ||
* @ignore | ||
*/ | ||
const all = union({ setCriteria, removeCriteria, hasSearched, hasSearchedReset }); | ||
export type Types = typeof all; |
3 changes: 2 additions & 1 deletion
3
showcase/src/app/demo-ui/pages/generic-search/actions/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from "./demo-generic-search.actions"; | ||
import * as DemoGenericSearchActions from "./demo-generic-search.actions"; | ||
export { DemoGenericSearchActions }; |
4 changes: 4 additions & 0 deletions
4
showcase/src/app/demo-ui/pages/generic-search/constants/demo-generic-search-store-key.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/** | ||
* Key defined to find the service in a store | ||
*/ | ||
export const demoGenericSearchStoreKey = "DemoGenericSearch"; |
1 change: 1 addition & 0 deletions
1
showcase/src/app/demo-ui/pages/generic-search/constants/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./demo-generic-search-store-key"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 13 additions & 15 deletions
28
showcase/src/app/demo-ui/pages/generic-search/reducers/demo-generic-search.reducer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,24 @@ | ||
import { StarkSearchState } from "@nationalbankbelgium/stark-ui"; | ||
import { HeroMovieSearchCriteria } from "../entities"; | ||
import { DemoGenericActionTypes, DemoGenericSearchActions } from "../actions"; | ||
import { DemoGenericSearchActions } from "../actions"; | ||
import {createReducer, on} from "@ngrx/store"; | ||
|
||
const INITIAL_STATE: Readonly<StarkSearchState<HeroMovieSearchCriteria>> = { | ||
criteria: new HeroMovieSearchCriteria(), | ||
hasBeenSearched: false | ||
}; | ||
|
||
const reducer = createReducer<StarkSearchState<HeroMovieSearchCriteria>, DemoGenericSearchActions.Types>( | ||
INITIAL_STATE, | ||
on(DemoGenericSearchActions.setCriteria, (state, action) => ({ ...state, criteria: action.criteria })), | ||
on(DemoGenericSearchActions.removeCriteria, (state) => ({ ...state, criteria: INITIAL_STATE.criteria })), | ||
on(DemoGenericSearchActions.hasSearched, (state) => ({ ...state, hasBeenSearched: true })), | ||
on(DemoGenericSearchActions.hasSearchedReset, (state) => ({ ...state, hasBeenSearched: false })) | ||
) | ||
|
||
export function demoGenericSearchReducer( | ||
state: Readonly<StarkSearchState<HeroMovieSearchCriteria>> = INITIAL_STATE, | ||
action: Readonly<DemoGenericSearchActions> | ||
state: Readonly<StarkSearchState<HeroMovieSearchCriteria>> | undefined, | ||
action: Readonly<DemoGenericSearchActions.Types> | ||
): Readonly<StarkSearchState<HeroMovieSearchCriteria>> { | ||
switch (action.type) { | ||
case DemoGenericActionTypes.SET_DEMO_GENERIC_SEARCH_CRITERIA: | ||
return { ...state, criteria: action.criteria }; | ||
case DemoGenericActionTypes.REMOVE_DEMO_GENERIC_SEARCH_CRITERIA: | ||
return { ...state, criteria: INITIAL_STATE.criteria }; | ||
case DemoGenericActionTypes.DEMO_GENERIC_HAS_SEARCHED: | ||
return { ...state, hasBeenSearched: true }; | ||
case DemoGenericActionTypes.DEMO_GENERIC_HAS_SEARCHED_RESET: | ||
return { ...state, hasBeenSearched: false }; | ||
default: | ||
return state; | ||
} | ||
return reducer(state, action); | ||
} |
9 changes: 5 additions & 4 deletions
9
showcase/src/app/demo-ui/pages/generic-search/reducers/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,19 @@ | ||
import { StarkSearchState } from "@nationalbankbelgium/stark-ui"; | ||
import { ActionReducerMap, createSelector, MemoizedSelector, createFeatureSelector } from "@ngrx/store"; | ||
import { ActionReducerMap, createSelector, createFeatureSelector } from "@ngrx/store"; | ||
import { HeroMovieSearchCriteria } from "../entities"; | ||
import { DemoGenericSearchActions } from "../actions"; | ||
import { demoGenericSearchReducer } from "./demo-generic-search.reducer"; | ||
import { demoGenericSearchStoreKey } from "../constants"; | ||
|
||
export interface DemoGenericSearchState { | ||
demoGenericSearch: StarkSearchState<HeroMovieSearchCriteria>; | ||
} | ||
|
||
export const demoGenericSearchReducers: ActionReducerMap<DemoGenericSearchState, DemoGenericSearchActions> = { | ||
export const demoGenericSearchReducers: ActionReducerMap<DemoGenericSearchState, DemoGenericSearchActions.Types> = { | ||
demoGenericSearch: demoGenericSearchReducer | ||
}; | ||
|
||
export const selectDemoGenericSearch: MemoizedSelector<object, StarkSearchState<HeroMovieSearchCriteria>> = createSelector( | ||
createFeatureSelector<DemoGenericSearchState>("DemoGenericSearch"), | ||
export const selectDemoGenericSearch = createSelector( | ||
createFeatureSelector<DemoGenericSearchState>(demoGenericSearchStoreKey), | ||
(state: DemoGenericSearchState) => state.demoGenericSearch | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters