-
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
Components: Extract a reusable Post Format Selector #3108
Conversation
editor/sidebar/post-format/index.js
Outdated
]; | ||
|
||
function PostFormat( { postType, onUpdatePostFormat, postFormat = 'standard', suggestedFormat, instanceId } ) { | ||
function PostFormat( { postType } ) { | ||
if ( ! get( postType.data, [ 'supports', 'post-formats' ] ) ) { |
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.
I hesitated whether to keep this in the reusable component. Even if we do so, we'd have to duplicate it here to avoid rendering the container panel as well. Thoughts @aduth ?
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.
Hm, if the reusable component is still "post aware" it seems to make sense to also be post post-type aware, and reasonable enough to render nothing if the post type does not support. That it's duplicated seems okay.
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.
Is it worth applying the same principle as with PostStickyCheck
in #3114?
Codecov Report
@@ Coverage Diff @@
## master #3108 +/- ##
==========================================
- Coverage 31.58% 31.51% -0.08%
==========================================
Files 219 221 +2
Lines 6291 6305 +14
Branches 1118 1121 +3
==========================================
Hits 1987 1987
- Misses 3618 3629 +11
- Partials 686 689 +3
Continue to review full report at Codecov.
|
editor/post-format/index.js
Outdated
const postFormatSelectorId = 'post-format-selector-' + instanceId; | ||
const suggestion = find( POST_FORMATS, ( format ) => format.id === suggestedFormat ); | ||
|
||
// Disable reason: A select with an onchange throws a warning |
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.
Existed previously but... "it's a warning" is not a reason to disable a warning.
editor/sidebar/post-format/index.js
Outdated
]; | ||
|
||
function PostFormat( { postType, onUpdatePostFormat, postFormat = 'standard', suggestedFormat, instanceId } ) { | ||
function PostFormat( { postType } ) { | ||
if ( ! get( postType.data, [ 'supports', 'post-formats' ] ) ) { |
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.
Hm, if the reusable component is still "post aware" it seems to make sense to also be post post-type aware, and reasonable enough to render nothing if the post type does not support. That it's duplicated seems okay.
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.
Looks good to me :)
editor/post-format/index.js
Outdated
const postFormatSelectorId = 'post-format-selector-' + instanceId; | ||
const suggestion = find( POST_FORMATS, ( format ) => format.id === suggestedFormat ); | ||
|
||
// Disable reason: We need to change the value immiediately to show/hide the suggestion if needed |
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.
Typo at immiediately :)
editor/post-format/index.js
Outdated
} | ||
|
||
const postFormatSelectorId = 'post-format-selector-' + instanceId; | ||
const suggestion = find( POST_FORMATS, ( format ) => format.id === suggestedFormat ); |
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.
Tip: lodash#find
allows find( xs, { id: suggestedFormat } )
syntax — unless you want to keep as-in to keep it closer to the Array#find
standard.
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.
Also, not sure where, but I think I've read that this syntax might be deprecated in lodash 5
editor/sidebar/post-format/index.js
Outdated
]; | ||
|
||
function PostFormat( { postType, onUpdatePostFormat, postFormat = 'standard', suggestedFormat, instanceId } ) { | ||
function PostFormat( { postType } ) { | ||
if ( ! get( postType.data, [ 'supports', 'post-formats' ] ) ) { |
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.
Is it worth applying the same principle as with PostStickyCheck
in #3114?
d4f26bd
to
4a2059f
Compare
Related to #2761 (comment)
This is the first one of multiple PRs addressing the comment above and extracting reusable pieces from our current sidebar panels. This PR does so for the PostFormat component.
Testing instructions