-
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
Comments Query Loop: Add discuss options to the block #37297
Merged
cbravobernal
merged 19 commits into
trunk
from
update/add-comments-query-loop-sorting-option
Jan 25, 2022
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
2e30d21
Add sort attribute to the editor
f76f296
Update the fixtures with the new comment template
9382c14
Update with default options from discussion
39d9dd2
Update fixtures
18b99dd
Update with order options
5b94607
Move settings to inspector controls
ed5036c
Move order setting to parent query loop block
3a110c0
Update test
c263423
Prevent side effects and undo trap
6f98847
Update docs with new attributes
58d28e7
Add inherit from settings option
ddcf08d
Add defaults from settings on comment load if inherit is enabled
8a34197
Fix default values if they were already defined
103ec3e
Fix default values if they were already defined
e97ed93
Remove not needed variables
8d69d1e
Remove not needed toolbar and side effects
00ecdd1
Update PHP with default order values
dc5c16b
Nitpicks suggested
67bfc8e
Update packages/block-library/src/comment-template/edit.js
cbravobernal 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
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
93 changes: 93 additions & 0 deletions
93
packages/block-library/src/comments-query-loop/edit/comments-inspector-controls.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,93 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { | ||
PanelBody, | ||
SelectControl, | ||
ToggleControl, | ||
__experimentalNumberControl as NumberControl, | ||
} from '@wordpress/components'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { InspectorControls } from '@wordpress/block-editor'; | ||
|
||
const orderOptions = [ | ||
{ | ||
label: __( 'Newest to oldest' ), | ||
value: 'desc', | ||
}, | ||
{ | ||
label: __( 'Oldest to newest' ), | ||
value: 'asc', | ||
}, | ||
]; | ||
|
||
export default function CommentsInspectorControls( { | ||
attributes: { TagName, perPage, order, inherit }, | ||
setAttributes, | ||
defaultSettings: { defaultPerPage, defaultOrder }, | ||
} ) { | ||
return ( | ||
<InspectorControls> | ||
<PanelBody title={ __( 'Settings' ) }> | ||
<ToggleControl | ||
label={ __( 'Inherit from Discussion Settings' ) } | ||
checked={ inherit } | ||
onChange={ () => { | ||
setAttributes( { | ||
inherit: ! inherit, | ||
order: inherit ? defaultOrder : null, | ||
perPage: inherit ? defaultPerPage : null, | ||
} ); | ||
} } | ||
/> | ||
{ ! inherit && ( | ||
<> | ||
<SelectControl | ||
label={ __( 'Order by' ) } | ||
value={ order } | ||
options={ orderOptions } | ||
onChange={ ( value ) => { | ||
setAttributes( { | ||
order: value, | ||
} ); | ||
} } | ||
/> | ||
<NumberControl | ||
__unstableInputWidth="60px" | ||
label={ __( 'Items per Page' ) } | ||
labelPosition="edge" | ||
min={ 1 } | ||
max={ 100 } | ||
onChange={ ( value ) => { | ||
const num = parseInt( value, 10 ); | ||
if ( isNaN( num ) || num < 1 || num > 100 ) { | ||
return; | ||
} | ||
setAttributes( { | ||
perPage: num, | ||
} ); | ||
} } | ||
step="1" | ||
value={ perPage } | ||
isDragEnabled={ false } | ||
/> | ||
</> | ||
) } | ||
</PanelBody> | ||
<InspectorControls __experimentalGroup="advanced"> | ||
<SelectControl | ||
label={ __( 'HTML element' ) } | ||
options={ [ | ||
{ label: __( 'Default (<div>)' ), value: 'div' }, | ||
{ label: '<section>', value: 'section' }, | ||
{ label: '<aside>', value: 'aside' }, | ||
] } | ||
value={ TagName } | ||
onChange={ ( value ) => | ||
setAttributes( { tagName: value } ) | ||
} | ||
/> | ||
</InspectorControls> | ||
</InspectorControls> | ||
); | ||
} |
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,3 @@ | ||
.block-library-comments-toolbar__popover .components-popover__content { | ||
min-width: 230px; | ||
} | ||
This file was deleted.
Oops, something went wrong.
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.
While working on #40522, @DAreRodz, @michalczaplinski and I found that this file doesn't seem to be used.
It seems that it was introduced to fix the issue mentioned here, but it appears the relevant settings were later moved to the inspector controls in the sidebar, making the styling obsolete.
Just documenting this here for posterity 😄