-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Framework: Hide The Editor Settings from the block author #2119
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2119 +/- ##
==========================================
+ Coverage 20.33% 22.05% +1.72%
==========================================
Files 136 138 +2
Lines 4274 4326 +52
Branches 724 739 +15
==========================================
+ Hits 869 954 +85
+ Misses 2872 2843 -29
+ Partials 533 529 -4
Continue to review full report at Codecov.
|
One big caveat with context is that it does not play well with I'm also wondering just how far we can push the fake divide between Editable / blocks and the editor itself. With these changes, Editable has knowledge of a parent editor, so it makes me question whether the distinction is worth making or could at least be shuffled around, or if we might as well |
Yes, there's no big difference between using the context for the editor settings and using the context for the redux store and storing the editor settings in the store. The only difference is that the store already has the "EventEmitter" interface if we suppose that the settings could change, thus I'm not against using the store and just connecting components (I guess it's the same for the EditableProvider). Also, I don't the think the distinction we have between editor/blocks like we have it now is a good one, I think the distinction introduced in #2065 is much more "logical".
I see these modules as a longer term goal we could achieve step by step. -- |
Ok so thinking more about this. In these components (Toolbars, controls...), we can't add a dependency to a store containing posts.... Unless we split the redux store (like done in #2065), we should keep this PR as is. When splitting out the editor's state from the store, we could reconsider. |
7677334
to
f04ff4c
Compare
I'd like to use the work done here as a start to avoid using the globally registered block types, Any objection in merging? or maybe any recommendation on how to make this better? |
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.
I noted it in #2108: the react-side-context
project is a neat agnostic "give-me-the-thing-in-context" / "i-have-the-thing-to-give" approach. Not sure if you think something like that could be useful, or if it encourages abuse of context.
I'm not so certain about all of the splitting you're proposing. In fact, I'm wondering if we should remove some of the splits more than I am considering making more. That is, blocks are very much related to the idea of an editor. It makes me uncomfortable to see withEditorSettings
("editor" specifically) only because we're pretending for them to be distinct things, when in fact they're pretty closely related.
In any case, this is a problem to be solved separately. The immediate effect of this removing settings concerns from the block implementer is a good one, and this gives us the flexibility to refactor in the future if we need 👍
@@ -53,3 +58,9 @@ export default function BlockAlignmentToolbar( { value, onChange, controls = DEF | |||
/> | |||
); | |||
} | |||
|
|||
export default withEditorSettings( | |||
( settings ) => ( { |
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.
Do we really need a mapping? Should we just pass all settings?
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.
I'm planning to introduce the blockTypes, fallbackBlockName.... to these settings and I expect several components to extract a single or multiple blockTypes from the settings. Mapping helps use factorize this using functions similar to selectors to avoid duplication.
Also, It's nice that the component prop is wideAlignmentsEnabled
instead of leaving the responsibility of extracting the prop to the component itself.
/** | ||
* Internal dependencies | ||
*/ | ||
import withEditorSettings from '../settings/with-editor-settings'; |
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.
Do we need the nesting in settings
. What else will live there? Maybe just blocks/with-editor-settings/index.js
?
@@ -107,7 +108,9 @@ export function createEditorInstance( id, post, editorSettings = DEFAULT_SETTING | |||
onUndo: undo, | |||
}, store.dispatch ) } | |||
> | |||
<Layout settings={ editorSettings } /> | |||
<EditorSettingsProvider settings={ editorSettings }> |
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.
I wonder if we can start thinking of a nicer way to compose all these providers...
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.
yeah, maybe composeProviders
or something :)
Maybe if we extract the editor, we could reduce the number of providers into one (inside the generic editor component) and provide an HoC like withEditorData
instead of withEditorSettings
to retrieve the editor settings/editor local state from any component. (just an idea we could explore later, not sure if it's a good one yet)
Thanks for the review, Andrew, really good notes here.
I missed the note, thanks for sharing here. I discover this library and I like it, I'll probably do some explorations with this lib later.
When it comes to module splitting, I think a "middle" approach is hard to do. I'd say the two options are:
I think splitting into small modules will help us re-using these pieces in the Customization etc... |
* Update ref: Correct slider step accordingly to the platform * Update gb ref Co-authored-by: Pinar Olguc <[email protected]>
* Release v1.26.0 (#2153) * Add tests for Latest-Posts Bock * Have the Automation tests Scroll the Block window to help locate Block buttons on Android * Update gutenberg reference * Update Gutenberg ref * Update Gutenberg ref * New template for release PRs This PR will add a new template for release PRs to make it easier to check all the steps needed and to standardize the release PRs. This template can then be used by using this link: `https://github.com/wordpress-mobile/gutenberg-mobile/pull/new?template=release_pull_request.md` * Update template file. * Fix: remove extra padding for post title and first `Paragraph` block (#2095) * Fix: remove extra padding for post title and first `Paragraph` block * Update Gutenberg ref * Add a new androidReplacements function to comply with Android Typography lint rules * Make sure the file gutenberg.pot exists before generating android and ios strings. * Update Gutenberg ref * Update gutenberg ref * Update gutenberg ref * Update gutenberg reference * Gutenberg update * Update Gutenberg ref * Update Gutenberg ref * Update Gutenberg ref * Update Gutenberg ref * Fix: prevent ripple effect on slider cell in BottomSheet and disable it completely on iOS (#2023) * prevent ripple effect on slider cell in BottomSheet and disable it completely on iOS * Update Gutenberg ref * Update Gutenberg ref * Accept multiple headers through OnAuthHeaderRequestedListener (#2080) * Blog layout template (#2114) * Update Gutenberg ref * Update Gutenberg ref * Update gutenberg reference * Fix failing UI tests Try scrolling in the Inserter for all platforms * Disable the failing test on iOS Co-authored-by: Matthew Kevins <[email protected]> Co-authored-by: Pinar Olguc <[email protected]> * Update gutenberg reference * Feat: Column block (#1661) * update ref to master (Columns Block) * Update gutenberg reference * Fix Latests Posts Tests by expanding the scroll to button functionality * Fix lint issue * Fix typography breakage in master To a version where the typography panel is not added to block settings. * Update GB reference. * Correct slider step value (#2119) * Update ref: Correct slider step accordingly to the platform * Update gb ref Co-authored-by: Pinar Olguc <[email protected]> * v1.26.0 * Add some missing release notes * Update Podfile.lock * Update gb ref * Update bundles Co-authored-by: Chip Snyder <[email protected]> Co-authored-by: Matthew Kevins <[email protected]> Co-authored-by: Gerardo Pacheco <[email protected]> Co-authored-by: Sérgio Estêvão <[email protected]> Co-authored-by: jbinda <[email protected]> Co-authored-by: Chip <[email protected]> Co-authored-by: Maxime Biais <[email protected]> Co-authored-by: Tugdual de Kerviler <[email protected]> Co-authored-by: Klymentiy Haykov <[email protected]> Co-authored-by: Matthew Kevins <[email protected]> Co-authored-by: Luke Walczak <[email protected]> * Update gb ref Co-authored-by: Chip Snyder <[email protected]> Co-authored-by: Matthew Kevins <[email protected]> Co-authored-by: Gerardo Pacheco <[email protected]> Co-authored-by: Sérgio Estêvão <[email protected]> Co-authored-by: jbinda <[email protected]> Co-authored-by: Chip <[email protected]> Co-authored-by: Maxime Biais <[email protected]> Co-authored-by: Tugdual de Kerviler <[email protected]> Co-authored-by: Klymentiy Haykov <[email protected]> Co-authored-by: Matthew Kevins <[email protected]> Co-authored-by: Luke Walczak <[email protected]>
* Add tests for Latest-Posts Bock * Have the Automation tests Scroll the Block window to help locate Block buttons on Android * Update gutenberg reference * Update Gutenberg ref * Update Gutenberg ref * New template for release PRs This PR will add a new template for release PRs to make it easier to check all the steps needed and to standardize the release PRs. This template can then be used by using this link: `https://github.com/wordpress-mobile/gutenberg-mobile/pull/new?template=release_pull_request.md` * Update template file. * Fix: remove extra padding for post title and first `Paragraph` block (#2095) * Fix: remove extra padding for post title and first `Paragraph` block * Update Gutenberg ref * Add a new androidReplacements function to comply with Android Typography lint rules * Make sure the file gutenberg.pot exists before generating android and ios strings. * Update Gutenberg ref * Update gutenberg ref * Update gutenberg ref * Update gutenberg reference * Gutenberg update * Update Gutenberg ref * Update Gutenberg ref * Update Gutenberg ref * Update Gutenberg ref * Fix: prevent ripple effect on slider cell in BottomSheet and disable it completely on iOS (#2023) * prevent ripple effect on slider cell in BottomSheet and disable it completely on iOS * Update Gutenberg ref * Update Gutenberg ref * Accept multiple headers through OnAuthHeaderRequestedListener (#2080) * Blog layout template (#2114) * Update Gutenberg ref * Update Gutenberg ref * Update gutenberg reference * Fix failing UI tests Try scrolling in the Inserter for all platforms * Disable the failing test on iOS Co-authored-by: Matthew Kevins <[email protected]> Co-authored-by: Pinar Olguc <[email protected]> * Update gutenberg reference * Feat: Column block (#1661) * update ref to master (Columns Block) * Update gutenberg reference * Fix Latests Posts Tests by expanding the scroll to button functionality * Fix lint issue * Fix typography breakage in master To a version where the typography panel is not added to block settings. * Update GB reference. * Correct slider step value (#2119) * Update ref: Correct slider step accordingly to the platform * Update gb ref Co-authored-by: Pinar Olguc <[email protected]> * v1.26.0 * Add some missing release notes * Update Podfile.lock * Update gb ref * Update bundles Co-authored-by: Chip Snyder <[email protected]> Co-authored-by: Matthew Kevins <[email protected]> Co-authored-by: Gerardo Pacheco <[email protected]> Co-authored-by: Sérgio Estêvão <[email protected]> Co-authored-by: jbinda <[email protected]> Co-authored-by: Chip <[email protected]> Co-authored-by: Maxime Biais <[email protected]> Co-authored-by: Tugdual de Kerviler <[email protected]> Co-authored-by: Klymentiy Haykov <[email protected]> Co-authored-by: Matthew Kevins <[email protected]> Co-authored-by: Luke Walczak <[email protected]>
as a follow up to #2116 this hides the editor settings from the block author and in the same time it provider a nicer way to retrieve these settings from any component using the
withEditorSettings
HoC. This uses the same technique we use for theEditableProvider
orReduxProvider
by storing the editor settings in the React Context.An alternative would have been to rely on the Redux Store to store the editor settings, an alternative I tried in #2065. I have a feeling that these settings should be separate from the store because they don't change over time but not sure either.
These settings could store more than this, think:
This could be the starting point of avoiding to rely on the global registered blockTypes inside the editor.