-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Try/publish in site editor #51408
Merged
Merged
Try/publish in site editor #51408
Changes from all commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
7213d66
add required inputs
SaxonF c938235
schedule date
SaxonF e46f5ff
add password and fix a few things
SaxonF 511bacc
re-add status modal
SaxonF 73f89b4
update change status modal
SaxonF d5013da
revert in sidebar status change
SaxonF fc692d0
refine a few status details
SaxonF 0d25392
fix merge issues
SaxonF 42145f0
fix status label
SaxonF 736fac9
use null for status date
SaxonF 46f7ad5
handle empty date
SaxonF 2df2fc9
change to add fields instead of modal
SaxonF 710e36c
default publish not draft
SaxonF 01b0a07
remove style import
SaxonF 7dec51c
add required inputs
SaxonF 368cdef
schedule date
SaxonF 12554e3
add password and fix a few things
SaxonF 01f58b3
re-add status modal
SaxonF 94031eb
update change status modal
SaxonF 6582538
revert in sidebar status change
SaxonF 2c05b56
refine a few status details
SaxonF 41e15e9
fix merge issues
SaxonF fc295e0
fix status label
SaxonF 96ba33f
use null for status date
SaxonF 1fa27ab
handle empty date
SaxonF 14e2254
change to add fields instead of modal
SaxonF 053c3cf
default publish not draft
SaxonF a3949c2
remove style import
SaxonF 2f088b9
Merge branch 'try/publish-in-site-editor' of https://github.com/WordP…
SaxonF cfbb607
Merge branch 'trunk' into try/publish-in-site-editor
SaxonF 3e51dff
remove css
SaxonF d07a143
only autofocus password field if empty
SaxonF ff96c4c
aria label on status popover
SaxonF 9e28a27
remove end line
SaxonF 2a13222
Merge branch 'trunk' into try/publish-in-site-editor
SaxonF ca88703
create radio with help component
SaxonF 8dbad15
Merge branch 'trunk' into try/publish-in-site-editor
SaxonF d0b09cc
adjust to use radiocontrol and hide password
SaxonF d4d7fde
radio label alignment
SaxonF 7cf6f3c
add form wrapper
SaxonF 6c55aa1
aria label
SaxonF File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
233 changes: 233 additions & 0 deletions
233
packages/edit-site/src/components/sidebar-edit-mode/page-panels/page-status.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,233 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { | ||
Button, | ||
BaseControl, | ||
ToggleControl, | ||
Dropdown, | ||
__experimentalText as Text, | ||
__experimentalHStack as HStack, | ||
__experimentalVStack as VStack, | ||
TextControl, | ||
RadioControl, | ||
} from '@wordpress/components'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { useDispatch } from '@wordpress/data'; | ||
import { useState, useMemo } from '@wordpress/element'; | ||
import { store as coreStore } from '@wordpress/core-data'; | ||
import { store as noticesStore } from '@wordpress/notices'; | ||
import { __experimentalInspectorPopoverHeader as InspectorPopoverHeader } from '@wordpress/block-editor'; | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import StatusLabel from '../../sidebar-navigation-screen-page/status-label'; | ||
|
||
const STATUS_OPTIONS = [ | ||
{ | ||
label: ( | ||
<> | ||
{ __( 'Draft' ) } | ||
<Text variant="muted">{ __( 'Not ready to publish.' ) }</Text> | ||
</> | ||
), | ||
value: 'draft', | ||
}, | ||
{ | ||
label: ( | ||
<> | ||
{ __( 'Pending' ) } | ||
<Text variant="muted"> | ||
{ __( 'Waiting for review before publishing.' ) } | ||
</Text> | ||
</> | ||
), | ||
value: 'pending', | ||
}, | ||
{ | ||
label: ( | ||
<> | ||
{ __( 'Private' ) } | ||
<Text variant="muted"> | ||
{ __( 'Only visible to site admins and editors.' ) } | ||
</Text> | ||
</> | ||
), | ||
value: 'private', | ||
}, | ||
{ | ||
label: ( | ||
<> | ||
{ __( 'Scheduled' ) } | ||
<Text variant="muted"> | ||
{ __( 'Publish automatically on a chosen date.' ) } | ||
</Text> | ||
</> | ||
), | ||
value: 'future', | ||
}, | ||
{ | ||
label: ( | ||
<> | ||
{ __( 'Published' ) } | ||
<Text variant="muted">{ __( 'Visible to everyone.' ) }</Text> | ||
</> | ||
), | ||
value: 'publish', | ||
}, | ||
]; | ||
|
||
export default function PageStatus( { | ||
postType, | ||
postId, | ||
status, | ||
password, | ||
date, | ||
} ) { | ||
const [ showPassword, setShowPassword ] = useState( !! password ); | ||
|
||
const { editEntityRecord } = useDispatch( coreStore ); | ||
const { createErrorNotice } = useDispatch( noticesStore ); | ||
|
||
const [ popoverAnchor, setPopoverAnchor ] = useState( null ); | ||
// Memoize popoverProps to avoid returning a new object every time. | ||
const popoverProps = useMemo( | ||
() => ( { | ||
// Anchor the popover to the middle of the entire row so that it doesn't | ||
// move around when the label changes. | ||
anchor: popoverAnchor, | ||
'aria-label': __( 'Change status' ), | ||
placement: 'bottom-end', | ||
} ), | ||
[ popoverAnchor ] | ||
); | ||
|
||
const saveStatus = async ( { | ||
status: newStatus = status, | ||
password: newPassword = password, | ||
date: newDate = date, | ||
} ) => { | ||
try { | ||
await editEntityRecord( 'postType', postType, postId, { | ||
status: newStatus, | ||
date: newDate, | ||
password: newPassword, | ||
} ); | ||
} catch ( error ) { | ||
const errorMessage = | ||
error.message && error.code !== 'unknown_error' | ||
? error.message | ||
: __( 'An error occurred while updating the status' ); | ||
|
||
createErrorNotice( errorMessage, { | ||
type: 'snackbar', | ||
} ); | ||
} | ||
}; | ||
|
||
const handleTogglePassword = ( value ) => { | ||
setShowPassword( value ); | ||
if ( ! value ) { | ||
saveStatus( { password: '' } ); | ||
} | ||
}; | ||
|
||
const handleStatus = ( value ) => { | ||
let newDate = date; | ||
let newPassword = password; | ||
if ( value === 'publish' ) { | ||
if ( new Date( date ) > new Date() ) { | ||
newDate = null; | ||
} | ||
} else if ( value === 'future' ) { | ||
if ( ! date || new Date( date ) < new Date() ) { | ||
newDate = new Date(); | ||
newDate.setDate( newDate.getDate() + 7 ); | ||
} | ||
} else if ( value === 'private' && password ) { | ||
setShowPassword( false ); | ||
newPassword = ''; | ||
} | ||
saveStatus( { | ||
status: value, | ||
date: newDate, | ||
password: newPassword, | ||
} ); | ||
}; | ||
|
||
return ( | ||
<HStack className="edit-site-summary-field"> | ||
<Text className="edit-site-summary-field__label"> | ||
{ __( 'Status' ) } | ||
</Text> | ||
<Dropdown | ||
contentClassName="edit-site-change-status__content" | ||
popoverProps={ popoverProps } | ||
focusOnMount | ||
ref={ setPopoverAnchor } | ||
renderToggle={ ( { onToggle } ) => ( | ||
<Button | ||
className="edit-site-summary-field__trigger" | ||
variant="tertiary" | ||
onClick={ onToggle } | ||
> | ||
<StatusLabel | ||
status={ password ? 'protected' : status } | ||
/> | ||
</Button> | ||
) } | ||
renderContent={ ( { onClose } ) => ( | ||
<> | ||
<InspectorPopoverHeader | ||
title={ __( 'Status' ) } | ||
onClose={ onClose } | ||
/> | ||
<form> | ||
<VStack spacing={ 5 }> | ||
<RadioControl | ||
className="edit-site-change-status__options" | ||
hideLabelFromVision | ||
label={ __( 'Status' ) } | ||
options={ STATUS_OPTIONS } | ||
onChange={ handleStatus } | ||
selected={ status } | ||
/> | ||
{ status !== 'private' && ( | ||
<BaseControl | ||
id={ `edit-site-change-status__password` } | ||
label={ __( 'Password' ) } | ||
> | ||
<ToggleControl | ||
label={ __( | ||
'Hide this page behind a password' | ||
) } | ||
checked={ showPassword } | ||
onChange={ handleTogglePassword } | ||
/> | ||
{ showPassword && ( | ||
<TextControl | ||
onChange={ ( value ) => | ||
saveStatus( { | ||
password: value, | ||
} ) | ||
} | ||
value={ password } | ||
/* eslint-disable jsx-a11y/no-autofocus */ | ||
autoFocus={ ! password } | ||
/* eslint-enable jsx-a11y/no-autofocus */ | ||
placeholder={ __( | ||
'Enter a secure password' | ||
) } | ||
type="password" | ||
/> | ||
) } | ||
</BaseControl> | ||
) } | ||
</VStack> | ||
</form> | ||
</> | ||
) } | ||
/> | ||
</HStack> | ||
); | ||
} |
35 changes: 35 additions & 0 deletions
35
packages/edit-site/src/components/sidebar-edit-mode/page-panels/page-summary.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __experimentalVStack as VStack } from '@wordpress/components'; | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import PageStatus from './page-status'; | ||
import PublishDate from './publish-date'; | ||
|
||
export default function PageSummary( { | ||
status, | ||
date, | ||
password, | ||
postId, | ||
postType, | ||
} ) { | ||
return ( | ||
<VStack> | ||
<PageStatus | ||
status={ status } | ||
date={ date } | ||
password={ password } | ||
postId={ postId } | ||
postType={ postType } | ||
/> | ||
<PublishDate | ||
status={ status } | ||
date={ date } | ||
postId={ postId } | ||
postType={ postType } | ||
/> | ||
</VStack> | ||
); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The popover doesn't have a descriptive name for screen readers, users might not even know that they land in a popover. Maybe we should add
aria-label
oraria-labelledby
here.The other thing is that
Popover
traps the focus but it doesn't set thedialog
role. This could be a bigger problem in general of the component design and I personally think it's an accessibility bug. We could set arole: 'dialog'
here but I'm not sure if it's the right move. Possibly better to consult an accessibility expert on this.It's still usable thought just a bit confusing so I don't think this should be blocking 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added an
aria-label
for the time being since I don't want to modifyInspectorPopoverHeader
orPublishDateTimePicker
as part of this PR to add ID to title.Let's create a separate issue referencing the Dropdown and Popover components in wordpress/components to review any accessibility concerns. Modal has a
title
prop that usesaria-labelledby
.