-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Block Editor: Check for multiple block usage in the block-editor pack…
…age (#62086) Co-authored-by: youknowriad <[email protected]> Co-authored-by: ellatrix <[email protected]>
- Loading branch information
1 parent
e8bec8d
commit a12fa90
Showing
6 changed files
with
77 additions
and
170 deletions.
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
46 changes: 46 additions & 0 deletions
46
packages/block-editor/src/components/block-edit/multiple-usage-warning.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,46 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { getBlockType } from '@wordpress/blocks'; | ||
import { Button } from '@wordpress/components'; | ||
import { useDispatch } from '@wordpress/data'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { store as blockEditorStore } from '../../store'; | ||
import Warning from '../warning'; | ||
|
||
export function MultipleUsageWarning( { | ||
originalBlockClientId, | ||
name, | ||
onReplace, | ||
} ) { | ||
const { selectBlock } = useDispatch( blockEditorStore ); | ||
const blockType = getBlockType( name ); | ||
|
||
return ( | ||
<Warning | ||
actions={ [ | ||
<Button | ||
key="find-original" | ||
variant="secondary" | ||
onClick={ () => selectBlock( originalBlockClientId ) } | ||
> | ||
{ __( 'Find original' ) } | ||
</Button>, | ||
<Button | ||
key="remove" | ||
variant="secondary" | ||
onClick={ () => onReplace( [] ) } | ||
> | ||
{ __( 'Remove' ) } | ||
</Button>, | ||
] } | ||
> | ||
<strong>{ blockType?.title }: </strong> | ||
{ __( 'This block can only be used once.' ) } | ||
</Warning> | ||
); | ||
} |
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 was deleted.
Oops, something went wrong.
163 changes: 0 additions & 163 deletions
163
packages/edit-post/src/hooks/validate-multiple-use/index.js
This file was deleted.
Oops, something went wrong.
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