woocommerce/plugins/woocommerce-admin/client/wc-api/reports/items/selectors.js

46 lines
1.1 KiB
JavaScript
Raw Normal View History

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 );
const data = requireResource( requirement, resourceName ) || {};
return data;
};
const isGetReportItemsRequesting = getResource => ( type, query = {} ) => {
const resourceName = getResourceName( `report-items-query-${ type }`, query );
const { lastRequested, lastReceived } = getResource( resourceName );
if ( isNil( lastRequested ) || isNil( lastReceived ) ) {
2018-12-05 17:10:54 +00:00
return true;
}
return lastRequested > lastReceived;
};
const isGetReportItemsError = getResource => ( type, query = {} ) => {
const resourceName = getResourceName( `report-items-query-${ type }`, query );
return getResource( resourceName ).error;
};
export default {
getReportItems,
isGetReportItemsRequesting,
isGetReportItemsError,
};