Skip to content
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

Categories block: use supports flag for alignment + wide alignment support #10666

Closed
wants to merge 1 commit into from
Closed

Categories block: use supports flag for alignment + wide alignment support #10666

wants to merge 1 commit into from

Conversation

ZebulanStanphill
Copy link
Member

@ZebulanStanphill ZebulanStanphill commented Oct 16, 2018

Description

Previously #10635.

This PR changes the code for the Categories block to use the supports flag. It also adds support for the wide alignment to the Categories block, which strangely was lacking support for it despite already supporting the full alignment.

How has this been tested?

I opened a post with an existing Categories block and checked to make sure setting alignments worked and applied the right classes in the editor and front-end.

Types of changes

  • The block now uses supports: { align: true } to add block alignment support. Note that the align attribute is still defined in PHP, as this is necessary for the alignments to work on the front-end.
  • Added support for the wide alignment. (The block already supported the full alignment.)

@ZebulanStanphill ZebulanStanphill changed the title Categories block: move attrs to PHP + wide alignment support Categories block: move attributes to PHP + wide alignment support Oct 16, 2018
@ZebulanStanphill
Copy link
Member Author

I made a mistake on the PR... will fix in a moment.

@ZebulanStanphill
Copy link
Member Author

Okay, I've fixed the issue. This PR is now ready for review. @chrisvanpatten

'attributes' => array(
'align' => array(
'type' => 'string',
'enum' => array( 'left', 'center', 'right', 'wide', 'full' ),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notably, the values passed to enum have no effect on what is allowed in the editor (removing full does not make the full option disappear from the block toolbar), but they do have an effect on what classes end up getting applied on the front-end (removing full causes the alignfull class to not be applied on the front-end).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The JS and the PHP don't communicate about this right now, but one thing to note is that by specifying the enum here, but not explicitly listing out the alignments in the JS supports.align, it could be possible that new alignment options are added to the editor but aren't supported here. I think that's not a huge deal, but worth noting.

@chrisvanpatten
Copy link
Member

@ZebulanStanphill I know you're keen to get consistency between blocks but it'll be trickier to merge this because of how big the changes are, without e2e tests.

Is there a reason you can't just update the block to use supports.align while keeping everything else? It would be much easier to guarantee the potential for regressions is minimised.

I wish we had more time to explore greater consistency between the server rendered blocks but because we're under the gun in terms of timeline I think it'd be much safer to simply update the alignment without making other potentially breaking changes.

Copy link
Member

@chrisvanpatten chrisvanpatten left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small suggestions, per my previous comment. The less we change here, the more we can ensure it's going to be consistent without e2e tests.

packages/block-library/src/categories/edit.js Show resolved Hide resolved
@@ -19,35 +19,11 @@ export const settings = {

category: 'widgets',

attributes: {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To keep us on track here I'd really recommend preserving the definitions in JS — it keeps the change surface minimised as we careen toward code freezes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chrisvanpatten If the definitions remain in JS but are removed from PHP, I can't stop invalid classes from being applied. Should I define the attributes in both JS and PHP?

Copy link
Member

@chrisvanpatten chrisvanpatten Oct 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The JS should already ensure that only valid alignments are set to the align attribute. It doesn't need to be reinforced in PHP (or to be more specific, we aren't currently enforcing it on PHP in this block and if an 'invalid' alignment somehow made it through to PHP anyway it isn't a site-breaking issue).

@ZebulanStanphill ZebulanStanphill changed the title Categories block: move attributes to PHP + wide alignment support Categories block: use supports flag for alignment + wide alignment support Oct 17, 2018
@ZebulanStanphill
Copy link
Member Author

@chrisvanpatten Addressed feedback. Note that, using the Code Editor, set the align attribute to an invalid value, and an invalid class will be applied on the front-end. To fix this would require moving the attributes definiton to PHP and defining the align attribute there with an enum property specifying the valid values.

However, since this can only really happen if the user is intentionally trying to mess up the alignment classes, and since (I think) this behavior also occurs on master, I guess it is alright. A future PR could move the attributes definition to PHP.

@ZebulanStanphill
Copy link
Member Author

Test failures seemed unrelated. Squashed and rebased.

@ZebulanStanphill
Copy link
Member Author

Tests are still failing and I can't figure out why. 😕 It seems to have something to do with #10682.

@chrisvanpatten
Copy link
Member

@ZebulanStanphill Tests are failing in a bunch of PRs; I can restart Travis a little later once the problem is fixed.

@ZebulanStanphill
Copy link
Member Author

@chrisvanpatten Tests are no longer failing on this, #10706, or #10707. 🙂

@ZebulanStanphill
Copy link
Member Author

@chrisvanpatten I have rebased this PR to resolve conflicts with master. 🙂

@ZebulanStanphill
Copy link
Member Author

Closing in favor of #13215, which has some tweaks based on feedback on #10758, as well as a more accurate branch title.

@ZebulanStanphill ZebulanStanphill deleted the update/categories-block-move-attributes-to-php-2 branch January 5, 2019 20:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Categories Affects the Categories Block
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants