Skip to content

Commit

Permalink
Simplify by presorting
Browse files Browse the repository at this point in the history
  • Loading branch information
oandregal committed Oct 19, 2023
1 parent 1ca610c commit 78c0609
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions packages/edit-site/src/components/page-pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ const defaultConfigPerViewType = {
};

export default function PagePages() {
const DEFAULT_STATUSES = 'publish,future,draft,pending,private'; // All statuses but 'trash'.
// DEFAULT_STATUSES is intentionally sorted. Items do not have spaces in between them.
// The reason for that is to match defaultStatuses because we compare both strings below (see useEffect).
const DEFAULT_STATUSES = 'draft,future,pending,private,publish'; // All statuses but 'trash'.
const [ view, setView ] = useState( {
type: 'list',
filters: {
Expand All @@ -56,6 +58,7 @@ export default function PagePages() {
: statuses
.filter( ( { slug } ) => slug !== 'trash' )
.map( ( { slug } ) => slug )
.sort()
.join();
}, [ statuses ] );

Expand All @@ -70,10 +73,7 @@ export default function PagePages() {
//
// By doing so, it avoids a second request to the pages endpoint
// upon receiving the statuses when they are the same (most common scenario).
if (
DEFAULT_STATUSES.split( ',' ).sort().join() !==
defaultStatuses.split( ',' ).sort().join()
) {
if ( DEFAULT_STATUSES !== defaultStatuses ) {
setView( {
...view,
filters: {
Expand Down

0 comments on commit 78c0609

Please sign in to comment.