Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Reuse sidebar-dataviews in templates
  • Loading branch information
oandregal committed Mar 27, 2026
commit f322d00feec200553ed9a5d9f7690df392f42ff3
4 changes: 0 additions & 4 deletions packages/edit-site/src/components/sidebar-dataviews/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
/**
* External dependencies
*/

/**
* WordPress dependencies
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
/**
* WordPress dependencies
*/
import { __experimentalItemGroup as ItemGroup } from '@wordpress/components';
import { store as coreStore } from '@wordpress/core-data';
import { useSelect } from '@wordpress/data';
import { privateApis as routerPrivateApis } from '@wordpress/router';
import { addQueryArgs } from '@wordpress/url';
import { useViewConfig } from '@wordpress/views';
import {
commentAuthorAvatar,
layout,
Expand All @@ -17,27 +13,10 @@ import {
/**
* Internal dependencies
*/
import SidebarNavigationItem from '../sidebar-navigation-item';
import { TEMPLATE_POST_TYPE } from '../../utils/constants';
import { unlock } from '../../lock-unlock';

const { useLocation } = unlock( routerPrivateApis );

const SOURCE_TO_ICON = {
user: commentAuthorAvatar,
theme: layout,
plugin: pluginIcon,
site: globe,
};
import DataViewsSidebarContent from '../sidebar-dataviews';

export default function DataviewsTemplatesSidebarContent() {
const {
query: { activeView = 'all' },
} = useLocation();
const { view_list: viewList } = useViewConfig( {
kind: 'postType',
name: TEMPLATE_POST_TYPE,
} );
const authorSourceMap = useSelect( ( select ) => {
const templates = select( coreStore ).getEntityRecords(
'postType',
Expand All @@ -60,26 +39,21 @@ export default function DataviewsTemplatesSidebarContent() {
return map;
}, [] );

const resolveIcon = ( view ) => {
const SOURCE_TO_ICON = {
user: commentAuthorAvatar,
theme: layout,
plugin: pluginIcon,
Comment thread
oandregal marked this conversation as resolved.
Outdated
site: globe,
};
const source = authorSourceMap[ view.slug ];
return SOURCE_TO_ICON[ source ] ?? layout;
};

return (
<ItemGroup className="edit-site-sidebar-navigation-screen-templates-browse">
{ viewList?.map( ( item ) => (
<SidebarNavigationItem
key={ item.slug }
to={
item.slug === 'all'
? '/template'
: addQueryArgs( '/template', {
activeView: item.slug,
} )
}
icon={
SOURCE_TO_ICON[ authorSourceMap[ item.slug ] ] ?? layout
}
aria-current={ activeView === item.slug }
>
{ item.title }
</SidebarNavigationItem>
) ) }
</ItemGroup>
<DataViewsSidebarContent
postType={ TEMPLATE_POST_TYPE }
resolveIcon={ resolveIcon }
/>
);
}
Loading