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

Wrap navigation editing features with filters #25329

Merged
merged 2 commits into from
Sep 25, 2020

Conversation

draganescu
Copy link
Contributor

@draganescu draganescu commented Sep 15, 2020

Advances #25233
Fixes #25508

Description

This PR makes the Navigation block's edit component customizable for the Navigation editor. It adds all the formatting controls, the modal list view control, the alignment control in filters and removes them in the Navigation editor.

How has this been tested?

Tested locally.

Types of changes

Non breaking changes, but new pattern that may have some effects I am not aware of.

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR.

@github-actions
Copy link

github-actions bot commented Sep 15, 2020

Size Change: -433 B (0%)

Total Size: 1.2 MB

Filename Size Change
build/block-library/index.js 134 kB -722 B (0%)
build/edit-navigation/index.js 10.7 kB +289 B (2%)
ℹ️ View Unchanged
Filename Size Change
build/a11y/index.js 1.14 kB 0 B
build/annotations/index.js 3.52 kB 0 B
build/api-fetch/index.js 3.34 kB 0 B
build/autop/index.js 2.72 kB 0 B
build/blob/index.js 620 B 0 B
build/block-directory/index.js 8.41 kB 0 B
build/block-directory/style-rtl.css 943 B 0 B
build/block-directory/style.css 942 B 0 B
build/block-editor/index.js 128 kB 0 B
build/block-editor/style-rtl.css 11.1 kB 0 B
build/block-editor/style.css 11.1 kB 0 B
build/block-library/editor-rtl.css 8.59 kB 0 B
build/block-library/editor.css 8.59 kB 0 B
build/block-library/style-rtl.css 7.6 kB 0 B
build/block-library/style.css 7.59 kB 0 B
build/block-library/theme-rtl.css 741 B 0 B
build/block-library/theme.css 741 B 0 B
build/block-serialization-default-parser/index.js 1.77 kB 0 B
build/block-serialization-spec-parser/index.js 3.1 kB 0 B
build/blocks/index.js 47.5 kB 0 B
build/components/index.js 202 kB 0 B
build/components/style-rtl.css 15.5 kB 0 B
build/components/style.css 15.5 kB 0 B
build/compose/index.js 9.42 kB 0 B
build/core-data/index.js 12 kB 0 B
build/data-controls/index.js 1.27 kB 0 B
build/data/index.js 8.43 kB 0 B
build/date/index.js 31.9 kB 0 B
build/deprecated/index.js 772 B 0 B
build/dom-ready/index.js 568 B 0 B
build/dom/index.js 4.42 kB 0 B
build/edit-navigation/style-rtl.css 868 B 0 B
build/edit-navigation/style.css 871 B 0 B
build/edit-post/index.js 306 kB 0 B
build/edit-post/style-rtl.css 6.24 kB 0 B
build/edit-post/style.css 6.22 kB 0 B
build/edit-site/index.js 19.6 kB 0 B
build/edit-site/style-rtl.css 3.3 kB 0 B
build/edit-site/style.css 3.3 kB 0 B
build/edit-widgets/index.js 17.6 kB 0 B
build/edit-widgets/style-rtl.css 2.79 kB 0 B
build/edit-widgets/style.css 2.79 kB 0 B
build/editor/editor-styles-rtl.css 492 B 0 B
build/editor/editor-styles.css 493 B 0 B
build/editor/index.js 45.3 kB 0 B
build/editor/style-rtl.css 3.8 kB 0 B
build/editor/style.css 3.8 kB 0 B
build/element/index.js 4.45 kB 0 B
build/escape-html/index.js 733 B 0 B
build/format-library/index.js 7.49 kB 0 B
build/format-library/style-rtl.css 547 B 0 B
build/format-library/style.css 548 B 0 B
build/hooks/index.js 1.74 kB 0 B
build/html-entities/index.js 622 B 0 B
build/i18n/index.js 3.54 kB 0 B
build/is-shallow-equal/index.js 711 B 0 B
build/keyboard-shortcuts/index.js 2.39 kB 0 B
build/keycodes/index.js 1.85 kB 0 B
build/list-reusable-blocks/index.js 3.02 kB 0 B
build/list-reusable-blocks/style-rtl.css 476 B 0 B
build/list-reusable-blocks/style.css 476 B 0 B
build/media-utils/index.js 5.12 kB 0 B
build/notices/index.js 1.69 kB 0 B
build/nux/index.js 3.27 kB 0 B
build/nux/style-rtl.css 671 B 0 B
build/nux/style.css 668 B 0 B
build/plugins/index.js 2.44 kB 0 B
build/primitives/index.js 1.34 kB 0 B
build/priority-queue/index.js 789 B 0 B
build/redux-routine/index.js 2.85 kB 0 B
build/rich-text/index.js 13.7 kB 0 B
build/server-side-render/index.js 2.6 kB 0 B
build/shortcode/index.js 1.7 kB 0 B
build/token-list/index.js 1.24 kB 0 B
build/url/index.js 4.06 kB 0 B
build/viewport/index.js 1.74 kB 0 B
build/warning/index.js 1.13 kB 0 B
build/wordcount/index.js 1.17 kB 0 B

compressed-size-action

@draganescu draganescu self-assigned this Sep 15, 2020
@draganescu draganescu changed the title wrap navigation editing features with filters Wrap navigation editing features with filters Sep 15, 2020
Copy link
Member

@kevin940726 kevin940726 left a comment

Choose a reason for hiding this comment

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

I would probably split them into different files src/navigation/with-inspector-controls.js, src/navigation/with-block-controls.js, etc. But it's fine either way 😆.

Copy link
Contributor

@talldan talldan left a comment

Choose a reason for hiding this comment

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

This is pretty clever. I would personally be happy with this approach if it could be implemented in such a way that it didn't need a new navigation.BlockEdit filter, as that constitutes a very specific public API for a single block. In my quick testing it should be possible to use the existing editor.BlockEdit filter. I added a comment below on that.

Also noting the item justification isn't working for me in master, but in this PR it's fixed 😄

packages/block-library/src/navigation/edit.js Outdated Show resolved Hide resolved
packages/block-library/src/navigation/edit.js Show resolved Hide resolved
packages/block-library/src/navigation/edit.js Outdated Show resolved Hide resolved
packages/block-library/src/navigation/edit.js Outdated Show resolved Hide resolved
@talldan talldan self-assigned this Sep 18, 2020
@talldan talldan force-pushed the try/navigation-use-filter-add-controls branch from 19b1c11 to 899e406 Compare September 18, 2020 07:24
@talldan
Copy link
Contributor

talldan commented Sep 18, 2020

@draganescu let me take over this PR, so I've made some changes:

  • Changed the nav block to use the __experimentalColors supports property so it's consistent with other blocks. This moves the color settings from the toolbar to the inspector and results in quite a bit of code deletion 🎉
  • Instead of adding features using filters and removing those filters I've done the inverse—added flag props to the navigation block edit that default to true, and then set them to false on the navigation screen using the BlockEdit filter. This solves an issue with the previous approach where the features were displayed while the block was still in its initial placeholder state.
  • I've used the registerBlockType filter to remove __experimentalColors and __experimentalFontSize support on the navigation screen.

Not sure if there are other options to remove. I wasn't sure about 'Anchor', is that in use?

@draganescu
Copy link
Contributor Author

Anchor for the Navigation block doesn't make much sense so we can remove that in all the places.

@talldan
Copy link
Contributor

talldan commented Sep 18, 2020

I've removed support for both anchor and additional class names on the nav screen for the nav block after a brief consult with @draganescu.

Copy link
Contributor Author

@draganescu draganescu left a comment

Choose a reason for hiding this comment

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

This works great @talldan

Comment on lines +35 to +52
function removeNavigationBlockSettingsUnsupportedFeatures( settings, name ) {
if ( name !== 'core/navigation' ) {
return settings;
}

return {
...settings,
supports: {
...omit( settings.supports, [
'anchor',
'customClassName',
'__experimentalColor',
'__experimentalFontSize',
] ),
customClassName: false,
},
};
}
Copy link
Contributor

@adamziel adamziel Sep 18, 2020

Choose a reason for hiding this comment

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

I feel like an allowlist would be a better choice than a denylist here. With an allowlist, worst case scenario is not offering a new feature on this screen. With a denylist, worst case scenario is breaking the screen with unsupported feature that was added without considering this editor.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure that would be possible as block supports settings are an already defined public API.

With a denylist, worst case scenario is breaking the screen with unsupported feature that was added without considering this editor.

I'm not sure it'd break anything, it'd be a setting that would never have its value saved.

Copy link
Contributor

Choose a reason for hiding this comment

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

I suppose the option would be to use a filter to add them to the post/site editor at registration, though I personally feel that blocks in the block library shouldn't require any extra configuration, they should work as intended out of the box.

Comment on lines +54 to +70
const removeNavigationBlockEditUnsupportedFeatures = createHigherOrderComponent(
( BlockEdit ) => ( props ) => {
if ( props.name !== 'core/navigation' ) {
return <BlockEdit { ...props } />;
}

return (
<BlockEdit
{ ...props }
hasSubmenuIndicatorSetting={ false }
hasItemJustificationControls={ false }
hasListViewModal={ false }
/>
);
},
'removeNavigationBlockEditUnsupportedFeatures'
);
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't agree as there are more cases where the setting needs to be true (post editor, site editor) than there are where it needs to be false (navigation editor). There are possibilities for mistakes either way.

draganescu and others added 2 commits September 22, 2020 08:32
Change navigation block to use __experimentalColor support option, and disable feature on navigation screen

Remove unused ref

Refactor to use feature flags injected as props to BlockEdit

Also remove font size support

Remove CSS Class and anchor support on navigation screen
@talldan talldan force-pushed the try/navigation-use-filter-add-controls branch from 6834c5c to e9670cc Compare September 22, 2020 00:49
Copy link
Member

@noisysocks noisysocks left a comment

Choose a reason for hiding this comment

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

I like the approach! Works well in testing too.

@noisysocks noisysocks merged commit a68265d into master Sep 25, 2020
@noisysocks noisysocks deleted the try/navigation-use-filter-add-controls branch September 25, 2020 03:26
@github-actions github-actions bot added this to the Gutenberg 9.1 milestone Sep 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Navigation Block: Add alignment options for menu
5 participants