Skip to content

Commit

Permalink
Add status to quick edit (#64398)
Browse files Browse the repository at this point in the history
Co-authored-by: oandregal <[email protected]>
Co-authored-by: youknowriad <[email protected]>
Co-authored-by: ntsekouras <[email protected]>
  • Loading branch information
4 people committed Aug 13, 2024
1 parent e8b45da commit 3ec1ced
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 10 deletions.
29 changes: 27 additions & 2 deletions packages/edit-site/src/components/post-edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,38 @@ function PostEditForm( { postType, postId } ) {
);
const [ multiEdits, setMultiEdits ] = useState( {} );
const { editEntityRecord } = useDispatch( coreDataStore );
const { fields } = usePostFields();
const { fields: _fields } = usePostFields();
const fields = useMemo(
() =>
_fields?.map( ( field ) => {
if ( field.id === 'status' ) {
return {
...field,
elements: field.elements.filter(
( element ) => element.value !== 'trash'
),
};
}
return field;
} ),
[ _fields ]
);
const form = {
type: 'panel',
fields: [ 'title', 'author', 'date', 'comment_status' ],
fields: [ 'title', 'status', 'date', 'author', 'comment_status' ],
};
const onChange = ( edits ) => {
for ( const id of ids ) {
if (
edits.status !== 'future' &&
record.status === 'future' &&
new Date( record.date ) > new Date()
) {
edits.date = null;
}
if ( edits.status === 'private' && record.password ) {
edits.password = '';
}
editEntityRecord( 'postType', postType, id, edits );
if ( ids.length > 1 ) {
setMultiEdits( ( prev ) => ( {
Expand Down
40 changes: 32 additions & 8 deletions packages/edit-site/src/components/post-fields/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,36 @@ import Media from '../media';
// See https://github.com/WordPress/gutenberg/issues/55886
// We do not support custom statutes at the moment.
const STATUSES = [
{ value: 'draft', label: __( 'Draft' ), icon: drafts },
{ value: 'future', label: __( 'Scheduled' ), icon: scheduled },
{ value: 'pending', label: __( 'Pending Review' ), icon: pending },
{ value: 'private', label: __( 'Private' ), icon: notAllowed },
{ value: 'publish', label: __( 'Published' ), icon: published },
{
value: 'draft',
label: __( 'Draft' ),
icon: drafts,
description: __( 'Not ready to publish.' ),
},
{
value: 'future',
label: __( 'Scheduled' ),
icon: scheduled,
description: __( 'Publish automatically on a chosen date.' ),
},
{
value: 'pending',
label: __( 'Pending Review' ),
icon: pending,
description: __( 'Waiting for review before publishing.' ),
},
{
value: 'private',
label: __( 'Private' ),
icon: notAllowed,
description: __( 'Only visible to site admins and editors.' ),
},
{
value: 'publish',
label: __( 'Published' ),
icon: published,
description: __( 'Visible to everyone.' ),
},
{ value: 'trash', label: __( 'Trash' ), icon: trash },
];

Expand Down Expand Up @@ -258,11 +283,10 @@ function usePostFields( viewType ) {
{
label: __( 'Status' ),
id: 'status',
getValue: ( { item } ) =>
STATUSES.find( ( { value } ) => value === item.status )
?.label ?? item.status,
type: 'text',
elements: STATUSES,
render: PostStatusField,
Edit: 'radio',
enableSorting: false,
filterBy: {
operators: [ OPERATOR_IS_ANY ],
Expand Down

0 comments on commit 3ec1ced

Please sign in to comment.