Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apps/odyssey-stats/src/page-middleware/setup-context.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ export const setupContextMiddleware = ( reduxStore, reactQueryClient ) => {
// page.js url parsing is broken so we had to disable it with `decodeURLComponents: false`
const parsed = getUrlParts( context.path );
const path = parsed.pathname + parsed.search || null;

context.prevPath = path === context.path ? false : path;
context.query = Object.fromEntries( parsed.searchParams.entries() );
context.pathname = parsed.pathname;

context.hashstring = ( parsed.hash && parsed.hash.substring( 1 ) ) || '';
// set `context.hash` (we have to parse manually)
Expand Down
10 changes: 4 additions & 6 deletions client/my-sites/stats/wordads/earnings.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -249,15 +249,14 @@ class WordAdsEarnings extends Component {
<ul className="ads__module-header-actions module-header-actions">
<li className="ads__module-header-action module-header-action toggle-info">
{ /* eslint-disable-next-line jsx-a11y/anchor-is-valid */ }
<a
href="#"
<button
className="ads__module-header-action-link module-header-action-link"
aria-label={ translate( 'Show or hide panel information' ) }
title={ translate( 'Show or hide panel information' ) }
onClick={ this.handleInfoToggle( type ) }
>
<Gridicon icon={ infoIcon } />
</a>
</button>
</li>
</ul>
</div>
Expand Down Expand Up @@ -298,15 +297,14 @@ class WordAdsEarnings extends Component {
<ul className="ads__module-header-actions module-header-actions">
<li className="ads__module-header-action module-header-action toggle-info">
{ /* eslint-disable-next-line jsx-a11y/anchor-is-valid */ }
<a
href="#"
<button
className="ads__module-header-action-link module-header-action-link"
aria-label={ translate( 'Show or hide panel information' ) }
title={ translate( 'Show or hide panel information' ) }
onClick={ this.handleEarningsNoticeToggle }
>
<Gridicon icon={ infoIcon } />
</a>
</button>
</li>
</ul>
</div>
Expand Down
18 changes: 6 additions & 12 deletions client/my-sites/stats/wordads/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { localize, translate, numberFormat } from 'i18n-calypso';
import { find } from 'lodash';
import moment from 'moment';
import page from 'page';
import { parse as parseQs, stringify as stringifyQs } from 'qs';
import { stringify as stringifyQs } from 'qs';
import { Component, Fragment } from 'react';
import { connect } from 'react-redux';
import titlecase from 'to-title-case';
Expand Down Expand Up @@ -34,13 +34,6 @@ import WordAdsEarnings from './earnings';
import './style.scss';
import 'calypso/my-sites/earn/ads/style.scss';

function updateQueryString( query = {} ) {
return {
...parseQs( window.location.search.substring( 1 ) ),
...query,
};
}

const formatCurrency = ( value ) => {
return '$' + numberFormat( value, 2 );
};
Expand Down Expand Up @@ -115,8 +108,9 @@ class WordAds extends Component {

barClick = ( bar ) => {
this.props.recordGoogleEvent( 'WordAds Stats', 'Clicked Chart Bar' );
const updatedQs = stringifyQs( updateQueryString( { startDate: bar.data.period } ) );
page.redirect( `${ window.location.pathname }?${ updatedQs }` );
const updatedQs = stringifyQs( { ...this.props.context.query, startDate: bar.data.period } );

page.redirect( `${ this.props.context.pathname }?${ updatedQs }` );
};

onChangeLegend = ( activeLegend ) => this.setState( { activeLegend } );
Expand All @@ -125,8 +119,8 @@ class WordAds extends Component {
if ( ! tab.loading && tab.attr !== this.state.chartTab ) {
this.props.recordGoogleEvent( 'WordAds Stats', 'Clicked ' + titlecase( tab.attr ) + ' Tab' );
// switch the tab by navigating to route with updated query string
const updatedQs = stringifyQs( updateQueryString( { tab: tab.attr } ) );
page.show( `${ window.location.pathname }?${ updatedQs }` );
const updatedQs = stringifyQs( { ...this.props.context.query, tab: tab.attr } );
page.show( `${ this.props.context.pathname }?${ updatedQs }` );
}
};

Expand Down