Skip to content
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

WordAds Stats: fix broken links in Odyssey #72360

Merged
merged 3 commits into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 2 additions & 4 deletions client/my-sites/stats/wordads/earnings.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,16 +180,14 @@ class WordAdsEarnings extends Component {
<h1 className="ads__module-header-title module-header-title">{ header_text }</h1>
<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
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 @@ -35,13 +35,6 @@ import HighlightsSection from './highlights-section';
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 @@ -116,8 +109,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 @@ -126,8 +120,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