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 OrdersPanel from './panels/orders';
|
||||||
import StockPanel from './panels/stock';
|
import StockPanel from './panels/stock';
|
||||||
import ReviewsPanel from './panels/reviews';
|
import ReviewsPanel from './panels/reviews';
|
||||||
|
import withSelect from 'wc-api/with-select';
|
||||||
import WordPressNotices from './wordpress-notices';
|
import WordPressNotices from './wordpress-notices';
|
||||||
|
|
||||||
class ActivityPanel extends Component {
|
class ActivityPanel extends Component {
|
||||||
|
@ -91,6 +92,7 @@ class ActivityPanel extends Component {
|
||||||
|
|
||||||
// @todo Pull in dynamic unread status/count
|
// @todo Pull in dynamic unread status/count
|
||||||
getTabs() {
|
getTabs() {
|
||||||
|
const { unreadOrders } = this.props;
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
name: 'inbox',
|
name: 'inbox',
|
||||||
|
@ -102,7 +104,7 @@ class ActivityPanel extends Component {
|
||||||
name: 'orders',
|
name: 'orders',
|
||||||
title: __( 'Orders', 'woocommerce-admin' ),
|
title: __( 'Orders', 'woocommerce-admin' ),
|
||||||
icon: <Gridicon icon="pages" />,
|
icon: <Gridicon icon="pages" />,
|
||||||
unread: true,
|
unread: unreadOrders,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'stock',
|
name: 'stock',
|
||||||
|
@ -124,7 +126,8 @@ class ActivityPanel extends Component {
|
||||||
case 'inbox':
|
case 'inbox':
|
||||||
return <InboxPanel />;
|
return <InboxPanel />;
|
||||||
case 'orders':
|
case 'orders':
|
||||||
return <OrdersPanel />;
|
const { unreadOrders } = this.props;
|
||||||
|
return <OrdersPanel isEmpty={ unreadOrders === false } />;
|
||||||
case 'stock':
|
case 'stock':
|
||||||
return <StockPanel />;
|
return <StockPanel />;
|
||||||
case 'reviews':
|
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(
|
export default compose(
|
||||||
withSelect( select => {
|
withSelect( ( select, props ) => {
|
||||||
const { getReportItems, getReportItemsError, isReportItemsRequesting } = select( 'wc-api' );
|
const { getReportItems, getReportItemsError, isReportItemsRequesting } = select( 'wc-api' );
|
||||||
|
const { isEmpty } = props;
|
||||||
const orderStatuses = wcSettings.wcAdminSettings.woocommerce_actionable_order_statuses || [
|
const orderStatuses = wcSettings.wcAdminSettings.woocommerce_actionable_order_statuses || [
|
||||||
'processing',
|
'processing',
|
||||||
'on-hold',
|
'on-hold',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
if ( ! orderStatuses.length ) {
|
||||||
|
return { orders: [], isError: true, isRequesting: false, orderStatuses };
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( isEmpty ) {
|
||||||
|
return { orders: [], isError: false, isRequesting: false, orderStatuses };
|
||||||
|
}
|
||||||
|
|
||||||
const ordersQuery = {
|
const ordersQuery = {
|
||||||
page: 1,
|
page: 1,
|
||||||
per_page: QUERY_DEFAULTS.pageSize,
|
per_page: QUERY_DEFAULTS.pageSize,
|
||||||
|
@ -230,10 +240,6 @@ export default compose(
|
||||||
extended_info: true,
|
extended_info: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
if ( ! orderStatuses.length ) {
|
|
||||||
return { orders: [], isError: true, isRequesting: false, orderStatuses };
|
|
||||||
}
|
|
||||||
|
|
||||||
const orders = getReportItems( 'orders', ordersQuery ).data;
|
const orders = getReportItems( 'orders', ordersQuery ).data;
|
||||||
const isError = Boolean( getReportItemsError( 'orders', ordersQuery ) );
|
const isError = Boolean( getReportItemsError( 'orders', ordersQuery ) );
|
||||||
const isRequesting = isReportItemsRequesting( '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' ),
|
'description' => __( 'Maximum number of items to be returned in result set.', 'woocommerce-admin' ),
|
||||||
'type' => 'integer',
|
'type' => 'integer',
|
||||||
'default' => 10,
|
'default' => 10,
|
||||||
'minimum' => 1,
|
'minimum' => 0,
|
||||||
'maximum' => 100,
|
'maximum' => 100,
|
||||||
'sanitize_callback' => 'absint',
|
'sanitize_callback' => 'absint',
|
||||||
'validate_callback' => 'rest_validate_request_arg',
|
'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'] );
|
$total_pages = (int) ceil( $db_records_count / $sql_query_params['per_page'] );
|
||||||
if ( $query_args['page'] < 1 || $query_args['page'] > $total_pages ) {
|
if ( $query_args['page'] < 1 || $query_args['page'] > $total_pages ) {
|
||||||
|
$data = (object) array(
|
||||||
|
'data' => array(),
|
||||||
|
'total' => $db_records_count,
|
||||||
|
);
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue