Skip to content

Commit

Permalink
Page List: Fix ESLint warnings (#52267)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mamaduka authored Jul 4, 2023
1 parent ee79eae commit b380a60
Showing 1 changed file with 54 additions and 51 deletions.
105 changes: 54 additions & 51 deletions packages/block-library/src/page-list/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,63 +183,66 @@ export default function PageListEdit( {
style: { ...context.style?.color },
} );

const getBlockList = ( parentId = parentPageID ) => {
const childPages = pagesByParentId.get( parentId );
const pagesTree = useMemo(
function makePagesTree( parentId = 0, level = 0 ) {
const childPages = pagesByParentId.get( parentId );

if ( ! childPages?.length ) {
return [];
}

return childPages.reduce( ( template, page ) => {
const hasChildren = pagesByParentId.has( page.id );
const pageProps = {
id: page.id,
label:
// translators: displayed when a page has an empty title.
page.title?.rendered?.trim() !== ''
? page.title?.rendered
: __( '(no title)' ),
title: page.title?.rendered,
link: page.url,
hasChildren,
};
let item = null;
const children = getBlockList( page.id );
item = createBlock( 'core/page-list-item', pageProps, children );
template.push( item );

return template;
}, [] );
};
if ( ! childPages?.length ) {
return [];
}

const makePagesTree = ( parentId = 0, level = 0 ) => {
const childPages = pagesByParentId.get( parentId );
return childPages.reduce( ( tree, page ) => {
const hasChildren = pagesByParentId.has( page.id );
const item = {
value: page.id,
label: '— '.repeat( level ) + page.title.rendered,
rawName: page.title.rendered,
};
tree.push( item );
if ( hasChildren ) {
tree.push( ...makePagesTree( page.id, level + 1 ) );
}
return tree;
}, [] );
},
[ pagesByParentId ]
);

if ( ! childPages?.length ) {
return [];
}
const blockList = useMemo(
function getBlockList( parentId = parentPageID ) {
const childPages = pagesByParentId.get( parentId );

return childPages.reduce( ( tree, page ) => {
const hasChildren = pagesByParentId.has( page.id );
const item = {
value: page.id,
label: '— '.repeat( level ) + page.title.rendered,
rawName: page.title.rendered,
};
tree.push( item );
if ( hasChildren ) {
tree.push( ...makePagesTree( page.id, level + 1 ) );
if ( ! childPages?.length ) {
return [];
}
return tree;
}, [] );
};

const pagesTree = useMemo( makePagesTree, [ pagesByParentId ] );

const blockList = useMemo( getBlockList, [
pagesByParentId,
parentPageID,
] );
return childPages.reduce( ( template, page ) => {
const hasChildren = pagesByParentId.has( page.id );
const pageProps = {
id: page.id,
label:
// translators: displayed when a page has an empty title.
page.title?.rendered?.trim() !== ''
? page.title?.rendered
: __( '(no title)' ),
title: page.title?.rendered,
link: page.url,
hasChildren,
};
let item = null;
const children = getBlockList( page.id );
item = createBlock(
'core/page-list-item',
pageProps,
children
);
template.push( item );

return template;
}, [] );
},
[ pagesByParentId, parentPageID ]
);

const {
isNested,
Expand Down

1 comment on commit b380a60

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in b380a60.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/5453682076
📝 Reported issues:

Please sign in to comment.