2017-04-25 21:12:19 -07:00
|
|
|
import { initializeState, createUrnMapping, receiveEntities, createPageMapping } from 'wherehows-web/reducers/entities';
|
2017-04-21 15:43:48 -07:00
|
|
|
import { ActionTypes } from 'wherehows-web/actions/metrics';
|
|
|
|
|
|
|
|
/**
|
2017-04-25 19:40:04 -07:00
|
|
|
* Takes the `datasets` slice of the state tree and performs the specified reductions for each action
|
|
|
|
* @param {Object} state slice of the state tree this reducer is responsible for
|
2017-04-21 15:43:48 -07:00
|
|
|
* @param {Object} action Flux Standard Action representing the action to be preformed on the state
|
|
|
|
* @prop {String} action.type actionType
|
|
|
|
* @return {Object}
|
|
|
|
*/
|
2017-04-25 21:12:19 -07:00
|
|
|
export default (state = initializeState(), action = {}) => {
|
2017-04-21 15:43:48 -07:00
|
|
|
switch (action.type) {
|
2017-04-25 19:40:04 -07:00
|
|
|
// Action indicating a request for metrics by page
|
2017-04-21 15:43:48 -07:00
|
|
|
case ActionTypes.SELECT_PAGED_METRICS:
|
|
|
|
case ActionTypes.REQUEST_PAGED_METRICS:
|
|
|
|
return Object.assign({}, state, {
|
2017-04-25 19:40:04 -07:00
|
|
|
query: Object.assign({}, state.query, {
|
|
|
|
page: action.payload.page
|
|
|
|
}),
|
|
|
|
baseURL: action.payload.baseURL,
|
2017-04-21 15:43:48 -07:00
|
|
|
isFetching: true
|
|
|
|
});
|
2017-04-25 19:40:04 -07:00
|
|
|
// Action indicating a receipt of metrics by page
|
|
|
|
case ActionTypes.RECEIVE_PAGED_METRICS:
|
|
|
|
return Object.assign({}, state, {
|
2017-04-25 21:12:19 -07:00
|
|
|
isFetching: false,
|
|
|
|
byUrn: createUrnMapping('metrics')(state.byUrn, action.payload),
|
|
|
|
byId: receiveEntities('metrics')(state.byId, action.payload),
|
|
|
|
byPage: createPageMapping('metrics')(state.byPage, action.payload)
|
2017-04-25 19:40:04 -07:00
|
|
|
});
|
2017-04-21 15:43:48 -07:00
|
|
|
|
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
};
|