Hook stock panel up to real data.

This commit is contained in:
Jeff Stieler 2019-04-01 15:34:17 -06:00
parent ad7cc4226a
commit 5d09ceb272
1 changed files with 59 additions and 16 deletions

View File

@ -4,11 +4,13 @@
*/ */
import { __ } from '@wordpress/i18n'; import { __ } from '@wordpress/i18n';
import { Component, Fragment } from '@wordpress/element'; import { Component, Fragment } from '@wordpress/element';
import { compose } from '@wordpress/compose';
import PropTypes from 'prop-types';
/** /**
* WooCommerce dependencies * WooCommerce dependencies
*/ */
import { Section } from '@woocommerce/components'; import { EmptyContent, Section } from '@woocommerce/components';
/** /**
* Internal dependencies * Internal dependencies
@ -16,23 +18,35 @@ import { Section } from '@woocommerce/components';
import { ActivityCardPlaceholder } from '../../activity-card'; import { ActivityCardPlaceholder } from '../../activity-card';
import ActivityHeader from '../../activity-header'; import ActivityHeader from '../../activity-header';
import ProductStockCard from './card'; import ProductStockCard from './card';
import { QUERY_DEFAULTS } from 'wc-api/constants';
import withSelect from 'wc-api/with-select';
class StockPanel extends Component { class StockPanel extends Component {
render() { render() {
const products = [ const { isError, isRequesting, products } = this.props;
{
id: 913, if ( isError ) {
parent_id: 911, const title = __(
type: 'variation', 'There was an error getting your low stock products. Please try again.',
name: 'Octopus Tshirt', 'woocommerce-admin'
permalink: '', );
image: { const actionLabel = __( 'Reload', 'woocommerce-admin' );
src: '/wp-content/uploads/2018/12/img-206939428-150x150.png', const actionCallback = () => {
}, // @todo Add tracking for how often an error is displayed, and the reload action is clicked.
stock_quantity: 2, window.location.reload();
}, };
];
const isRequesting = false; return (
<Fragment>
<EmptyContent
title={ title }
actionLabel={ actionLabel }
actionURL={ null }
actionCallback={ actionCallback }
/>
</Fragment>
);
}
return ( return (
<Fragment> <Fragment>
@ -53,4 +67,33 @@ class StockPanel extends Component {
} }
} }
export default StockPanel; StockPanel.propTypes = {
products: PropTypes.array.isRequired,
isError: PropTypes.bool,
isRequesting: PropTypes.bool,
};
StockPanel.defaultProps = {
products: [],
isError: false,
isRequesting: false,
};
export default compose(
withSelect( select => {
const { getItems, getItemsError, isGetItemsRequesting } = select( 'wc-api' );
const productsQuery = {
page: 1,
per_page: QUERY_DEFAULTS.pageSize,
low_in_stock: true,
status: 'publish',
};
const products = Array.from( getItems( 'products', productsQuery ).values() );
const isError = Boolean( getItemsError( 'products', productsQuery ) );
const isRequesting = isGetItemsRequesting( 'products', productsQuery );
return { products, isError, isRequesting };
} )
)( StockPanel );