Skip to content

Commit

Permalink
Site editor sidebar: home template details (#51223)
Browse files Browse the repository at this point in the history
* Initial commit:
- refactoring page details so that the styles and components can be used in templates
- getting home template details in order

* - displaying template areas
- refactoring footer to show last modified in template and page details

* - bare bones rest controller changes to return modified for `get_item`
- linking up template areas

* - passing footer class to row

* - hooking into settings.

* Refactoring input controls layout
Tweaking CSS accordingly

* Reverted prefix change to file that was not copied to GB

* Removing last modified changes until the templates API supports it.
We can reinstate these changes once it's merged (also adding the property to core-data/src/entity-types/wp-template-part.ts)

* Showing the details pages for the index template
Updating translations for entity types when saving

* Fixed new unlock path

* updating design of area buttons
switching over site title editing to posts page title editing

* Updated hover states of area buttons

* This commit:
- adds a last updated footer (if the modified property is available)
- removes all controls and addes details

* Don't need these

* Reinstate post title and posts per page controls
Reinstate allow comments control
Abstract last modified footer

* Updated copy

* Update help text

* SidebarNavigationItem instead of button for links to template parts from the home template

* Wrap areas in ItemGroup

* Remove bottom margin on last detail panel

* Spacing

* Large inputs

* Leave border radius on inputs as 2px for now

* Use NumberControl

* Remove debounce
Use spin custom controls on the number control component
Update changelog

* Restore since annotation change made in #51362

---------

Co-authored-by: James Koster <james@jameskoster.co.uk>
  • Loading branch information
ramonjd and jameskoster authored Jun 20, 2023
1 parent c5d2660 commit 7efbf84
Show file tree
Hide file tree
Showing 20 changed files with 487 additions and 84 deletions.
4 changes: 4 additions & 0 deletions packages/core-data/src/entity-types/wp-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ declare module './base-entity-records' {
* Whether a template is a custom template.
*/
is_custom: Record< string, string >;
/**
* The date the template was last modified, in the site's timezone.
*/
modified: ContextualField< string, 'view' | 'edit', C >;
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions packages/edit-site/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

### Enhancements
- Site editor sidebar: add home template details and controls [#51223](https://github.com/WordPress/gutenberg/pull/51223).

## 5.12.0 (2023-06-07)

## 5.11.0 (2023-05-24)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* WordPress dependencies
*/
import { __, sprintf } from '@wordpress/i18n';
import { humanTimeDiff } from '@wordpress/date';
import { createInterpolateElement } from '@wordpress/element';

/**
* Internal dependencies
*/
import {
SidebarNavigationScreenDetailsPanelRow,
SidebarNavigationScreenDetailsPanelLabel,
SidebarNavigationScreenDetailsPanelValue,
} from '../sidebar-navigation-screen-details-panel';

export default function SidebarNavigationScreenDetailsFooter( {
lastModifiedDateTime,
} ) {
return (
<SidebarNavigationScreenDetailsPanelRow className="edit-site-sidebar-navigation-screen-details-footer">
<SidebarNavigationScreenDetailsPanelLabel>
{ __( 'Last modified' ) }
</SidebarNavigationScreenDetailsPanelLabel>
<SidebarNavigationScreenDetailsPanelValue>
{ createInterpolateElement(
sprintf(
/* translators: %s: is the relative time when the post was last modified. */
__( '<time>%s</time>' ),
humanTimeDiff( lastModifiedDateTime )
),
{
time: <time dateTime={ lastModifiedDateTime } />,
}
) }
</SidebarNavigationScreenDetailsPanelValue>
</SidebarNavigationScreenDetailsPanelRow>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.edit-site-sidebar-navigation-screen-details-footer {
padding-top: $grid-unit-10;
padding-bottom: $grid-unit-10;
padding-left: $grid-unit-20;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* WordPress dependencies
*/
import {
__experimentalVStack as VStack,
__experimentalHeading as Heading,
} from '@wordpress/components';

/**
* Internal dependencies
*/
import SidebarNavigationScreenDetailsPanelLabel from './sidebar-navigation-screen-details-panel-label';
import SidebarNavigationScreenDetailsPanelRow from './sidebar-navigation-screen-details-panel-row';
import SidebarNavigationScreenDetailsPanelValue from './sidebar-navigation-screen-details-panel-value';

function SidebarNavigationScreenDetailsPanel( { title, children, spacing } ) {
return (
<VStack
className="edit-site-sidebar-navigation-details-screen-panel"
spacing={ spacing }
>
{ title && (
<Heading
className="edit-site-sidebar-navigation-details-screen-panel__heading"
level={ 3 }
>
{ title }
</Heading>
) }
{ children }
</VStack>
);
}

export {
SidebarNavigationScreenDetailsPanel,
SidebarNavigationScreenDetailsPanelRow,
SidebarNavigationScreenDetailsPanelLabel,
SidebarNavigationScreenDetailsPanelValue,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* WordPress dependencies
*/
import { __experimentalText as Text } from '@wordpress/components';

export default function SidebarNavigationScreenDetailsPanelLabel( {
children,
} ) {
return (
<Text className="edit-site-sidebar-navigation-details-screen-panel__label">
{ children }
</Text>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* External dependencies
*/
import classnames from 'classnames';

/**
* WordPress dependencies
*/
import { __experimentalHStack as HStack } from '@wordpress/components';

export default function SidebarNavigationScreenDetailsPanelRow( {
label,
children,
className,
} ) {
return (
<HStack
key={ label }
spacing={ 5 }
alignment="left"
className={ classnames(
'edit-site-sidebar-navigation-details-screen-panel__row',
className
) }
>
{ children }
</HStack>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* WordPress dependencies
*/
import { __experimentalText as Text } from '@wordpress/components';

export default function SidebarNavigationScreenDetailsPanelValue( {
children,
} ) {
return (
<Text className="edit-site-sidebar-navigation-details-screen-panel__value">
{ children }
</Text>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
.edit-site-sidebar-navigation-details-screen-panel {
margin-bottom: $grid-unit-30;

&:last-of-type {
margin-bottom: 0;
}

.edit-site-sidebar-navigation-details-screen-panel__heading {
color: $gray-400;
text-transform: uppercase;
font-weight: 500;
font-size: 11px;
padding: 0;
margin-bottom: 0;
}
}

.edit-site-sidebar-navigation-details-screen-panel__label.edit-site-sidebar-navigation-details-screen-panel__label {
color: $gray-600;
width: 100px;
}

.edit-site-sidebar-navigation-details-screen-panel__value.edit-site-sidebar-navigation-details-screen-panel__value {
color: $gray-200;
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
/**
* WordPress dependencies
*/
import { __, sprintf } from '@wordpress/i18n';
import { __ } from '@wordpress/i18n';
import { useDispatch, useSelect } from '@wordpress/data';
import {
__experimentalUseNavigator as useNavigator,
__experimentalVStack as VStack,
ExternalLink,
__experimentalTruncate as Truncate,
__experimentalHStack as HStack,
__experimentalText as Text,
} from '@wordpress/components';
import { store as coreStore, useEntityRecord } from '@wordpress/core-data';
import { decodeEntities } from '@wordpress/html-entities';
import { pencil } from '@wordpress/icons';
import { humanTimeDiff } from '@wordpress/date';
import { createInterpolateElement } from '@wordpress/element';
import { __unstableStripHTML as stripHTML } from '@wordpress/dom';
import { escapeAttribute } from '@wordpress/escape-html';

Expand All @@ -26,9 +22,9 @@ import SidebarNavigationScreen from '../sidebar-navigation-screen';
import { unlock } from '../../lock-unlock';
import { store as editSiteStore } from '../../store';
import SidebarButton from '../sidebar-button';
import SidebarNavigationSubtitle from '../sidebar-navigation-subtitle';
import PageDetails from './page-details';
import PageActions from '../page-actions';
import SidebarNavigationScreenDetailsFooter from '../sidebar-navigation-screen-details-footer';

export default function SidebarNavigationScreenPage() {
const navigator = useNavigator();
Expand Down Expand Up @@ -121,35 +117,14 @@ export default function SidebarNavigationScreenPage() {
{ stripHTML( record.excerpt.rendered ) }
</Truncate>
) }
<SidebarNavigationSubtitle>
{ __( 'Details' ) }
</SidebarNavigationSubtitle>
<PageDetails id={ postId } />
</>
}
footer={
!! record?.modified && (
<HStack
spacing={ 5 }
alignment="left"
className="edit-site-sidebar-navigation-screen-page__details edit-site-sidebar-navigation-screen-page__footer"
>
<Text className="edit-site-sidebar-navigation-screen-page__details-label">
{ __( 'Last modified' ) }
</Text>
<Text className="edit-site-sidebar-navigation-screen-page__details-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 } />,
}
) }
</Text>
</HStack>
<SidebarNavigationScreenDetailsFooter
lastModifiedDateTime={ record.modified }
/>
)
}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@
* WordPress dependencies
*/
import { __, _x, sprintf } from '@wordpress/i18n';
import {
__experimentalHStack as HStack,
__experimentalText as Text,
__experimentalVStack as VStack,
__experimentalTruncate as Truncate,
} from '@wordpress/components';
import { __experimentalTruncate as Truncate } from '@wordpress/components';
import { count as wordCount } from '@wordpress/wordcount';
import { useSelect } from '@wordpress/data';
import { decodeEntities } from '@wordpress/html-entities';
Expand All @@ -19,6 +14,12 @@ import { store as coreStore, useEntityRecord } from '@wordpress/core-data';
import StatusLabel from './status-label';
import { unlock } from '../../lock-unlock';
import { store as editSiteStore } from '../../store';
import {
SidebarNavigationScreenDetailsPanel,
SidebarNavigationScreenDetailsPanelRow,
SidebarNavigationScreenDetailsPanelLabel,
SidebarNavigationScreenDetailsPanelValue,
} from '../sidebar-navigation-screen-details-panel';

// Taken from packages/editor/src/components/time-to-read/index.js.
const AVERAGE_READING_RATE = 189;
Expand Down Expand Up @@ -138,26 +139,21 @@ export default function PageDetails( { id } ) {
[ record?.parent ]
);
return (
<VStack spacing={ 5 }>
<SidebarNavigationScreenDetailsPanel title={ __( 'Details' ) }>
{ getPageDetails( {
parentTitle,
templateTitle,
...record,
} ).map( ( { label, value } ) => (
<HStack
key={ label }
spacing={ 5 }
alignment="left"
className="edit-site-sidebar-navigation-screen-page__details"
>
<Text className="edit-site-sidebar-navigation-screen-page__details-label">
<SidebarNavigationScreenDetailsPanelRow key={ label }>
<SidebarNavigationScreenDetailsPanelLabel>
{ label }
</Text>
<Text className="edit-site-sidebar-navigation-screen-page__details-value">
</SidebarNavigationScreenDetailsPanelLabel>
<SidebarNavigationScreenDetailsPanelValue>
{ value }
</Text>
</HStack>
</SidebarNavigationScreenDetailsPanelValue>
</SidebarNavigationScreenDetailsPanelRow>
) ) }
</VStack>
</SidebarNavigationScreenDetailsPanel>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

.edit-site-sidebar-navigation-screen-page__excerpt {
font-size: $helptext-font-size;
margin-bottom: $grid-unit-30;
}

.edit-site-sidebar-navigation-screen-page__modified {
Expand Down Expand Up @@ -60,21 +61,3 @@
fill: $alert-green;
}
}

.edit-site-sidebar-navigation-screen-page__footer {
padding-top: $grid-unit-10;
padding-bottom: $grid-unit-10;
padding-left: $grid-unit-20;
}

.edit-site-sidebar-navigation-screen-page__details {
.edit-site-sidebar-navigation-screen-page__details-label {
color: $gray-600;
width: 100px;
}

.edit-site-sidebar-navigation-screen-page__details-value.edit-site-sidebar-navigation-screen-page__details-value {
color: $gray-200;
}
}

Loading

1 comment on commit 7efbf84

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 7efbf84.
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/5317672081
📝 Reported issues:

Please sign in to comment.