Skip to content

Commit

Permalink
Logged-in Performance Profiler: Allow re-running test
Browse files Browse the repository at this point in the history
  • Loading branch information
zaguiini committed Sep 13, 2024
1 parent bb8582a commit 2c99832
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 10 deletions.
10 changes: 9 additions & 1 deletion client/hosting/performance/hooks/useSitePages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,22 @@ const getPages = ( siteId: number, query = '' ) => {
} );
};

export const getSitePagesQueryKey = ( {
siteId,
query,
}: {
siteId?: number | null;
query: string;
} ) => [ 'useSitePages', siteId, query ];

export const useSitePages = ( { query = '' } ) => {
const { __ } = useI18n();

const site = useSelector( getSelectedSite );
const siteId = site?.ID;

const { data } = useQuery( {
queryKey: [ 'useSitePages', siteId, query ],
queryKey: getSitePagesQueryKey( { siteId, query } ),
queryFn: () => getPages( siteId!, query ),
refetchOnWindowFocus: false,
enabled: !! siteId,
Expand Down
59 changes: 50 additions & 9 deletions client/hosting/performance/site-performance.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import page from '@automattic/calypso-router';
import { useQueryClient } from '@tanstack/react-query';
import { Button } from '@wordpress/components';
import { useDebouncedInput } from '@wordpress/compose';
import { translate } from 'i18n-calypso';
import moment from 'moment';
Expand All @@ -15,7 +17,7 @@ import { getSelectedSiteId } from 'calypso/state/ui/selectors';
import { PageSelector } from './components/PageSelector';
import { PerformanceReport } from './components/PerformanceReport';
import { DeviceTabControls, Tab } from './components/device-tab-control';
import { useSitePages } from './hooks/useSitePages';
import { getSitePagesQueryKey, useSitePages } from './hooks/useSitePages';

import './style.scss';

Expand Down Expand Up @@ -93,6 +95,17 @@ export const SitePerformance = () => {
[ pages, currentPageId ]
);

const queryClient = useQueryClient();

const retestPage = () => {
// TODO: Trigger new test

queryClient.invalidateQueries( {
queryKey: getSitePagesQueryKey( { siteId, query } ),
exact: true,
} );
};

const performanceReport = usePerformanceReport( currentPage?.wpcom_performance_url, activeTab );

return (
Expand All @@ -101,14 +114,42 @@ export const SitePerformance = () => {
<NavigationHeader
className="site-performance__navigation-header"
title={ translate( 'Performance' ) }
subtitle={ translate(
'Optimize your site for lightning-fast performance. {{link}}Learn more.{{/link}}',
{
components: {
link: <InlineSupportLink supportContext="site-monitoring" showIcon={ false } />,
},
}
) }
subtitle={
performanceReport.performanceReport
? translate( 'Tested on %(testedDate)s. {{button}}Test again{{/button}}', {
args: {
testedDate: moment( performanceReport.performanceReport.timestamp ).format(
'MMMM Do, YYYY h:mm:ss A'
),
},
components: {
button: (
<Button
css={ {
textDecoration: 'none !important',
':hover': {
textDecoration: 'underline !important',
},
fontSize: 'inherit',
whiteSpace: 'nowrap',
} }
variant="link"
onClick={ retestPage }
/>
),
},
} )
: translate(
'Optimize your site for lightning-fast performance. {{link}}Learn more.{{/link}}',
{
components: {
link: (
<InlineSupportLink supportContext="site-monitoring" showIcon={ false } />
),
},
}
)
}
/>
<PageSelector
onFilterValueChange={ setQuery }
Expand Down

0 comments on commit 2c99832

Please sign in to comment.