-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Add pattern title in create modal in post editor #59550
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
117 changes: 117 additions & 0 deletions
117
packages/edit-post/src/components/init-pattern-modal/index.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,117 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useSelect, useDispatch } from '@wordpress/data'; | ||
import { __, _x } from '@wordpress/i18n'; | ||
import { | ||
Modal, | ||
Button, | ||
__experimentalHStack as HStack, | ||
__experimentalVStack as VStack, | ||
ToggleControl, | ||
TextControl, | ||
} from '@wordpress/components'; | ||
import { useEffect, useState } from '@wordpress/element'; | ||
import { store as editorStore } from '@wordpress/editor'; | ||
import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
|
||
import { unlock } from '../../lock-unlock'; | ||
|
||
const { ReusableBlocksRenameHint } = unlock( blockEditorPrivateApis ); | ||
|
||
export default function InitPatternModal() { | ||
const { editPost } = useDispatch( editorStore ); | ||
const [ isModalOpen, setIsModalOpen ] = useState( false ); | ||
const [ syncType, setSyncType ] = useState( undefined ); | ||
const [ title, setTitle ] = useState( '' ); | ||
|
||
const { postType, isNewPost } = useSelect( ( select ) => { | ||
const { getEditedPostAttribute, isCleanNewPost } = | ||
select( editorStore ); | ||
return { | ||
postType: getEditedPostAttribute( 'type' ), | ||
isNewPost: isCleanNewPost(), | ||
}; | ||
}, [] ); | ||
|
||
useEffect( () => { | ||
if ( isNewPost && postType === 'wp_block' ) { | ||
setIsModalOpen( true ); | ||
} | ||
// We only want the modal to open when the page is first loaded. | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [] ); | ||
|
||
if ( postType !== 'wp_block' || ! isNewPost ) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<> | ||
{ isModalOpen && ( | ||
<Modal | ||
title={ __( 'Create pattern' ) } | ||
onRequestClose={ () => { | ||
setIsModalOpen( false ); | ||
} } | ||
overlayClassName="reusable-blocks-menu-items__convert-modal" | ||
> | ||
<form | ||
onSubmit={ ( event ) => { | ||
event.preventDefault(); | ||
setIsModalOpen( false ); | ||
editPost( { | ||
title, | ||
meta: { | ||
wp_pattern_sync_status: syncType, | ||
}, | ||
} ); | ||
} } | ||
> | ||
<VStack spacing="5"> | ||
<TextControl | ||
label={ __( 'Name' ) } | ||
value={ title } | ||
onChange={ setTitle } | ||
placeholder={ __( 'My pattern' ) } | ||
className="patterns-create-modal__name-input" | ||
__nextHasNoMarginBottom | ||
__next40pxDefaultSize | ||
/> | ||
<ReusableBlocksRenameHint /> | ||
<ToggleControl | ||
label={ _x( | ||
'Synced', | ||
'Option that makes an individual pattern synchronized' | ||
) } | ||
help={ __( | ||
'Sync this pattern across multiple locations.' | ||
) } | ||
checked={ ! syncType } | ||
onChange={ () => { | ||
setSyncType( | ||
! syncType ? 'unsynced' : undefined | ||
); | ||
} } | ||
/> | ||
<HStack justify="right"> | ||
<Button | ||
variant="primary" | ||
type="submit" | ||
disabled={ ! title } | ||
__experimentalIsFocusable | ||
> | ||
{ __( 'Create' ) } | ||
</Button> | ||
</HStack> | ||
</VStack> | ||
</form> | ||
</Modal> | ||
) } | ||
</> | ||
); | ||
} |
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
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
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
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.
I moved this in
edit-post
since this is the only place is used. Additionally we should probably look into how we can consolidate this one withCreatePatternModal
frompatterns
package. This could be in a follow up though and not a block for this PR to land for 6.5