Skip to content

Commit 1089e25

Browse files
NikschavanCopilot
andauthored
STATS-74: Don't navigate the history for date navigation using the arrow navigation (#103728)
* Don't navigate the history for date navigation using the arrow navigation * Add comment as to why using page.redirect instead of page() * Set the NAVIGATION_METHOD_ARROW as a const instead of repeating the text * Update inline comment for page.redirect usage Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Don't clean up drill down flag The drill down flag is cleared only after clicking on back button * cs fixes --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 9875871 commit 1089e25

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

client/my-sites/stats/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,5 @@ export const STATS_FEATURE_UTM_STATS = 'stats_utm';
8888
export const STATS_DO_YOU_LOVE_JETPACK_STATS_NOTICE = 'DoYouLoveJetpackStatsNotice';
8989

9090
export const DATE_FORMAT = 'YYYY-MM-DD';
91+
92+
export const NAVIGATION_METHOD_ARROW = 'arrow';

client/my-sites/stats/stats-date-picker/date-label-drill/index.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ const DateLabelDrill = ( { children, previousDisplayDate }: DateLabelDrillProps
1515

1616
useEffect( () => {
1717
setIsAnimated( true );
18-
// Remove the flag after the drill-up action button is shown.
19-
sessionStorage.removeItem( 'jetpack_stats_date_range_is_drilling_down' );
2018
}, [] );
2119

2220
const goBack = () => {

client/my-sites/stats/stats-date-picker/index.jsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { connect } from 'react-redux';
66
import { getShortcuts } from 'calypso/components/date-range/use-shortcuts';
77
import { withLocalizedMoment } from 'calypso/components/localized-moment';
88
import memoizeLast from 'calypso/lib/memoize-last';
9+
import { NAVIGATION_METHOD_ARROW } from 'calypso/my-sites/stats/constants';
910
import { getMomentSiteZone } from 'calypso/my-sites/stats/hooks/use-moment-site-zone';
1011
import {
1112
getSiteStatsQueryDate,
@@ -212,6 +213,12 @@ class StatsDatePicker extends Component {
212213
const dateHistory = JSON.parse(
213214
sessionStorage.getItem( 'jetpack_stats_date_range_is_drilling_down_date_history' ) || '[]'
214215
);
216+
const isArrowNavigation = this.props?.queryParams?.navigation === NAVIGATION_METHOD_ARROW;
217+
218+
// For the arrow navigation, we want to replace the last element with the new date.
219+
if ( isArrowNavigation ) {
220+
dateHistory.pop();
221+
}
215222

216223
// Only update history if the date is new
217224
if ( ! dateHistory.includes( displayDate ) ) {

client/my-sites/stats/stats-period-navigation/index.jsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import StatsDateControl from 'calypso/components/stats-date-control';
1414
import {
1515
STATS_FEATURE_DATE_CONTROL,
1616
STATS_FEATURE_INTERVAL_DROPDOWN,
17+
NAVIGATION_METHOD_ARROW,
1718
} from 'calypso/my-sites/stats/constants';
1819
import { recordGoogleEvent as recordGoogleEventAction } from 'calypso/state/analytics/actions';
1920
import { isJetpackSite } from 'calypso/state/sites/selectors';
@@ -242,11 +243,14 @@ class StatsPeriodNavigation extends PureComponent {
242243

243244
const path = `/stats/${ period }/${ slug }`;
244245
const url = getPathWithUpdatedQueryString(
245-
{ chartStart, chartEnd, navigation: 'arrow' },
246+
{ chartStart, chartEnd, navigation: NAVIGATION_METHOD_ARROW },
246247
path
247248
);
248249

249-
page( url );
250+
// Redirect to the page by replacing the current history entry,
251+
// rather than pushing a new one. This ensures the navigation
252+
// does not create an additional entry in the browser's history stack.
253+
page.redirect( url );
250254
};
251255

252256
queryParamsForPreviousDate = ( previousDay ) => {

0 commit comments

Comments
 (0)