-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Store Dashboard: Refactor, Update widgets to use DashboardWidget #22859
Changes from all commits
f0e82a8
0a41100
852e7cc
4173a98
ad27ecd
aa6d7b4
bca462a
98a3969
19774f2
478486f
35b078d
e76c162
be7e8fe
5d59df0
b13ecff
94cc371
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,25 @@ | ||
/** @format */ | ||
|
||
/** | ||
* External dependencies | ||
*/ | ||
|
||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import classNames from 'classnames'; | ||
import config from 'config'; | ||
import { bindActionCreators } from 'redux'; | ||
import { connect } from 'react-redux'; | ||
import classNames from 'classnames'; | ||
import { localize } from 'i18n-calypso'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import Button from 'components/button'; | ||
import DashboardWidget from 'woocommerce/components/dashboard-widget'; | ||
import DashboardWidgetRow from 'woocommerce/components/dashboard-widget/row'; | ||
import LabelsSetupNotice from 'woocommerce/woocommerce-services/components/labels-setup-notice'; | ||
import { fetchOrders } from 'woocommerce/state/sites/orders/actions'; | ||
import { fetchReviews } from 'woocommerce/state/sites/reviews/actions'; | ||
import formatCurrency from 'lib/format-currency'; | ||
import { | ||
areOrdersLoading, | ||
areOrdersLoaded, | ||
|
@@ -30,9 +31,7 @@ import { getSelectedSiteWithFallback } from 'woocommerce/state/sites/selectors'; | |
import { getLink } from 'woocommerce/lib/nav-utils'; | ||
import { getPaymentCurrencySettings } from 'woocommerce/state/sites/settings/general/selectors'; | ||
import { getTotalReviews } from 'woocommerce/state/sites/reviews/selectors'; | ||
import ProcessOrdersWidget from 'woocommerce/components/process-orders-widget'; | ||
import ShareWidget from 'woocommerce/components/share-widget'; | ||
import Card from 'components/card'; | ||
import QuerySettingsGeneral from 'woocommerce/components/query-settings-general'; | ||
|
||
class ManageOrdersView extends Component { | ||
|
@@ -84,45 +83,60 @@ class ManageOrdersView extends Component { | |
} | ||
}; | ||
|
||
shouldShowPendingReviews = () => { | ||
return config.isEnabled( 'woocommerce/extension-reviews' ) && this.props.pendingReviews; | ||
}; | ||
|
||
possiblyRenderProcessOrdersWidget = () => { | ||
const { site, orders, ordersRevenue, currency } = this.props; | ||
const { currency, orders, ordersRevenue, site, translate } = this.props; | ||
if ( ! orders.length ) { | ||
return null; | ||
} | ||
const currencyValue = ( currency && currency.value ) || ''; | ||
const orderCountPhrase = translate( '✨ New order', '✨ New orders', { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi! I've found a possible matching string that has already been translated 18 times: Help me improve these suggestions: react with 👎 if the suggestion doesn't make any sense, or with 👍 if it's a particularly good one (even if not implemented). |
||
count: orders.length, | ||
} ); | ||
const classes = classNames( 'dashboard__process-orders-container', { | ||
'has-reviews': this.shouldShowPendingReviews(), | ||
} ); | ||
return ( | ||
<ProcessOrdersWidget | ||
className="dashboard__process-orders-widget" | ||
site={ site } | ||
orders={ orders } | ||
ordersRevenue={ ordersRevenue } | ||
currency={ currency } | ||
/> | ||
<DashboardWidgetRow className={ classes }> | ||
<DashboardWidget className="dashboard__process-orders-total"> | ||
<span className="dashboard__process-orders-value">{ orders.length }</span> | ||
<span className="dashboard__process-orders-label">{ orderCountPhrase }</span> | ||
</DashboardWidget> | ||
<DashboardWidget className="dashboard__process-orders-revenue"> | ||
<span className="dashboard__process-orders-value"> | ||
{ formatCurrency( ordersRevenue, currencyValue ) || ordersRevenue } | ||
</span> | ||
<span className="dashboard__process-orders-label">{ translate( '💰 Revenue' ) }</span> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
</DashboardWidget> | ||
<DashboardWidget className="dashboard__process-orders-action"> | ||
<Button href={ getLink( '/store/orders/:site', site ) }> | ||
{ translate( 'Process orders' ) } | ||
</Button> | ||
</DashboardWidget> | ||
</DashboardWidgetRow> | ||
); | ||
}; | ||
|
||
possiblyRenderReviewsWidget = () => { | ||
const { site, pendingReviews, translate } = this.props; | ||
if ( ! pendingReviews ) { | ||
if ( ! this.shouldShowPendingReviews() ) { | ||
return null; | ||
} | ||
|
||
const classes = classNames( 'card', 'dashboard__reviews-widget' ); | ||
const countText = translate( 'Pending review', 'Pending reviews', { | ||
const { site, pendingReviews, translate } = this.props; | ||
const countText = translate( '%d pending review', '%d pending reviews', { | ||
args: [ pendingReviews ], | ||
count: pendingReviews, | ||
} ); | ||
|
||
return ( | ||
<div className={ classes }> | ||
<div> | ||
<span>{ pendingReviews }</span> | ||
<span>{ countText }</span> | ||
</div> | ||
<div> | ||
<Button href={ getLink( '/store/reviews/:site', site ) }> | ||
{ translate( 'Moderate', { context: 'Product reviews widget moderation button' } ) } | ||
</Button> | ||
</div> | ||
</div> | ||
<DashboardWidget className="dashboard__reviews-widget" title={ countText } width="third"> | ||
<Button href={ getLink( '/store/reviews/:site', site ) }> | ||
{ translate( 'Moderate', { context: 'Product reviews widget moderation button' } ) } | ||
</Button> | ||
</DashboardWidget> | ||
); | ||
}; | ||
|
||
|
@@ -138,7 +152,7 @@ class ManageOrdersView extends Component { | |
); | ||
}; | ||
|
||
render = () => { | ||
render() { | ||
const { site, translate, orders, user } = this.props; | ||
return ( | ||
<div className="dashboard__manage-has-orders"> | ||
|
@@ -156,34 +170,33 @@ class ManageOrdersView extends Component { | |
|
||
<LabelsSetupNotice /> | ||
|
||
<div className="dashboard__queue-widgets"> | ||
<DashboardWidgetRow> | ||
{ this.possiblyRenderProcessOrdersWidget() } | ||
{ config.isEnabled( 'woocommerce/extension-reviews' ) && | ||
this.possiblyRenderReviewsWidget() } | ||
</div> | ||
{ this.possiblyRenderReviewsWidget() } | ||
</DashboardWidgetRow> | ||
|
||
<DashboardWidget | ||
className="dashboard__reports-widget" | ||
image="/calypso/images/extensions/woocommerce/woocommerce-reports.svg" | ||
imagePosition="right" | ||
title={ translate( 'Reports' ) } | ||
> | ||
<p> | ||
{ translate( | ||
'See a detailed breakdown of how your store is doing on the stats screen.' | ||
) } | ||
</p> | ||
<p> | ||
<Button href={ getLink( '/store/stats/orders/day/:site', site ) }> | ||
{ orders.length ? translate( 'View full reports' ) : translate( 'View reports' ) } | ||
</Button> | ||
</p> | ||
</DashboardWidget> | ||
|
||
<Card className="dashboard__reports-widget"> | ||
<div className="dashboard__reports-widget-content-wrapper"> | ||
<img src="/calypso/images/extensions/woocommerce/woocommerce-reports.svg" alt="" /> | ||
<div className="dashboard__reports-widget-content"> | ||
<h2>{ translate( 'Reports' ) }</h2> | ||
<p> | ||
{ translate( | ||
'See a detailed breakdown of how your store is doing on the stats screen.' | ||
) } | ||
</p> | ||
<p> | ||
<Button href={ getLink( '/store/stats/orders/day/:site', site ) }> | ||
{ orders.length ? translate( 'View full reports' ) : translate( 'View reports' ) } | ||
</Button> | ||
</p> | ||
</div> | ||
</div> | ||
</Card> | ||
{ this.possiblyRenderShareWidget() } | ||
</div> | ||
); | ||
}; | ||
} | ||
} | ||
|
||
function mapStateToProps( state ) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is live and likely won't be turned off, we could just remove this logic now that you are updating this component. Thought it could also be done in a follow-up PR that removes the config settings too.