-
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 Reusable Post Sticky Component #3114
Conversation
*/ | ||
import { getCurrentPostType } from '../selectors'; | ||
|
||
export function PostStickyCheck( { postType, children, user } ) { |
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.
To avoid duplicating the "support sticky" check, I extracted it to its own component. I could reuse this approach for all the other sidebar panels.
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.
This works well.
Otherwise, I could imagine the following:
// new HoC
const withUserPrivileges = ( predicate ) =>
flowRight(
withAPIData( constant( { user: '/wp/v2…' } ) ),
withRenderIf( predicate )
);
// consumer
import withUserPrivilege from …;
const applyPostStickyCheck = withUserPrivileges( ( { postType, user } ) =>
postType !== 'post' ||
! user.data ||
! user.data.capabilities.publish_posts ||
! user.data.capabilities.edit_others_posts
);
export default applyPostStickyCheck( MyComponent );
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.
This could obfuscate component render logic, though. Right now most HoCs only deal with prop injection and side effects (like click-outside), not affecting when things should be rendered. Which is why the current way seems appropriate. 👌
Codecov Report
@@ Coverage Diff @@
## master #3114 +/- ##
==========================================
- Coverage 32.23% 32.17% -0.07%
==========================================
Files 216 218 +2
Lines 6151 6160 +9
Branches 1081 1083 +2
==========================================
- Hits 1983 1982 -1
- Misses 3517 3525 +8
- Partials 651 653 +2
Continue to review full report at Codecov.
|
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.
Nice and clean.
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 PostSticky component.
Testing instructions