2019-06-11 12:47:53 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { isNil } from 'lodash';
|
2019-05-20 20:50:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import { getResourceName } from '../utils';
|
|
|
|
import { DEFAULT_REQUIREMENT } from '../constants';
|
|
|
|
|
2019-06-11 12:47:53 +00:00
|
|
|
const getImportStatus = ( getResource, requireResource ) => (
|
|
|
|
timestamp,
|
|
|
|
requirement = DEFAULT_REQUIREMENT
|
|
|
|
) => {
|
|
|
|
const resourceName = getResourceName( 'import-status', timestamp );
|
|
|
|
return requireResource( requirement, resourceName ).data || {};
|
|
|
|
};
|
|
|
|
|
2020-02-14 02:23:21 +00:00
|
|
|
const isGetImportStatusRequesting = ( getResource ) => ( timestamp ) => {
|
2019-06-11 12:47:53 +00:00
|
|
|
const resourceName = getResourceName( 'import-status', timestamp );
|
|
|
|
const { lastRequested, lastReceived } = getResource( resourceName );
|
|
|
|
|
|
|
|
if ( isNil( lastRequested ) || isNil( lastReceived ) ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return lastRequested > lastReceived;
|
|
|
|
};
|
|
|
|
|
2019-05-20 20:50:25 +00:00
|
|
|
const getImportTotals = ( getResource, requireResource ) => (
|
|
|
|
query = {},
|
2019-06-11 12:47:53 +00:00
|
|
|
timestamp,
|
2019-05-20 20:50:25 +00:00
|
|
|
requirement = DEFAULT_REQUIREMENT
|
|
|
|
) => {
|
2019-06-11 12:47:53 +00:00
|
|
|
const identifier = { ...query, timestamp };
|
|
|
|
const resourceName = getResourceName( 'import-totals', identifier );
|
|
|
|
return requireResource( requirement, resourceName ).data || {};
|
2019-05-20 20:50:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default {
|
2019-06-11 12:47:53 +00:00
|
|
|
getImportStatus,
|
|
|
|
isGetImportStatusRequesting,
|
2019-05-20 20:50:25 +00:00
|
|
|
getImportTotals,
|
|
|
|
};
|