Skip to content

Conversation

@talldan
Copy link
Contributor

@talldan talldan commented Jul 30, 2021

Description

Partly addresses #31965

A WIP PR for generalising the concept of editor preferences so that implementing them across editors is easier.

So far all the boolean preferences in the standalone widgets editor have been migrated.

I've moved this to the interface package, but it could also be a separate package. It does seem to fit into the interface package's remit.

Tasks:

  • Create an API setting preferences defaults
  • Add store state for preferences
  • Create some components to make building the editor more menu easier.
  • Persist the preferences
  • Look into options for migrating existing preferences in local storage (or making the persistence plugin use the existing keys in local storage)
  • Tests / README / Changelog updates

Follow ups:

  • Expand to more editors
  • Handle non-boolean preferences
  • Refactor the preferences modal into Interface
  • Refactor the block manager into Interface (or maybe it's own package?)

How has this been tested?

General testing

  1. Open the Appearance > Widgets screen
  2. Open the more menu and change some settings

Testing that preferences in local storage are migrated to interface.

  1. Clear local storage (or just any keys that begin with WP_DATA_USER)
  2. Checkout trunk and rebuild
  3. Open the Appearance > Widgets screen
  4. Open the editor more menu and change some preferences and remember what they were
  5. Checkout this branch and rebuild
  6. Open the Appearance > Widgets screen
  7. Preferences should be the same as at step 4

Screenshots

Types of changes

New feature (non-breaking change which adds functionality)

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • I've tested my changes with keyboard and screen readers.
  • 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 (please manually search all *.native.js files for terms that need renaming or removal).

@talldan talldan added [Type] New API New API to be used by plugin developers or package users. [Package] Interface /packages/interface labels Jul 30, 2021
@talldan talldan self-assigned this Jul 30, 2021
@github-actions
Copy link

github-actions bot commented Jul 30, 2021

Size Change: +1.3 kB (0%)

Total Size: 1.03 MB

Filename Size Change
build/data/index.min.js 7.07 kB -109 B (-2%)
build/edit-navigation/index.min.js 13.6 kB +270 B (+2%)
build/edit-navigation/style-rtl.css 3.19 kB +98 B (+3%)
build/edit-navigation/style.css 3.19 kB +94 B (+3%)
build/edit-post/index.min.js 28.6 kB +202 B (+1%)
build/edit-post/style-rtl.css 7.23 kB +50 B (+1%)
build/edit-post/style.css 7.22 kB +50 B (+1%)
build/edit-site/index.min.js 26.2 kB +235 B (+1%)
build/edit-site/style-rtl.css 5.07 kB +63 B (+1%)
build/edit-site/style.css 5.07 kB +63 B (+1%)
build/edit-widgets/index.min.js 16 kB +192 B (+1%)
build/edit-widgets/style-rtl.css 4.06 kB +47 B (+1%)
build/edit-widgets/style.css 4.06 kB +46 B (+1%)
ℹ️ View Unchanged
Filename Size
build/a11y/index.min.js 931 B
build/admin-manifest/index.min.js 1.09 kB
build/annotations/index.min.js 2.7 kB
build/api-fetch/index.min.js 2.19 kB
build/autop/index.min.js 2.08 kB
build/blob/index.min.js 459 B
build/block-directory/index.min.js 6.21 kB
build/block-directory/style-rtl.css 1.01 kB
build/block-directory/style.css 1.01 kB
build/block-editor/index.min.js 118 kB
build/block-editor/style-rtl.css 13.8 kB
build/block-editor/style.css 13.8 kB
build/block-library/blocks/archives/editor-rtl.css 61 B
build/block-library/blocks/archives/editor.css 60 B
build/block-library/blocks/archives/style-rtl.css 65 B
build/block-library/blocks/archives/style.css 65 B
build/block-library/blocks/audio/editor-rtl.css 58 B
build/block-library/blocks/audio/editor.css 58 B
build/block-library/blocks/audio/style-rtl.css 111 B
build/block-library/blocks/audio/style.css 111 B
build/block-library/blocks/audio/theme-rtl.css 125 B
build/block-library/blocks/audio/theme.css 125 B
build/block-library/blocks/block/editor-rtl.css 161 B
build/block-library/blocks/block/editor.css 161 B
build/block-library/blocks/button/editor-rtl.css 474 B
build/block-library/blocks/button/editor.css 474 B
build/block-library/blocks/button/style-rtl.css 605 B
build/block-library/blocks/button/style.css 604 B
build/block-library/blocks/buttons/editor-rtl.css 315 B
build/block-library/blocks/buttons/editor.css 315 B
build/block-library/blocks/buttons/style-rtl.css 370 B
build/block-library/blocks/buttons/style.css 370 B
build/block-library/blocks/calendar/style-rtl.css 207 B
build/block-library/blocks/calendar/style.css 207 B
build/block-library/blocks/categories/editor-rtl.css 84 B
build/block-library/blocks/categories/editor.css 83 B
build/block-library/blocks/categories/style-rtl.css 79 B
build/block-library/blocks/categories/style.css 79 B
build/block-library/blocks/code/style-rtl.css 90 B
build/block-library/blocks/code/style.css 90 B
build/block-library/blocks/code/theme-rtl.css 131 B
build/block-library/blocks/code/theme.css 131 B
build/block-library/blocks/columns/editor-rtl.css 194 B
build/block-library/blocks/columns/editor.css 193 B
build/block-library/blocks/columns/style-rtl.css 474 B
build/block-library/blocks/columns/style.css 475 B
build/block-library/blocks/cover/editor-rtl.css 666 B
build/block-library/blocks/cover/editor.css 670 B
build/block-library/blocks/cover/style-rtl.css 1.23 kB
build/block-library/blocks/cover/style.css 1.23 kB
build/block-library/blocks/embed/editor-rtl.css 488 B
build/block-library/blocks/embed/editor.css 488 B
build/block-library/blocks/embed/style-rtl.css 400 B
build/block-library/blocks/embed/style.css 400 B
build/block-library/blocks/embed/theme-rtl.css 124 B
build/block-library/blocks/embed/theme.css 124 B
build/block-library/blocks/file/editor-rtl.css 300 B
build/block-library/blocks/file/editor.css 300 B
build/block-library/blocks/file/style-rtl.css 255 B
build/block-library/blocks/file/style.css 255 B
build/block-library/blocks/file/view.min.js 322 B
build/block-library/blocks/freeform/editor-rtl.css 2.44 kB
build/block-library/blocks/freeform/editor.css 2.44 kB
build/block-library/blocks/gallery/editor-rtl.css 707 B
build/block-library/blocks/gallery/editor.css 706 B
build/block-library/blocks/gallery/style-rtl.css 1.05 kB
build/block-library/blocks/gallery/style.css 1.05 kB
build/block-library/blocks/gallery/theme-rtl.css 122 B
build/block-library/blocks/gallery/theme.css 122 B
build/block-library/blocks/group/editor-rtl.css 159 B
build/block-library/blocks/group/editor.css 159 B
build/block-library/blocks/group/style-rtl.css 57 B
build/block-library/blocks/group/style.css 57 B
build/block-library/blocks/group/theme-rtl.css 93 B
build/block-library/blocks/group/theme.css 93 B
build/block-library/blocks/heading/editor-rtl.css 152 B
build/block-library/blocks/heading/editor.css 152 B
build/block-library/blocks/heading/style-rtl.css 76 B
build/block-library/blocks/heading/style.css 76 B
build/block-library/blocks/home-link/style-rtl.css 247 B
build/block-library/blocks/home-link/style.css 247 B
build/block-library/blocks/html/editor-rtl.css 283 B
build/block-library/blocks/html/editor.css 284 B
build/block-library/blocks/image/editor-rtl.css 728 B
build/block-library/blocks/image/editor.css 728 B
build/block-library/blocks/image/style-rtl.css 482 B
build/block-library/blocks/image/style.css 487 B
build/block-library/blocks/image/theme-rtl.css 124 B
build/block-library/blocks/image/theme.css 124 B
build/block-library/blocks/latest-comments/style-rtl.css 284 B
build/block-library/blocks/latest-comments/style.css 284 B
build/block-library/blocks/latest-posts/editor-rtl.css 137 B
build/block-library/blocks/latest-posts/editor.css 137 B
build/block-library/blocks/latest-posts/style-rtl.css 528 B
build/block-library/blocks/latest-posts/style.css 527 B
build/block-library/blocks/list/style-rtl.css 63 B
build/block-library/blocks/list/style.css 63 B
build/block-library/blocks/media-text/editor-rtl.css 266 B
build/block-library/blocks/media-text/editor.css 263 B
build/block-library/blocks/media-text/style-rtl.css 488 B
build/block-library/blocks/media-text/style.css 485 B
build/block-library/blocks/more/editor-rtl.css 431 B
build/block-library/blocks/more/editor.css 431 B
build/block-library/blocks/navigation-link/editor-rtl.css 474 B
build/block-library/blocks/navigation-link/editor.css 474 B
build/block-library/blocks/navigation-link/style-rtl.css 94 B
build/block-library/blocks/navigation-link/style.css 94 B
build/block-library/blocks/navigation/editor-rtl.css 1.69 kB
build/block-library/blocks/navigation/editor.css 1.69 kB
build/block-library/blocks/navigation/style-rtl.css 1.65 kB
build/block-library/blocks/navigation/style.css 1.64 kB
build/block-library/blocks/navigation/view.min.js 2.52 kB
build/block-library/blocks/nextpage/editor-rtl.css 395 B
build/block-library/blocks/nextpage/editor.css 395 B
build/block-library/blocks/page-list/editor-rtl.css 310 B
build/block-library/blocks/page-list/editor.css 310 B
build/block-library/blocks/page-list/style-rtl.css 242 B
build/block-library/blocks/page-list/style.css 242 B
build/block-library/blocks/paragraph/editor-rtl.css 157 B
build/block-library/blocks/paragraph/editor.css 157 B
build/block-library/blocks/paragraph/style-rtl.css 248 B
build/block-library/blocks/paragraph/style.css 248 B
build/block-library/blocks/post-author/editor-rtl.css 210 B
build/block-library/blocks/post-author/editor.css 210 B
build/block-library/blocks/post-author/style-rtl.css 182 B
build/block-library/blocks/post-author/style.css 181 B
build/block-library/blocks/post-comments-form/style-rtl.css 140 B
build/block-library/blocks/post-comments-form/style.css 140 B
build/block-library/blocks/post-comments/style-rtl.css 360 B
build/block-library/blocks/post-comments/style.css 359 B
build/block-library/blocks/post-content/editor-rtl.css 138 B
build/block-library/blocks/post-content/editor.css 138 B
build/block-library/blocks/post-excerpt/editor-rtl.css 73 B
build/block-library/blocks/post-excerpt/editor.css 73 B
build/block-library/blocks/post-excerpt/style-rtl.css 69 B
build/block-library/blocks/post-excerpt/style.css 69 B
build/block-library/blocks/post-featured-image/editor-rtl.css 398 B
build/block-library/blocks/post-featured-image/editor.css 398 B
build/block-library/blocks/post-featured-image/style-rtl.css 143 B
build/block-library/blocks/post-featured-image/style.css 143 B
build/block-library/blocks/post-template/editor-rtl.css 99 B
build/block-library/blocks/post-template/editor.css 98 B
build/block-library/blocks/post-template/style-rtl.css 378 B
build/block-library/blocks/post-template/style.css 379 B
build/block-library/blocks/post-terms/style-rtl.css 73 B
build/block-library/blocks/post-terms/style.css 73 B
build/block-library/blocks/post-title/style-rtl.css 60 B
build/block-library/blocks/post-title/style.css 60 B
build/block-library/blocks/preformatted/style-rtl.css 103 B
build/block-library/blocks/preformatted/style.css 103 B
build/block-library/blocks/pullquote/editor-rtl.css 198 B
build/block-library/blocks/pullquote/editor.css 198 B
build/block-library/blocks/pullquote/style-rtl.css 361 B
build/block-library/blocks/pullquote/style.css 360 B
build/block-library/blocks/pullquote/theme-rtl.css 167 B
build/block-library/blocks/pullquote/theme.css 167 B
build/block-library/blocks/query-pagination-numbers/editor-rtl.css 122 B
build/block-library/blocks/query-pagination-numbers/editor.css 121 B
build/block-library/blocks/query-pagination/editor-rtl.css 270 B
build/block-library/blocks/query-pagination/editor.css 262 B
build/block-library/blocks/query-pagination/style-rtl.css 168 B
build/block-library/blocks/query-pagination/style.css 168 B
build/block-library/blocks/query-title/editor-rtl.css 85 B
build/block-library/blocks/query-title/editor.css 85 B
build/block-library/blocks/query/editor-rtl.css 131 B
build/block-library/blocks/query/editor.css 132 B
build/block-library/blocks/quote/style-rtl.css 169 B
build/block-library/blocks/quote/style.css 169 B
build/block-library/blocks/quote/theme-rtl.css 220 B
build/block-library/blocks/quote/theme.css 222 B
build/block-library/blocks/rss/editor-rtl.css 202 B
build/block-library/blocks/rss/editor.css 204 B
build/block-library/blocks/rss/style-rtl.css 289 B
build/block-library/blocks/rss/style.css 288 B
build/block-library/blocks/search/editor-rtl.css 165 B
build/block-library/blocks/search/editor.css 165 B
build/block-library/blocks/search/style-rtl.css 374 B
build/block-library/blocks/search/style.css 375 B
build/block-library/blocks/search/theme-rtl.css 64 B
build/block-library/blocks/search/theme.css 64 B
build/block-library/blocks/separator/editor-rtl.css 99 B
build/block-library/blocks/separator/editor.css 99 B
build/block-library/blocks/separator/style-rtl.css 250 B
build/block-library/blocks/separator/style.css 250 B
build/block-library/blocks/separator/theme-rtl.css 172 B
build/block-library/blocks/separator/theme.css 172 B
build/block-library/blocks/shortcode/editor-rtl.css 474 B
build/block-library/blocks/shortcode/editor.css 474 B
build/block-library/blocks/site-logo/editor-rtl.css 462 B
build/block-library/blocks/site-logo/editor.css 464 B
build/block-library/blocks/site-logo/style-rtl.css 153 B
build/block-library/blocks/site-logo/style.css 153 B
build/block-library/blocks/site-tagline/editor-rtl.css 86 B
build/block-library/blocks/site-tagline/editor.css 86 B
build/block-library/blocks/site-title/editor-rtl.css 84 B
build/block-library/blocks/site-title/editor.css 84 B
build/block-library/blocks/social-link/editor-rtl.css 165 B
build/block-library/blocks/social-link/editor.css 165 B
build/block-library/blocks/social-links/editor-rtl.css 812 B
build/block-library/blocks/social-links/editor.css 811 B
build/block-library/blocks/social-links/style-rtl.css 1.33 kB
build/block-library/blocks/social-links/style.css 1.33 kB
build/block-library/blocks/spacer/editor-rtl.css 307 B
build/block-library/blocks/spacer/editor.css 307 B
build/block-library/blocks/spacer/style-rtl.css 48 B
build/block-library/blocks/spacer/style.css 48 B
build/block-library/blocks/table/editor-rtl.css 471 B
build/block-library/blocks/table/editor.css 472 B
build/block-library/blocks/table/style-rtl.css 481 B
build/block-library/blocks/table/style.css 481 B
build/block-library/blocks/table/theme-rtl.css 188 B
build/block-library/blocks/table/theme.css 188 B
build/block-library/blocks/tag-cloud/style-rtl.css 146 B
build/block-library/blocks/tag-cloud/style.css 146 B
build/block-library/blocks/template-part/editor-rtl.css 636 B
build/block-library/blocks/template-part/editor.css 635 B
build/block-library/blocks/template-part/theme-rtl.css 101 B
build/block-library/blocks/template-part/theme.css 101 B
build/block-library/blocks/term-description/editor-rtl.css 90 B
build/block-library/blocks/term-description/editor.css 90 B
build/block-library/blocks/text-columns/editor-rtl.css 95 B
build/block-library/blocks/text-columns/editor.css 95 B
build/block-library/blocks/text-columns/style-rtl.css 166 B
build/block-library/blocks/text-columns/style.css 166 B
build/block-library/blocks/verse/style-rtl.css 87 B
build/block-library/blocks/verse/style.css 87 B
build/block-library/blocks/video/editor-rtl.css 571 B
build/block-library/blocks/video/editor.css 572 B
build/block-library/blocks/video/style-rtl.css 173 B
build/block-library/blocks/video/style.css 173 B
build/block-library/blocks/video/theme-rtl.css 124 B
build/block-library/blocks/video/theme.css 124 B
build/block-library/common-rtl.css 1.29 kB
build/block-library/common.css 1.29 kB
build/block-library/editor-rtl.css 9.87 kB
build/block-library/editor.css 9.85 kB
build/block-library/index.min.js 147 kB
build/block-library/reset-rtl.css 527 B
build/block-library/reset.css 527 B
build/block-library/style-rtl.css 10.2 kB
build/block-library/style.css 10.3 kB
build/block-library/theme-rtl.css 688 B
build/block-library/theme.css 692 B
build/block-serialization-default-parser/index.min.js 1.09 kB
build/block-serialization-spec-parser/index.min.js 2.79 kB
build/blocks/index.min.js 47 kB
build/components/index.min.js 209 kB
build/components/style-rtl.css 15.7 kB
build/components/style.css 15.8 kB
build/compose/index.min.js 10.2 kB
build/core-data/index.min.js 12.3 kB
build/customize-widgets/index.min.js 10.4 kB
build/customize-widgets/style-rtl.css 1.5 kB
build/customize-widgets/style.css 1.49 kB
build/data-controls/index.min.js 614 B
build/date/index.min.js 31.5 kB
build/deprecated/index.min.js 428 B
build/dom-ready/index.min.js 304 B
build/dom/index.min.js 4.53 kB
build/edit-post/classic-rtl.css 492 B
build/edit-post/classic.css 494 B
build/editor/index.min.js 37.5 kB
build/editor/style-rtl.css 3.92 kB
build/editor/style.css 3.91 kB
build/element/index.min.js 3.16 kB
build/escape-html/index.min.js 517 B
build/format-library/index.min.js 5.36 kB
build/format-library/style-rtl.css 668 B
build/format-library/style.css 669 B
build/hooks/index.min.js 1.55 kB
build/html-entities/index.min.js 424 B
build/i18n/index.min.js 3.59 kB
build/is-shallow-equal/index.min.js 501 B
build/keyboard-shortcuts/index.min.js 1.49 kB
build/keycodes/index.min.js 1.25 kB
build/list-reusable-blocks/index.min.js 1.85 kB
build/list-reusable-blocks/style-rtl.css 838 B
build/list-reusable-blocks/style.css 838 B
build/media-utils/index.min.js 2.88 kB
build/notices/index.min.js 845 B
build/nux/index.min.js 2.03 kB
build/nux/style-rtl.css 747 B
build/nux/style.css 743 B
build/plugins/index.min.js 1.83 kB
build/primitives/index.min.js 921 B
build/priority-queue/index.min.js 582 B
build/react-i18n/index.min.js 671 B
build/redux-routine/index.min.js 2.63 kB
build/reusable-blocks/index.min.js 2.28 kB
build/reusable-blocks/style-rtl.css 256 B
build/reusable-blocks/style.css 256 B
build/rich-text/index.min.js 10.6 kB
build/server-side-render/index.min.js 1.32 kB
build/shortcode/index.min.js 1.48 kB
build/token-list/index.min.js 562 B
build/url/index.min.js 1.72 kB
build/viewport/index.min.js 1.02 kB
build/warning/index.min.js 248 B
build/widgets/index.min.js 6.27 kB
build/widgets/style-rtl.css 1.04 kB
build/widgets/style.css 1.04 kB
build/wordcount/index.min.js 1.04 kB

compressed-size-action

<MenuGroup label={ _x( 'View', 'noun' ) }>
<FeatureToggle
<MoreMenuFeatureToggle
scope="core/edit-widgets"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Having to define core/edit-widgets everywhere gets a bit repetitive. An option could be a ScopeProvider as part of the interface package.

Copy link
Member

Choose a reason for hiding this comment

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

A local component might help, too:

const MoreMenuWidgetsFeatureToggle = ( props ) => <MoreMenuFeatureToggle { ...props } scope="core/edit-widgets />;

I think that it's how this issue is mitigated in the edit post package. It had some backward compatiblity considerations, so we can explore other ideas, too.

Copy link
Member

Choose a reason for hiding this comment

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

I like the idea of using a Provider. We can embed the provider inside <InterfaceSkeleton> seamlessly unless there're needs to use the components outside the tree.

An alternative could be to use hook-like API to re-implement this.

// edit-widgets/src/components/preference.js
const Preference = createPreference( 'core/edit-widgets', defaultPreferences );

export const PreferenceProvider = Preference.Provider; // The provider component
export const getPreference = Preference.get; // Getter function to get the preference data
export const setPreference = Preference.set; // Setter function to set the preference data
export const usePreference = Preference.usePreference; // A hook to react to changes and be used in components

So that all descendent components can use the hook to automatically get the preference data without having to specify scope.

A downside of this API is that it's not an idiomatic @wordpress/data-style selector we're used to, so it might be harder for third-party developers to hook into.

I'm in favor of the current approach, just want to throw out some alternative approaches to see if it can bring up some ideas from others.

Copy link
Contributor Author

@talldan talldan Aug 11, 2021

Choose a reason for hiding this comment

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

I like the idea of using a Provider. We can embed the provider inside seamlessly unless there're needs to use the components outside the tree.

Yeah, this is exactly what I was thinking. It would still be possible for scope to be overridden if a prop is provided to a context using component, but I wouldn't see that being a common use case.

There are other components within the interface package that use scope, so I'd have to double-check how they work, but I can work on a separate proof of concept.

I also think it's worth seeing how this will work for editors that have more settings, edit/widgets isn't really a great example of this being a challenge, it may be that @gziolo's suggestion is easier and makes more sense in the post editor.

One point on that is that context won't help for the selectors or actions, the solutions there would be a custom react hook, or alternatively registry selectors / generator actions. There's existing evidence of that here in the edit-post package:

export function* openGeneralSidebar( name ) {
yield controls.dispatch(
interfaceStore.name,
'enableComplementaryArea',
editPostStore.name,
name
);
}
/**
* Returns an action object signalling that the user closed the sidebar.
*
* @yield {Object} Action object.
*/
export function* closeGeneralSidebar() {
yield controls.dispatch(
interfaceStore.name,
'disableComplementaryArea',
editPostStore.name
);
}

Copy link
Contributor

Choose a reason for hiding this comment

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

If some of the options are shared across editors, we'll be using more than one scope here. Defining the scope manually might the best way to go until we've got this working everywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it'd still be ok with any of the approaches. It could be a separate component that doesn't use the context (GlobalFeatureToggle), or a prop that overrides the scope from context.

@gziolo
Copy link
Member

gziolo commented Jul 30, 2021

Look into options for migrating existing preferences in local storage (or making the persistence plugin use the existing keys in local storage)

We had a migration logic present in the past. It operated on the local storage level and it would copy settings between namespaces. The only challenge was that it had to take into account that the same settings could be consumed with the plugin enabled and disabled. If I recall correctly, that prevented clean-up of copied settings.

@gziolo gziolo added the [Feature] Extensibility The ability to extend blocks or the editing experience label Jul 30, 2021
@talldan
Copy link
Contributor Author

talldan commented Aug 5, 2021

Looks like there's this code for handling migrations:

/**
* Deprecated: Remove this function and the code in WordPress Core that calls
* it once WordPress 5.4 is released.
*/
persistencePlugin.__unstableMigrate = ( pluginOptions ) => {

The comment mentions an intention to remove this, but seems like it would be straightforward to repurpose it for this PR.

@talldan talldan added the [Package] Edit Widgets /packages/edit-widgets label Aug 5, 2021
@talldan
Copy link
Contributor Author

talldan commented Aug 5, 2021

This is almost ready for review. There's a bug at the moment where the first time a value is toggled it's from undefined rather than the default value. That's why the widget e2e test is failing. Will work on solving that next.

@talldan talldan marked this pull request as ready for review August 9, 2021 05:04
@talldan
Copy link
Contributor Author

talldan commented Aug 9, 2021

This is all working now, so marking as ready for review 😄

@talldan talldan force-pushed the refactor/editor-preferences-to-interface-package branch from cba0892 to 904d9b4 Compare August 9, 2021 05:52
@talldan talldan changed the title WIP: Refactor editor preferences to interface package Refactor editor preferences to interface package Aug 10, 2021
@talldan talldan changed the title Refactor editor preferences to interface package Refactor editor 'feature' preferences to interface package Aug 10, 2021
Copy link
Contributor

@tellthemachines tellthemachines left a comment

Choose a reason for hiding this comment

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

Looks good! I left a bunch of questions, mostly about cross-editor feature sharing as this will help #24370 along.

persistence.set( interfaceStoreName, {
preferences: {
features: {
[ sourceStoreName ]: sourceFeatures,
Copy link
Contributor

Choose a reason for hiding this comment

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

Will we at a later stage be consolidating the features that are to be shared across editors (not necessarily all of them) under a "shared" key or something?

Copy link
Contributor Author

@talldan talldan Aug 11, 2021

Choose a reason for hiding this comment

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

This aspect wasn't something I'd considered when working on this task, but it's absolutely possible after this change now that the values are stored in one place.

I think the challenge will be how we reconcile that a user might already have conflicting values for preferences across editors. If I have Top Toolbar active in the post editor, but not active in customize widgets, which one is right?

Other than that, I don't think the implementation of a shared preference would be difficult now, I can think of a few different ways to do it, it all depends on how we'd want it to work. Would it be as simple as one value to rule them all, or might we allow a combination of a global and local preferences?

Some thoughts:

  • It might be that some preferences are singleton, they use a single 'scope' via a shared key
  • It might be that there are still different scopes, but the user is able to change them all to one value in a single action (e.g. a global setting in the WordPress settings menu)
  • It might be that a global setting acts more like a default value, but the user can still override it in an individual editor

Copy link
Contributor

Choose a reason for hiding this comment

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

These are all great points.

Regarding global vs local, I was thinking for some options - mostly the a11y/usability related ones, such as text labels on buttons and keeping the cursor inside the block - it make sense to just set them globally, as it's unlikely someone would want to use them in only one editor. For the others, maybe a global option with local override, or local-only makes more sense.

I initially thought of site settings as the best place to put global options, but might be good to get some design input on that too.

<MenuGroup label={ _x( 'View', 'noun' ) }>
<FeatureToggle
<MoreMenuFeatureToggle
scope="core/edit-widgets"
Copy link
Contributor

Choose a reason for hiding this comment

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

If some of the options are shared across editors, we'll be using more than one scope here. Defining the scope manually might the best way to go until we've got this working everywhere.

@talldan talldan mentioned this pull request Aug 11, 2021
@talldan talldan force-pushed the refactor/editor-preferences-to-interface-package branch from 904d9b4 to cc6edb6 Compare August 16, 2021 09:08
@talldan
Copy link
Contributor Author

talldan commented Aug 16, 2021

Feedback should all be addressed, and this is ready for another round of reviews again.

@talldan talldan force-pushed the refactor/editor-preferences-to-interface-package branch from 6c511c7 to 9f58d3a Compare August 18, 2021 06:00
@talldan
Copy link
Contributor Author

talldan commented Aug 18, 2021

Thanks for the reviews, I believe everything is addressed, so merging now 🚢

@talldan talldan merged commit c65a6ab into trunk Aug 18, 2021
@talldan talldan deleted the refactor/editor-preferences-to-interface-package branch August 18, 2021 06:53
@github-actions github-actions bot added this to the Gutenberg 11.4 milestone Aug 18, 2021
@gziolo
Copy link
Member

gziolo commented Aug 18, 2021

Thank you @talldan for working on this refactoring. This is a great step towards providing a unified UI for different editor screens 💯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Extensibility The ability to extend blocks or the editing experience [Package] Edit Widgets /packages/edit-widgets [Package] Interface /packages/interface [Type] New API New API to be used by plugin developers or package users.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants