-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Edit Post: Add block management modal #14224
Merged
Merged
Changes from all commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
86c88a1
Edit Post: Provide default preferences by higher-order reducer
aduth 8af0287
Edit Post: Add block management modal
aduth f83be63
Edit Post: Rephrase block disable as block hide
aduth 8fc50d9
Edit Post: Update "Hide All" to "Hide all blocks"
aduth c61ccd7
Edit Post: Remove block manager autoFocus
aduth 9ac28ec
Edit Post: Close Block Manager panels by default
aduth ae02300
Edit Post: Show visible label for Block Manager search
aduth 40ffefe
Edit Post: Generalize block search to blocks selector
aduth c8d5b98
Edit Post: Show hidden block types in Block Manager as labelled
aduth b28cbb0
Edit Post: Avoid generating unnecessary hasChildBlocksWithInserterSup…
aduth b681ecb
Edit Post: Split Block Manager category render to own component
aduth f8a1874
Edit Post: Filter Block Manager items by inserter support
aduth 98e55eb
Edit Post: Render Block Manager item as toggle button
aduth 32e2490
Edit Post: Render Block Manager results as labelled region
aduth 2de9a7e
Edit Post: Constrain Block Manager width to 485px
aduth 8671702
Components: Add className prop support for ToggleControl
aduth fccc796
Edit Post: Add margin surrounding Hide all checkbox
aduth f092ff6
Edit Post: Avoid changing label in toggle button
aduth 25b185c
Blocks: Regenerate docs for isMatchingSearchTerm
aduth fbf5410
Update components CHANGELOG to use "class name" phrasing
gziolo 9ce3def
Edit Post: Use consistent "Manage Block Visibility" label
aduth bfc1a38
Blocks: Add unit tests for isMatchingSearchTerm
aduth 6171177
Edit Post: Add "No Results" text for empty Manage Blocks search
aduth c0b9a23
Edit Post: Render Manage Blocks Visibility as checklist
aduth fc978e5
Edit Post: Reverse behavior of "all" visible toggle to show
aduth 9297f8d
Components: Add mirror prop support to CheckboxControl
aduth e194aa0
Edit Post: Mirror checkboxes in Manage Blocks modal
aduth 1555f58
Edit Post: Fix Firefox scroll overflow in Manage Blocks
aduth 2d9b379
Edit Post: Render Manage Blocks group as role=group
aduth 6798964
Checkbox margin adjustment.
mapk 76fb031
Merge branch 'add/block-manager' of github.com:WordPress/gutenberg in…
mapk ac202ff
Icon colors changed to -gray-500
mapk a71f799
Changed title back to Block Manager based on design feedback
mapk 3d7de09
Edit Post: Fix Block Manager "Show All" toggle checked as all checked
aduth 6e8072a
Edit Post: Refactor Block Manager checkbox margin as precise override
aduth 0d985a2
Revert "Edit Post: Fix Block Manager "Show All" toggle checked as all…
mapk dca4049
Revert "Components: Add mirror prop support to CheckboxControl"
aduth 40c7694
Edit Post: Display block manager entries as indented checklist
aduth 22ad54b
Edit Post: Restore Block Manager toggle label association
aduth 0b45148
Edit Post: Adjust mobile, margin styling for mixed checkbox
aduth 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { getChildBlockNames } from '../selectors'; | ||
import { | ||
getChildBlockNames, | ||
isMatchingSearchTerm, | ||
} from '../selectors'; | ||
|
||
describe( 'selectors', () => { | ||
describe( 'getChildBlockNames', () => { | ||
|
@@ -134,4 +137,66 @@ describe( 'selectors', () => { | |
expect( getChildBlockNames( state, 'parent2' ) ).toEqual( [ 'child2' ] ); | ||
} ); | ||
} ); | ||
|
||
describe( 'isMatchingSearchTerm', () => { | ||
const name = 'core/paragraph'; | ||
const blockType = { | ||
title: 'Paragraph', | ||
category: 'common', | ||
keywords: [ 'text' ], | ||
}; | ||
|
||
const state = { | ||
blockTypes: { | ||
[ name ]: blockType, | ||
}, | ||
}; | ||
|
||
describe.each( [ | ||
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. This thing (https://jestjs.io/docs/en/api#describeeachtable-name-fn-timeout) has a bit hard to follow API but once you learn it is awesome 👍 I like how it keeps the readability of the |
||
[ 'name', name ], | ||
[ 'block type', blockType ], | ||
] )( 'by %s', ( label, nameOrType ) => { | ||
it( 'should return false if not match', () => { | ||
const result = isMatchingSearchTerm( state, nameOrType, 'Quote' ); | ||
|
||
expect( result ).toBe( false ); | ||
} ); | ||
|
||
it( 'should return true if match by title', () => { | ||
const result = isMatchingSearchTerm( state, nameOrType, 'Paragraph' ); | ||
|
||
expect( result ).toBe( true ); | ||
} ); | ||
|
||
it( 'should return true if match ignoring case', () => { | ||
const result = isMatchingSearchTerm( state, nameOrType, 'PARAGRAPH' ); | ||
|
||
expect( result ).toBe( true ); | ||
} ); | ||
|
||
it( 'should return true if match ignoring diacritics', () => { | ||
const result = isMatchingSearchTerm( state, nameOrType, 'PÁRAGRAPH' ); | ||
|
||
expect( result ).toBe( true ); | ||
} ); | ||
|
||
it( 'should return true if match ignoring whitespace', () => { | ||
const result = isMatchingSearchTerm( state, nameOrType, ' PARAGRAPH ' ); | ||
|
||
expect( result ).toBe( true ); | ||
} ); | ||
|
||
it( 'should return true if match using the keywords', () => { | ||
const result = isMatchingSearchTerm( state, nameOrType, 'TEXT' ); | ||
|
||
expect( result ).toBe( true ); | ||
} ); | ||
|
||
it( 'should return true if match using the categories', () => { | ||
const result = isMatchingSearchTerm( state, nameOrType, 'COMMON' ); | ||
|
||
expect( result ).toBe( true ); | ||
} ); | ||
} ); | ||
} ); | ||
} ); |
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
103 changes: 103 additions & 0 deletions
103
packages/edit-post/src/components/manage-blocks-modal/category.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,103 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { without, map } from 'lodash'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { withSelect, withDispatch } from '@wordpress/data'; | ||
import { compose, withInstanceId } from '@wordpress/compose'; | ||
import { CheckboxControl } from '@wordpress/components'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import BlockTypesChecklist from './checklist'; | ||
|
||
function BlockManagerCategory( { | ||
instanceId, | ||
category, | ||
blockTypes, | ||
hiddenBlockTypes, | ||
toggleVisible, | ||
toggleAllVisible, | ||
} ) { | ||
if ( ! blockTypes.length ) { | ||
return null; | ||
} | ||
|
||
const checkedBlockNames = without( | ||
map( blockTypes, 'name' ), | ||
...hiddenBlockTypes | ||
); | ||
|
||
const titleId = 'edit-post-manage-blocks-modal__category-title-' + instanceId; | ||
|
||
const isAllChecked = checkedBlockNames.length === blockTypes.length; | ||
|
||
let ariaChecked; | ||
if ( isAllChecked ) { | ||
ariaChecked = 'true'; | ||
} else if ( checkedBlockNames.length > 0 ) { | ||
ariaChecked = 'mixed'; | ||
} else { | ||
ariaChecked = 'false'; | ||
} | ||
|
||
return ( | ||
<div | ||
role="group" | ||
aria-labelledby={ titleId } | ||
className="edit-post-manage-blocks-modal__category" | ||
> | ||
<CheckboxControl | ||
checked={ isAllChecked } | ||
onChange={ toggleAllVisible } | ||
className="edit-post-manage-blocks-modal__category-title" | ||
aria-checked={ ariaChecked } | ||
label={ <span id={ titleId }>{ category.title }</span> } | ||
/> | ||
<BlockTypesChecklist | ||
blockTypes={ blockTypes } | ||
value={ checkedBlockNames } | ||
onItemChange={ toggleVisible } | ||
/> | ||
</div> | ||
); | ||
} | ||
|
||
export default compose( [ | ||
withInstanceId, | ||
withSelect( ( select ) => { | ||
const { getPreference } = select( 'core/edit-post' ); | ||
|
||
return { | ||
hiddenBlockTypes: getPreference( 'hiddenBlockTypes' ), | ||
}; | ||
} ), | ||
withDispatch( ( dispatch, ownProps ) => { | ||
const { | ||
showBlockTypes, | ||
hideBlockTypes, | ||
} = dispatch( 'core/edit-post' ); | ||
|
||
return { | ||
toggleVisible( blockName, nextIsChecked ) { | ||
if ( nextIsChecked ) { | ||
showBlockTypes( blockName ); | ||
} else { | ||
hideBlockTypes( blockName ); | ||
} | ||
}, | ||
toggleAllVisible( nextIsChecked ) { | ||
const blockNames = map( ownProps.blockTypes, 'name' ); | ||
if ( nextIsChecked ) { | ||
showBlockTypes( blockNames ); | ||
} else { | ||
hideBlockTypes( blockNames ); | ||
} | ||
}, | ||
}; | ||
} ), | ||
] )( BlockManagerCategory ); |
37 changes: 37 additions & 0 deletions
37
packages/edit-post/src/components/manage-blocks-modal/checklist.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,37 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { partial } from 'lodash'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { Fragment } from '@wordpress/element'; | ||
import { BlockIcon } from '@wordpress/block-editor'; | ||
import { CheckboxControl } from '@wordpress/components'; | ||
|
||
function BlockTypesChecklist( { blockTypes, value, onItemChange } ) { | ||
return ( | ||
<ul className="edit-post-manage-blocks-modal__checklist"> | ||
{ blockTypes.map( ( blockType ) => ( | ||
<li | ||
key={ blockType.name } | ||
className="edit-post-manage-blocks-modal__checklist-item" | ||
> | ||
<CheckboxControl | ||
label={ ( | ||
<Fragment> | ||
{ blockType.title } | ||
<BlockIcon icon={ blockType.icon } /> | ||
</Fragment> | ||
) } | ||
checked={ value.includes( blockType.name ) } | ||
onChange={ partial( onItemChange, blockType.name ) } | ||
/> | ||
</li> | ||
) ) } | ||
</ul> | ||
); | ||
} | ||
|
||
export default BlockTypesChecklist; |
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.
In the follow-up PR we should cover this new selector with basic unit tests.
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.
Yeah, I can get those in place today.
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.
Added unit tests in bfc1a38.