Skip to content

Commit

Permalink
Logged in Profiler: Allow searching pages in dropdown and show empty …
Browse files Browse the repository at this point in the history
…states (#95415)

* adds a no page found component

* remove call to backend when a page is not found in the list

* remove no page found component

* read check for current page

* add disclaimer at the bottom of the dropdown

* allow the disclaimer to always show

* force a no pages found message when no pages are found

* remove comment

* Update copy

---------

Co-authored-by: Candy Tsai <[email protected]>
  • Loading branch information
vykes-mac and candy02058912 authored Oct 17, 2024
1 parent bc78002 commit 8bffce1
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 16 deletions.
24 changes: 18 additions & 6 deletions client/hosting/performance/components/PageSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,24 @@ export const PageSelector = ( props: ComponentProps< typeof SearchableDropdown >
<SearchableDropdown
{ ...props }
className="site-performance__page-selector-drowdown"
__experimentalRenderItem={ ( { item } ) => (
<div className="site-performance__page-selector-item" aria-label={ item.label }>
<span>{ item.label }</span>
<span className="subtitle">{ item.path }</span>
</div>
) }
__experimentalRenderItem={ ( { item } ) => {
if ( item.value === '-1' ) {
return (
<div className="message">
{ translate( 'Performance testing is available for the 20 most popular pages.' ) }
</div>
);
}
if ( item.value === '-2' ) {
return <div className="message">{ translate( 'No pages found' ) }</div>;
}
return (
<div className="site-performance__page-selector-item" aria-label={ item.label }>
<span>{ item.label }</span>
<span className="subtitle">{ item.path }</span>
</div>
);
} }
/>
<div className="site-performance__page-selector-search-icon">
<Icon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const FIELDS_TO_RETRIEVE = [ 'id', 'link', 'title', 'wpcom_performance_report_ur
const getPages = ( siteId: number, query = '' ) => {
return wpcomRequest< SitePage[] >( {
path: addQueryArgs( `/sites/${ siteId }/pages`, {
per_page: 10,
per_page: 20,
search: query,
page: 1,
status: 'publish',
Expand Down
38 changes: 30 additions & 8 deletions client/hosting/performance/site-performance.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import page from '@automattic/calypso-router';
import { useMobileBreakpoint } from '@automattic/viewport-react';
import { Button } from '@wordpress/components';
import { useDebouncedInput } from '@wordpress/compose';
import { translate } from 'i18n-calypso';
import moment from 'moment';
import { useCallback, useEffect, useMemo, useState } from 'react';
Expand Down Expand Up @@ -156,15 +155,12 @@ export const SitePerformance = () => {
}, [ dispatch, siteId ] );

const queryParams = useSelector( getCurrentQueryArguments );
const [ , setQuery, query ] = useDebouncedInput();
const {
pages,
isInitialLoading,
savePerformanceReportUrl,
refetch: refetchPages,
} = useSitePerformancePageReports( {
query,
} );
} = useSitePerformancePageReports();

const orderedPages = useMemo( () => {
return [ ...pages ].sort( ( a, b ) => {
Expand Down Expand Up @@ -196,9 +192,12 @@ export const SitePerformance = () => {
currentPageUserSelection ?? pages?.find( ( page ) => page.value === currentPageId );

const pageOptions = useMemo( () => {
return currentPage
const options = currentPage
? [ currentPage, ...orderedPages.filter( ( p ) => p.value !== currentPage.value ) ]
: orderedPages;

// Add a disabled option at the end that will show a disclaimer message.
return [ ...options, { label: '', value: '-1', path: '', disabled: true } ];
}, [ currentPage, orderedPages ] );

const handleRecommendationsFilterChange = ( filter?: string ) => {
Expand Down Expand Up @@ -270,11 +269,34 @@ export const SitePerformance = () => {
} );
};

// This forces a no pages found message in the dropdown
const [ noPagesFound, setNoPagesFound ] = useState( { query: '', found: true } );

const options = ! noPagesFound.found
? [
{
label: noPagesFound.query,
value: '-2',
disabled: true,
},
]
: pageOptions;

const pageSelector = (
<PageSelector
onFilterValueChange={ setQuery }
onFilterValueChange={ ( value ) => {
const filter = pageOptions.find( ( option ) =>
option.label.toLowerCase().startsWith( value )
);

if ( filter ) {
setNoPagesFound( { query: '', found: true } );
return;
}
setNoPagesFound( { query: value, found: false } );
} }
allowReset={ false }
options={ pageOptions }
options={ options }
disabled={ disableControls }
onChange={ ( page_id ) => {
const url = new URL( window.location.href );
Expand Down
11 changes: 10 additions & 1 deletion client/hosting/performance/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,15 @@ $section-max-width: 1224px;

}

.message {
padding-inline: 18px;
padding-block: 16px;
font-size: $font-body-extra-small;
font-family: $font-sf-pro-text;
color: #949494 !important;
background: var(--color-surface);
}

.site-performance__page-selector-item {
display: flex;
flex-direction: column;
Expand Down Expand Up @@ -237,7 +246,7 @@ $section-max-width: 1224px;
border-top: 1px solid #F0F0F0;
}

&.is-selected * {
&.is-selected > .site-performance__page-selector-item > .subtitle {
color: #fff !important;
}
}
Expand Down

0 comments on commit 8bffce1

Please sign in to comment.