Skip to content
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/template detail #51150

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* WordPress dependencies
*/
import { Button, Icon } from '@wordpress/components';
import { chevronRightSmall } from '@wordpress/icons';

export default function DataListDrilldown( { label, ...props } ) {
return (
<Button
as="a"
{ ...props }
className="edit-site-sidebar-data-list-drilldown"
>
<span className="edit-site-sidebar-data-list-drilldown__label">
{ label }
</span>
<Icon
className="edit-site-sidebar-data-list-drilldown__icon"
icon={ chevronRightSmall }
/>
</Button>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ export default function DataListItem( { label, value } ) {
<Text className="edit-site-sidebar-navigation_data-list__label">
{ label }
</Text>
<Text className="edit-site-sidebar-navigation_data-list__value">
<Text
as="div"
className="edit-site-sidebar-navigation_data-list__value"
>
{ value }
</Text>
</HStack>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default function SidebarDetails( { details } ) {
return (
<VStack
className="edit-site-sidebar-navigation_data-list"
spacing={ 5 }
spacing={ 2 }
>
{ details.map( ( detail ) => (
<DataListItem
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,36 @@


.edit-site-sidebar-navigation_data-list__item {
height: $button-size;
.edit-site-sidebar-navigation_data-list__label {
color: $gray-600;
width: 100px;
}

.edit-site-sidebar-navigation_data-list__value.edit-site-sidebar-navigation_data-list__value {
.edit-site-sidebar-navigation_data-list__value {
color: $gray-200;
flex-grow: 1;
height: $button-size;
display: inline-flex;
align-items: center;
}
.components-button.is-tertiary {
color: $gray-200;
flex-grow: 1;
margin-left: -$grid-unit-10;
&:hover {
background-color: $gray-800;
color: $gray-100;
}
}
}

.edit-site-sidebar-data-list-drilldown {
.edit-site-sidebar-data-list-drilldown__label {
flex-grow: 1;
text-align: left;
}
.edit-site-sidebar-data-list-drilldown__icon {
color: $gray-600;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/**
* WordPress dependencies
*/
import { __, sprintf, _x } from '@wordpress/i18n';
import { useDispatch, useSelect } from '@wordpress/data';
import { pencil } from '@wordpress/icons';
import {
__experimentalUseNavigator as useNavigator,
Icon,
} from '@wordpress/components';
import { store as coreStore } from '@wordpress/core-data';

/**
* Internal dependencies
*/
import SidebarNavigationScreen from '../sidebar-navigation-screen';
import useEditedEntityRecord from '../use-edited-entity-record';
import { unlock } from '../../private-apis';
import { store as editSiteStore } from '../../store';
import SidebarButton from '../sidebar-button';
import { useAddedBy } from '../list/added-by';

function useTemplateTitleAndDescription( postType, postId ) {
const { getDescription, getTitle, record } = useEditedEntityRecord(
postType,
postId
);
const currentTheme = useSelect(
( select ) => select( coreStore ).getCurrentTheme(),
[]
);
const addedBy = useAddedBy( postType, postId );
const isAddedByActiveTheme =
addedBy.type === 'theme' && record.theme === currentTheme?.stylesheet;
const title = getTitle();
let descriptionText = getDescription();

if ( ! descriptionText && addedBy.text ) {
descriptionText = sprintf(
// translators: %s: template part title e.g: "Header".
__( 'This is your %s template part.' ),
getTitle()
);
}

const description = (
<>
{ descriptionText }

{ addedBy.text && ! isAddedByActiveTheme && (
<span className="edit-site-sidebar-navigation-screen-template__added-by-description">
<span className="edit-site-sidebar-navigation-screen-template__added-by-description-author">
<span className="edit-site-sidebar-navigation-screen-template__added-by-description-author-icon">
{ addedBy.imageUrl ? (
<img
src={ addedBy.imageUrl }
alt=""
width="24"
height="24"
/>
) : (
<Icon icon={ addedBy.icon } />
) }
</span>
{ addedBy.text }
</span>

{ addedBy.isCustomized && (
<span className="edit-site-sidebar-navigation-screen-template__added-by-description-customized">
{ _x( '(Customized)', 'template part' ) }
</span>
) }
</span>
) }
</>
);

return { title, description };
}

export default function SidebarNavigationScreenTemplatePart() {
const { params } = useNavigator();
const { postType, postId } = params;
const { setCanvasMode } = unlock( useDispatch( editSiteStore ) );
const { title, description } = useTemplateTitleAndDescription(
postType,
postId
);

return (
<SidebarNavigationScreen
title={ title }
actions={
<SidebarButton
onClick={ () => setCanvasMode( 'edit' ) }
label={ __( 'Edit' ) }
icon={ pencil }
/>
}
description={ description }
/>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
*/
import { __, sprintf, _x } from '@wordpress/i18n';
import { useDispatch, useSelect } from '@wordpress/data';
import { pencil } from '@wordpress/icons';
import { pencil, header, footer } from '@wordpress/icons';
import {
__experimentalUseNavigator as useNavigator,
Icon,
} from '@wordpress/components';
import { store as coreStore } from '@wordpress/core-data';
import { store as coreStore, useEntityRecord } from '@wordpress/core-data';
import { humanTimeDiff } from '@wordpress/date';

/**
* Internal dependencies
Expand All @@ -19,6 +20,11 @@ import { unlock } from '../../private-apis';
import { store as editSiteStore } from '../../store';
import SidebarButton from '../sidebar-button';
import { useAddedBy } from '../list/added-by';
import SidebarDetails from '../sidebar-navigation-data-list';
import DataListItem from '../sidebar-navigation-data-list/data-list-item';
import DataListDrilldown from '../sidebar-navigation-data-list/data-list-drilldown';
import SidebarNavigationSubtitle from '../sidebar-navigation-subtitle';
import { createInterpolateElement } from '@wordpress/element';

function useTemplateTitleAndDescription( postType, postId ) {
const { getDescription, getTitle, record } = useEditedEntityRecord(
Expand All @@ -36,17 +42,9 @@ function useTemplateTitleAndDescription( postType, postId ) {
let descriptionText = getDescription();

if ( ! descriptionText && addedBy.text ) {
if ( record.type === 'wp_template' && record.is_custom ) {
descriptionText = __(
'This is a custom template that can be applied manually to any Post or Page.'
);
} else if ( record.type === 'wp_template_part' ) {
descriptionText = sprintf(
// translators: %s: template part title e.g: "Header".
__( 'This is your %s template part.' ),
getTitle()
);
}
descriptionText = __(
'This is a custom template that can be applied manually to any Post or Page.'
);
}

const description = (
Expand All @@ -73,9 +71,7 @@ function useTemplateTitleAndDescription( postType, postId ) {

{ addedBy.isCustomized && (
<span className="edit-site-sidebar-navigation-screen-template__added-by-description-customized">
{ postType === 'wp_template'
? _x( '(Customized)', 'template' )
: _x( '(Customized)', 'template part' ) }
{ _x( '(Customized)', 'template' ) }
</span>
) }
</span>
Expand All @@ -94,8 +90,9 @@ export default function SidebarNavigationScreenTemplate() {
postType,
postId
);
const { record } = useEntityRecord( 'postType', 'wp_template', postId );

return (
return record ? (
<SidebarNavigationScreen
title={ title }
actions={
Expand All @@ -105,7 +102,51 @@ export default function SidebarNavigationScreenTemplate() {
icon={ pencil }
/>
}
content={
<>
<SidebarNavigationSubtitle>Areas</SidebarNavigationSubtitle>
<SidebarDetails
details={ [
{
label: 'Header',
value: (
<DataListDrilldown
variant="tertiary"
icon={ header }
label="Primary"
/>
),
},
{
label: 'Footer',
value: (
<DataListDrilldown
variant="tertiary"
icon={ footer }
label="Primary"
/>
),
},
] }
/>
</>
}
footer={
<DataListItem
label={ __( 'Last modified' ) }
value={ createInterpolateElement(
sprintf(
/* translators: %s: is the relative time when the post was last modified. */
__( '<time>%s</time>' ),
humanTimeDiff( record.modified )
),
{
time: <time dateTime={ record.modified } />,
}
) }
/>
}
description={ description }
/>
);
) : null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
font-weight: 500;
font-size: 11px;
padding: $grid-unit-10 0;
margin-bottom: $grid-unit-05;
}
6 changes: 5 additions & 1 deletion packages/edit-site/src/components/sidebar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { privateApis as routerPrivateApis } from '@wordpress/router';
import SidebarNavigationScreenMain from '../sidebar-navigation-screen-main';
import SidebarNavigationScreenTemplates from '../sidebar-navigation-screen-templates';
import SidebarNavigationScreenTemplate from '../sidebar-navigation-screen-template';
import SidebarNavigationScreenTemplatePart from '../sidebar-navigation-screen-template-part';
import useSyncPathWithURL, {
getPathFromURL,
} from '../sync-state-with-url/use-sync-path-with-url';
Expand Down Expand Up @@ -51,13 +52,16 @@ function SidebarScreens() {
<NavigatorScreen path="/page/:postId">
<SidebarNavigationScreenPage />
</NavigatorScreen>
<NavigatorScreen path="/:postType(wp_template_part)/:postId">
<SidebarNavigationScreenTemplatePart />
</NavigatorScreen>
<NavigatorScreen path="/:postType(wp_template|wp_template_part)">
<SidebarNavigationScreenTemplates />
</NavigatorScreen>
<NavigatorScreen path="/:postType(wp_template|wp_template_part)/all">
<SidebarNavigationScreenTemplatesBrowse />
</NavigatorScreen>
<NavigatorScreen path="/:postType(wp_template|wp_template_part)/:postId">
<NavigatorScreen path="/:postType(wp_template)/:postId">
<SidebarNavigationScreenTemplate />
</NavigatorScreen>
</>
Expand Down