-
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.
Show theme, plugin or author in Added By column with appropriate icon…
… or avatar
- Loading branch information
Showing
4 changed files
with
130 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __experimentalHStack as HStack, Icon } from '@wordpress/components'; | ||
import { store as coreStore } from '@wordpress/core-data'; | ||
import { useSelect } from '@wordpress/data'; | ||
import { | ||
layout as themeIcon, | ||
plugins as pluginIcon, | ||
commentAuthorAvatar as customizedByUserIcon, | ||
} from '@wordpress/icons'; | ||
|
||
const TEMPLATE_POST_TYPE_NAMES = [ 'wp_template', 'wp_template_part' ]; | ||
const NON_PLUGIN_SOURCES = [ 'theme', 'custom' ]; | ||
|
||
function AddedByTheme( { slug } ) { | ||
const theme = useSelect( | ||
( select ) => select( coreStore ).getTheme( slug ), | ||
[ slug ] | ||
); | ||
|
||
return ( | ||
<HStack alignment="left"> | ||
<div className="edit-site-list-added-by__icon"> | ||
<Icon icon={ themeIcon } /> | ||
</div> | ||
<span>{ theme?.name?.rendered }</span> | ||
</HStack> | ||
); | ||
} | ||
|
||
function AddedByPlugin( { slug } ) { | ||
const plugin = useSelect( | ||
( select ) => select( coreStore ).getPlugin( slug ), | ||
[ slug ] | ||
); | ||
|
||
return ( | ||
<HStack alignment="left"> | ||
<div className="edit-site-list-added-by__icon"> | ||
<Icon icon={ pluginIcon } /> | ||
</div> | ||
<span>{ plugin?.name?.rendered }</span> | ||
</HStack> | ||
); | ||
} | ||
|
||
function AddedByAuthor( { id } ) { | ||
const user = useSelect( ( select ) => select( coreStore ).getUser( id ), [ | ||
id, | ||
] ); | ||
|
||
return ( | ||
<HStack alignment="left"> | ||
<img | ||
className="edit-site-list-added-by__avatar" | ||
alt="" | ||
src={ user?.avatar_urls[ 48 ] } | ||
/> | ||
<span>{ user?.nickname }</span> | ||
</HStack> | ||
); | ||
} | ||
|
||
export default function AddedBy( { templateType, template } ) { | ||
if ( ! template ) { | ||
return; | ||
} | ||
|
||
if ( TEMPLATE_POST_TYPE_NAMES.includes( templateType ) ) { | ||
if ( template.has_theme_file && template.source === 'theme' ) { | ||
return <AddedByTheme slug={ template.theme } />; | ||
} | ||
|
||
if ( ! NON_PLUGIN_SOURCES.includes( template.source ) ) { | ||
return <AddedByPlugin slug={ template.source } />; | ||
} | ||
|
||
// Fallback for any custom template already created without an assigned | ||
// author. | ||
if ( | ||
! template.has_theme_file && | ||
template.source === 'custom' && | ||
! template.author | ||
) { | ||
return ( | ||
<HStack alignment="left"> | ||
<div className="edit-site-list-added-by__icon"> | ||
<Icon icon={ customizedByUserIcon } /> | ||
</div> | ||
<span>Customized by user</span> | ||
</HStack> | ||
); | ||
} | ||
} | ||
|
||
return <AddedByAuthor id={ template.author } />; | ||
} |
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