2018-08-22 17:54:48 +00:00
|
|
|
/** @format */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { merge } from 'lodash';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import { ERROR } from 'store/constants';
|
2018-09-03 15:25:38 +00:00
|
|
|
import { getJsonString } from 'store/utils';
|
2018-08-22 17:54:48 +00:00
|
|
|
|
|
|
|
const DEFAULT_STATE = {};
|
|
|
|
|
|
|
|
export default function reportStatsReducer( state = DEFAULT_STATE, action ) {
|
|
|
|
if ( 'SET_REPORT_STATS' === action.type ) {
|
|
|
|
const queryKey = getJsonString( action.query );
|
|
|
|
return merge( {}, state, {
|
|
|
|
[ action.endpoint ]: {
|
2018-09-03 15:25:38 +00:00
|
|
|
[ queryKey ]: {
|
2018-09-04 14:10:07 +00:00
|
|
|
data: action.report,
|
2018-09-03 15:25:38 +00:00
|
|
|
totalResults: action.totalResults,
|
|
|
|
totalPages: action.totalPages,
|
|
|
|
},
|
2018-08-22 17:54:48 +00:00
|
|
|
},
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( 'SET_REPORT_STATS_ERROR' === action.type ) {
|
|
|
|
const queryKey = getJsonString( action.query );
|
|
|
|
return merge( {}, state, {
|
|
|
|
[ action.endpoint ]: {
|
|
|
|
[ queryKey ]: ERROR,
|
|
|
|
},
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
return state;
|
|
|
|
}
|