-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Add a control to reset pattern overrides #57845
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 1 commit
9462711
6b4c307
ab97ea5
5e93c42
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -208,15 +208,18 @@ export default function ReusableBlockEdit( { | |||||||||||||||||
| [ innerBlocks, setBlockEditingMode ] | ||||||||||||||||||
| ); | ||||||||||||||||||
|
|
||||||||||||||||||
| // Apply the initial overrides from the pattern block to the inner blocks. | ||||||||||||||||||
| useEffect( () => { | ||||||||||||||||||
| const initialBlocks = | ||||||||||||||||||
| const initialBlocks = useMemo( | ||||||||||||||||||
| () => | ||||||||||||||||||
| // Clone the blocks to generate new client IDs. | ||||||||||||||||||
| editedRecord.blocks?.map( ( block ) => cloneBlock( block ) ) ?? | ||||||||||||||||||
| ( editedRecord.content && typeof editedRecord.content !== 'function' | ||||||||||||||||||
| ? parse( editedRecord.content ) | ||||||||||||||||||
| : [] ); | ||||||||||||||||||
| : [] ), | ||||||||||||||||||
| [ editedRecord.blocks, editedRecord.content ] | ||||||||||||||||||
| ); | ||||||||||||||||||
|
|
||||||||||||||||||
| // Apply the initial overrides from the pattern block to the inner blocks. | ||||||||||||||||||
| useEffect( () => { | ||||||||||||||||||
| defaultValuesRef.current = {}; | ||||||||||||||||||
| const editingMode = getBlockEditingMode( patternClientId ); | ||||||||||||||||||
| // Replace the contents of the blocks with the overrides. | ||||||||||||||||||
|
|
@@ -237,7 +240,7 @@ export default function ReusableBlockEdit( { | |||||||||||||||||
| }, [ | ||||||||||||||||||
| __unstableMarkNextChangeAsNotPersistent, | ||||||||||||||||||
| patternClientId, | ||||||||||||||||||
| editedRecord, | ||||||||||||||||||
| initialBlocks, | ||||||||||||||||||
| replaceInnerBlocks, | ||||||||||||||||||
| registry, | ||||||||||||||||||
| getBlockEditingMode, | ||||||||||||||||||
|
|
@@ -293,6 +296,10 @@ export default function ReusableBlockEdit( { | |||||||||||||||||
| editOriginalProps.onClick( event ); | ||||||||||||||||||
| }; | ||||||||||||||||||
|
|
||||||||||||||||||
| const resetOverrides = () => { | ||||||||||||||||||
| replaceInnerBlocks( patternClientId, initialBlocks ); | ||||||||||||||||||
| }; | ||||||||||||||||||
|
|
||||||||||||||||||
| let children = null; | ||||||||||||||||||
|
|
||||||||||||||||||
| if ( hasAlreadyRendered ) { | ||||||||||||||||||
|
|
@@ -333,6 +340,15 @@ export default function ReusableBlockEdit( { | |||||||||||||||||
| </ToolbarGroup> | ||||||||||||||||||
| </BlockControls> | ||||||||||||||||||
| ) } | ||||||||||||||||||
| { overrides ? ( | ||||||||||||||||||
| <BlockControls> | ||||||||||||||||||
| <ToolbarGroup> | ||||||||||||||||||
| <ToolbarButton onClick={ resetOverrides }> | ||||||||||||||||||
| { __( 'Reset overrides' ) } | ||||||||||||||||||
| </ToolbarButton> | ||||||||||||||||||
| </ToolbarGroup> | ||||||||||||||||||
| </BlockControls> | ||||||||||||||||||
| ) : null } | ||||||||||||||||||
|
||||||||||||||||||
| function setBlockEditMode( setEditMode, blocks, mode ) { | |
| blocks.forEach( ( block ) => { | |
| const editMode = | |
| mode || ( isPartiallySynced( block ) ? 'contentOnly' : 'disabled' ); | |
| setEditMode( block.clientId, editMode ); | |
| setBlockEditMode( setEditMode, block.innerBlocks, mode ); | |
| } ); | |
| } |
So given we do that we could also derive whether the pattern has any override attributes within it at the same time and use that to control visibility of the button. I think you end up with three states:
- Pattern has inner blocks that can be overriden but has no override state - show the button but disabled
- Pattern has inner blocks that can be overriden and has override state - show the button enabled
- None of the pattern's inner blocks can be overriden - don't show the button
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.
Oh I see what you mean now! I was only considering the (1) and the (2) states.
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.
A thought. I wonder if 'Reset to original' might be a slight improvement on the copy. It fits nicely with the 'Edit original' button next to it, and is slightly less technical.