2018-12-05 17:10:54 +00:00
|
|
|
/** @format */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { isNil } from 'lodash';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import { getResourceName } from '../../utils';
|
|
|
|
import { DEFAULT_REQUIREMENT } from '../../constants';
|
|
|
|
|
|
|
|
const getReportItems = ( getResource, requireResource ) => (
|
|
|
|
type,
|
|
|
|
query = {},
|
|
|
|
requirement = DEFAULT_REQUIREMENT
|
|
|
|
) => {
|
|
|
|
const resourceName = getResourceName( `report-items-query-${ type }`, query );
|
2018-12-05 23:12:34 +00:00
|
|
|
return requireResource( requirement, resourceName ) || {};
|
2018-12-05 17:10:54 +00:00
|
|
|
};
|
|
|
|
|
2018-12-05 23:12:34 +00:00
|
|
|
const isReportItemsRequesting = getResource => ( type, query = {} ) => {
|
2018-12-05 17:10:54 +00:00
|
|
|
const resourceName = getResourceName( `report-items-query-${ type }`, query );
|
|
|
|
const { lastRequested, lastReceived } = getResource( resourceName );
|
|
|
|
|
2018-12-05 18:39:51 +00:00
|
|
|
if ( isNil( lastRequested ) || isNil( lastReceived ) ) {
|
2018-12-05 17:10:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return lastRequested > lastReceived;
|
|
|
|
};
|
|
|
|
|
2018-12-05 23:12:34 +00:00
|
|
|
const isReportItemsError = getResource => ( type, query = {} ) => {
|
2018-12-05 17:10:54 +00:00
|
|
|
const resourceName = getResourceName( `report-items-query-${ type }`, query );
|
|
|
|
return getResource( resourceName ).error;
|
|
|
|
};
|
|
|
|
|
|
|
|
export default {
|
|
|
|
getReportItems,
|
2018-12-05 23:12:34 +00:00
|
|
|
isReportItemsRequesting,
|
|
|
|
isReportItemsError,
|
2018-12-05 17:10:54 +00:00
|
|
|
};
|