-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update: Show template sources on templates Dataviews sidebar. #58124
Merged
jorgefilipecosta
merged 7 commits into
trunk
from
add/show-template-source-on-dataviews-all-templates-sidebar
Jan 23, 2024
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
933bcfe
Update: Show template sources on templates Dataviews sidebar.
jorgefilipecosta 166b279
Fix rebase
oandregal 106049f
Remove leftover suffix
oandregal 9cf01c9
Make sidebar work for templates & parts
oandregal 3e3a87d
Fix view name
oandregal 9025abf
Update component
oandregal 5598ff1
Do not reset layout
oandregal File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
73 changes: 73 additions & 0 deletions
73
packages/edit-site/src/components/sidebar-navigation-screen-templates-browse/content.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,73 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useEntityRecords } from '@wordpress/core-data'; | ||
import { useMemo } from '@wordpress/element'; | ||
import { __experimentalItemGroup as ItemGroup } from '@wordpress/components'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import DataViewItem from '../sidebar-dataviews/dataview-item'; | ||
import { useAddedBy } from '../list/added-by'; | ||
import { layout } from '@wordpress/icons'; | ||
|
||
const EMPTY_ARRAY = []; | ||
|
||
function TemplateDataviewItem( { template, isActive } ) { | ||
const { text, icon } = useAddedBy( template.type, template.id ); | ||
return ( | ||
<DataViewItem | ||
key={ text } | ||
slug={ text } | ||
title={ text } | ||
icon={ icon } | ||
isActive={ isActive } | ||
isCustom="false" | ||
/> | ||
); | ||
} | ||
|
||
export default function DataviewsTemplatesSidebarContent( { | ||
activeView, | ||
postType, | ||
config, | ||
} ) { | ||
const { records } = useEntityRecords( 'postType', postType, { | ||
per_page: -1, | ||
} ); | ||
const firstItemPerAuthorText = useMemo( () => { | ||
const firstItemPerAuthor = records?.reduce( ( acc, template ) => { | ||
const author = template.author_text; | ||
if ( author && ! acc[ author ] ) { | ||
acc[ author ] = template; | ||
} | ||
return acc; | ||
}, {} ); | ||
return ( | ||
( firstItemPerAuthor && Object.values( firstItemPerAuthor ) ) ?? | ||
EMPTY_ARRAY | ||
); | ||
}, [ records ] ); | ||
|
||
return ( | ||
<ItemGroup> | ||
<DataViewItem | ||
slug={ 'all' } | ||
title={ config[ postType ].title } | ||
icon={ layout } | ||
isActive={ activeView === 'all' } | ||
isCustom="false" | ||
/> | ||
{ firstItemPerAuthorText.map( ( template ) => { | ||
return ( | ||
<TemplateDataviewItem | ||
key={ template.author_text } | ||
template={ template } | ||
isActive={ activeView === template.author_text } | ||
/> | ||
); | ||
} ) } | ||
</ItemGroup> | ||
); | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why do we need this change? In pages list it certainly creates problems(at least in pages list) when changing views. For example if we change a view from the sidebar which has a
grid
view set, I'd expect this to be respected without taking into account the currentlayout
param set.In general the logic is hard to follow with side effects, when handling the views in sidebar and it would be great if we can simplify and also have more consistency between the different lists(pages, templates).