2018-05-23 23:15:52 +00:00
|
|
|
/** @format */
|
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
import { Component } from '@wordpress/element';
|
2018-05-28 10:55:19 +00:00
|
|
|
import { filter } from 'lodash';
|
|
|
|
import PropTypes from 'prop-types';
|
2018-05-23 23:15:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import SegmentedSelection from 'components/segmented-selection';
|
|
|
|
|
2018-05-28 10:55:19 +00:00
|
|
|
const presetValues = [
|
2018-07-10 12:48:06 +00:00
|
|
|
{ value: 'today', label: __( 'Today', 'wc-admin' ) },
|
|
|
|
{ value: 'yesterday', label: __( 'Yesterday', 'wc-admin' ) },
|
|
|
|
{ value: 'week', label: __( 'Week to Date', 'wc-admin' ) },
|
|
|
|
{ value: 'last_week', label: __( 'Last Week', 'wc-admin' ) },
|
|
|
|
{ value: 'month', label: __( 'Month to Date', 'wc-admin' ) },
|
|
|
|
{ value: 'last_month', label: __( 'Last Month', 'wc-admin' ) },
|
|
|
|
{ value: 'quarter', label: __( 'Quarter to Date', 'wc-admin' ) },
|
|
|
|
{ value: 'last_quarter', label: __( 'Last Quarter', 'wc-admin' ) },
|
|
|
|
{ value: 'year', label: __( 'Year to Date', 'wc-admin' ) },
|
|
|
|
{ value: 'last_year', label: __( 'Last Year', 'wc-admin' ) },
|
|
|
|
{ value: 'custom', label: __( 'Custom', 'wc-admin' ) },
|
2018-05-28 10:55:19 +00:00
|
|
|
];
|
|
|
|
|
2018-05-23 23:15:52 +00:00
|
|
|
class PresetPeriods extends Component {
|
|
|
|
render() {
|
|
|
|
const { onSelect, period } = this.props;
|
|
|
|
return (
|
|
|
|
<SegmentedSelection
|
2018-05-28 10:55:19 +00:00
|
|
|
options={ filter( presetValues, preset => preset.value !== 'custom' ) }
|
2018-05-23 23:15:52 +00:00
|
|
|
selected={ period }
|
|
|
|
onSelect={ onSelect }
|
|
|
|
name="period"
|
2018-07-10 12:48:06 +00:00
|
|
|
legend={ __( 'select a preset period', 'wc-admin' ) }
|
2018-05-23 23:15:52 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-28 10:55:19 +00:00
|
|
|
PresetPeriods.propTypes = {
|
|
|
|
onSelect: PropTypes.func.isRequired,
|
|
|
|
period: PropTypes.string,
|
|
|
|
};
|
|
|
|
|
|
|
|
export { presetValues };
|
2018-05-23 23:15:52 +00:00
|
|
|
export default PresetPeriods;
|