2018-11-16 03:35:10 +00:00
|
|
|
/** @format */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { merge } from 'lodash';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import { ERROR } from 'store/constants';
|
|
|
|
import { getJsonString } from 'store/utils';
|
|
|
|
|
|
|
|
const DEFAULT_STATE = {};
|
|
|
|
|
2018-11-22 23:12:12 +00:00
|
|
|
export default function reportItemsReducer( state = DEFAULT_STATE, action ) {
|
2018-11-16 03:35:10 +00:00
|
|
|
const queryKey = getJsonString( action.query );
|
|
|
|
|
|
|
|
switch ( action.type ) {
|
2018-11-22 23:12:12 +00:00
|
|
|
case 'SET_REPORT_ITEMS':
|
2018-11-16 03:35:10 +00:00
|
|
|
return merge( {}, state, {
|
2018-11-22 23:12:12 +00:00
|
|
|
[ action.endpoint ]: {
|
2018-11-29 14:03:04 +00:00
|
|
|
[ queryKey ]: {
|
|
|
|
data: action.data,
|
|
|
|
totalCount: action.totalCount,
|
|
|
|
},
|
2018-11-22 23:12:12 +00:00
|
|
|
},
|
2018-11-16 03:35:10 +00:00
|
|
|
} );
|
|
|
|
|
2018-11-22 23:12:12 +00:00
|
|
|
case 'SET_REPORT_ITEMS_ERROR':
|
2018-11-16 03:35:10 +00:00
|
|
|
return merge( {}, state, {
|
2018-11-22 23:12:12 +00:00
|
|
|
[ action.endpoint ]: {
|
|
|
|
[ queryKey ]: ERROR,
|
|
|
|
},
|
2018-11-16 03:35:10 +00:00
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
return state;
|
|
|
|
}
|