Add dashboard chart interval preferences (https://github.com/woocommerce/woocommerce-admin/pull/1230)
* Add user interval preferences for dashboard charts * Add interval selector styling
This commit is contained in:
parent
41b933e714
commit
bdb9525afe
|
@ -9,13 +9,14 @@ import { compose } from '@wordpress/compose';
|
||||||
import Gridicon from 'gridicons';
|
import Gridicon from 'gridicons';
|
||||||
import { isEqual, xor } from 'lodash';
|
import { isEqual, xor } from 'lodash';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { ToggleControl, IconButton, NavigableMenu } from '@wordpress/components';
|
import { ToggleControl, IconButton, NavigableMenu, SelectControl } from '@wordpress/components';
|
||||||
import { withDispatch } from '@wordpress/data';
|
import { withDispatch } from '@wordpress/data';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* WooCommerce dependencies
|
* WooCommerce dependencies
|
||||||
*/
|
*/
|
||||||
import { EllipsisMenu, MenuItem, SectionHeader } from '@woocommerce/components';
|
import { EllipsisMenu, MenuItem, SectionHeader } from '@woocommerce/components';
|
||||||
|
import { getAllowedIntervalsForQuery } from '@woocommerce/date';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal dependencies
|
* Internal dependencies
|
||||||
|
@ -31,7 +32,7 @@ class DashboardCharts extends Component {
|
||||||
this.state = {
|
this.state = {
|
||||||
chartType: props.userPrefChartType || 'line',
|
chartType: props.userPrefChartType || 'line',
|
||||||
hiddenChartKeys: props.userPrefCharts || [],
|
hiddenChartKeys: props.userPrefCharts || [],
|
||||||
query: props.query,
|
interval: props.userPrefIntervals || 'day',
|
||||||
};
|
};
|
||||||
|
|
||||||
this.toggle = this.toggle.bind( this );
|
this.toggle = this.toggle.bind( this );
|
||||||
|
@ -40,8 +41,9 @@ class DashboardCharts extends Component {
|
||||||
componentDidUpdate( {
|
componentDidUpdate( {
|
||||||
userPrefCharts: prevUserPrefCharts,
|
userPrefCharts: prevUserPrefCharts,
|
||||||
userPrefChartType: prevUserPrefChartType,
|
userPrefChartType: prevUserPrefChartType,
|
||||||
|
userPrefChartInterval: prevUserPrefChartInterval,
|
||||||
} ) {
|
} ) {
|
||||||
const { userPrefCharts, userPrefChartType } = this.props;
|
const { userPrefCharts, userPrefChartInterval, userPrefChartType } = this.props;
|
||||||
if ( userPrefCharts && ! isEqual( userPrefCharts, prevUserPrefCharts ) ) {
|
if ( userPrefCharts && ! isEqual( userPrefCharts, prevUserPrefCharts ) ) {
|
||||||
/* eslint-disable react/no-did-update-set-state */
|
/* eslint-disable react/no-did-update-set-state */
|
||||||
this.setState( {
|
this.setState( {
|
||||||
|
@ -56,6 +58,13 @@ class DashboardCharts extends Component {
|
||||||
} );
|
} );
|
||||||
/* eslint-enable react/no-did-update-set-state */
|
/* eslint-enable react/no-did-update-set-state */
|
||||||
}
|
}
|
||||||
|
if ( userPrefChartInterval !== prevUserPrefChartInterval ) {
|
||||||
|
/* eslint-disable react/no-did-update-set-state */
|
||||||
|
this.setState( {
|
||||||
|
interval: userPrefChartInterval,
|
||||||
|
} );
|
||||||
|
/* eslint-enable react/no-did-update-set-state */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
toggle( key ) {
|
toggle( key ) {
|
||||||
|
@ -97,14 +106,56 @@ class DashboardCharts extends Component {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
renderIntervalSelector() {
|
||||||
|
const allowedIntervals = getAllowedIntervalsForQuery( this.props.query );
|
||||||
|
if ( ! allowedIntervals || allowedIntervals.length < 1 ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const intervalLabels = {
|
||||||
|
hour: __( 'By hour', 'wc-admin' ),
|
||||||
|
day: __( 'By day', 'wc-admin' ),
|
||||||
|
week: __( 'By week', 'wc-admin' ),
|
||||||
|
month: __( 'By month', 'wc-admin' ),
|
||||||
|
quarter: __( 'By quarter', 'wc-admin' ),
|
||||||
|
year: __( 'By year', 'wc-admin' ),
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<SelectControl
|
||||||
|
className="woocommerce-chart__interval-select"
|
||||||
|
value={ this.state.interval }
|
||||||
|
options={ allowedIntervals.map( allowedInterval => ( {
|
||||||
|
value: allowedInterval,
|
||||||
|
label: intervalLabels[ allowedInterval ],
|
||||||
|
} ) ) }
|
||||||
|
onChange={ this.setInterval }
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
setInterval = interval => {
|
||||||
|
this.setState( { interval }, () => {
|
||||||
|
const userDataFields = {
|
||||||
|
[ 'dashboard_chart_interval' ]: this.state.interval,
|
||||||
|
};
|
||||||
|
this.props.updateCurrentUserData( userDataFields );
|
||||||
|
} );
|
||||||
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { path } = this.props;
|
const { path } = this.props;
|
||||||
const { chartType, hiddenChartKeys } = this.state;
|
const { chartType, hiddenChartKeys, interval } = this.state;
|
||||||
const query = { ...this.props.query, type: chartType };
|
const query = { ...this.props.query, type: chartType, interval };
|
||||||
return (
|
return (
|
||||||
<Fragment>
|
<Fragment>
|
||||||
<div className="woocommerce-dashboard__dashboard-charts">
|
<div className="woocommerce-dashboard__dashboard-charts">
|
||||||
<SectionHeader title={ __( 'Charts', 'wc-admin' ) } menu={ this.renderMenu() }>
|
<SectionHeader
|
||||||
|
title={ __( 'Charts', 'wc-admin' ) }
|
||||||
|
menu={ this.renderMenu() }
|
||||||
|
className={ 'has-interval-select' }
|
||||||
|
>
|
||||||
|
{ this.renderIntervalSelector() }
|
||||||
<NavigableMenu
|
<NavigableMenu
|
||||||
className="woocommerce-chart__types"
|
className="woocommerce-chart__types"
|
||||||
orientation="horizontal"
|
orientation="horizontal"
|
||||||
|
@ -167,6 +218,7 @@ export default compose(
|
||||||
return {
|
return {
|
||||||
userPrefCharts: userData.dashboard_charts,
|
userPrefCharts: userData.dashboard_charts,
|
||||||
userPrefChartType: userData.dashboard_chart_type,
|
userPrefChartType: userData.dashboard_chart_type,
|
||||||
|
userPrefChartInterval: userData.dashboard_chart_interval,
|
||||||
};
|
};
|
||||||
} ),
|
} ),
|
||||||
withDispatch( dispatch => {
|
withDispatch( dispatch => {
|
||||||
|
|
|
@ -42,6 +42,7 @@ function updateCurrentUserData( resourceNames, data, fetch ) {
|
||||||
'variations_report_columns',
|
'variations_report_columns',
|
||||||
'dashboard_charts',
|
'dashboard_charts',
|
||||||
'dashboard_chart_type',
|
'dashboard_chart_type',
|
||||||
|
'dashboard_chart_interval',
|
||||||
'dashboard_leaderboards',
|
'dashboard_leaderboards',
|
||||||
'dashboard_leaderboard_rows',
|
'dashboard_leaderboard_rows',
|
||||||
];
|
];
|
||||||
|
|
|
@ -401,6 +401,7 @@ function wc_admin_get_user_data_fields() {
|
||||||
'variations_report_columns',
|
'variations_report_columns',
|
||||||
'dashboard_charts',
|
'dashboard_charts',
|
||||||
'dashboard_chart_type',
|
'dashboard_chart_type',
|
||||||
|
'dashboard_chart_interval',
|
||||||
'dashboard_leaderboards',
|
'dashboard_leaderboards',
|
||||||
'dashboard_leaderboard_rows',
|
'dashboard_leaderboard_rows',
|
||||||
);
|
);
|
||||||
|
|
|
@ -21,6 +21,19 @@
|
||||||
height: 1px;
|
height: 1px;
|
||||||
margin: 0 10px;
|
margin: 0 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@include breakpoint( '<782px' ) {
|
||||||
|
&.has-interval-select {
|
||||||
|
position: relative;
|
||||||
|
padding-bottom: 30px;
|
||||||
|
.woocommerce-chart__interval-select {
|
||||||
|
position: absolute;
|
||||||
|
left: 0;
|
||||||
|
bottom: 0;
|
||||||
|
padding-left: 6px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.woocommerce-section-header__actions,
|
.woocommerce-section-header__actions,
|
||||||
|
@ -31,6 +44,18 @@
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-grow: 1;
|
flex-grow: 1;
|
||||||
justify-content: flex-end;
|
justify-content: flex-end;
|
||||||
|
align-items: center;
|
||||||
|
|
||||||
|
.components-base-control {
|
||||||
|
padding-top: 0;
|
||||||
|
min-height: 34px;
|
||||||
|
}
|
||||||
|
.components-base-control__field {
|
||||||
|
margin-bottom: 0;
|
||||||
|
select {
|
||||||
|
background: transparent;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.woocommerce-ellipsis-menu__toggle {
|
.woocommerce-ellipsis-menu__toggle {
|
||||||
|
@ -48,7 +73,7 @@
|
||||||
// EllipsisMenu is 24px, so to match we add 6px padding around the
|
// EllipsisMenu is 24px, so to match we add 6px padding around the
|
||||||
// heading text, which we know is 18px from line-height.
|
// heading text, which we know is 18px from line-height.
|
||||||
padding: 3px 0;
|
padding: 3px 0;
|
||||||
@include font-size( 15 );
|
@include font-size( 18 );
|
||||||
line-height: 2.2;
|
line-height: 2.2;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue