Skip to content

Commit

Permalink
refine a few status details
Browse files Browse the repository at this point in the history
  • Loading branch information
SaxonF committed Jun 13, 2023
1 parent f03cec0 commit eb424b2
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 30 deletions.
35 changes: 27 additions & 8 deletions packages/edit-site/src/components/change-status/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,22 @@ import { useDispatch } from '@wordpress/data';
import { useState } from '@wordpress/element';
import { store as coreStore } from '@wordpress/core-data';
import { store as noticesStore } from '@wordpress/notices';
/**
* Internal dependencies
*/
import StatusLabel from '../sidebar-navigation-screen-page/status-label';

const STATUS_OPTIONS = [
{
label: __( 'Draft' ),
value: 'draft',
hint: __( 'Not ready to publish' ),
},
{
label: __( 'Published' ),
value: 'publish',
hint: __( 'Anyone with the url can access' ),
},
{
label: __( 'Private' ),
value: 'private',
Expand All @@ -39,11 +48,6 @@ const STATUS_OPTIONS = [
value: 'future',
hint: __( 'Publish automatically on a chosen date' ),
},
{
label: __( 'Published' ),
value: 'publish',
hint: __( 'Anyone with the url can access' ),
},
];

export default function ChangeStatus( { post } ) {
Expand Down Expand Up @@ -102,10 +106,24 @@ export default function ChangeStatus( { post } ) {
}
};

const handleStatus = ( value ) => {
if ( value === 'published' ) {
setDate( undefined );
}
setStatus( value );
};

return (
<>
<Button variant="secondary" onClick={ openModal }>
Change status
<Button
className="edit-site-change-status__trigger"
variant="tertiary"
onClick={ openModal }
>
<StatusLabel
status={ post?.password ? 'protected' : post.status }
date={ post?.date }
/>
</Button>
{ isOpen && (
<Modal
Expand Down Expand Up @@ -136,7 +154,7 @@ export default function ChangeStatus( { post } ) {
name={ `edit-site-change-status__status` }
value={ option.value }
onChange={ ( e ) =>
setStatus( e.target.value )
handleStatus( e.target.value )
}
checked={ option.value === status }
/>
Expand All @@ -161,6 +179,7 @@ export default function ChangeStatus( { post } ) {
<DateTimePicker
className="components-datetime__time__one-row"
currentDate={ date }
is12Hour
onChange={ setDate }
/>
</div>
Expand Down
4 changes: 1 addition & 3 deletions packages/edit-site/src/components/change-status/style.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.edit-site-change-status {
min-width: 480px;
width: 540px;
min-height: 400px;
.components-radio-control__option.with-hint {
display: flex;
Expand Down Expand Up @@ -60,8 +60,6 @@

fieldset:first-child {
.components-datetime__time-wrapper {
flex-direction: column;
align-items: flex-start;
> .components-flex-item {
display: none;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
import {
PanelBody,
__experimentalText as Text,
__experimentalVStack as VStack,
Button,
} from '@wordpress/components';
Expand All @@ -21,6 +22,7 @@ import { store as editSiteStore } from '../../../store';
import useEditedEntityRecord from '../../use-edited-entity-record';
import SidebarCard from '../sidebar-card';
import PageContent from './page-content';
import ChangeStatus from '../../change-status';

export default function PagePanels() {
const context = useSelect(
Expand Down Expand Up @@ -54,11 +56,18 @@ export default function PagePanels() {
<SidebarCard
title={ page.title }
icon={ pageIcon }
description={ sprintf(
// translators: %s: Human-readable time difference, e.g. "2 days ago".
__( 'Last edited %s' ),
humanTimeDiff( page.modified )
) }
description={
<VStack>
<Text>
{ sprintf(
// translators: %s: Human-readable time difference, e.g. "2 days ago".
__( 'Last edited %s' ),
humanTimeDiff( page.modified )
) }
</Text>
<ChangeStatus post={ page } />
</VStack>
}
/>
</PanelBody>
<PanelBody title={ __( 'Content' ) }>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@
.edit-site-page-panels__edit-template-button {
justify-content: center;
}

.edit-site-sidebar-card__description {
.edit-site-change-status__trigger {
margin-left: -$grid-unit-15;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import SidebarButton from '../sidebar-button';
import SidebarNavigationSubtitle from '../sidebar-navigation-subtitle';
import PageDetails from './page-details';
import PageActions from '../page-actions';
import ChangeStatus from '../change-status';

export default function SidebarNavigationScreenPage() {
const navigator = useNavigator();
Expand Down Expand Up @@ -96,15 +95,12 @@ export default function SidebarNavigationScreenPage() {
</>
}
meta={
<VStack>
<ExternalLink
className="edit-site-sidebar-navigation-screen__page-link"
href={ record.link }
>
{ record.link.replace( /^(https?:\/\/)?/, '' ) }
</ExternalLink>
<ChangeStatus post={ record } />
</VStack>
<ExternalLink
className="edit-site-sidebar-navigation-screen__page-link"
href={ record.link }
>
{ record.link.replace( /^(https?:\/\/)?/, '' ) }
</ExternalLink>
}
content={
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ function getPageDetails( page ) {
<StatusLabel
status={ page?.password ? 'protected' : page.status }
date={ page?.date }
short
/>
),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import classnames from 'classnames';
* WordPress dependencies
*/
import { __, sprintf } from '@wordpress/i18n';
import { dateI18n, getDate, getSettings, humanTimeDiff } from '@wordpress/date';
import { dateI18n, getDate, humanTimeDiff } from '@wordpress/date';
import { createInterpolateElement } from '@wordpress/element';
import { Path, SVG } from '@wordpress/primitives';

Expand Down Expand Up @@ -41,7 +41,7 @@ const pendingIcon = (
</SVG>
);

export default function StatusLabel( { status, date } ) {
export default function StatusLabel( { status, date, short } ) {
const relateToNow = humanTimeDiff( date );
let statusLabel = '';
let statusIcon = pendingIcon;
Expand All @@ -59,13 +59,13 @@ export default function StatusLabel( { status, date } ) {
break;
case 'future':
const formattedDate = dateI18n(
getSettings().formats.date,
short ? 'M j' : 'F j',
getDate( date )
);
statusLabel = createInterpolateElement(
sprintf(
/* translators: %s: is the formatted date and time on which the post is scheduled to be published. */
__( 'Scheduled for <time>%s</time>' ),
__( 'Scheduled: <time>%s</time>' ),
formattedDate
),
{ time: <time dateTime={ date } /> }
Expand Down

0 comments on commit eb424b2

Please sign in to comment.