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

51 lines
1.1 KiB
JavaScript
Raw Normal View History

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