Activity Panel: set orders unread indicator based on real data (https://github.com/woocommerce/woocommerce-admin/pull/1824)
This commit is contained in:
parent
36a60c59d5
commit
58154d1d39
|
@ -20,6 +20,7 @@ import InboxPanel from './panels/inbox';
|
|||
import OrdersPanel from './panels/orders';
|
||||
import StockPanel from './panels/stock';
|
||||
import ReviewsPanel from './panels/reviews';
|
||||
import withSelect from 'wc-api/with-select';
|
||||
import WordPressNotices from './wordpress-notices';
|
||||
|
||||
class ActivityPanel extends Component {
|
||||
|
@ -91,6 +92,7 @@ class ActivityPanel extends Component {
|
|||
|
||||
// @todo Pull in dynamic unread status/count
|
||||
getTabs() {
|
||||
const { unreadOrders } = this.props;
|
||||
return [
|
||||
{
|
||||
name: 'inbox',
|
||||
|
@ -102,7 +104,7 @@ class ActivityPanel extends Component {
|
|||
name: 'orders',
|
||||
title: __( 'Orders', 'woocommerce-admin' ),
|
||||
icon: <Gridicon icon="pages" />,
|
||||
unread: true,
|
||||
unread: unreadOrders,
|
||||
},
|
||||
{
|
||||
name: 'stock',
|
||||
|
@ -124,7 +126,8 @@ class ActivityPanel extends Component {
|
|||
case 'inbox':
|
||||
return <InboxPanel />;
|
||||
case 'orders':
|
||||
return <OrdersPanel />;
|
||||
const { unreadOrders } = this.props;
|
||||
return <OrdersPanel isEmpty={ unreadOrders === false } />;
|
||||
case 'stock':
|
||||
return <StockPanel />;
|
||||
case 'reviews':
|
||||
|
@ -254,4 +257,36 @@ class ActivityPanel extends Component {
|
|||
}
|
||||
}
|
||||
|
||||
export default clickOutside( ActivityPanel );
|
||||
export default withSelect( select => {
|
||||
const { getReportItems, getReportItemsError, isReportItemsRequesting } = select( 'wc-api' );
|
||||
const orderStatuses = wcSettings.wcAdminSettings.woocommerce_actionable_order_statuses || [
|
||||
'processing',
|
||||
'on-hold',
|
||||
];
|
||||
|
||||
if ( ! orderStatuses.length ) {
|
||||
return { unreadOrders: false };
|
||||
}
|
||||
|
||||
const ordersQuery = {
|
||||
page: 1,
|
||||
per_page: 0,
|
||||
status_is: orderStatuses,
|
||||
};
|
||||
|
||||
const totalOrders = getReportItems( 'orders', ordersQuery ).totalResults;
|
||||
const isError = Boolean( getReportItemsError( 'orders', ordersQuery ) );
|
||||
const isRequesting = isReportItemsRequesting( 'orders', ordersQuery );
|
||||
|
||||
let unreadOrders = null;
|
||||
|
||||
if ( ! isError && ! isRequesting ) {
|
||||
if ( totalOrders > 0 ) {
|
||||
unreadOrders = true;
|
||||
} else {
|
||||
unreadOrders = false;
|
||||
}
|
||||
}
|
||||
|
||||
return { unreadOrders };
|
||||
} )( clickOutside( ActivityPanel ) );
|
||||
|
|
|
@ -217,12 +217,22 @@ OrdersPanel.defaultProps = {
|
|||
};
|
||||
|
||||
export default compose(
|
||||
withSelect( select => {
|
||||
withSelect( ( select, props ) => {
|
||||
const { getReportItems, getReportItemsError, isReportItemsRequesting } = select( 'wc-api' );
|
||||
const { isEmpty } = props;
|
||||
const orderStatuses = wcSettings.wcAdminSettings.woocommerce_actionable_order_statuses || [
|
||||
'processing',
|
||||
'on-hold',
|
||||
];
|
||||
|
||||
if ( ! orderStatuses.length ) {
|
||||
return { orders: [], isError: true, isRequesting: false, orderStatuses };
|
||||
}
|
||||
|
||||
if ( isEmpty ) {
|
||||
return { orders: [], isError: false, isRequesting: false, orderStatuses };
|
||||
}
|
||||
|
||||
const ordersQuery = {
|
||||
page: 1,
|
||||
per_page: QUERY_DEFAULTS.pageSize,
|
||||
|
@ -230,10 +240,6 @@ export default compose(
|
|||
extended_info: true,
|
||||
};
|
||||
|
||||
if ( ! orderStatuses.length ) {
|
||||
return { orders: [], isError: true, isRequesting: false, orderStatuses };
|
||||
}
|
||||
|
||||
const orders = getReportItems( 'orders', ordersQuery ).data;
|
||||
const isError = Boolean( getReportItemsError( 'orders', ordersQuery ) );
|
||||
const isRequesting = isReportItemsRequesting( 'orders', ordersQuery );
|
||||
|
|
|
@ -244,7 +244,7 @@ class WC_Admin_REST_Reports_Orders_Controller extends WC_Admin_REST_Reports_Cont
|
|||
'description' => __( 'Maximum number of items to be returned in result set.', 'woocommerce-admin' ),
|
||||
'type' => 'integer',
|
||||
'default' => 10,
|
||||
'minimum' => 1,
|
||||
'minimum' => 0,
|
||||
'maximum' => 100,
|
||||
'sanitize_callback' => 'absint',
|
||||
'validate_callback' => 'rest_validate_request_arg',
|
||||
|
|
|
@ -179,6 +179,10 @@ class WC_Admin_Reports_Orders_Data_Store extends WC_Admin_Reports_Data_Store imp
|
|||
|
||||
$total_pages = (int) ceil( $db_records_count / $sql_query_params['per_page'] );
|
||||
if ( $query_args['page'] < 1 || $query_args['page'] > $total_pages ) {
|
||||
$data = (object) array(
|
||||
'data' => array(),
|
||||
'total' => $db_records_count,
|
||||
);
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue