actions.js
2 years ago
constants.js
2 years ago
dispatchers.js
2 years ago
index.js
2 years ago
reducer.js
2 years ago
selectors.js
2 years ago
selectors.js
74 lines
| 1 | const selectors = { |
| 2 | getTypeIndex( state, slug ) { |
| 3 | return state.types.findIndex( event => event.value === slug ); |
| 4 | }, |
| 5 | getTypes( state ) { |
| 6 | return state.types; |
| 7 | }, |
| 8 | getGatewayTypes( state ) { |
| 9 | return state.types.filter( event => ( |
| 10 | 'gateway' in event |
| 11 | ) ); |
| 12 | }, |
| 13 | getAlwaysTypes( state ) { |
| 14 | return state.types.filter( event => ( |
| 15 | 'always' in event |
| 16 | ) ); |
| 17 | }, |
| 18 | getDynamicTypes( state ) { |
| 19 | return state.types.filter( ( { isDynamic } ) => isDynamic ); |
| 20 | }, |
| 21 | getType( state, slug ) { |
| 22 | const index = selectors.getTypeIndex( state, slug ); |
| 23 | |
| 24 | return state.types[ index ]; |
| 25 | }, |
| 26 | getUnsupported( state, actionId ) { |
| 27 | const action = state.lockedActions[ actionId ] ?? false; |
| 28 | |
| 29 | if ( false === action ) { |
| 30 | return []; |
| 31 | } |
| 32 | |
| 33 | return action.unsupported; |
| 34 | }, |
| 35 | getSupported( state, actionId ) { |
| 36 | const action = state.lockedActions[ actionId ] ?? false; |
| 37 | |
| 38 | if ( false === action ) { |
| 39 | return []; |
| 40 | } |
| 41 | |
| 42 | return action.supported; |
| 43 | }, |
| 44 | isValid( state, actionId, eventSlug ) { |
| 45 | const unsupported = selectors.getUnsupported( state, actionId ); |
| 46 | |
| 47 | if ( unsupported.length && unsupported.includes( eventSlug ) ) { |
| 48 | return false; |
| 49 | } |
| 50 | |
| 51 | const supported = selectors.getSupported( state, actionId ); |
| 52 | |
| 53 | return ( |
| 54 | !supported.length || supported.includes( eventSlug ) |
| 55 | ); |
| 56 | }, |
| 57 | filterList( state, actionId, eventList ) { |
| 58 | return eventList.filter( |
| 59 | current => selectors.isValid( state, actionId, current ) ); |
| 60 | }, |
| 61 | getHelpMap( state ) { |
| 62 | const map = {}; |
| 63 | |
| 64 | for ( const { value, help } of state.types ) { |
| 65 | map[ value ] = help; |
| 66 | } |
| 67 | |
| 68 | return map; |
| 69 | }, |
| 70 | }; |
| 71 | |
| 72 | export default { |
| 73 | ...selectors, |
| 74 | }; |