-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Site Editor Sidebar: Add "Areas" details panel to all templates and u…
…pdate icon (#55677) * Site Editor Sidebar: Add "Areas" details panel to all templates * Use symbolFilled icon for general template parts * Remove unnecessary code
- Loading branch information
Showing
3 changed files
with
144 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
packages/edit-site/src/components/sidebar-navigation-screen-template/template-areas.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { useSelect } from '@wordpress/data'; | ||
import { | ||
__experimentalTruncate as Truncate, | ||
__experimentalItemGroup as ItemGroup, | ||
} from '@wordpress/components'; | ||
import { store as editorStore } from '@wordpress/editor'; | ||
import { useMemo } from '@wordpress/element'; | ||
import { decodeEntities } from '@wordpress/html-entities'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { | ||
SidebarNavigationScreenDetailsPanel, | ||
SidebarNavigationScreenDetailsPanelRow, | ||
} from '../sidebar-navigation-screen-details-panel'; | ||
import { unlock } from '../../lock-unlock'; | ||
import { store as editSiteStore } from '../../store'; | ||
import { useLink } from '../routes/link'; | ||
import SidebarNavigationItem from '../sidebar-navigation-item'; | ||
import { TEMPLATE_PART_POST_TYPE } from '../../utils/constants'; | ||
|
||
function TemplateAreaButton( { postId, area, title } ) { | ||
const templatePartArea = useSelect( | ||
( select ) => { | ||
const defaultAreas = | ||
select( | ||
editorStore | ||
).__experimentalGetDefaultTemplatePartAreas(); | ||
|
||
return defaultAreas.find( | ||
( defaultArea ) => defaultArea.area === area | ||
); | ||
}, | ||
[ area ] | ||
); | ||
const linkInfo = useLink( { | ||
postType: TEMPLATE_PART_POST_TYPE, | ||
postId, | ||
} ); | ||
|
||
return ( | ||
<SidebarNavigationItem | ||
className="edit-site-sidebar-navigation-screen-template__template-area-button" | ||
{ ...linkInfo } | ||
icon={ templatePartArea?.icon } | ||
withChevron | ||
> | ||
<Truncate | ||
limit={ 20 } | ||
ellipsizeMode="tail" | ||
numberOfLines={ 1 } | ||
className="edit-site-sidebar-navigation-screen-template__template-area-label-text" | ||
> | ||
{ decodeEntities( title ) } | ||
</Truncate> | ||
</SidebarNavigationItem> | ||
); | ||
} | ||
|
||
export default function TemplateAreas() { | ||
const { templatePartAreas, currentTemplateParts } = useSelect( | ||
( select ) => { | ||
const { getSettings, getCurrentTemplateTemplateParts } = unlock( | ||
select( editSiteStore ) | ||
); | ||
return { | ||
templatePartAreas: getSettings()?.defaultTemplatePartAreas, | ||
currentTemplateParts: getCurrentTemplateTemplateParts(), | ||
}; | ||
}, | ||
[] | ||
); | ||
|
||
/* | ||
* Merge data in currentTemplateParts with templatePartAreas, | ||
* which contains the template icon and fallback labels | ||
*/ | ||
const templateAreas = useMemo( () => { | ||
// Keep track of template part IDs that have already been added to the array. | ||
const templatePartIds = new Set(); | ||
const filterOutDuplicateTemplateParts = ( currentTemplatePart ) => { | ||
// If the template part has already been added to the array, skip it. | ||
if ( templatePartIds.has( currentTemplatePart.templatePart.id ) ) { | ||
return; | ||
} | ||
// Add to the array of template part IDs. | ||
templatePartIds.add( currentTemplatePart.templatePart.id ); | ||
return currentTemplatePart; | ||
}; | ||
|
||
return currentTemplateParts.length && templatePartAreas | ||
? currentTemplateParts | ||
.filter( filterOutDuplicateTemplateParts ) | ||
.map( ( { templatePart, block } ) => ( { | ||
...templatePartAreas?.find( | ||
( { area } ) => area === templatePart?.area | ||
), | ||
...templatePart, | ||
clientId: block.clientId, | ||
} ) ) | ||
: []; | ||
}, [ currentTemplateParts, templatePartAreas ] ); | ||
|
||
if ( ! templateAreas.length ) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<SidebarNavigationScreenDetailsPanel | ||
title={ __( 'Areas' ) } | ||
spacing={ 3 } | ||
> | ||
<ItemGroup> | ||
{ templateAreas.map( | ||
( { clientId, label, area, theme, slug, title } ) => ( | ||
<SidebarNavigationScreenDetailsPanelRow | ||
key={ clientId } | ||
> | ||
<TemplateAreaButton | ||
postId={ `${ theme }//${ slug }` } | ||
title={ title?.rendered || label } | ||
area={ area } | ||
/> | ||
</SidebarNavigationScreenDetailsPanelRow> | ||
) | ||
) } | ||
</ItemGroup> | ||
</SidebarNavigationScreenDetailsPanel> | ||
); | ||
} |
2642697
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flaky tests detected in 2642697.
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/7162692314
📝 Reported issues:
/test/e2e/specs/site-editor/font-library.spec.js