-
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.
Add content schema to pattern editing view (#59977)
* Add new quick navigation component for pattern schema * Implement panel and fix minor issues * Rename to pattern content, and avoid showing panel when there are no blocks * Don't try to unlock what's already unlocked, just turn the handle. * Rename content panel title from 'Content' to 'Overrides' * Rename component to `OverridesPanel`
- Loading branch information
Showing
8 changed files
with
110 additions
and
19 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
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
26 changes: 26 additions & 0 deletions
26
packages/editor/src/components/pattern-overrides-panel/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,26 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useSelect } from '@wordpress/data'; | ||
import { privateApis as patternsPrivateApis } from '@wordpress/patterns'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { store as editorStore } from '../../store'; | ||
import { unlock } from '../../lock-unlock'; | ||
|
||
const { OverridesPanel } = unlock( patternsPrivateApis ); | ||
|
||
export default function PatternOverridesPanel() { | ||
const supportsPatternOverridesPanel = useSelect( | ||
( select ) => select( editorStore ).getCurrentPostType() === 'wp_block', | ||
[] | ||
); | ||
|
||
if ( ! supportsPatternOverridesPanel ) { | ||
return null; | ||
} | ||
|
||
return <OverridesPanel />; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { PARTIAL_SYNCING_SUPPORTED_BLOCKS } from '../constants'; | ||
|
||
/** | ||
* Determines whether a block is overridable. | ||
* | ||
* @param {WPBlock} block The block to test. | ||
* | ||
* @return {boolean} `true` if a block is overridable, `false` otherwise. | ||
*/ | ||
export function isOverridableBlock( block ) { | ||
return ( | ||
Object.keys( PARTIAL_SYNCING_SUPPORTED_BLOCKS ).includes( | ||
block.name | ||
) && | ||
!! block.attributes.metadata?.bindings && | ||
Object.values( block.attributes.metadata.bindings ).some( | ||
( binding ) => binding.source === 'core/pattern-overrides' | ||
) | ||
); | ||
} |
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,45 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { | ||
privateApis as blockEditorPrivateApis, | ||
store as blockEditorStore, | ||
} from '@wordpress/block-editor'; | ||
import { PanelBody } from '@wordpress/components'; | ||
import { useSelect } from '@wordpress/data'; | ||
import { useMemo } from '@wordpress/element'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { isOverridableBlock } from '../api'; | ||
import { unlock } from '../lock-unlock'; | ||
|
||
const { BlockQuickNavigation } = unlock( blockEditorPrivateApis ); | ||
|
||
export default function OverridesPanel() { | ||
const allClientIds = useSelect( | ||
( select ) => select( blockEditorStore ).getClientIdsWithDescendants(), | ||
[] | ||
); | ||
const { getBlock } = useSelect( blockEditorStore ); | ||
const clientIdsWithOverrides = useMemo( | ||
() => | ||
allClientIds.filter( ( clientId ) => { | ||
const block = getBlock( clientId ); | ||
return isOverridableBlock( block ); | ||
} ), | ||
[ allClientIds, getBlock ] | ||
); | ||
|
||
if ( ! clientIdsWithOverrides?.length ) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<PanelBody title={ __( 'Overrides' ) }> | ||
<BlockQuickNavigation clientIds={ clientIdsWithOverrides } /> | ||
</PanelBody> | ||
); | ||
} |
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
bc7e98c
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.
Flaky tests detected in bc7e98c.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.
🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/8519321002
📝 Reported issues:
/test/e2e/specs/editor/various/multi-block-selection.spec.js