-
Notifications
You must be signed in to change notification settings - Fork 798
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
Widget Visibility: add controls to widget block editor #20731
Conversation
Caution: This PR has changes that must be merged to WordPress.com |
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available. Once your PR is ready for review, check one last time that all required checks (other than "Required review") appearing at the bottom of this PR are passing or skipped. Jetpack plugin:
|
2d74cbd
to
55a2ba7
Compare
how does core handle this? |
I added code that recursively filters blocks based on their visibility conditions. For example, you could have a widget that's two columns, then set the right column to only display on certain pages. [{"blockName":"core\/columns","attrs":{"conditions":{"action":"show","rules":[],"match_all":"0"}},"innerBlocks":[{"blockName":"core\/column","attrs":{"conditions":{"action":"show","rules":[],"match_all":"0"}},"innerBlocks":[{"blockName":"core\/paragraph","attrs":{"conditions":{"action":"show","rules":[{"major":"page","minor":"front"}],"match_all":"0"}},"innerBlocks":[],"innerHTML":"\n<p>Home Page Only<\/p>\n","innerContent":["\n<p>Home Page Only<\/p>\n"]}],"innerHTML":"\n<div class=\"wp-block-column\"><\/div>\n","innerContent":["\n<div class=\"wp-block-column\">",null,"<\/div>\n"]},{"blockName":"core\/column","attrs":{"conditions":{"action":"show","rules":[],"match_all":"0"}},"innerBlocks":[],"innerHTML":"\n<div class=\"wp-block-column\"><\/div>\n","innerContent":["\n<div class=\"wp-block-column\">",null,"<\/div>\n"]}],"innerHTML":"\n<div class=\"wp-block-columns\">\n\n<\/div>\n","innerContent":["\n<div class=\"wp-block-columns\">",null,"\n\n",null,"<\/div>\n"]}] ^ That's an example $blocks that fails to render. I believe it's because I've wiped out the innerBlocks the column, but the Edit: This is now fixed in 5498fd1 |
Some design examples from other plugins at pbAok1-2dI-p2 |
@dsas could you take a look please cause I will be AFK? |
0079db6
to
5498fd1
Compare
I was able to get the recursive block filtering working on the front-end. Here's a quick demo (turn on sound for commentary): block-filtering-demo.mp4 |
e542aca
to
332e837
Compare
I think core doesn't have a widget visibility feature, and it's always been a jetpack feature. However I'm not certain. |
There's an issue when using the customizer to edit the widget on a jetpack site. After setting up a widget with at least one visibility rule and toggling the match all / match one, it goes straight back to the widget list, rather than staying on the edit widget screen. The toggle does take effect though. Here's a short video: https://d.pr/v/DDlJwE |
I'm able to replicate this. For me, it's only bringing me back the first time. If I go to advanced and then toggle the match all, it brings me back to the widget list. But if I go back into the same advanced screen, I'm free to toggle it more without being sent back. https://user-images.githubusercontent.com/937354/130149922-d762b531-f39c-4303-b35d-431a68b08dc3.mp4 I've also noticed it happens when I do other settings, like colors: https://user-images.githubusercontent.com/937354/130149989-ee169b10-62bd-4546-8ec9-f55ce514bd8a.mp4 I also tried it on a production simple site. I found that any edit I made in the advanced section sent me back Additionally, it didn't have the "Only first edit" restriction like I was seeing on jetpack. https://user-images.githubusercontent.com/937354/130150071-fcd80fe6-f7c5-49d4-b7a7-0a8bd4ad2dde.mp4 Something it definitely going on. I don't think it's caused by any of this code, but I agree it would make working in the rules area very difficult if it continues to work this way, so perhaps we can identify what it is and how to disable it. |
projects/plugins/jetpack/modules/widget-visibility/widget-conditions/widget-conditions.js
Outdated
Show resolved
Hide resolved
@jeherve Can you help with some build environment questions? In |
Works identically on a simple site too 👍
This is correct. |
… not when rendering the control Seems to help with some strange errors and upcoming changes.
097a12e
to
95ea54e
Compare
Rebased and reported the above bug in Automattic/wp-calypso#56509 . I think we're ready to proceed here. |
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 looks good to me, let's merge it! 🚢
Great news! One last step: head over to your WordPress.com diff, D65619-code, and commit it. Thank you! |
rWP232223 |
This has been reverted due to causing 500 errors. Two separate issues: |
Fixes #20057
Changes proposed in this Pull Request:
Issues
Issues (Fixed)
Fixed, however it isn't perfect.widget_conditions_data
has some nested arrays as options, that render fancy nested selects.<optgroup
elements. (which is what the legacy visbility section uses)* Major option "Taxonomy" should be hidden if there's not a non-default taxonomyuser and role major options should be hidden on wpcom. Fixed.Does not actually control visibility on the front end.Fixed.Javascript buildI'd like to write in JSX, but I haven't found a way. So I'm using element.createElement.Well, I did see instant search, which uses its own preact+webpack+babel setup, but it looked so complicated that I would probably be spending days just on environment setup. babel, package.json and moreI am using ES6 features, but I think my code isn't being run by babel, so I might have to convert it to ES5 (this could be tricky with the immutable updates).Technically, legacy widgets are also blocks. This means you can currently specify their visibility on two levels, the legacy level and the new block based one, which would lead to confusing results.Fixed: These are no longer allowed to have controls.Accessibility issues on the delete buttonOn this branch, the /wp-admin/widgets.php page loads with the footer collapsed. There is an uncaughtException { name: "NS_ERROR_FAILURE", message: "", result: 2147500037,
shown in the browser console that's related to this behavior.setAttributes
on thecore/legacy-widget
andcore/widget-area
blocks, which don't need visibility settings.I cannot add attributes to these types of blocks: 'core/archives', 'core/latest-comments', 'core/latest-posts'. Most blocks let me add a custom attribute, but with these, they start crashing when I add an attribute to them. Why? And are there others that will crash that I haven't found yet?(1) Customizer Bug. F5 -> Visit customizer -> Widgets -> Select a block widget -> Three dots menu -> Show more settings -> Advanced -> Add new rule.Random Musings
Jetpack product discussion
Does this pull request change what data or activity we track or use?
Testing instructions:
jetpack docker up
jetpack docker install
, and possibly edit one of the env files such that your password isn't easily guessable if you decide to use a tunneling solution in the future.jetpack watch plugins/jetpack
jetpack build plugins/jetpack
first.^ Here it is with no design (although, it might be challenging to fit in sidebar)
Compare to the legacy visibility which we are re-implementing:
^ Legacy visibility, not in this PR
Testing on DotCom