diff --git a/plugins/woocommerce-admin/client/components/calendar/index.js b/plugins/woocommerce-admin/client/components/calendar/index.js index 21d7c4f5966..d07ecb948c4 100644 --- a/plugins/woocommerce-admin/client/components/calendar/index.js +++ b/plugins/woocommerce-admin/client/components/calendar/index.js @@ -34,11 +34,11 @@ class DateRange extends Component { constructor( props ) { super( props ); - const { start, end } = props; + const { after, before } = props; this.state = { focusedInput: START_DATE, - startText: start ? start.format( shortDateFormat ) : '', - endText: end ? end.format( shortDateFormat ) : '', + afterText: after ? after.format( shortDateFormat ) : '', + beforeText: before ? before.format( shortDateFormat ) : '', }; this.onDatesChange = this.onDatesChange.bind( this ); @@ -49,12 +49,12 @@ class DateRange extends Component { onDatesChange( { startDate, endDate } ) { this.setState( { - startText: startDate ? startDate.format( shortDateFormat ) : '', - endText: endDate ? endDate.format( shortDateFormat ) : '', + afterText: startDate ? startDate.format( shortDateFormat ) : '', + beforeText: endDate ? endDate.format( shortDateFormat ) : '', } ); this.props.onSelect( { - start: startDate, - end: endDate, + after: startDate, + before: endDate, } ); } @@ -66,15 +66,12 @@ class DateRange extends Component { onInputChange( input, event ) { const value = event.target.value; - this.setState( { [ input ]: value } ); + this.setState( { [ input + 'Text' ]: value } ); const date = toMoment( shortDateFormat, value ); if ( date ) { - const match = input.match( /.*(?=Text)/ ); - if ( match ) { - this.props.onSelect( { - [ match[ 0 ] ]: date, - } ); - } + this.props.onSelect( { + [ input ]: date, + } ); } } @@ -95,22 +92,22 @@ class DateRange extends Component { } render() { - const { focusedInput, startText, endText } = this.state; - const { start, end } = this.props; + const { focusedInput, afterText, beforeText } = this.state; + const { after, before } = this.props; const isOutsideRange = this.getOutsideRange(); const isMobile = isMobileViewport(); return (
-

+

{ sprintf( __( "Date input describing a selected date range's start date in format %s", @@ -121,14 +118,14 @@ class DateRange extends Component {

{ __( 'to', 'woo-dash' ) } -

+

{ sprintf( __( "Date input describing a selected date range's end date in format %s", @@ -147,10 +144,10 @@ class DateRange extends Component { onDatesChange={ this.onDatesChange } onFocusChange={ this.onFocusChange } focusedInput={ focusedInput } - startDate={ start } + startDate={ after } startDateId={ START_DATE } startDatePlaceholderText={ 'Start Date' } - endDate={ end } + endDate={ before } endDateId={ END_DATE } endDatePlaceholderText={ 'End Date' } orientation={ 'horizontal' } @@ -159,7 +156,7 @@ class DateRange extends Component { minimumNights={ 0 } hideKeyboardShortcutsPanel noBorder - initialVisibleMonth={ () => start || moment() } + initialVisibleMonth={ () => after || moment() } phrases={ phrases } />

@@ -169,8 +166,8 @@ class DateRange extends Component { } DateRange.propTypes = { - start: PropTypes.object, - end: PropTypes.object, + after: PropTypes.object, + before: PropTypes.object, onSelect: PropTypes.func.isRequired, inValidDays: PropTypes.oneOfType( [ PropTypes.oneOf( [ 'past', 'future', 'none' ] ), diff --git a/plugins/woocommerce-admin/client/components/date-picker/content.js b/plugins/woocommerce-admin/client/components/date-picker/content.js index 614cac1e535..a15c20cc517 100644 --- a/plugins/woocommerce-admin/client/components/date-picker/content.js +++ b/plugins/woocommerce-admin/client/components/date-picker/content.js @@ -38,8 +38,8 @@ class DatePickerContent extends Component { const { period, compare, - start, - end, + after, + before, onSelect, onClose, getUpdatePath, @@ -83,8 +83,8 @@ class DatePickerContent extends Component { ) } { selectedTab === 'custom' && ( diff --git a/plugins/woocommerce-admin/client/components/date-picker/index.js b/plugins/woocommerce-admin/client/components/date-picker/index.js index 2141e2cf66b..a1ca690e86c 100644 --- a/plugins/woocommerce-admin/client/components/date-picker/index.js +++ b/plugins/woocommerce-admin/client/components/date-picker/index.js @@ -29,12 +29,12 @@ class DatePicker extends Component { this.setState( this.addQueryDefaults( nextProps.query ) ); } - addQueryDefaults( { period, compare, start, end } ) { + addQueryDefaults( { period, compare, after, before } ) { return { period: period || 'today', compare: compare || 'previous_period', - start: start ? moment( start ) : null, - end: end ? moment( end ) : null, + after: after ? moment( after ) : null, + before: before ? moment( before ) : null, }; } @@ -43,22 +43,22 @@ class DatePicker extends Component { } getOtherQueries( query ) { - const { period, compare, start, end, ...otherQueries } = query; // eslint-disable-line no-unused-vars + const { period, compare, after, before, ...otherQueries } = query; // eslint-disable-line no-unused-vars return otherQueries; } getUpdatePath( selectedTab ) { const { path, query } = this.props; const otherQueries = this.getOtherQueries( query ); - const { period, compare, start, end } = this.state; + const { period, compare, after, before } = this.state; const data = { period: 'custom' === selectedTab ? 'custom' : period, compare, }; if ( 'custom' === selectedTab ) { Object.assign( data, { - start: start ? start.format( isoDateFormat ) : '', - end: end ? end.format( isoDateFormat ) : '', + after: after ? after.format( isoDateFormat ) : '', + before: before ? before.format( isoDateFormat ) : '', } ); } const queryString = stringifyQueryObject( Object.assign( otherQueries, data ) ); @@ -81,15 +81,15 @@ class DatePicker extends Component { } isValidSelection( selectedTab ) { - const { compare, start, end } = this.state; + const { compare, after, before } = this.state; if ( 'custom' === selectedTab ) { - return compare && start && end; + return compare && after && before; } return true; } render() { - const { period, compare, start, end } = this.state; + const { period, compare, after, before } = this.state; return ( { +export const getCurrentDates = ( { period, compare, after, before } ) => { const { primaryStart, primaryEnd, secondaryStart, secondaryEnd } = getDateValue( period, compare, - start, - end + after, + before ); return { primary: { label: find( presetValues, item => item.value === period ).label, range: getRangeLabel( primaryStart, primaryEnd ), - start: primaryStart, - end: primaryEnd, + after: primaryStart, + before: primaryEnd, }, secondary: { label: find( compareValues, item => item.value === compare ).label, range: getRangeLabel( secondaryStart, secondaryEnd ), - start: secondaryStart, - end: secondaryEnd, + after: secondaryStart, + before: secondaryEnd, }, }; };