2018-10-11 23:33:18 +00:00
|
|
|
/** @format */
|
2018-10-12 19:20:48 +00:00
|
|
|
|
2018-10-16 19:46:00 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { get } from 'lodash';
|
|
|
|
import { select } from '@wordpress/data';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import { getJsonString } from 'store/utils';
|
|
|
|
import { ERROR } from 'store/constants';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns notes for a specific query.
|
|
|
|
*
|
|
|
|
* @param {Object} state Current state
|
|
|
|
* @param {Object} query Note query parameters
|
|
|
|
* @return {Array} Notes
|
|
|
|
*/
|
|
|
|
function getNotes( state, query = {} ) {
|
2018-10-16 20:07:34 +00:00
|
|
|
return get( state, [ 'notes', getJsonString( query ) ], [] );
|
2018-10-16 19:46:00 +00:00
|
|
|
}
|
|
|
|
|
2018-10-12 19:20:48 +00:00
|
|
|
export default {
|
2018-10-16 19:46:00 +00:00
|
|
|
getNotes,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if a query is pending.
|
|
|
|
*
|
|
|
|
* @param {Object} state Current state
|
|
|
|
* @return {Boolean} True if the `getNotes` request is pending, false otherwise
|
|
|
|
*/
|
|
|
|
isGetNotesRequesting( state, ...args ) {
|
|
|
|
return select( 'core/data' ).isResolving( 'wc-admin', 'getNotes', args );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if a get notes request has returned an error.
|
|
|
|
*
|
|
|
|
* @param {Object} state Current state
|
|
|
|
* @param {Object} query Query parameters
|
|
|
|
* @return {Boolean} True if the `getNotes` request has failed, false otherwise
|
|
|
|
*/
|
|
|
|
isGetNotesError( state, query ) {
|
|
|
|
return ERROR === getNotes( state, query );
|
2018-10-12 19:20:48 +00:00
|
|
|
},
|
|
|
|
};
|