2018-12-05 17:10:54 +00:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
) => {
|
2020-02-14 02:23:21 +00:00
|
|
|
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
|
|
|
};
|
|
|
|
|
2020-02-14 02:23:21 +00:00
|
|
|
const getReportItemsError = ( getResource ) => ( type, query = {} ) => {
|
|
|
|
const resourceName = getResourceName(
|
|
|
|
`report-items-query-${ type }`,
|
|
|
|
query
|
|
|
|
);
|
2018-12-15 12:38:54 +00:00
|
|
|
return getResource( resourceName ).error;
|
|
|
|
};
|
|
|
|
|
2020-02-14 02:23:21 +00:00
|
|
|
const isReportItemsRequesting = ( getResource ) => ( type, query = {} ) => {
|
|
|
|
const resourceName = getResourceName(
|
|
|
|
`report-items-query-${ type }`,
|
|
|
|
query
|
|
|
|
);
|
2018-12-05 17:10:54 +00:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
|
|
|
export default {
|
|
|
|
getReportItems,
|
2018-12-15 12:38:54 +00:00
|
|
|
getReportItemsError,
|
2018-12-05 23:12:34 +00:00
|
|
|
isReportItemsRequesting,
|
2018-12-05 17:10:54 +00:00
|
|
|
};
|