-
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 notice of disabled blocks to block inserter when no results are found #17338
Closed
+45
−3
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
d52429c
Add notice of disabled blocks to block inserter when no results are f…
brentswisher 5c78b86
Remove old classname and bad property from new block manager button
brentswisher 617dd60
Replace isArray and length check with size in hiddenBlock lookup
brentswisher 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
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 |
---|---|---|
|
@@ -7,6 +7,7 @@ import { | |
findIndex, | ||
flow, | ||
groupBy, | ||
size, | ||
isEmpty, | ||
map, | ||
some, | ||
|
@@ -27,6 +28,7 @@ import { | |
PanelBody, | ||
withSpokenMessages, | ||
Tip, | ||
Button, | ||
} from '@wordpress/components'; | ||
import { | ||
getCategories, | ||
|
@@ -253,7 +255,7 @@ export class InserterMenu extends Component { | |
} | ||
|
||
render() { | ||
const { instanceId, onSelect, rootClientId, showInserterHelpPanel } = this.props; | ||
const { instanceId, onSelect, rootClientId, showInserterHelpPanel, numberOfHiddenBlocks, openModal } = this.props; | ||
const { | ||
childItems, | ||
hoveredItem, | ||
|
@@ -356,7 +358,32 @@ export class InserterMenu extends Component { | |
</PanelBody> | ||
) } | ||
{ isEmpty( suggestedItems ) && isEmpty( reusableItems ) && isEmpty( itemsPerCategory ) && ( | ||
<p className="editor-inserter__no-results block-editor-inserter__no-results">{ __( 'No blocks found.' ) }</p> | ||
<p className="editor-inserter__no-results block-editor-inserter__no-results"> | ||
{ numberOfHiddenBlocks > 0 ? __( 'No active blocks found.' ) : __( 'No blocks found.' ) } | ||
{ numberOfHiddenBlocks > 0 && ( | ||
<> | ||
<br /> | ||
{ | ||
sprintf( | ||
_n( | ||
'%1$d block is disabled.', | ||
'%1$d blocks are disabled.', | ||
numberOfHiddenBlocks | ||
), | ||
numberOfHiddenBlocks | ||
) | ||
} | ||
<br /> | ||
<Button | ||
isDefault | ||
className="block-editor-inserter__block-manager-button" | ||
onClick={ () => openModal( 'edit-post/manage-blocks' ) } | ||
> | ||
{ __( 'Manage Blocks' ) } | ||
</Button> | ||
</> | ||
) } | ||
</p> | ||
) } | ||
</div> | ||
</div> | ||
|
@@ -429,6 +456,9 @@ export default compose( | |
const { | ||
getChildBlockNames, | ||
} = select( 'core/blocks' ); | ||
const { | ||
getPreference, | ||
} = select( 'core/edit-post' ); | ||
|
||
let destinationRootClientId = rootClientId; | ||
if ( ! destinationRootClientId && ! clientId && ! isAppender ) { | ||
|
@@ -438,12 +468,15 @@ export default compose( | |
} | ||
} | ||
const destinationRootBlockName = getBlockName( destinationRootClientId ); | ||
const hiddenBlockTypes = getPreference( 'hiddenBlockTypes' ); | ||
const numberOfHiddenBlocks = size( hiddenBlockTypes ); | ||
|
||
return { | ||
rootChildBlocks: getChildBlockNames( destinationRootBlockName ), | ||
items: getInserterItems( destinationRootClientId ), | ||
showInserterHelpPanel: getSettings().showInserterHelpPanel, | ||
destinationRootClientId, | ||
numberOfHiddenBlocks, | ||
}; | ||
} ), | ||
withDispatch( ( dispatch, ownProps, { select } ) => { | ||
|
@@ -457,6 +490,10 @@ export default compose( | |
__experimentalFetchReusableBlocks: fetchReusableBlocks, | ||
} = dispatch( 'core/editor' ); | ||
|
||
const { | ||
openModal, | ||
} = dispatch( 'core/edit-post' ); | ||
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. Same here, we're not allowed to use actions from the |
||
|
||
// To avoid duplication, getInsertionIndex is extracted and used in two event handlers | ||
// This breaks the withDispatch not containing any logic rule. | ||
// Since it's a function only called when the event handlers are called, | ||
|
@@ -516,6 +553,7 @@ export default compose( | |
|
||
ownProps.onSelect(); | ||
}, | ||
openModal, | ||
}; | ||
} ), | ||
withSpokenMessages, | ||
|
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
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.
The inserter is a generic component from the
block-editor
package. It can't use a selector from the core/edit-post package. I wonder if the hiddenBlocks are available in thegetSettings
selector of theblock-editor
store instead.