Skip to content

Commit

Permalink
Stats: Refactor "stats-redirect" folder (#95507)
Browse files Browse the repository at this point in the history
* Remove the StatsRedirectFlow component and its usage

* Refactor StatsPageLoader folder

* Use StatsPageLoader to wrap purchase page
  • Loading branch information
dognose24 authored Oct 22, 2024
1 parent 8bab616 commit 0ba0ed5
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 62 deletions.
22 changes: 11 additions & 11 deletions client/my-sites/stats/controller.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import PageLoading from './pages/shared/page-loading';
import StatsSite from './site';
import StatsEmailDetail from './stats-email-detail';
import StatsEmailSummary from './stats-email-summary';
import LoadStatsPage from './stats-redirect/load-stats-page';
import StatsPageLoader from './stats-page-loader';

function getNumPeriodAgo( momentSiteZone, date, period ) {
const endOfCurrentPeriod = momentSiteZone.endOf( period );
Expand Down Expand Up @@ -141,14 +141,14 @@ export function overview( context, next ) {

context.primary =
siteId !== null ? (
<LoadStatsPage>
<StatsPageLoader>
<AsyncLoad
require="calypso/my-sites/stats/overview"
placeholder={ PageLoading }
period={ activeFilter.period }
path={ context.pathname }
/>
</LoadStatsPage>
</StatsPageLoader>
) : (
<AsyncLoad
require="calypso/my-sites/stats/overview"
Expand Down Expand Up @@ -202,15 +202,15 @@ export function site( context, next ) {
const chartTab = validTabs.includes( queryOptions.tab ) ? queryOptions.tab : 'views';

context.primary = (
<LoadStatsPage>
<StatsPageLoader>
<StatsSite
path={ context.pathname }
date={ date }
chartTab={ chartTab }
context={ context }
period={ rangeOfPeriod( activeFilter.period, date ) }
/>
</LoadStatsPage>
</StatsPageLoader>
);

next();
Expand Down Expand Up @@ -286,7 +286,7 @@ export function summary( context, next ) {
}

context.primary = (
<LoadStatsPage>
<StatsPageLoader>
<AsyncLoad
require="calypso/my-sites/stats/summary"
placeholder={ PageLoading }
Expand All @@ -297,7 +297,7 @@ export function summary( context, next ) {
period={ period }
{ ...extraProps }
/>
</LoadStatsPage>
</StatsPageLoader>
);

next();
Expand All @@ -315,15 +315,15 @@ export function post( context, next ) {
}

context.primary = (
<LoadStatsPage>
<StatsPageLoader>
<AsyncLoad
require="calypso/my-sites/stats/stats-post-detail"
placeholder={ PageLoading }
path={ context.path }
postId={ postId }
context={ context }
/>
</LoadStatsPage>
</StatsPageLoader>
);

next();
Expand Down Expand Up @@ -353,7 +353,7 @@ export function follows( context, next ) {
}

context.primary = (
<LoadStatsPage>
<StatsPageLoader>
<AsyncLoad
require="calypso/my-sites/stats/comment-follows"
placeholder={ PageLoading }
Expand All @@ -364,7 +364,7 @@ export function follows( context, next ) {
domain={ siteDomain }
siteId={ siteId }
/>
</LoadStatsPage>
</StatsPageLoader>
);

next();
Expand Down
14 changes: 8 additions & 6 deletions client/my-sites/stats/pages/purchase/controller.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import AsyncLoad from 'calypso/components/async-load';
import StatsPageLoader from '../../stats-page-loader';
import PageLoading from '../shared/page-loading';
import type { Context } from '@automattic/calypso-router';

function purchase( context: Context, next: () => void ) {
context.primary = (
// DO NOT WRAP WITH <LoadStatsPage /> or you will get an infinite loop
<AsyncLoad
require="calypso/my-sites/stats/pages/purchase"
placeholder={ PageLoading }
query={ context.query }
/>
<StatsPageLoader>
<AsyncLoad
require="calypso/my-sites/stats/pages/purchase"
placeholder={ PageLoading }
query={ context.query }
/>
</StatsPageLoader>
);
next();
}
Expand Down
6 changes: 1 addition & 5 deletions client/my-sites/stats/pages/purchase/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { useEffect, useMemo } from 'react';
import StatsNavigation from 'calypso/blocks/stats-navigation';
import DocumentHead from 'calypso/components/data/document-head';
import QueryProductsList from 'calypso/components/data/query-products-list';
import QuerySitePurchases from 'calypso/components/data/query-site-purchases';
import InlineSupportLink from 'calypso/components/inline-support-link';
import JetpackColophon from 'calypso/components/jetpack-colophon';
import Main from 'calypso/components/main';
Expand All @@ -24,13 +23,13 @@ import isVipSite from 'calypso/state/selectors/is-vip-site';
import { getSiteSlug, getSiteOption } from 'calypso/state/sites/selectors';
import { getSelectedSiteId } from 'calypso/state/ui/selectors';
import useStatsPurchases from '../../hooks/use-stats-purchases';
import StatsLoader from '../../stats-page-loader/stats-loader';
import PageViewTracker from '../../stats-page-view-tracker';
import { StatsPurchaseNoticePage } from '../../stats-purchase/stats-purchase-notice';
import {
StatsSingleItemPagePurchase,
StatsSingleItemPersonalPurchasePage,
} from '../../stats-purchase/stats-purchase-single-item';
import StatsLoader from '../../stats-redirect/stats-loader';
import './style.scss';

const StatsPurchasePage = ( {
Expand Down Expand Up @@ -199,9 +198,6 @@ const StatsPurchasePage = ( {
/>
</>
) }

{ /* Only query site purchases on Calypso via existing data component */ }
<QuerySitePurchases siteId={ siteId } />
<QueryProductsList type="jetpack" />
{ isLoading && (
<div className="stats-purchase-page__loader">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ import getCurrentRouteParameterized from 'calypso/state/selectors/get-current-ro
import isJetpackModuleActive from 'calypso/state/selectors/is-jetpack-module-active';
import { isJetpackSite } from 'calypso/state/sites/selectors';
import { getSelectedSiteId } from 'calypso/state/ui/selectors';
import { StatsGlobalValuesProvider } from './../pages/providers/global-provider';
import StatsRedirectFlow from './index';
import { StatsGlobalValuesProvider } from '../pages/providers/global-provider';

type AsyncLoadProps = {
children: ReactNode;
Expand Down Expand Up @@ -68,7 +67,7 @@ const InsufficientPermissionsNotice = () => {
);
};

export default function LoadStatsPage( { children }: AsyncLoadProps ) {
export default function StatsPageLoader( { children }: AsyncLoadProps ) {
const siteId = useSelector( getSelectedSiteId ) as number;
const isOdysseyStats = config.isEnabled( 'is_running_in_jetpack_site' );
const isJetpack = useSelector( ( state ) => isJetpackSite( state, siteId ) );
Expand Down Expand Up @@ -119,7 +118,7 @@ export default function LoadStatsPage( { children }: AsyncLoadProps ) {
<StatsGlobalValuesProvider>
<>
<QuerySitePurchases siteId={ siteId } />
<StatsRedirectFlow>{ children }</StatsRedirectFlow>
{ children }
</>
</StatsGlobalValuesProvider>
);
Expand Down
36 changes: 0 additions & 36 deletions client/my-sites/stats/stats-redirect/index.tsx

This file was deleted.

0 comments on commit 0ba0ed5

Please sign in to comment.