-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Template activation: duplicate modal on static template click, remove auto-drafting #72285
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
Changes from all commits
0d1f415
311665f
dd86b23
f1cc765
6f264e5
a85339b
e88b8e6
87f4a7b
c5fdbac
d4d81c7
91c0d91
430e4b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -93,16 +93,6 @@ export function receiveEntityRecords( | |
| edits, | ||
| meta | ||
| ) { | ||
| // If we receive an auto-draft template, pretend it's already published. | ||
| if ( kind === 'postType' && name === 'wp_template' ) { | ||
| records = ( Array.isArray( records ) ? records : [ records ] ).map( | ||
| ( record ) => | ||
| record.status === 'auto-draft' | ||
| ? { ...record, status: 'publish' } | ||
| : record | ||
| ); | ||
| } | ||
|
|
||
| // Auto drafts should not have titles, but some plugins rely on them so we can't filter this | ||
| // on the server. | ||
| if ( kind === 'postType' ) { | ||
|
|
@@ -709,11 +699,6 @@ export const saveEntityRecord = | |
| ), | ||
| }; | ||
| } | ||
| // Unless there is no persisted record, set the status to | ||
| // publish. | ||
| if ( name === 'wp_template' && persistedRecord ) { | ||
| edits.status = 'publish'; | ||
| } | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @youknowriad Removes this hack as you were hoping for in https://github.com/WordPress/gutenberg/pull/67125/files#r2354891236 |
||
| updatedRecord = await __unstableFetch( { | ||
| path, | ||
| method: recordId ? 'PUT' : 'POST', | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,7 +2,8 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * WordPress dependencies | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { Page } from '@wordpress/admin-ui'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { __ } from '@wordpress/i18n'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { __, sprintf } from '@wordpress/i18n'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { decodeEntities } from '@wordpress/html-entities'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { useState, useMemo, useCallback } from '@wordpress/element'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| privateApis as corePrivateApis, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -12,10 +13,11 @@ import { DataViews, filterSortAndPaginate } from '@wordpress/dataviews'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { privateApis as routerPrivateApis } from '@wordpress/router'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { privateApis as editorPrivateApis } from '@wordpress/editor'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { addQueryArgs } from '@wordpress/url'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { useSelect } from '@wordpress/data'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { useSelect, useDispatch } from '@wordpress/data'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { useEvent } from '@wordpress/compose'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { useView } from '@wordpress/views'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { Button } from '@wordpress/components'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { Button, Modal } from '@wordpress/components'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { store as noticesStore } from '@wordpress/notices'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Internal dependencies | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -45,6 +47,8 @@ export default function PageTemplates() { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { path, query } = useLocation(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { activeView = 'active', postId } = query; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const [ selection, setSelection ] = useState( [ postId ] ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const [ selectedRegisteredTemplate, setSelectedRegisteredTemplate ] = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| useState( false ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const defaultView = useMemo( () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return getDefaultView( activeView ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, [ activeView ] ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -207,15 +211,54 @@ export default function PageTemplates() { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| elements, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return _fields; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, [ users, activeView ] ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, [ users, activeView, themeField ] ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { data, paginationInfo } = useMemo( () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return filterSortAndPaginate( records, view, fields ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, [ records, view, fields ] ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { createSuccessNotice } = useDispatch( noticesStore ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const onActionPerformed = useCallback( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is actually a copy of the site editor's gutenberg/packages/edit-post/src/components/layout/index.js Lines 592 to 624 in 81142e2
Ideally we check what those other actions are and merge the behavior. These actions should probably all be valid for all site editor screens. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ( actionId, items ) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| switch ( actionId ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case 'duplicate-post': | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const newItem = items[ 0 ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const _title = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| typeof newItem.title === 'string' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ? newItem.title | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| : newItem.title?.rendered; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| createSuccessNotice( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sprintf( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // translators: %s: Title of the created post or template, e.g: "Hello world". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| __( '"%s" successfully created.' ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| decodeEntities( _title ) || __( '(no title)' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type: 'snackbar', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| id: 'duplicate-post-action', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| actions: [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| label: __( 'Edit' ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onClick: () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| history.navigate( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| `/${ newItem.type }/${ newItem.id }?canvas=edit` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [ history, createSuccessNotice ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const postTypeActions = usePostActions( { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| postType: TEMPLATE_POST_TYPE, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| context: 'list', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onActionPerformed, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const editAction = useEditPostAction(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const setActiveTemplateAction = useSetActiveTemplateAction(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -235,6 +278,10 @@ export default function PageTemplates() { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| updateView( newView ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const duplicateAction = actions.find( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ( action ) => action.id === 'duplicate-post' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Page | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| className="edit-site-page-templates" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -268,13 +315,34 @@ export default function PageTemplates() { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onChangeSelection={ onChangeSelection } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| isItemClickable={ () => true } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onClickItem={ ( item ) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| history.navigate( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| `/${ item.type }/${ item.id }?canvas=edit` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ( item.type === 'wp_registered_template' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setSelectedRegisteredTemplate( item ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| history.navigate( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| `/${ item.type }/${ item.id }?canvas=edit` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| selection={ selection } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| defaultLayouts={ defaultLayouts } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { selectedRegisteredTemplate && duplicateAction && ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Modal | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| title={ __( 'Duplicate' ) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onRequestClose={ () => setSelectedRegisteredTemplate() } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| size="small" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <duplicateAction.RenderModal | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| items={ [ selectedRegisteredTemplate ] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| closeModal={ () => setSelectedRegisteredTemplate() } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onActionPerformed={ ( [ item ] ) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| history.navigate( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| `/${ item.type }/${ item.id }?canvas=edit` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </Modal> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </Page> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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.
@Mamaduka @draganescu Reverted this from the original PR now, as you were hoping for in https://github.com/WordPress/gutenberg/pull/67125/files#r1853705137