From 0e598d51632419385692ad30fbcf773a925f7fc6 Mon Sep 17 00:00:00 2001
From: Saxon Fletcher
Date: Tue, 16 May 2023 09:16:04 +1000
Subject: [PATCH 01/12] setting the stage for page detail
---
.../sidebar-navigation-data-list/index.js | 33 +++
.../sidebar-navigation-data-list/style.scss | 5 +
.../sidebar-navigation-screen-page/index.js | 240 +++++++++++++++++-
.../sidebar-navigation-screen/index.js | 16 +-
.../sidebar-navigation-screen/style.scss | 39 ++-
.../sidebar-navigation-subtitle/style.scss | 2 +-
packages/edit-site/src/style.scss | 1 +
7 files changed, 319 insertions(+), 17 deletions(-)
create mode 100644 packages/edit-site/src/components/sidebar-navigation-data-list/index.js
create mode 100644 packages/edit-site/src/components/sidebar-navigation-data-list/style.scss
diff --git a/packages/edit-site/src/components/sidebar-navigation-data-list/index.js b/packages/edit-site/src/components/sidebar-navigation-data-list/index.js
new file mode 100644
index 00000000000000..5cfcb3674e7d16
--- /dev/null
+++ b/packages/edit-site/src/components/sidebar-navigation-data-list/index.js
@@ -0,0 +1,33 @@
+/**
+ * WordPress dependencies
+ */
+import {
+ __experimentalHStack as HStack,
+ __experimentalVStack as VStack,
+ __experimentalText as Text,
+} from '@wordpress/components';
+
+/**
+ * Internal dependencies
+ */
+
+export default function SidebarDetails( { details } ) {
+ return (
+
+ { details.map( ( detail ) => (
+
+
+ { detail.label }
+
+
+ { detail.value }
+
+
+ ) ) }
+
+ );
+}
diff --git a/packages/edit-site/src/components/sidebar-navigation-data-list/style.scss b/packages/edit-site/src/components/sidebar-navigation-data-list/style.scss
new file mode 100644
index 00000000000000..4bbce5222f25c1
--- /dev/null
+++ b/packages/edit-site/src/components/sidebar-navigation-data-list/style.scss
@@ -0,0 +1,5 @@
+.edit-site-sidebar-data-list {
+ .edit-site-sidebar-data-list__label {
+ color: $gray-600;
+ }
+}
diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-page/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-page/index.js
index 5acfc98ffe52c1..5bdce47b876328 100644
--- a/packages/edit-site/src/components/sidebar-navigation-screen-page/index.js
+++ b/packages/edit-site/src/components/sidebar-navigation-screen-page/index.js
@@ -5,6 +5,9 @@ import { __ } from '@wordpress/i18n';
import { useDispatch } from '@wordpress/data';
import {
__experimentalUseNavigator as useNavigator,
+ __experimentalHStack as HStack,
+ __experimentalVStack as VStack,
+ __experimentalText as Text,
ExternalLink,
} from '@wordpress/components';
import { useEntityRecord } from '@wordpress/core-data';
@@ -18,6 +21,8 @@ import SidebarNavigationScreen from '../sidebar-navigation-screen';
import { unlock } from '../../private-apis';
import { store as editSiteStore } from '../../store';
import SidebarButton from '../sidebar-button';
+import SidebarNavigationSubtitle from '../sidebar-navigation-subtitle';
+import SidebarDetails from '../sidebar-navigation-data-list';
export default function SidebarNavigationScreenPage() {
const { setCanvasMode } = unlock( useDispatch( editSiteStore ) );
@@ -36,24 +41,231 @@ export default function SidebarNavigationScreenPage() {
icon={ pencil }
/>
}
- description={ __(
- 'Pages are static and are not listed by date. Pages do not use tags or categories.'
- ) }
+ meta={
+ record ? (
+
+ { record?.link && (
+
+ { record.link }
+
+ ) }
+
+
+ ) : null
+ }
+ footer={
+ record && (
+
+ )
+ }
content={
<>
- { record?.link ? (
-
- { record.link }
-
- ) : null }
- { record
- ? decodeEntities( record?.description?.rendered )
- : null }
+
+ { record?.excerpt?.raw && (
+ { decodeEntities( record?.excerpt?.raw ) }
+ ) }
+
+ Details
+
+
>
}
/>
);
}
+
+const statusLabels = {
+ publish: 'Published',
+ future: 'Scheduled',
+ draft: 'Draft',
+ pending: 'Pending',
+};
+
+function relativeTime( date1, date2 ) {
+ const diffInSeconds = Math.abs( date1.getTime() - date2.getTime() ) / 1000;
+
+ const units = [
+ { name: 'second', limit: 60, in_seconds: 1 },
+ { name: 'minute', limit: 3600, in_seconds: 60 },
+ { name: 'hour', limit: 86400, in_seconds: 3600 },
+ { name: 'day', limit: 604800, in_seconds: 86400 },
+ { name: 'week', limit: 2629743, in_seconds: 604800 },
+ { name: 'month', limit: 31556926, in_seconds: 2629743 },
+ { name: 'year', limit: Infinity, in_seconds: 31556926 },
+ ];
+
+ let i = 0,
+ unit;
+ while ( ( unit = units[ i++ ] ) ) {
+ if ( diffInSeconds < unit.limit || ! unit.limit ) {
+ const diff = Math.floor( diffInSeconds / unit.in_seconds );
+ return (
+ diff +
+ ' ' +
+ unit.name +
+ ( diff > 1 ? 's' : '' ) +
+ ' ' +
+ ( date1 > date2 ? 'ago' : 'from now' )
+ );
+ }
+ }
+}
+
+export const PostStatus = ( { status, date } ) => {
+ const statusLabel = statusLabels[ status ] ?? 'Unknown';
+ const formattedDate = date
+ ? relativeTime( new Date(), new Date( date ) )
+ : null;
+
+ return (
+
+ { /* */ }
+ { statusLabel }
+ { formattedDate && { formattedDate } }
+
+ );
+};
+
+// const StatusIcon = ( { status } ) => {
+// switch ( status ) {
+// case 'draft':
+// return ;
+// case 'pending':
+// return ;
+// case 'future':
+// return ;
+// case 'publish':
+// return ;
+// }
+// return null;
+// };
+
+const PostModified = ( { date } ) => {
+ return (
+
+
+
+ Last modified { relativeTime( new Date(), new Date( date ) ) }{ ' ' }
+ by Dan
+
+
+ );
+};
+
+// const DraftIcon = () => (
+//
+// );
+
+// const PendingIcon = () => (
+//
+// );
+
+// const ScheduledIcon = () => (
+//
+// );
+
+// const PublishIcon = () => (
+//
+// );
diff --git a/packages/edit-site/src/components/sidebar-navigation-screen/index.js b/packages/edit-site/src/components/sidebar-navigation-screen/index.js
index 77b9bedba3e655..a1bd2cacb60e21 100644
--- a/packages/edit-site/src/components/sidebar-navigation-screen/index.js
+++ b/packages/edit-site/src/components/sidebar-navigation-screen/index.js
@@ -27,7 +27,9 @@ export default function SidebarNavigationScreen( {
isRoot,
title,
actions,
+ meta,
content,
+ footer,
description,
} ) {
const { dashboardLink } = useSelect( ( select ) => {
@@ -40,7 +42,7 @@ export default function SidebarNavigationScreen( {
const theme = getTheme( currentlyPreviewingTheme() );
return (
-
+
{ actions }
+ { meta && (
+ <>
+
+ { meta }
+
+ >
+ ) }
+ { footer && (
+
+ ) }
);
}
diff --git a/packages/edit-site/src/components/sidebar-navigation-screen/style.scss b/packages/edit-site/src/components/sidebar-navigation-screen/style.scss
index b72edaba63f7df..2605e3da345880 100644
--- a/packages/edit-site/src/components/sidebar-navigation-screen/style.scss
+++ b/packages/edit-site/src/components/sidebar-navigation-screen/style.scss
@@ -6,8 +6,38 @@
}
.edit-site-sidebar-navigation-screen__content {
+ margin: 0 0 $grid-unit-20 0;
+ color: $gray-400;
+ padding: $grid-unit-20;
+ .components-text {
+ color: $gray-400;
+ }
+ //z-index: z-index(".edit-site-sidebar-navigation-screen__content");
+}
+
+.edit-site-sidebar-navigation-screen__meta {
+ margin: 0 0 $grid-unit-20 0;
+ color: $gray-400;
+ margin-left: $grid-unit-20;
+ .components-text {
+ color: $gray-400;
+ }
+ //z-index: z-index(".edit-site-sidebar-navigation-screen__content");
+}
+
+.edit-site-sidebar-modified {
margin: 0 0 $grid-unit-20 0;
color: $gray-600;
+ margin-left: $grid-unit-20;
+ .components-text {
+ color: $gray-600;
+ }
+ .edit-site-sidebar-modified__avatar {
+ width: 16px;
+ height: 16px;
+ border-radius: 999px;
+ background: $gray-700;
+ }
//z-index: z-index(".edit-site-sidebar-navigation-screen__content");
}
@@ -22,10 +52,17 @@
.components-external-link__icon {
margin-left: $grid-unit-05;
}
- margin-left: $grid-unit-20;
display: inline-block;
}
+.edit-site-sidebar-navigation-screen__page-image {
+ width: 100%;
+ border-radius: 2px;
+ margin-bottom: $grid-unit-20;
+ display: block;
+ max-height: 128px;
+}
+
.edit-site-sidebar-navigation-screen__title-icon {
position: sticky;
top: 0;
diff --git a/packages/edit-site/src/components/sidebar-navigation-subtitle/style.scss b/packages/edit-site/src/components/sidebar-navigation-subtitle/style.scss
index 735145ca1d80ce..53124a298f63af 100644
--- a/packages/edit-site/src/components/sidebar-navigation-subtitle/style.scss
+++ b/packages/edit-site/src/components/sidebar-navigation-subtitle/style.scss
@@ -3,5 +3,5 @@
text-transform: uppercase;
font-weight: 500;
font-size: 11px;
- padding: $grid-unit-20 0 0 $grid-unit-20;
+ padding: $grid-unit-20 0 $grid-unit-10;
}
diff --git a/packages/edit-site/src/style.scss b/packages/edit-site/src/style.scss
index 3be15cd02d2599..aa922a7feac97e 100644
--- a/packages/edit-site/src/style.scss
+++ b/packages/edit-site/src/style.scss
@@ -29,6 +29,7 @@
@import "./components/sidebar-navigation-screen-template/style.scss";
@import "./components/sidebar-navigation-screen-templates/style.scss";
@import "./components/sidebar-navigation-subtitle/style.scss";
+@import "./components/sidebar-navigation-data-list/style.scss";
@import "./components/site-hub/style.scss";
@import "./components/sidebar-navigation-screen-navigation-menus/style.scss";
@import "./components/site-icon/style.scss";
From 237a864b6bdb1fe3237ad4eba1c6497e7a8145dd Mon Sep 17 00:00:00 2001
From: Saxon Fletcher
Date: Tue, 16 May 2023 09:37:29 +1000
Subject: [PATCH 02/12] fix padding issues
---
.../sidebar-navigation-screen-navigation-menus/style.scss | 2 +-
.../src/components/sidebar-navigation-screen/style.scss | 7 +++++--
.../src/components/sidebar-navigation-subtitle/style.scss | 2 +-
3 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menus/style.scss b/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menus/style.scss
index e594fa0384e1db..6ecf61df710a47 100644
--- a/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menus/style.scss
+++ b/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menus/style.scss
@@ -1,5 +1,5 @@
.edit-site-sidebar-navigation-screen__description {
- margin: 0 0 $grid-unit-40 $grid-unit-20;
+ margin: 0 0 $grid-unit-40 0;
}
.edit-site-sidebar-navigation-screen-navigation-menus__content {
diff --git a/packages/edit-site/src/components/sidebar-navigation-screen/style.scss b/packages/edit-site/src/components/sidebar-navigation-screen/style.scss
index 2605e3da345880..5efcd29bf1313e 100644
--- a/packages/edit-site/src/components/sidebar-navigation-screen/style.scss
+++ b/packages/edit-site/src/components/sidebar-navigation-screen/style.scss
@@ -8,7 +8,11 @@
.edit-site-sidebar-navigation-screen__content {
margin: 0 0 $grid-unit-20 0;
color: $gray-400;
- padding: $grid-unit-20;
+ padding: 0 $grid-unit-20;
+ .components-item-group {
+ margin-left: -$grid-unit-20;
+ margin-right: -$grid-unit-20;
+ }
.components-text {
color: $gray-400;
}
@@ -80,7 +84,6 @@
}
.edit-site-sidebar-navigation-screen__content .edit-site-global-styles-style-variations-container {
- margin-left: $grid-unit-20;
.edit-site-global-styles-variations_item-preview {
border: $gray-900 $border-width solid;
}
diff --git a/packages/edit-site/src/components/sidebar-navigation-subtitle/style.scss b/packages/edit-site/src/components/sidebar-navigation-subtitle/style.scss
index 53124a298f63af..e44f9f39d7b90f 100644
--- a/packages/edit-site/src/components/sidebar-navigation-subtitle/style.scss
+++ b/packages/edit-site/src/components/sidebar-navigation-subtitle/style.scss
@@ -3,5 +3,5 @@
text-transform: uppercase;
font-weight: 500;
font-size: 11px;
- padding: $grid-unit-20 0 $grid-unit-10;
+ padding: $grid-unit-10 0;
}
From f38ff6929cae8963f88bf6be4815fbadfe3aa14e Mon Sep 17 00:00:00 2001
From: ramon
Date: Tue, 16 May 2023 16:24:30 +1000
Subject: [PATCH 03/12] Filling in the details :)
---
.../sidebar-navigation-screen-page/index.js | 109 ++++++++++++++++--
1 file changed, 101 insertions(+), 8 deletions(-)
diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-page/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-page/index.js
index 5bdce47b876328..4cda481b2832c4 100644
--- a/packages/edit-site/src/components/sidebar-navigation-screen-page/index.js
+++ b/packages/edit-site/src/components/sidebar-navigation-screen-page/index.js
@@ -2,7 +2,7 @@
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
-import { useDispatch } from '@wordpress/data';
+import { useDispatch, useSelect } from '@wordpress/data';
import {
__experimentalUseNavigator as useNavigator,
__experimentalHStack as HStack,
@@ -10,7 +10,11 @@ import {
__experimentalText as Text,
ExternalLink,
} from '@wordpress/components';
-import { useEntityRecord } from '@wordpress/core-data';
+import {
+ store as coreStore,
+ useEntityRecord,
+ useEntityRecords,
+} from '@wordpress/core-data';
import { decodeEntities } from '@wordpress/html-entities';
import { pencil } from '@wordpress/icons';
@@ -24,12 +28,102 @@ import SidebarButton from '../sidebar-button';
import SidebarNavigationSubtitle from '../sidebar-navigation-subtitle';
import SidebarDetails from '../sidebar-navigation-data-list';
+function countWordsInHTML( htmlString ) {
+ const parser = new window.DOMParser();
+ const doc = parser.parseFromString( htmlString, 'text/html' );
+
+ let wordCount = 0;
+
+ function countWords( node ) {
+ if ( node.nodeType === 3 ) {
+ const text = node.textContent.trim();
+
+ if ( text !== '' ) {
+ const words = text.split( /\s+/ );
+ wordCount += words.length;
+ }
+ } else if ( node.nodeType === 1 ) {
+ const children = node.childNodes;
+ for ( let i = 0; i < children.length; i++ ) {
+ countWords( children[ i ] );
+ }
+ }
+ }
+
+ countWords( doc.body );
+ return wordCount;
+}
+const estimateReadingTime = ( wordCount, wordsPerMinute = 200 ) =>
+ Math.ceil( wordCount / wordsPerMinute );
+
+function getPageDetails( page ) {
+ if ( ! page ) {
+ return [];
+ }
+
+ const wordCount = countWordsInHTML( page?.content?.rendered ) || 0;
+ const readingTime = estimateReadingTime( wordCount );
+
+ return [
+ {
+ label: 'Template',
+ value: page?.templateTitle,
+ },
+ {
+ label: 'Parent',
+ value: page?.parentTitle,
+ },
+ {
+ label: 'Words',
+ value: wordCount.toLocaleString() || 'Unknown',
+ },
+ {
+ label: 'Time to read',
+ value:
+ readingTime > 1
+ ? `${ readingTime.toLocaleString() } mins`
+ : '1 min',
+ },
+ ];
+}
+
export default function SidebarNavigationScreenPage() {
const { setCanvasMode } = unlock( useDispatch( editSiteStore ) );
const {
params: { postId },
} = useNavigator();
+
const { record } = useEntityRecord( 'postType', 'page', postId );
+ const { records: templates, isResolving: areTemplatesLoading } =
+ useEntityRecords( 'postType', 'wp_template', {
+ per_page: -1,
+ } );
+
+ const templateTitle = areTemplatesLoading
+ ? ''
+ : templates?.find( ( template ) => template?.slug === record?.template )
+ ?.title?.rendered || 'Default';
+
+ const parentTitle = useSelect(
+ ( select ) => {
+ const parent = record?.parent
+ ? select( coreStore ).getEntityRecord(
+ 'postType',
+ 'page',
+ record.parent
+ )
+ : null;
+
+ if ( parent ) {
+ return parent?.title?.rendered
+ ? decodeEntities( parent.title.rendered )
+ : 'No title';
+ }
+
+ return 'Top level';
+ },
+ [ record ]
+ );
return (
>
}
From b027db41c873a3182332de81b68c3b0767673556 Mon Sep 17 00:00:00 2001
From: ramon
Date: Mon, 22 May 2023 16:32:39 +1000
Subject: [PATCH 04/12] This commit: - exports `getMediaDetails()` from the
post-featured-image sidebar component and uses it if there's a featured image
in the post record - cleans up components and unused functions - uses
available wordcount and readtime functions - implements i18n strings -
shuffles page-specific styles around - update package log after importing
@wordpress/wordcount - truncating titles and other long excerpts - adding
status icons - adding featured image description and loading placeholder
---
package-lock.json | 25 +-
packages/date/src/test/index.js | 31 +-
packages/edit-site/package.json | 1 +
.../sidebar-navigation-data-list/index.js | 13 +-
.../sidebar-navigation-data-list/style.scss | 10 +-
.../sidebar-navigation-screen-page/index.js | 490 ++++++++----------
.../sidebar-navigation-screen-page/style.scss | 110 ++++
.../sidebar-navigation-screen-pages/index.js | 12 +-
.../sidebar-navigation-screen/index.js | 3 +-
.../sidebar-navigation-screen/style.scss | 36 +-
packages/edit-site/src/style.scss | 1 +
packages/editor/src/components/index.js | 5 +-
.../components/post-featured-image/index.js | 2 +-
13 files changed, 423 insertions(+), 316 deletions(-)
create mode 100644 packages/edit-site/src/components/sidebar-navigation-screen-page/style.scss
diff --git a/package-lock.json b/package-lock.json
index 9a9358f11a53fa..3a9abff6cc62d6 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -17778,6 +17778,7 @@
"@wordpress/url": "file:packages/url",
"@wordpress/viewport": "file:packages/viewport",
"@wordpress/widgets": "file:packages/widgets",
+ "@wordpress/wordcount": "file:packages/wordcount",
"classnames": "^2.3.1",
"colord": "^2.9.2",
"downloadjs": "^1.4.7",
@@ -25879,7 +25880,7 @@
"array-ify": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/array-ify/-/array-ify-1.0.0.tgz",
- "integrity": "sha1-nlKHYrSpBmrRY6aWKjZEGOlibs4=",
+ "integrity": "sha512-c5AMf34bKdvPhQ7tBGhqkgKNUzMr4WUs+WDtC2ZUGOUncbxKMTvqxYctiseW3+L4bA8ec+GcZ6/A/FW4m8ukng==",
"dev": true
},
"array-includes": {
@@ -31048,7 +31049,7 @@
"debuglog": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/debuglog/-/debuglog-1.0.1.tgz",
- "integrity": "sha1-qiT/uaw9+aI1GDfPstJ5NgzXhJI=",
+ "integrity": "sha512-syBZ+rnAK3EgMsH2aYEOLUW7mZSY9Gb+0wUMCFsZvcmiz+HigA0LOcq/HoQqVuGG+EKykunc7QG2bzrponfaSw==",
"dev": true
},
"decache": {
@@ -35890,7 +35891,7 @@
"git-remote-origin-url": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/git-remote-origin-url/-/git-remote-origin-url-2.0.0.tgz",
- "integrity": "sha1-UoJlna4hBxRaERJhEq0yFuxfpl8=",
+ "integrity": "sha512-eU+GGrZgccNJcsDH5LkXR3PB9M958hxc7sbA8DFJjrv9j4L2P/eZfKhM+QD6wyzpiv+b1BpK0XrYCxkovtjSLw==",
"dev": true,
"requires": {
"gitconfiglocal": "^1.0.0",
@@ -35937,7 +35938,7 @@
"gitconfiglocal": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/gitconfiglocal/-/gitconfiglocal-1.0.0.tgz",
- "integrity": "sha1-QdBF84UaXqiPA/JMocYXgRRGS5s=",
+ "integrity": "sha512-spLUXeTAVHxDtKsJc8FkFVgFtMdEN9qPGpL23VfSHx4fP4+Ds097IXLvymbnDH8FnmxX5Nr9bPw3A+AQ6mWEaQ==",
"dev": true,
"requires": {
"ini": "^1.3.2"
@@ -37211,7 +37212,7 @@
"humanize-ms": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/humanize-ms/-/humanize-ms-1.2.1.tgz",
- "integrity": "sha1-xG4xWaKT9riW2ikxbYtv6Lt5u+0=",
+ "integrity": "sha512-Fl70vYtsAFb/C06PTS9dZBo7ihau+Tu/DNCk/OyHhea07S+aeMWpFFkUaXRa8fI+ScZbEI8dfSxwY7gxZ9SAVQ==",
"dev": true,
"requires": {
"ms": "^2.0.0"
@@ -38227,7 +38228,7 @@
"is-text-path": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/is-text-path/-/is-text-path-1.0.1.tgz",
- "integrity": "sha1-Thqg+1G/vLPpJogAE5cgLBd1tm4=",
+ "integrity": "sha512-xFuJpne9oFz5qDaodwmmG08e3CawH/2ZV8Qqza1Ko7Sk8POWbkRdwIoAWVhqvq0XeUzANEhKo2n0IXUGBm7A/w==",
"dev": true,
"requires": {
"text-extensions": "^1.0.0"
@@ -40000,7 +40001,7 @@
"jsonparse": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/jsonparse/-/jsonparse-1.3.1.tgz",
- "integrity": "sha1-P02uSpH6wxX3EGL4UhzCOfE2YoA=",
+ "integrity": "sha512-POQXvpdL69+CluYsillJ7SUhKvytYjW9vG/GKpnf+xP8UWgYEM/RaMzHHofbALDiKbbP1W8UEYmgGl39WkPZsg==",
"dev": true
},
"jsprim": {
@@ -41100,7 +41101,7 @@
"lodash.ismatch": {
"version": "4.4.0",
"resolved": "https://registry.npmjs.org/lodash.ismatch/-/lodash.ismatch-4.4.0.tgz",
- "integrity": "sha1-dWy1FQyjum8RCFp4hJZF8Yj4Xzc=",
+ "integrity": "sha512-fPMfXjGQEV9Xsq/8MTSgUf255gawYRbjwMyDbcvDhXgV7enSZA0hynz6vMPnpAb5iONEzBHBPsT+0zes5Z301g==",
"dev": true
},
"lodash.isplainobject": {
@@ -48603,7 +48604,7 @@
"promzard": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/promzard/-/promzard-0.3.0.tgz",
- "integrity": "sha1-JqXW7ox97kyxIggwWs+5O6OCqe4=",
+ "integrity": "sha512-JZeYqd7UAcHCwI+sTOeUDYkvEU+1bQ7iE0UT1MgB/tERkAPkesW46MrpIySzODi+owTjZtiF8Ay5j9m60KmMBw==",
"dev": true,
"requires": {
"read": "1"
@@ -48637,7 +48638,7 @@
"proto-list": {
"version": "1.2.4",
"resolved": "https://registry.npmjs.org/proto-list/-/proto-list-1.2.4.tgz",
- "integrity": "sha1-IS1b/hMYMGpCD2QCuOJv85ZHqEk=",
+ "integrity": "sha512-vtK/94akxsTMhe0/cbfpR+syPuszcuwhqVjJq26CuNDgFGj682oRBXOP5MJpv2r7JtE8MsiepGIqvvOTBwn2vA==",
"dev": true
},
"protocols": {
@@ -50194,7 +50195,7 @@
"read": {
"version": "1.0.7",
"resolved": "https://registry.npmjs.org/read/-/read-1.0.7.tgz",
- "integrity": "sha1-s9oZvQUkMal2cdRKQmNK33ELQMQ=",
+ "integrity": "sha512-rSOKNYUmaxy0om1BNjMN4ezNT6VKK+2xF4GBhc81mkH7L60i6dp8qPYrkndNLT3QPphoII3maL9PVC9XmhHwVQ==",
"dev": true,
"requires": {
"mute-stream": "~0.0.4"
@@ -55551,7 +55552,7 @@
"temp-dir": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/temp-dir/-/temp-dir-1.0.0.tgz",
- "integrity": "sha1-CnwOom06Oa+n4OvqnB/AvE2qAR0=",
+ "integrity": "sha512-xZFXEGbG7SNC3itwBzI3RYjq/cEhBkx2hJuKGIUOcEULmkQExXiHat2z/qkISYsuR+IKumhEfKKbV5qXmhICFQ==",
"dev": true
},
"terminal-link": {
diff --git a/packages/date/src/test/index.js b/packages/date/src/test/index.js
index ff82748e02f23a..1832d4c7c55a2b 100644
--- a/packages/date/src/test/index.js
+++ b/packages/date/src/test/index.js
@@ -623,7 +623,7 @@ describe( 'Moment.js Localization', () => {
} );
describe( 'humanTimeDiff', () => {
- it( 'should return human readable time differences', () => {
+ it( 'should return human readable time differences in the past', () => {
expect(
humanTimeDiff(
'2023-04-28T11:00:00.000Z',
@@ -642,6 +642,35 @@ describe( 'Moment.js Localization', () => {
'2023-04-30T13:00:00.000Z'
)
).toBe( '2 days ago' );
+
+ expect(
+ humanTimeDiff(
+ '2023-04-28T11:00:00.000Z',
+ '2023-04-28T13:00:00.000Z'
+ )
+ ).toBe( '2 hours ago' );
+
+ expect(
+ humanTimeDiff(
+ '2023-04-26T13:00:00.000Z',
+ '2023-04-28T13:00:00.000Z'
+ )
+ ).toBe( '2 days ago' );
+ } );
+
+ it( 'should return human readable time differences in the future', () => {
+ // Future.
+ const now = new Date();
+ const twoHoursLater = new Date(
+ now.getTime() + 2 * 60 * 60 * 1000
+ );
+ expect( humanTimeDiff( twoHoursLater ) ).toBe( 'in 2 hours' );
+
+ const twoDaysLater = new Date(
+ now.getTime() + 2 * 24 * 60 * 60 * 1000
+ ); // Adding 2 days in milliseconds
+
+ expect( humanTimeDiff( twoDaysLater ) ).toBe( 'in 2 days' );
} );
} );
} );
diff --git a/packages/edit-site/package.json b/packages/edit-site/package.json
index 8eba789d5713ed..265f18b9a95974 100644
--- a/packages/edit-site/package.json
+++ b/packages/edit-site/package.json
@@ -61,6 +61,7 @@
"@wordpress/url": "file:../url",
"@wordpress/viewport": "file:../viewport",
"@wordpress/widgets": "file:../widgets",
+ "@wordpress/wordcount": "file:../wordcount",
"classnames": "^2.3.1",
"colord": "^2.9.2",
"downloadjs": "^1.4.7",
diff --git a/packages/edit-site/src/components/sidebar-navigation-data-list/index.js b/packages/edit-site/src/components/sidebar-navigation-data-list/index.js
index 5cfcb3674e7d16..a6e63a036950fa 100644
--- a/packages/edit-site/src/components/sidebar-navigation-data-list/index.js
+++ b/packages/edit-site/src/components/sidebar-navigation-data-list/index.js
@@ -13,17 +13,20 @@ import {
export default function SidebarDetails( { details } ) {
return (
-
+
{ details.map( ( detail ) => (
-
+
{ detail.label }
-
+
{ detail.value }
diff --git a/packages/edit-site/src/components/sidebar-navigation-data-list/style.scss b/packages/edit-site/src/components/sidebar-navigation-data-list/style.scss
index 4bbce5222f25c1..792930fe711926 100644
--- a/packages/edit-site/src/components/sidebar-navigation-data-list/style.scss
+++ b/packages/edit-site/src/components/sidebar-navigation-data-list/style.scss
@@ -1,5 +1,7 @@
-.edit-site-sidebar-data-list {
- .edit-site-sidebar-data-list__label {
- color: $gray-600;
- }
+.edit-site-sidebar-navigation_data-list__label {
+ color: $gray-600;
+}
+
+.edit-site-sidebar-navigation_data-list__item .edit-site-sidebar-navigation_data-list__value {
+ color: $white;
}
diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-page/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-page/index.js
index 4cda481b2832c4..d0f71ca943f2e9 100644
--- a/packages/edit-site/src/components/sidebar-navigation-screen-page/index.js
+++ b/packages/edit-site/src/components/sidebar-navigation-screen-page/index.js
@@ -1,7 +1,12 @@
+/**
+ * External dependencies
+ */
+import classnames from 'classnames';
+
/**
* WordPress dependencies
*/
-import { __ } from '@wordpress/i18n';
+import { __, _x, sprintf } from '@wordpress/i18n';
import { useDispatch, useSelect } from '@wordpress/data';
import {
__experimentalUseNavigator as useNavigator,
@@ -9,6 +14,7 @@ import {
__experimentalVStack as VStack,
__experimentalText as Text,
ExternalLink,
+ __experimentalTruncate as Truncate,
} from '@wordpress/components';
import {
store as coreStore,
@@ -17,6 +23,10 @@ import {
} from '@wordpress/core-data';
import { decodeEntities } from '@wordpress/html-entities';
import { pencil } from '@wordpress/icons';
+import { dateI18n, getDate, getSettings, humanTimeDiff } from '@wordpress/date';
+import { count as wordCount } from '@wordpress/wordcount';
+import { getMediaDetails } from '@wordpress/editor';
+import { createInterpolateElement } from '@wordpress/element';
/**
* Internal dependencies
@@ -28,63 +38,131 @@ import SidebarButton from '../sidebar-button';
import SidebarNavigationSubtitle from '../sidebar-navigation-subtitle';
import SidebarDetails from '../sidebar-navigation-data-list';
-function countWordsInHTML( htmlString ) {
- const parser = new window.DOMParser();
- const doc = parser.parseFromString( htmlString, 'text/html' );
-
- let wordCount = 0;
-
- function countWords( node ) {
- if ( node.nodeType === 3 ) {
- const text = node.textContent.trim();
+// Taken from packages/editor/src/components/time-to-read/index.js.
+const AVERAGE_READING_RATE = 189;
- if ( text !== '' ) {
- const words = text.split( /\s+/ );
- wordCount += words.length;
- }
- } else if ( node.nodeType === 1 ) {
- const children = node.childNodes;
- for ( let i = 0; i < children.length; i++ ) {
- countWords( children[ i ] );
- }
- }
+function StatusLabel( { status, date } ) {
+ const relateToNow = humanTimeDiff( date );
+ let statusLabel = '';
+ switch ( status ) {
+ case 'publish':
+ statusLabel = createInterpolateElement(
+ sprintf(
+ /* translators: %s: is the relative time when the post was published. */
+ __( 'Published ' ),
+ relateToNow
+ ),
+ { time: }
+ );
+ break;
+ case 'future':
+ const formattedDate = dateI18n(
+ getSettings().formats.date,
+ getDate( date )
+ );
+ statusLabel = createInterpolateElement(
+ sprintf(
+ /* translators: %s: is the formatted date and time on which the post is scheduled to be published. */
+ __( 'Scheduled for ' ),
+ formattedDate
+ ),
+ { time: }
+ );
+ break;
+ case 'draft':
+ statusLabel = __( 'Draft' );
+ break;
+ case 'pending':
+ statusLabel = __( 'Pending' );
+ break;
+ default:
+ statusLabel = __( 'Unknown' );
+ break;
}
- countWords( doc.body );
- return wordCount;
+ return (
+
+
+ { statusLabel }
+
+ );
}
-const estimateReadingTime = ( wordCount, wordsPerMinute = 200 ) =>
- Math.ceil( wordCount / wordsPerMinute );
function getPageDetails( page ) {
if ( ! page ) {
return [];
}
+ const details = [];
+
+ if ( page?.status ) {
+ details.push( {
+ label: 'Status',
+ value: ,
+ } );
+ }
- const wordCount = countWordsInHTML( page?.content?.rendered ) || 0;
- const readingTime = estimateReadingTime( wordCount );
+ if ( page?.slug ) {
+ details.push( {
+ label: 'Slug',
+ value: { page.slug },
+ } );
+ }
- return [
- {
+ if ( page?.templateTitle ) {
+ details.push( {
label: 'Template',
- value: page?.templateTitle,
- },
- {
- label: 'Parent',
- value: page?.parentTitle,
- },
- {
- label: 'Words',
- value: wordCount.toLocaleString() || 'Unknown',
- },
- {
- label: 'Time to read',
- value:
- readingTime > 1
- ? `${ readingTime.toLocaleString() } mins`
- : '1 min',
- },
- ];
+ value: page.templateTitle,
+ } );
+ }
+
+ details.push( {
+ label: 'Parent',
+ value: page?.parentTitle,
+ } );
+
+ /*
+ * translators: If your word count is based on single characters (e.g. East Asian characters),
+ * enter 'characters_excluding_spaces' or 'characters_including_spaces'. Otherwise, enter 'words'.
+ * Do not translate into your own language.
+ */
+ const wordCountType = _x( 'words', 'Word count type. Do not translate!' );
+ const wordsCounted = page?.content?.raw
+ ? wordCount( page.content.raw, wordCountType )
+ : 0;
+ const readingTime = Math.round( wordsCounted / AVERAGE_READING_RATE );
+
+ if ( wordsCounted ) {
+ details.push(
+ {
+ label: 'Words',
+ value: wordsCounted.toLocaleString() || __( 'Unknown' ),
+ },
+ {
+ label: 'Time to read',
+ value:
+ readingTime > 1
+ ? sprintf(
+ /* translators: %s: is the number of minutes. */
+ __( '%s mins' ),
+ readingTime.toLocaleString()
+ )
+ : __( '< 1 min' ),
+ }
+ );
+ }
+ return details;
}
export default function SidebarNavigationScreenPage() {
@@ -92,20 +170,35 @@ export default function SidebarNavigationScreenPage() {
const {
params: { postId },
} = useNavigator();
-
const { record } = useEntityRecord( 'postType', 'page', postId );
+ /*
+ * Only custom template slugs are available in the post entity record
+ * Pages using theme templates will not have a template slug.
+ */
const { records: templates, isResolving: areTemplatesLoading } =
useEntityRecords( 'postType', 'wp_template', {
per_page: -1,
} );
-
const templateTitle = areTemplatesLoading
? ''
: templates?.find( ( template ) => template?.slug === record?.template )
- ?.title?.rendered || 'Default';
+ ?.title?.rendered || '';
- const parentTitle = useSelect(
+ const {
+ parentTitle,
+ featuredMediaDetails: { mediaSourceUrl, mediaDescription },
+ } = useSelect(
( select ) => {
+ // Featured image.
+ const attachedMedia = record?.featured_media
+ ? select( coreStore ).getEntityRecord(
+ 'postType',
+ 'attachment',
+ record?.featured_media
+ )
+ : null;
+
+ // Parent page title.
const parent = record?.parent
? select( coreStore ).getEntityRecord(
'postType',
@@ -113,21 +206,35 @@ export default function SidebarNavigationScreenPage() {
record.parent
)
: null;
-
+ let _parentTitle = __( 'Top level' );
if ( parent ) {
- return parent?.title?.rendered
+ _parentTitle = parent?.title?.rendered
? decodeEntities( parent.title.rendered )
- : 'No title';
+ : __( 'Untitled' );
}
- return 'Top level';
+ return {
+ parentTitle: _parentTitle,
+ featuredMediaDetails: {
+ ...getMediaDetails( attachedMedia, postId ),
+ mediaDescription: attachedMedia?.description?.raw,
+ },
+ };
},
[ record ]
);
+ const displayLink = record?.link
+ ? record.link.replace( /^(https?:\/\/)?/, '' )
+ : null;
return (
setCanvasMode( 'edit' ) }
@@ -136,40 +243,57 @@ export default function SidebarNavigationScreenPage() {
/>
}
meta={
- record ? (
-
- { record?.link && (
-
- { record.link }
-
- ) }
-
-
- ) : null
- }
- footer={
- record && (
-
+ !! record?.link && (
+
+ { displayLink }
+
)
}
content={
<>
-
- { record?.excerpt?.raw && (
- { decodeEntities( record?.excerpt?.raw ) }
+
+
+ { record && ! record?.featured_media && (
+
{ __( 'No featured image' ) }
+ ) }
+
+ { mediaSourceUrl && mediaDescription && (
+
+ { decodeEntities( mediaDescription ) }
+
+ ) }
+
+ { !! record?.excerpt?.raw && (
+
+ { decodeEntities( record?.excerpt?.raw ) }
+
) }
Details
@@ -181,184 +305,28 @@ export default function SidebarNavigationScreenPage() {
...record,
} ) }
/>
+ { !! record && (
+
+
+ { createInterpolateElement(
+ sprintf(
+ /* translators: %s: is the relative time when the post was last modified. */
+ __( 'Last modified ' ),
+ humanTimeDiff( record.modified )
+ ),
+ {
+ time: (
+
+ ),
+ }
+ ) }
+
+
+ ) }
>
}
/>
);
}
-
-const statusLabels = {
- publish: 'Published',
- future: 'Scheduled',
- draft: 'Draft',
- pending: 'Pending',
-};
-
-function relativeTime( date1, date2 ) {
- const diffInSeconds = Math.abs( date1.getTime() - date2.getTime() ) / 1000;
-
- const units = [
- { name: 'second', limit: 60, in_seconds: 1 },
- { name: 'minute', limit: 3600, in_seconds: 60 },
- { name: 'hour', limit: 86400, in_seconds: 3600 },
- { name: 'day', limit: 604800, in_seconds: 86400 },
- { name: 'week', limit: 2629743, in_seconds: 604800 },
- { name: 'month', limit: 31556926, in_seconds: 2629743 },
- { name: 'year', limit: Infinity, in_seconds: 31556926 },
- ];
-
- let i = 0,
- unit;
- while ( ( unit = units[ i++ ] ) ) {
- if ( diffInSeconds < unit.limit || ! unit.limit ) {
- const diff = Math.floor( diffInSeconds / unit.in_seconds );
- return (
- diff +
- ' ' +
- unit.name +
- ( diff > 1 ? 's' : '' ) +
- ' ' +
- ( date1 > date2 ? 'ago' : 'from now' )
- );
- }
- }
-}
-
-export const PostStatus = ( { status, date } ) => {
- const statusLabel = statusLabels[ status ] ?? 'Unknown';
- const formattedDate = date
- ? relativeTime( new Date(), new Date( date ) )
- : null;
-
- return (
-
- { /* */ }
- { statusLabel }
- { formattedDate && { formattedDate } }
-
- );
-};
-
-// const StatusIcon = ( { status } ) => {
-// switch ( status ) {
-// case 'draft':
-// return ;
-// case 'pending':
-// return ;
-// case 'future':
-// return ;
-// case 'publish':
-// return ;
-// }
-// return null;
-// };
-
-const PostModified = ( { date } ) => {
- return (
-
-
-
- Last modified { relativeTime( new Date(), new Date( date ) ) }{ ' ' }
- by Dan
-
-
- );
-};
-
-// const DraftIcon = () => (
-//
-// );
-
-// const PendingIcon = () => (
-//
-// );
-
-// const ScheduledIcon = () => (
-//
-// );
-
-// const PublishIcon = () => (
-//
-// );
diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-page/style.scss b/packages/edit-site/src/components/sidebar-navigation-screen-page/style.scss
new file mode 100644
index 00000000000000..056ba0866f07c8
--- /dev/null
+++ b/packages/edit-site/src/components/sidebar-navigation-screen-page/style.scss
@@ -0,0 +1,110 @@
+.edit-site-sidebar-navigation-screen-page {
+ .edit-site-sidebar-navigation-screen__sticky-section {
+ padding: $grid-unit-40 0;
+ margin: $grid-unit-40 0;
+ }
+}
+
+.edit-site-sidebar-navigation-screen-page__featured-image-wrapper {
+ padding: $grid-unit-10;
+ background-color: $gray-800;
+ margin-bottom: $grid-unit-20;
+ min-height: 128px;
+ .edit-site-sidebar-navigation-screen-page__featured-image {
+ border-radius: 2px;
+ height: 128px;
+ overflow: hidden;
+ width: 100%;
+ background-size: cover;
+ background-position: 50% 50%;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ color: $gray-600;
+ }
+
+ .edit-site-sidebar-navigation-screen-page__featured-image-description {
+ font-size: $helptext-font-size;
+ }
+}
+
+.edit-site-sidebar-navigation-screen-page__excerpt {
+ font-size: $helptext-font-size;
+}
+
+.edit-site-sidebar-navigation-screen-page__modified {
+ margin: 0 0 $grid-unit-20 0;
+ color: $gray-600;
+ margin-left: $grid-unit-20;
+ .components-text {
+ color: $gray-600;
+ }
+}
+
+.edit-site-sidebar-navigation-screen-page__status .components-text {
+ color: $white;
+}
+
+.edit-site-sidebar-navigation-screen-page__status-indicator {
+ display: none;
+ &.has-status {
+ border-radius: 999px;
+ height: 16px;
+ width: 16px;
+ display: flex;
+ align-items: center;
+ position: relative;
+ justify-content: center;
+
+ &::before {
+ height: 12px;
+ width: 12px;
+ border-radius: 60%;
+ border: 2px solid $gray-900;
+ display: block;
+ content: "";
+ position: absolute;
+ }
+ }
+
+ &.has-publish-status {
+ background-color: $alert-green;
+ &::before {
+ background-color: $alert-green;
+ border: none;
+ width: inherit;
+ height: inherit;
+ content: "\2713";
+ text-align: center;
+ color: $gray-900;
+ font-weight: 700;
+ }
+ }
+
+ &.has-future-status {
+ background-color: $alert-green;
+ &::before {
+ background-color: $alert-green;
+ }
+ }
+
+ &.has-pending-status {
+ background-color: $alert-yellow;
+ &::before {
+ background-color: $alert-yellow;
+ }
+ }
+
+ &.has-draft-status {
+ background-color: $alert-yellow;
+ &::before {
+ background-color: $gray-900;
+ border: 0;
+ border-radius: 0 0 8px 8px;
+ height: 8px;
+ left: -1px;
+ transform: rotate(90deg);
+ width: 13px;
+ }
+ }
+}
diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-pages/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-pages/index.js
index 5f4958f44d2514..ebb38d9478fc4e 100644
--- a/packages/edit-site/src/components/sidebar-navigation-screen-pages/index.js
+++ b/packages/edit-site/src/components/sidebar-navigation-screen-pages/index.js
@@ -4,6 +4,7 @@
import {
__experimentalItemGroup as ItemGroup,
__experimentalItem as Item,
+ __experimentalTruncate as Truncate,
} from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { useEntityRecords } from '@wordpress/core-data';
@@ -28,7 +29,8 @@ const PageItem = ( { postId, ...props } ) => {
export default function SidebarNavigationScreenPages() {
const { records: pages, isResolving: isLoading } = useEntityRecords(
'postType',
- 'page'
+ 'page',
+ { status: 'any' }
);
return (
@@ -57,9 +59,11 @@ export default function SidebarNavigationScreenPages() {
key={ page.id }
withChevron
>
- { decodeEntities(
- page.title?.rendered
- ) ?? __( '(no title)' ) }
+
+ { decodeEntities(
+ page.title?.rendered
+ ) ?? __( 'Untitled' ) }
+
) ) }
{
const { getSettings } = unlock( select( editSiteStore ) );
@@ -42,7 +43,7 @@ export default function SidebarNavigationScreen( {
const theme = getTheme( currentlyPreviewingTheme() );
return (
-
+
);
-function getMediaDetails( media, postId ) {
+export function getMediaDetails( media, postId ) {
if ( ! media ) {
return {};
}
From 5eeb21a1912349a46c40367f18335a81cf56d082 Mon Sep 17 00:00:00 2001
From: ramon
Date: Thu, 25 May 2023 11:52:32 +1000
Subject: [PATCH 05/12] Adding SVG icons for status labels
Removing duped/unused test expectations
De-nesting BEM rules
Remove unused comments
i18n
---
package-lock.json | 1 +
packages/date/src/test/index.js | 14 ---
packages/edit-site/package.json | 1 +
.../sidebar-navigation-data-list/index.js | 4 -
.../sidebar-navigation-data-list/style.scss | 2 +-
.../sidebar-navigation-screen-page/index.js | 71 +----------
.../status-label.js | 98 ++++++++++++++++
.../sidebar-navigation-screen-page/style.scss | 111 ++++++------------
8 files changed, 140 insertions(+), 162 deletions(-)
create mode 100644 packages/edit-site/src/components/sidebar-navigation-screen-page/status-label.js
diff --git a/package-lock.json b/package-lock.json
index 3a9abff6cc62d6..0e67df36e8185f 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -17771,6 +17771,7 @@
"@wordpress/notices": "file:packages/notices",
"@wordpress/plugins": "file:packages/plugins",
"@wordpress/preferences": "file:packages/preferences",
+ "@wordpress/primitives": "file:packages/primitives",
"@wordpress/private-apis": "file:packages/private-apis",
"@wordpress/reusable-blocks": "file:packages/reusable-blocks",
"@wordpress/router": "file:packages/router",
diff --git a/packages/date/src/test/index.js b/packages/date/src/test/index.js
index 1832d4c7c55a2b..3c52aae1fbd0df 100644
--- a/packages/date/src/test/index.js
+++ b/packages/date/src/test/index.js
@@ -642,20 +642,6 @@ describe( 'Moment.js Localization', () => {
'2023-04-30T13:00:00.000Z'
)
).toBe( '2 days ago' );
-
- expect(
- humanTimeDiff(
- '2023-04-28T11:00:00.000Z',
- '2023-04-28T13:00:00.000Z'
- )
- ).toBe( '2 hours ago' );
-
- expect(
- humanTimeDiff(
- '2023-04-26T13:00:00.000Z',
- '2023-04-28T13:00:00.000Z'
- )
- ).toBe( '2 days ago' );
} );
it( 'should return human readable time differences in the future', () => {
diff --git a/packages/edit-site/package.json b/packages/edit-site/package.json
index 265f18b9a95974..6ddb0bf50926fa 100644
--- a/packages/edit-site/package.json
+++ b/packages/edit-site/package.json
@@ -54,6 +54,7 @@
"@wordpress/notices": "file:../notices",
"@wordpress/plugins": "file:../plugins",
"@wordpress/preferences": "file:../preferences",
+ "@wordpress/primitives": "file:../primitives",
"@wordpress/private-apis": "file:../private-apis",
"@wordpress/reusable-blocks": "file:../reusable-blocks",
"@wordpress/router": "file:../router",
diff --git a/packages/edit-site/src/components/sidebar-navigation-data-list/index.js b/packages/edit-site/src/components/sidebar-navigation-data-list/index.js
index a6e63a036950fa..c028060f62933e 100644
--- a/packages/edit-site/src/components/sidebar-navigation-data-list/index.js
+++ b/packages/edit-site/src/components/sidebar-navigation-data-list/index.js
@@ -7,10 +7,6 @@ import {
__experimentalText as Text,
} from '@wordpress/components';
-/**
- * Internal dependencies
- */
-
export default function SidebarDetails( { details } ) {
return (
%s' ),
- relateToNow
- ),
- { time: }
- );
- break;
- case 'future':
- const formattedDate = dateI18n(
- getSettings().formats.date,
- getDate( date )
- );
- statusLabel = createInterpolateElement(
- sprintf(
- /* translators: %s: is the formatted date and time on which the post is scheduled to be published. */
- __( 'Scheduled for ' ),
- formattedDate
- ),
- { time: }
- );
- break;
- case 'draft':
- statusLabel = __( 'Draft' );
- break;
- case 'pending':
- statusLabel = __( 'Pending' );
- break;
- default:
- statusLabel = __( 'Unknown' );
- break;
- }
-
- return (
-
-
- { statusLabel }
-
- );
-}
-
function getPageDetails( page ) {
if ( ! page ) {
return [];
@@ -108,27 +49,27 @@ function getPageDetails( page ) {
if ( page?.status ) {
details.push( {
- label: 'Status',
+ label: __( 'Status' ),
value: ,
} );
}
if ( page?.slug ) {
details.push( {
- label: 'Slug',
+ label: __( 'Slug' ),
value: { page.slug },
} );
}
if ( page?.templateTitle ) {
details.push( {
- label: 'Template',
+ label: __( 'Template' ),
value: page.templateTitle,
} );
}
details.push( {
- label: 'Parent',
+ label: __( 'Parent' ),
value: page?.parentTitle,
} );
diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-page/status-label.js b/packages/edit-site/src/components/sidebar-navigation-screen-page/status-label.js
new file mode 100644
index 00000000000000..5674d16bcf6373
--- /dev/null
+++ b/packages/edit-site/src/components/sidebar-navigation-screen-page/status-label.js
@@ -0,0 +1,98 @@
+/**
+ * External dependencies
+ */
+import classnames from 'classnames';
+
+/**
+ * WordPress dependencies
+ */
+import { __, sprintf } from '@wordpress/i18n';
+import { dateI18n, getDate, getSettings, humanTimeDiff } from '@wordpress/date';
+import { createInterpolateElement } from '@wordpress/element';
+import { Path, SVG } from '@wordpress/primitives';
+
+const publishedIcon = (
+
+);
+
+const draftIcon = (
+
+);
+
+const pendingIcon = (
+
+);
+
+export default function StatusLabel( { status, date } ) {
+ const relateToNow = humanTimeDiff( date );
+ let statusLabel = '';
+ let statusIcon = pendingIcon;
+ switch ( status ) {
+ case 'publish':
+ statusLabel = createInterpolateElement(
+ sprintf(
+ /* translators: %s: is the relative time when the post was published. */
+ __( 'Published ' ),
+ relateToNow
+ ),
+ { time: }
+ );
+ statusIcon = publishedIcon;
+ break;
+ case 'future':
+ const formattedDate = dateI18n(
+ getSettings().formats.date,
+ getDate( date )
+ );
+ statusLabel = createInterpolateElement(
+ sprintf(
+ /* translators: %s: is the formatted date and time on which the post is scheduled to be published. */
+ __( 'Scheduled for ' ),
+ formattedDate
+ ),
+ { time: }
+ );
+ break;
+ case 'draft':
+ statusLabel = __( 'Draft' );
+ statusIcon = draftIcon;
+ break;
+ case 'pending':
+ statusLabel = __( 'Pending' );
+ break;
+ default:
+ statusLabel = __( 'Unknown' );
+ break;
+ }
+
+ return (
+
+ { statusIcon } { statusLabel }
+
+ );
+}
diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-page/style.scss b/packages/edit-site/src/components/sidebar-navigation-screen-page/style.scss
index 056ba0866f07c8..5d51ad6e15198d 100644
--- a/packages/edit-site/src/components/sidebar-navigation-screen-page/style.scss
+++ b/packages/edit-site/src/components/sidebar-navigation-screen-page/style.scss
@@ -1,8 +1,6 @@
-.edit-site-sidebar-navigation-screen-page {
- .edit-site-sidebar-navigation-screen__sticky-section {
- padding: $grid-unit-40 0;
- margin: $grid-unit-40 0;
- }
+.edit-site-sidebar-navigation-screen__sticky-section {
+ padding: $grid-unit-40 0;
+ margin: $grid-unit-40 0;
}
.edit-site-sidebar-navigation-screen-page__featured-image-wrapper {
@@ -10,22 +8,23 @@
background-color: $gray-800;
margin-bottom: $grid-unit-20;
min-height: 128px;
- .edit-site-sidebar-navigation-screen-page__featured-image {
- border-radius: 2px;
- height: 128px;
- overflow: hidden;
- width: 100%;
- background-size: cover;
- background-position: 50% 50%;
- display: flex;
- align-items: center;
- justify-content: center;
- color: $gray-600;
- }
+}
- .edit-site-sidebar-navigation-screen-page__featured-image-description {
- font-size: $helptext-font-size;
- }
+.edit-site-sidebar-navigation-screen-page__featured-image {
+ border-radius: 2px;
+ height: 128px;
+ overflow: hidden;
+ width: 100%;
+ background-size: cover;
+ background-position: 50% 50%;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ color: $gray-600;
+}
+
+.edit-site-sidebar-navigation-screen-page__featured-image-description {
+ font-size: $helptext-font-size;
}
.edit-site-sidebar-navigation-screen-page__excerpt {
@@ -41,70 +40,26 @@
}
}
-.edit-site-sidebar-navigation-screen-page__status .components-text {
- color: $white;
-}
-
-.edit-site-sidebar-navigation-screen-page__status-indicator {
- display: none;
- &.has-status {
- border-radius: 999px;
- height: 16px;
- width: 16px;
- display: flex;
- align-items: center;
- position: relative;
- justify-content: center;
+.edit-site-sidebar-navigation-screen-page__status {
+ display: inline-flex;
- &::before {
- height: 12px;
- width: 12px;
- border-radius: 60%;
- border: 2px solid $gray-900;
- display: block;
- content: "";
- position: absolute;
- }
+ time {
+ display: contents;
}
- &.has-publish-status {
- background-color: $alert-green;
- &::before {
- background-color: $alert-green;
- border: none;
- width: inherit;
- height: inherit;
- content: "\2713";
- text-align: center;
- color: $gray-900;
- font-weight: 700;
- }
- }
-
- &.has-future-status {
- background-color: $alert-green;
- &::before {
- background-color: $alert-green;
- }
+ svg {
+ height: 16px;
+ width: 16px;
+ margin-right: $grid-unit-10;
}
- &.has-pending-status {
- background-color: $alert-yellow;
- &::before {
- background-color: $alert-yellow;
- }
+ &.has-publish-status svg,
+ &.has-future-status svg {
+ fill: $alert-green;
}
- &.has-draft-status {
- background-color: $alert-yellow;
- &::before {
- background-color: $gray-900;
- border: 0;
- border-radius: 0 0 8px 8px;
- height: 8px;
- left: -1px;
- transform: rotate(90deg);
- width: 13px;
- }
+ &.has-pending-status svg,
+ &.has-draft-status svg {
+ fill: $alert-yellow;
}
}
From e9d241c804530745d9e02846d53c4998289dfeed Mon Sep 17 00:00:00 2001
From: ramon
Date: Thu, 25 May 2023 14:46:44 +1000
Subject: [PATCH 06/12] Removing duped/unused test expectations De-nesting BEM
rules Remove unused comments i18n
---
.../src/components/sidebar-navigation-screen-page/index.js | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-page/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-page/index.js
index 1d4c534f798c5c..9e9f0f37bb13b3 100644
--- a/packages/edit-site/src/components/sidebar-navigation-screen-page/index.js
+++ b/packages/edit-site/src/components/sidebar-navigation-screen-page/index.js
@@ -87,11 +87,11 @@ function getPageDetails( page ) {
if ( wordsCounted ) {
details.push(
{
- label: 'Words',
+ label: __( 'Words' ),
value: wordsCounted.toLocaleString() || __( 'Unknown' ),
},
{
- label: 'Time to read',
+ label: __( 'Time to read' ),
value:
readingTime > 1
? sprintf(
From 40e2825134e594f0ce4ae6b97446df34017cefe7 Mon Sep 17 00:00:00 2001
From: ramon
Date: Thu, 25 May 2023 15:25:20 +1000
Subject: [PATCH 07/12] Displaying templates
---
.../sidebar-navigation-screen-page/index.js | 28 +++++++++++--------
1 file changed, 16 insertions(+), 12 deletions(-)
diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-page/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-page/index.js
index 9e9f0f37bb13b3..ff400569c6e3b5 100644
--- a/packages/edit-site/src/components/sidebar-navigation-screen-page/index.js
+++ b/packages/edit-site/src/components/sidebar-navigation-screen-page/index.js
@@ -112,24 +112,15 @@ export default function SidebarNavigationScreenPage() {
params: { postId },
} = useNavigator();
const { record } = useEntityRecord( 'postType', 'page', postId );
- /*
- * Only custom template slugs are available in the post entity record
- * Pages using theme templates will not have a template slug.
- */
- const { records: templates, isResolving: areTemplatesLoading } =
- useEntityRecords( 'postType', 'wp_template', {
- per_page: -1,
- } );
- const templateTitle = areTemplatesLoading
- ? ''
- : templates?.find( ( template ) => template?.slug === record?.template )
- ?.title?.rendered || '';
const {
parentTitle,
featuredMediaDetails: { mediaSourceUrl, mediaDescription },
+ templateSlug,
} = useSelect(
( select ) => {
+ const { getEditedPostContext } = unlock( select( editSiteStore ) );
+
// Featured image.
const attachedMedia = record?.featured_media
? select( coreStore ).getEntityRecord(
@@ -156,6 +147,7 @@ export default function SidebarNavigationScreenPage() {
return {
parentTitle: _parentTitle,
+ templateSlug: getEditedPostContext()?.templateSlug,
featuredMediaDetails: {
...getMediaDetails( attachedMedia, postId ),
mediaDescription: attachedMedia?.description?.raw,
@@ -164,6 +156,18 @@ export default function SidebarNavigationScreenPage() {
},
[ record ]
);
+
+ // Match template slug to template title.
+ const { records: templates, isResolving: areTemplatesLoading } =
+ useEntityRecords( 'postType', 'wp_template', {
+ per_page: -1,
+ } );
+ const templateTitle =
+ ! areTemplatesLoading && templateSlug
+ ? templates?.find( ( template ) => template?.slug === templateSlug )
+ ?.title?.rendered || templateSlug
+ : '';
+
const displayLink = record?.link
? record.link.replace( /^(https?:\/\/)?/, '' )
: null;
From 929f2e6fda200e960e0d820b2bfc2c37f050782c Mon Sep 17 00:00:00 2001
From: ramon
Date: Thu, 25 May 2023 15:33:36 +1000
Subject: [PATCH 08/12] We no longer need to pass down a className to
SidebarNavigationScreen. Reverting.
---
.../src/components/sidebar-navigation-screen-page/index.js | 1 -
.../src/components/sidebar-navigation-screen/index.js | 3 +--
2 files changed, 1 insertion(+), 3 deletions(-)
diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-page/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-page/index.js
index ff400569c6e3b5..565d05b1552b90 100644
--- a/packages/edit-site/src/components/sidebar-navigation-screen-page/index.js
+++ b/packages/edit-site/src/components/sidebar-navigation-screen-page/index.js
@@ -174,7 +174,6 @@ export default function SidebarNavigationScreenPage() {
return (
{
const { getSettings } = unlock( select( editSiteStore ) );
@@ -43,7 +42,7 @@ export default function SidebarNavigationScreen( {
const theme = getTheme( currentlyPreviewingTheme() );
return (
-
+
Date: Thu, 25 May 2023 17:24:52 +1000
Subject: [PATCH 09/12] style changes page detail site editor
---
.../data-list-item.js | 25 +++++++
.../sidebar-navigation-data-list/index.js | 27 +++-----
.../sidebar-navigation-data-list/style.scss | 15 +++--
.../sidebar-navigation-screen-page/index.js | 66 +++++++++----------
.../sidebar-navigation-screen-page/style.scss | 9 ++-
.../sidebar-navigation-screen/index.js | 2 +-
6 files changed, 83 insertions(+), 61 deletions(-)
create mode 100644 packages/edit-site/src/components/sidebar-navigation-data-list/data-list-item.js
diff --git a/packages/edit-site/src/components/sidebar-navigation-data-list/data-list-item.js b/packages/edit-site/src/components/sidebar-navigation-data-list/data-list-item.js
new file mode 100644
index 00000000000000..beeff0b6367b56
--- /dev/null
+++ b/packages/edit-site/src/components/sidebar-navigation-data-list/data-list-item.js
@@ -0,0 +1,25 @@
+/**
+ * WordPress dependencies
+ */
+import {
+ __experimentalHStack as HStack,
+ __experimentalText as Text,
+} from '@wordpress/components';
+
+export default function DataListItem( { label, value } ) {
+ return (
+
+
+ { label }
+
+
+ { value }
+
+
+ );
+}
diff --git a/packages/edit-site/src/components/sidebar-navigation-data-list/index.js b/packages/edit-site/src/components/sidebar-navigation-data-list/index.js
index c028060f62933e..aeff422026591a 100644
--- a/packages/edit-site/src/components/sidebar-navigation-data-list/index.js
+++ b/packages/edit-site/src/components/sidebar-navigation-data-list/index.js
@@ -1,31 +1,24 @@
/**
* WordPress dependencies
*/
-import {
- __experimentalHStack as HStack,
- __experimentalVStack as VStack,
- __experimentalText as Text,
-} from '@wordpress/components';
+import { __experimentalVStack as VStack } from '@wordpress/components';
+/**
+ * Internal dependencies
+ */
+import DataListItem from './data-list-item';
export default function SidebarDetails( { details } ) {
return (
{ details.map( ( detail ) => (
-
-
- { detail.label }
-
-
- { detail.value }
-
-
+ label={ detail.label }
+ value={ detail.value }
+ />
) ) }
);
diff --git a/packages/edit-site/src/components/sidebar-navigation-data-list/style.scss b/packages/edit-site/src/components/sidebar-navigation-data-list/style.scss
index 8a782c81905d1c..df52d488b0a00e 100644
--- a/packages/edit-site/src/components/sidebar-navigation-data-list/style.scss
+++ b/packages/edit-site/src/components/sidebar-navigation-data-list/style.scss
@@ -1,7 +1,12 @@
-.edit-site-sidebar-navigation_data-list__label {
- color: $gray-600;
-}
-.edit-site-sidebar-navigation_data-list__value.edit-site-sidebar-navigation_data-list__value {
- color: $white;
+
+.edit-site-sidebar-navigation_data-list__item {
+ .edit-site-sidebar-navigation_data-list__label {
+ color: $gray-400;
+ width: 100px;
+ }
+
+ .edit-site-sidebar-navigation_data-list__value.edit-site-sidebar-navigation_data-list__value {
+ color: $white;
+ }
}
diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-page/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-page/index.js
index 565d05b1552b90..ae7c45a3e303af 100644
--- a/packages/edit-site/src/components/sidebar-navigation-screen-page/index.js
+++ b/packages/edit-site/src/components/sidebar-navigation-screen-page/index.js
@@ -11,7 +11,6 @@ import { useDispatch, useSelect } from '@wordpress/data';
import {
__experimentalUseNavigator as useNavigator,
__experimentalVStack as VStack,
- __experimentalText as Text,
ExternalLink,
__experimentalTruncate as Truncate,
} from '@wordpress/components';
@@ -36,6 +35,7 @@ import { store as editSiteStore } from '../../store';
import SidebarButton from '../sidebar-button';
import SidebarNavigationSubtitle from '../sidebar-navigation-subtitle';
import SidebarDetails from '../sidebar-navigation-data-list';
+import DataListItem from '../sidebar-navigation-data-list/data-list-item';
import StatusLabel from './status-label';
// Taken from packages/editor/src/components/time-to-read/index.js.
@@ -210,26 +210,23 @@ export default function SidebarNavigationScreenPage() {
'has-image': !! mediaSourceUrl,
}
) }
- style={
- !! mediaSourceUrl
- ? {
- backgroundImage: `url(${ mediaSourceUrl })`,
- }
- : {}
- }
>
+ { !! mediaSourceUrl && (
+
+ ) }
{ record && ! record?.featured_media && (
{ __( 'No featured image' ) }
) }
- { mediaSourceUrl && mediaDescription && (
-
- { decodeEntities( mediaDescription ) }
-
- ) }
{ !! record?.excerpt?.raw && (
- { !! record && (
-
-
- { createInterpolateElement(
- sprintf(
- /* translators: %s: is the relative time when the post was last modified. */
- __( 'Last modified ' ),
- humanTimeDiff( record.modified )
- ),
- {
- time: (
-
- ),
- }
- ) }
-
-
- ) }
>
}
+ footer={
+ !! record ? (
+ %s' ),
+ humanTimeDiff( record.modified )
+ ),
+ {
+ time: ,
+ }
+ ) }
+ />
+ ) : null
+ }
/>
);
}
diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-page/style.scss b/packages/edit-site/src/components/sidebar-navigation-screen-page/style.scss
index 5d51ad6e15198d..66018b39250860 100644
--- a/packages/edit-site/src/components/sidebar-navigation-screen-page/style.scss
+++ b/packages/edit-site/src/components/sidebar-navigation-screen-page/style.scss
@@ -1,10 +1,9 @@
.edit-site-sidebar-navigation-screen__sticky-section {
padding: $grid-unit-40 0;
- margin: $grid-unit-40 0;
+ margin: $grid-unit-40 $grid-unit-20;
}
.edit-site-sidebar-navigation-screen-page__featured-image-wrapper {
- padding: $grid-unit-10;
background-color: $gray-800;
margin-bottom: $grid-unit-20;
min-height: 128px;
@@ -21,6 +20,12 @@
align-items: center;
justify-content: center;
color: $gray-600;
+ img {
+ object-fit: cover;
+ height: 100%;
+ width: 100%;
+ object-position: 50% 50%;
+ }
}
.edit-site-sidebar-navigation-screen-page__featured-image-description {
diff --git a/packages/edit-site/src/components/sidebar-navigation-screen/index.js b/packages/edit-site/src/components/sidebar-navigation-screen/index.js
index a1bd2cacb60e21..0baac6278c4307 100644
--- a/packages/edit-site/src/components/sidebar-navigation-screen/index.js
+++ b/packages/edit-site/src/components/sidebar-navigation-screen/index.js
@@ -102,7 +102,7 @@ export default function SidebarNavigationScreen( {
{ content }
{ footer && (
-
- { !! record?.excerpt?.raw && (
+ { !! record?.excerpt?.rendered && (
- { decodeEntities( record?.excerpt?.raw ) }
+ { stripHTML( record.excerpt.rendered ) }
) }
@@ -249,22 +244,20 @@ export default function SidebarNavigationScreenPage() {
>
}
footer={
- !! record ? (
- %s' ),
- humanTimeDiff( record.modified )
- ),
- {
- time: ,
- }
- ) }
- />
- ) : null
+ %s' ),
+ humanTimeDiff( record.modified )
+ ),
+ {
+ time: ,
+ }
+ ) }
+ />
}
/>
- );
+ ) : null;
}
diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-page/status-label.js b/packages/edit-site/src/components/sidebar-navigation-screen-page/status-label.js
index 5674d16bcf6373..514d3094a2cddb 100644
--- a/packages/edit-site/src/components/sidebar-navigation-screen-page/status-label.js
+++ b/packages/edit-site/src/components/sidebar-navigation-screen-page/status-label.js
@@ -78,9 +78,6 @@ export default function StatusLabel( { status, date } ) {
case 'pending':
statusLabel = __( 'Pending' );
break;
- default:
- statusLabel = __( 'Unknown' );
- break;
}
return (
diff --git a/packages/editor/src/components/index.js b/packages/editor/src/components/index.js
index fd4dc4303d1684..410fa6b38a61e8 100644
--- a/packages/editor/src/components/index.js
+++ b/packages/editor/src/components/index.js
@@ -25,10 +25,7 @@ export { default as PostAuthorCheck } from './post-author/check';
export { default as PostComments } from './post-comments';
export { default as PostExcerpt } from './post-excerpt';
export { default as PostExcerptCheck } from './post-excerpt/check';
-export {
- default as PostFeaturedImage,
- getMediaDetails,
-} from './post-featured-image';
+export { default as PostFeaturedImage } from './post-featured-image';
export { default as PostFeaturedImageCheck } from './post-featured-image/check';
export { default as PostFormat } from './post-format';
export { default as PostFormatCheck } from './post-format/check';
diff --git a/packages/editor/src/components/post-featured-image/get-featured-media-details.js b/packages/editor/src/components/post-featured-image/get-featured-media-details.js
new file mode 100644
index 00000000000000..a2a9ab71449c52
--- /dev/null
+++ b/packages/editor/src/components/post-featured-image/get-featured-media-details.js
@@ -0,0 +1,64 @@
+/**
+ * WordPress dependencies
+ */
+import { applyFilters } from '@wordpress/hooks';
+
+/**
+ * The media details object.
+ *
+ * @typedef {Object} MediaDetails
+ *
+ * @property {string} mediaWidth Width value of the media.
+ * @property {string} mediaHeight Height value of the media.
+ * @property {string} mediaSourceUrl URL of the media.
+ */
+
+/**
+ * Returns the featured media dimensions and source URL.
+ *
+ * @param {Object} media The media object.
+ * @param {number} postId The post ID of the media
+ * @return {MediaDetails} The featured media details.
+ */
+export default function getFeaturedMediaDetails( media, postId ) {
+ if ( ! media ) {
+ return {};
+ }
+
+ const defaultSize = applyFilters(
+ 'editor.PostFeaturedImage.imageSize',
+ 'large',
+ media.id,
+ postId
+ );
+ if ( defaultSize in ( media?.media_details?.sizes ?? {} ) ) {
+ return {
+ mediaWidth: media.media_details.sizes[ defaultSize ].width,
+ mediaHeight: media.media_details.sizes[ defaultSize ].height,
+ mediaSourceUrl: media.media_details.sizes[ defaultSize ].source_url,
+ };
+ }
+
+ // Use fallbackSize when defaultSize is not available.
+ const fallbackSize = applyFilters(
+ 'editor.PostFeaturedImage.imageSize',
+ 'thumbnail',
+ media.id,
+ postId
+ );
+ if ( fallbackSize in ( media?.media_details?.sizes ?? {} ) ) {
+ return {
+ mediaWidth: media.media_details.sizes[ fallbackSize ].width,
+ mediaHeight: media.media_details.sizes[ fallbackSize ].height,
+ mediaSourceUrl:
+ media.media_details.sizes[ fallbackSize ].source_url,
+ };
+ }
+
+ // Use full image size when fallbackSize and defaultSize are not available.
+ return {
+ mediaWidth: media.media_details.width,
+ mediaHeight: media.media_details.height,
+ mediaSourceUrl: media.source_url,
+ };
+}
diff --git a/packages/editor/src/components/post-featured-image/index.js b/packages/editor/src/components/post-featured-image/index.js
index fd0675b83da165..1595e2518f25a7 100644
--- a/packages/editor/src/components/post-featured-image/index.js
+++ b/packages/editor/src/components/post-featured-image/index.js
@@ -2,7 +2,6 @@
* WordPress dependencies
*/
import { __, sprintf } from '@wordpress/i18n';
-import { applyFilters } from '@wordpress/hooks';
import {
DropZone,
Button,
@@ -28,6 +27,7 @@ import { store as coreStore } from '@wordpress/core-data';
*/
import PostFeaturedImageCheck from './check';
import { store as editorStore } from '../../store';
+import getFeaturedMediaDetails from './get-featured-media-details';
const ALLOWED_MEDIA_TYPES = [ 'image' ];
@@ -43,49 +43,6 @@ const instructions = (
);
-export function getMediaDetails( media, postId ) {
- if ( ! media ) {
- return {};
- }
-
- const defaultSize = applyFilters(
- 'editor.PostFeaturedImage.imageSize',
- 'large',
- media.id,
- postId
- );
- if ( defaultSize in ( media?.media_details?.sizes ?? {} ) ) {
- return {
- mediaWidth: media.media_details.sizes[ defaultSize ].width,
- mediaHeight: media.media_details.sizes[ defaultSize ].height,
- mediaSourceUrl: media.media_details.sizes[ defaultSize ].source_url,
- };
- }
-
- // Use fallbackSize when defaultSize is not available.
- const fallbackSize = applyFilters(
- 'editor.PostFeaturedImage.imageSize',
- 'thumbnail',
- media.id,
- postId
- );
- if ( fallbackSize in ( media?.media_details?.sizes ?? {} ) ) {
- return {
- mediaWidth: media.media_details.sizes[ fallbackSize ].width,
- mediaHeight: media.media_details.sizes[ fallbackSize ].height,
- mediaSourceUrl:
- media.media_details.sizes[ fallbackSize ].source_url,
- };
- }
-
- // Use full image size when fallbackSize and defaultSize are not available.
- return {
- mediaWidth: media.media_details.width,
- mediaHeight: media.media_details.height,
- mediaSourceUrl: media.source_url,
- };
-}
-
function PostFeaturedImage( {
currentPostId,
featuredImageId,
@@ -101,7 +58,7 @@ function PostFeaturedImage( {
const mediaUpload = useSelect( ( select ) => {
return select( blockEditorStore ).getSettings().mediaUpload;
}, [] );
- const { mediaWidth, mediaHeight, mediaSourceUrl } = getMediaDetails(
+ const { mediaWidth, mediaHeight, mediaSourceUrl } = getFeaturedMediaDetails(
media,
currentPostId
);
diff --git a/packages/editor/src/private-apis.js b/packages/editor/src/private-apis.js
index cdec27b0ab9021..1de3d1d70f140e 100644
--- a/packages/editor/src/private-apis.js
+++ b/packages/editor/src/private-apis.js
@@ -4,9 +4,11 @@
import { ExperimentalEditorProvider } from './components/provider';
import { lock } from './lockUnlock';
import { EntitiesSavedStatesExtensible } from './components/entities-saved-states';
+import getFeaturedMediaDetails from './components/post-featured-image/get-featured-media-details';
export const privateApis = {};
lock( privateApis, {
ExperimentalEditorProvider,
EntitiesSavedStatesExtensible,
+ getFeaturedMediaDetails,
} );
From 8bbb116e4d866133c21ce53ec990a1830cc8e73f Mon Sep 17 00:00:00 2001
From: ramon
Date: Fri, 26 May 2023 14:07:48 +1000
Subject: [PATCH 12/12] Let's show password protected and private page status
as well.
---
.../components/sidebar-navigation-screen-page/index.js | 8 +++++++-
.../sidebar-navigation-screen-page/status-label.js | 6 ++++++
.../components/sidebar-navigation-screen-page/style.scss | 6 +-----
3 files changed, 14 insertions(+), 6 deletions(-)
diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-page/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-page/index.js
index 479a2ec6213dff..332c6ba62bfd4b 100644
--- a/packages/edit-site/src/components/sidebar-navigation-screen-page/index.js
+++ b/packages/edit-site/src/components/sidebar-navigation-screen-page/index.js
@@ -47,10 +47,16 @@ function getPageDetails( page ) {
if ( ! page ) {
return [];
}
+
const details = [
{
label: __( 'Status' ),
- value: ,
+ value: (
+
+ ),
},
{
label: __( 'Slug' ),
diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-page/status-label.js b/packages/edit-site/src/components/sidebar-navigation-screen-page/status-label.js
index 514d3094a2cddb..208d8adc59ab93 100644
--- a/packages/edit-site/src/components/sidebar-navigation-screen-page/status-label.js
+++ b/packages/edit-site/src/components/sidebar-navigation-screen-page/status-label.js
@@ -78,6 +78,12 @@ export default function StatusLabel( { status, date } ) {
case 'pending':
statusLabel = __( 'Pending' );
break;
+ case 'private':
+ statusLabel = __( 'Private' );
+ break;
+ case 'protected':
+ statusLabel = __( 'Password protected' );
+ break;
}
return (
diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-page/style.scss b/packages/edit-site/src/components/sidebar-navigation-screen-page/style.scss
index 9b1a930aa6f368..94dd7aa67096b1 100644
--- a/packages/edit-site/src/components/sidebar-navigation-screen-page/style.scss
+++ b/packages/edit-site/src/components/sidebar-navigation-screen-page/style.scss
@@ -57,15 +57,11 @@
height: 16px;
width: 16px;
margin-right: $grid-unit-10;
+ fill: $alert-yellow;
}
&.has-publish-status svg,
&.has-future-status svg {
fill: $alert-green;
}
-
- &.has-pending-status svg,
- &.has-draft-status svg {
- fill: $alert-yellow;
- }
}