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

[RNMobile] Prevent "Undo Level" after Setting Featured Image via Image Block #33057

Merged
merged 19 commits into from
Aug 9, 2021

Conversation

SiobhyB
Copy link
Contributor

@SiobhyB SiobhyB commented Jun 28, 2021

This PR is intended as a temporary workaround for #32937

gutenberg-mobile: wordpress-mobile/gutenberg-mobile#3682

Description

As outlined in #32937, the undo/redo functionality doesn't work as expected after setting a featured image via the image block.

After setting a featured image via the block and then tapping undo, it appears as though the action has successfully reverted, as the Featured banner is removed from the block. However, the image still remains as the post's featured image.

With this PR, the issue is worked around by preventing an "undo level" from being created after a featured image is set via the image block. Tapping undo or redo immediately after setting a featured image via the image block should no longer have any effect.

Note, this PR doesn't solve the original issue. In fact, it will introduce a new UX issue, since the undo/redo buttons won’t work as the user would expect i.e. an undo will revert changes they made just before setting a featured image, rather than the featured setting, and may be confusing. However, this inconvenience should be considered preferable to the current experience in production, where changes to the featured image via the image block are not saved, despite the UI indicating the undo is successful.

The Future Considerations section of this PR can be referred to for further hopes/considerations for any future iterations.

How has this been tested?

  • In the app, navigate to HomeBlog Posts to create a new blog post, one which doesn't already have a featured image set.
  • Add a new image block and upload an image to it.
  • Tap the image block's cog/gear icon to access its settings and then tap the Set as Featured button at the bottom.
  • Verify that you see a confirmation message about the newly set featured image and that the block now has a Featured banner overlaying it.
  • Tap the undo button in the app's toolbar.
  • With this PR, tapping undo should have no effect on the post's featured image. Verify that tapping undo or redo doesn't change the featured image by observing whether there are any changes to the Featured banner and verifying that the image remains the same via Post Settings.

Screenshots

The following screenshots show the before and after footer in the image settings, with the updated footer noting that the undo/redo buttons won't work as expected for users:

Before After

Types of changes

This PR introduces a bug fix (a non-breaking change that fixes an issue), with the following main changes to the code:

  • A call to editEntityRecord is currently triggered whenever a request to change the featured image is received from the apps (i.e. when the Set/Remove as Featured button is tapped from the image block). That action creator includes an undoIgnore parameter that makes it possible to ignore an edit in the undo history. For our purposes, that parameter is set to true so that a new undo level isn't created after the featured image is updated via the app.
  • Additional text has also been added to the bottom of the image block's settings. The additional text reads as follows: Changes to featured image will not be affected by the undo/redo buttons

Future Considerations

As a more permanent fix for the original problem, the team discussed adding side effects to the undo/redo buttons, however, this deviates a lot from existing patterns in Gutenberg and is something we decided against pursuing.

The ideal fix would involve completely refactoring the existing data flow so that Gutenberg’s store is the primary location that the apps read from. A refactor would involve the following non-trivial changes:

  • Refactoring the Post Settings flow will require changes in the Android and iOS codebases, with careful testing to account for all the unknowns. There’s also the possibility of this raising a wider architectural debate around the Post Settings panel in the apps, potentially including redesigning the whole user flow.
  • The logic around a confirmation dialog currently exists on the native side of each app (here for Android and here for iOS). This will need to be refactored so that it lives on the JS side. Again, this would be a desirable endpoint that would actually aid in implementing this enhancement. It has also been suggested that the confirmation dialog could be removed completely, which would be an interesting idea to explore with the design team.

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).

"editEntityRecord" includes an "undoIgnore: true" parameter that makes it possible to ignore an edit in the undo history. Reference: https://developer.wordpress.org/block-editor/reference-guides/data/data-core/#editEntityRecord

With this commit, that parameter is set to true so that a new undo level *isn't* created after the featured image is updated via the app.
@SiobhyB SiobhyB added Mobile App - i.e. Android or iOS Native mobile impl of the block editor. (Note: used in scripts, ping mobile folks to change) [Package] Block library /packages/block-library [Block] Image Affects the Image Block [Feature] History History, undo, redo, revisions, autosave. labels Jun 28, 2021
@github-actions
Copy link

github-actions bot commented Jun 28, 2021

Size Change: 0 B

Total Size: 1.07 MB

ℹ️ View Unchanged
Filename Size
build/a11y/index.min.js 1.12 kB
build/admin-manifest/index.min.js 1.46 kB
build/annotations/index.min.js 2.93 kB
build/api-fetch/index.min.js 2.44 kB
build/autop/index.min.js 2.28 kB
build/blob/index.min.js 673 B
build/block-directory/index.min.js 6.62 kB
build/block-directory/style-rtl.css 1.01 kB
build/block-directory/style.css 1.01 kB
build/block-editor/index.min.js 127 kB
build/block-editor/style-rtl.css 13.9 kB
build/block-editor/style.css 13.9 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 189 B
build/block-library/blocks/columns/editor.css 188 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 711 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.67 kB
build/block-library/blocks/navigation/editor.css 1.68 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.84 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 412 B
build/block-library/blocks/post-featured-image/editor.css 412 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 209 B
build/block-library/blocks/search/editor.css 209 B
build/block-library/blocks/search/style-rtl.css 368 B
build/block-library/blocks/search/style.css 372 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.2 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.3 kB
build/block-serialization-spec-parser/index.min.js 3.06 kB
build/blocks/index.min.js 47.2 kB
build/components/index.min.js 216 kB
build/components/style-rtl.css 15.8 kB
build/components/style.css 15.8 kB
build/compose/index.min.js 10.3 kB
build/core-data/index.min.js 12.6 kB
build/customize-widgets/index.min.js 10.8 kB
build/customize-widgets/style-rtl.css 1.5 kB
build/customize-widgets/style.css 1.49 kB
build/data-controls/index.min.js 831 B
build/data/index.min.js 7.22 kB
build/date/index.min.js 31.8 kB
build/deprecated/index.min.js 737 B
build/dom-ready/index.min.js 576 B
build/dom/index.min.js 4.78 kB
build/edit-navigation/index.min.js 13.9 kB
build/edit-navigation/style-rtl.css 3.1 kB
build/edit-navigation/style.css 3.1 kB
build/edit-post/classic-rtl.css 492 B
build/edit-post/classic.css 494 B
build/edit-post/index.min.js 29.9 kB
build/edit-post/style-rtl.css 7.18 kB
build/edit-post/style.css 7.17 kB
build/edit-site/index.min.js 26 kB
build/edit-site/style-rtl.css 5.01 kB
build/edit-site/style.css 5.01 kB
build/edit-widgets/index.min.js 16.6 kB
build/edit-widgets/style-rtl.css 4.01 kB
build/edit-widgets/style.css 4.02 kB
build/editor/index.min.js 38.3 kB
build/editor/style-rtl.css 3.92 kB
build/editor/style.css 3.91 kB
build/element/index.min.js 3.44 kB
build/escape-html/index.min.js 739 B
build/format-library/index.min.js 5.72 kB
build/format-library/style-rtl.css 668 B
build/format-library/style.css 669 B
build/hooks/index.min.js 1.76 kB
build/html-entities/index.min.js 628 B
build/i18n/index.min.js 3.73 kB
build/is-shallow-equal/index.min.js 710 B
build/keyboard-shortcuts/index.min.js 1.74 kB
build/keycodes/index.min.js 1.49 kB
build/list-reusable-blocks/index.min.js 2.07 kB
build/list-reusable-blocks/style-rtl.css 838 B
build/list-reusable-blocks/style.css 838 B
build/media-utils/index.min.js 3.08 kB
build/notices/index.min.js 1.07 kB
build/nux/index.min.js 2.31 kB
build/nux/style-rtl.css 747 B
build/nux/style.css 743 B
build/plugins/index.min.js 1.99 kB
build/primitives/index.min.js 1.06 kB
build/priority-queue/index.min.js 791 B
build/react-i18n/index.min.js 922 B
build/redux-routine/index.min.js 2.82 kB
build/reusable-blocks/index.min.js 2.56 kB
build/reusable-blocks/style-rtl.css 256 B
build/reusable-blocks/style.css 256 B
build/rich-text/index.min.js 10.8 kB
build/server-side-render/index.min.js 1.64 kB
build/shortcode/index.min.js 1.68 kB
build/token-list/index.min.js 847 B
build/url/index.min.js 1.95 kB
build/viewport/index.min.js 1.28 kB
build/warning/index.min.js 1.16 kB
build/widgets/index.min.js 6.48 kB
build/widgets/style-rtl.css 1.04 kB
build/widgets/style.css 1.04 kB
build/wordcount/index.min.js 1.24 kB

compressed-size-action

@SiobhyB SiobhyB added the [Type] Bug An existing feature does not function as intended label Jun 29, 2021
@SiobhyB SiobhyB changed the title [RNMobile] Fix Broken Undo/Redo Behaviour after Setting Featured Image via Image Block [RNMobile] Prevent "Undo Level" after Setting Featured Image via Image Block Jun 29, 2021
@SiobhyB
Copy link
Contributor Author

SiobhyB commented Jun 29, 2021

Noting here that this PR isn't a direct fix for the core issue, which is that the post's featured image doesn't update in accordance with the undo/redo actions. Instead, it's more of a workaround where a new "undo level" simply isn't created when an image is set as featured via the image block in the mobile app.

While exploring possible solutions to this issue, I experimented with the following thoughts:

  • Set up a listener in the image block's edit.native.js file, then send back an updated ID each time a change to the post's featured image is detected. This seemed similar to an earlier approach I'd taken to the overall featured functionality in the image block, but this was eventually ruled out for a few reasons, one being that it would create a lot of requests for image-heavy posts.
  • Explore ways this is solved in other areas of the app. Nothing stood out to me as being directly relevant to this issue while searching through mobile issues that mentioned "undo" in the Gutenberg and the Gutenberg Mobile repos. As the native apps are being used as the "source of truth" when it comes to updating a featured image's ID, approaches like the one followed for adding undo/redo support for post titles won't work for our needs. I couldn't find a solution that didn't seem like it would muddy the way data is flowing.

Although the "ideal" solution would be for the post's featured image to actually change with the undo/redo functionality, I think the workaround in this PR may be the best compromise given the above considerations and the issue's relatively low priority.

@hypest, I wondered if I could get your thoughts on this whenever you have the chance? This isn't a high priority and I wanted to ask you as you're the most familiar with how data is currently flowing for this issue. I'd be really grateful to hear your thoughts and whether I'm possibly missing another approach.

I'll keep this issue as a draft until I'm a bit more certain on the approach to take.

@hypest
Copy link
Contributor

hypest commented Jun 30, 2021

@hypest, I wondered if I could get your thoughts on this whenever you have the chance? This isn't a high priority and I wanted to ask you as you're the most familiar with how data is currently flowing for this issue. I'd be really grateful to hear your thoughts and whether I'm possibly missing another approach.

Aha, interesting problem to have in our hands Siobhan, thanks for pinging. The way I see and understand it, I would explore how perhaps to attach a "side effect" action to undo/redo since, in the current way we have the data flow set up, we expect the native side to update the internal state of the feature_media attribute in GB. Which means that currently, we need to call the native side to modify the featured image id. I'm referring to a "side effect" here in the sense that the undo/redo won't change any data inside Gutenberg, but we want to trigger a new "call to native side to change the id", which will then have the added effect of updating the id kept in the editorStore. Does that make sense?

Alternatively, but perhaps a bigger refactor could be to change the data flow in such a way that the editor would only depend and change the internal state kept in the editorStore but we'll put listeners in place to detect the changes and propagate the side effects to/from the native side. This could potentially unify the editor side support, but sounds like a bigger ask at this point. At this stage, I'd explore the first idea first, to attach side-effect callbacks to undo/redo for calling the native side.

@SiobhyB
Copy link
Contributor Author

SiobhyB commented Jun 30, 2021

Thanks @hypest, that makes sense and sounds inline with what I'd been experimenting with, without success so far. I'll continue experimenting, as it sounds like there should be a way to achieve this and it'd be preferable to preventing the undo level.

@hypest
Copy link
Contributor

hypest commented Jun 30, 2021

and it'd be preferable to preventing the undo level.

Indeed, I feel that suppressing/preventing undo/redo would mainly be perceived as a bug by the user anyway so, maybe not much of a value exchanging one buggy behavior with another. That said, this has the signs of a fix that could spiral out to a whole project, so we might need to reassess our plan after the additional exploration.

@SiobhyB
Copy link
Contributor Author

SiobhyB commented Jul 27, 2021

I've added details to the Future Considerations this PR's description to give further context around why we've decided to go this route, following the existing comments here and internal discussion.

@fluiddot, I've requested your review, and welcome anyone else's opinion here. 🙇‍♀️

I'd especially love to hear feedback on text I've added to the confirmation notice: (Note, this action can only be undone within the block\'s settings or the Post Settings panel.)My aim was to be as succinct as possible, given the small amount of space and time it's displayed on screen. Open to any feedback or suggestions for improvement!

@SiobhyB SiobhyB requested a review from fluiddot July 27, 2021 11:26
@fluiddot
Copy link
Contributor

I've added details to the Future Considerations this PR's description to give further context around why we've decided to go this route, following the existing comments here and internal discussion.

@fluiddot, I've requested your review, and welcome anyone else's opinion here. 🙇‍♀️

I'd especially love to hear feedback on text I've added to the confirmation notice: (Note, this action can only be undone within the block\'s settings or the Post Settings panel.)My aim was to be as succinct as possible, given the small amount of space and time it's displayed on screen. Open to any feedback or suggestions for improvement!

I think the message is clear but I'm concerned about the small amount of time to read it, I'm wondering if we could display it within the block settings, similar as we do in other cases like in the Columns block, wdyt?

Columns block settings Image block settings

@SiobhyB
Copy link
Contributor Author

SiobhyB commented Jul 27, 2021

@fluiddot, good idea! I'd only be a little worried about possibly cluttering the settings with details that may not be of importance for the majority. But, I agree it'd be more readable than adding this to the notice.

For the mock of this, I updated the text to the following: Note: The editor's undo/redo buttons won't revert any changes to the featured image. The setting/removal of featured images can only be done within the block's settings or the Post Settings panel. Here's how it looks:

I think it works a bit better than the notice changes. Any thoughts on its design or the updated text?

cc-ing @iamthomasbishop for thoughts and the final say on this, too.

@fluiddot
Copy link
Contributor

@fluiddot, good idea! I'd only be a little worried about possibly cluttering the settings with details that may not be of importance for the majority. But, I agree it'd be more readable than adding this to the notice.

Good point, from my POV I think it makes sense to have it here but I agree that may not be of importance for the majority. However, at the same time, if we don't consider it important enough probably we shouldn't even display it in the notice 😄 .

For the mock of this, I updated the text to the following: Note: The editor's undo/redo buttons won't revert any changes to the featured image. The setting/removal of featured images can only be done within the block's settings or the Post Settings panel. Here's how it looks:

Not sure if it's doable but I'd expect the message to be right after the link and before the separator line, otherwise it feels like it's not related to it, wdyt?

Screenshot 2021-07-27 at 17 26 17

I think it works a bit better than the notice changes. Any thoughts on its design or the updated text?

The text looks great and very clear to me 👍 .

@SiobhyB
Copy link
Contributor Author

SiobhyB commented Jul 29, 2021

Thanks, Carlos! 🙇‍♀️

I'm in favour of having the text in the settings given further thought. Although it might not be relevant to everyone accessing the setting, I do think it holds some valuable details that we shouldn't completely leave users to figure out by themselves.

Not sure if it's doable but I'd expect the message to be right after the link and before the separator line, otherwise it feels like it's not related to it, wdyt?

I kind of like the text after the separator, so that it doesn't completely detract attention away from the button, but see your point of view too and could be swayed in either direction. @iamthomasbishop, do you have any strong opinions here? If not, I'll go with Carlos' preference and update the PR for review.

@iamthomasbishop
Copy link

@SiobhyB Thanks for the ping! A few things I'd like to suggest, with hopes of finding a balance between clarity and simplicity here.

  • First and foremost, I agree that it's a good idea to have some form of messaging on the settings sheet, but imo it's a bit wordy/complex, so perhaps we can make it more concise and simplify the wording. What do you think about something along the lines of: Changes to featured image will not be affected by undo/redo. or Changes to featured image are not accessible through undo/redo.? The idea here is to shorten it to the essential—I'm not sure how helpful the part in the current message about where to access the setting is as necessary as the undo/redo constraint.
  • Similarly, the copy that shows on the Notice upon set/remove is a bit longer than I'd like to use in a Notice; typically I try to keep it to a few words, similar to a Snackbar component. Personally, I think we can probably revert back to the "current" copy, as long as we have the message on the settings bottom sheet. If you feel strongly about keeping a message there, let's try to find a way to shorten it considerably.
  • I believe we typically put labels like this below the cell's border, so the placing it below the button border makes sense in this context. One thing I'd like to do here is align the text label to the left — in some cases centered buttons work well, but in this case it has started to throw the alignment/rhythm off. Can we try that?
  • Is there any way we can keep the bottomSheet open when the user taps on the set/remove action? I was on the fence about this during the last iteration, but after seeing it for a bit I think it'd make sense to keep the user in place (on the settings bottomSheet).

Here is a quick sketch of what I'm imagining for these changes:

Separately, I want to propose a couple of other things now that we've seen this in use for a bit. These can probably be split into other tickets and aren't urgent.

  • I'd like to add a section heading for Featured Image, to break up the "link settings" section before it to add some separation, if possible.
  • I'm not sure if this one has been discussed already, but it would be useful to be able to clear a featured image from the "edit" menu at the top-right of an Image block. The flow would look something like this (piggy-backing on my proposed copy changes from earlier):

Let me know if you have any thoughts or disagree w/ any of the above. Happy to iterate on it, and it'd probably be good to get a copy review from editorial when we get to a good place 😄 .

By adding the settings for changing a featured image under their own section heading, it's being clearly separated from the other sections.

This will help with the overall alignment/rhythm of the settings panel, which is important given we're adding an additional note.
@SiobhyB
Copy link
Contributor Author

SiobhyB commented Jul 30, 2021

Thank you so much for the help, @iamthomasbishop!

First and foremost, I agree that it's a good idea to have some form of messaging on the settings sheet, but imo it's a bit wordy/complex, so perhaps we can make it more concise and simplify the wording. What do you think about something along the lines of: Changes to featured image will not be affected by undo/redo. or Changes to featured image are not accessible through undo/redo.? The idea here is to shorten it to the essential—I'm not sure how helpful the part in the current message about where to access the setting is as necessary as the undo/redo constraint.

I'm all for the idea of making the wording more concise, I agree the previous copy is verbose and likely overly cautious on my side. I worry that users won't recognise what we mean by "undo/redo" and wanted to be careful not to give an impression that they're not able to revert changes to their featured image at all.

How about tweaking your wording a little to make it abundantly clear what we mean by "undo/redo"? Changes to featured image will not be affected by the undo/redo buttons perhaps?

it'd probably be good to get a copy review from editorial when we get to a good place

That's a good idea! I've added the Needs Copy Review label for @automattic/editorial and also added a Copy Review Request section to the PR's description to sum things up. For their notes, here are the ideas we've thrown around so far:

  • Note, this action can only be undone within the block\s settings or the Post Settings panel.
  • Note: The editor's undo/redo buttons won't revert any changes to the featured image. The setting/removal of featured images can only be done within the block's settings or the Post Settings panel.
  • Changes to featured image will not be affected by undo/redo.
  • Changes to featured image are not accessible through undo/redo.
  • Changes to featured image will not be affected by the undo/redo button.

I'll address your other feedback in separate comments too.

@SiobhyB SiobhyB added the Needs Copy Review Needs review of user-facing copy (language, phrasing) label Jul 30, 2021
@SiobhyB
Copy link
Contributor Author

SiobhyB commented Aug 2, 2021

Thank you so much @clucasrowlands. ❤️ I've gone ahead to update the text to be Changes to featured image will not be affected by the undo/redo buttons.

We may want to remove the border between the button cell and footer cell because this is a single-cell section, if that's not a bother.

Looking at the standard footer message component, I believe all we'd have to do here is remove the padding-top to "collapse", but essentially what I'm going for is for the spacing to be equidistant between the button and its neighbors:

@iamthomasbishop, I went ahead to remove the bottom border from the button in 89f15ac and also removed the bottom padding in 6ac5e79, with the following results:

Before After

Removing the bottom padding actually served to increase the spacing between the top of the button and the section's "Featured Image" header. I believe that's related to flexbox. I was going to dig deeper but then realised the spacing between the section's header and the button now matches the amount of spacing between other section headers and their content e.g. the "Link Settings" header and the "Link To" tab. I wanted to check with you to see if this is a desired end point or if you'd prefer to see some more tweaks around the spacing here? Thanks in advance!

@iamthomasbishop
Copy link

and also removed the bottom padding

@SiobhyB Just wanted to clarify, I'd like to keep the button sizing as-is so that we provide an adequate tap-target size. So the heading and footer cells would get collapsed, like this:

Looking closer at your "after" screenshot above, it looks like the spacing between header/button/footer is equal, but in practice it looks like a bit too much space. Would it be possible to remove the spacing here?

I'm assuming that will require a change to the cell components themselves, so if we're not able to do this easily, I'm okay with either of the options in your before/after above — with a slight preference toward the latter.

@SiobhyB
Copy link
Contributor Author

SiobhyB commented Aug 3, 2021

@iamthomasbishop, I've been having a bit of a difficult time trying to style the components in the way set out in the sketch today.

The padding beneath the Featured image header is being set here and I haven't been able to find a way to target it directly from the image block's styles.native.scss file for the image block. Amongst other things, I've tried adding a custom class to that section, but no luck.

I also believe the current spacing is a result of flexbox and have been trying to change things, but again no luck in getting close to the sketch.

@fluiddot, do you perhaps see any approaches or options I'm missing here?

@iamthomasbishop
Copy link

@SiobhyB That all makes sense. If it makes it easier, let's just roll with your "before" example above—meaning the one that has the separator between the button and footer cell, like this:

I was on the fence, but I think having a separator between is probably "technically" correct from a design perspective so we can roll with that.

Siobhan and others added 4 commits August 6, 2021 10:50
With this commit, the content in the "Set as Featured" button and the footer message is aligned to the top of their containers.

This will prevent flexbox from automatically adding spacing to the top of their containers, which goes against the design we want.
As we need to tweak the spacing around the panel's title, I've added a new "titleStyle" prop to the PanelBody component.

That prop is then used to remove the bottom spacing for the "Featured Image" panel's title.

The prop can now be re-used by anyone else who needs to tweak the title in a PanelBody in the future.
Following the previous changes, this commit increases the height and "tappable area" of the "Set/Remove as Featured Image" button by adding both top and bottom padding.
@SiobhyB
Copy link
Contributor Author

SiobhyB commented Aug 6, 2021

@iamthomasbishop, thanks for your continued help/feedback here! I've been able to get this closer to the design you set out here following a session with @fluiddot:

Let me know if you'd prefer a change in the padding or if you want the border at the top of the footer note, as that should be fairly straightforward to change now.

@fluiddot, I think the PR is ready for your review now, with the note that there may be some small changes to the CSS following any further design feedback. :)

There's also an installable build for Android available here and I'll work to create one for iOS now that the iOS side of the functionality has been merged. Edited: Installable builds not currently available due to bridge conflicts in develop. I'll aim to update when they're resolved.

@iamthomasbishop
Copy link

That looks great @SiobhyB , thank you!

Siobhan added 2 commits August 6, 2021 16:29
Due to an error when merging, the code was referencing an old function name, "getSetFeaturedButton". It should instead reference the name name, "getFeaturedButtonPanel".
For consistency with other selectors, this commit updates the name of "setFeaturedCellContainer" to "setFeaturedButtonCellContainer".
Comment on lines 571 to 580
<PanelBody>
<FooterMessageControl
label={ __(
'Changes to featured image will not be affected by the undo/redo buttons.'
) }
cellContainerStyle={
styles.setFeaturedButtonCellContainer
}
/>
</PanelBody>
Copy link
Contributor

Choose a reason for hiding this comment

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

I was wondering if we really need to have the footer message under a new panel body, if the purpose is to prevent rendering a separator, you could disable it by passing the prop separatorType="none" to the BottomSheet.Cell components defined in the getFeaturedButtonPanel function. This way you could render the FooterMessageControl component in the same panel body as the featured button.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right that there's no meaningful reason for the footer message to exist in its own panel body. I've gone ahead to move it within the featured panel in 5662508, and have removed the separator as per your suggestion. :)

Siobhan added 2 commits August 9, 2021 10:26
The placement of the component is moved within the main "Featured Image" panel, as this is more semantically correct than having the component within its own, separate panel.
@fluiddot fluiddot self-requested a review August 9, 2021 11:58
Copy link
Contributor

@fluiddot fluiddot left a comment

Choose a reason for hiding this comment

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

LGTM 🎊 ! Amazing work @SiobhyB 💯 !

I tested this PR on Samsung Galaxy S20 FE 5G (Android 10) and Simulator iPhone 11 Pro Max (iOS 14.4).

NOTE: When opening the Image block settings, I noticed that the following error was logged in the console:

ExceptionsManager.js:180 Warning: Cannot update a component (`Unknown`) while rendering a different component (`BottomSheetTextControl`). To locate the bad setState() call inside `BottomSheetTextControl`, follow the stack trace as described in https://reactjs.org/link/setstate-in-render
    in BottomSheetTextControl (at edit.native.js:416)

Looks like it's related to this line because if I set an empty function on that prop the error stops. I think it's out of the scope of this PR but I wanted to let you know as it might have been introduced in this PR, as per this commit.

@SiobhyB
Copy link
Contributor Author

SiobhyB commented Aug 9, 2021

Thank you so much for your help, @fluiddot! I'll address the error you've noted in a separate PR. 🙇‍♀️

I'll go ahead to merge this PR and also wanted to sum up the following pending issues that have been discussed in the comments:

The plan is for me to start diving into different areas of the codebase, so there is no guarantee of when the above items will be prioritized or if I'll be the one to work on them in the future, but they're at least documented and I'd be happy to help in any way I can with any of them. Thanks to all involved on this project so far for the help and patience. :)

@SiobhyB SiobhyB merged commit e9611ea into trunk Aug 9, 2021
@SiobhyB SiobhyB deleted the fix/featured-button-undo-redo-functionality branch August 9, 2021 13:13
@github-actions github-actions bot added this to the Gutenberg 11.3 milestone Aug 9, 2021
SiobhyB pushed a commit that referenced this pull request Aug 10, 2021
This commit aims to fix the render error outlined here: #33057 (review)

The "outside" changes that happen when text is changed in the BottomSheetTextControl component should not be called directly from that component. Instead, they're now called within the useEffect hook.
SiobhyB added a commit that referenced this pull request Sep 3, 2021
)

* Resolve render error

This commit aims to fix the render error outlined here: #33057 (review)

The "outside" changes that happen when text is changed in the BottomSheetTextControl component should not be called directly from that component. Instead, they're now called within the useEffect hook.

* Replace "value" prop with "defaultValue"

The purpose of this commit is to address the text entry issues that currently exist for the TextInput component, as described here: facebook/react-native#30503

A working workaround propose in that thread is to replace the "value" prop with "defaultValue".

* Simplify component by removing unecessary hooks

The introduction of the "defaultValue" prop in f6d9697 means that it's no longer necessary to keep the value in state. "defaultValue" allows for text to be automatically changed as it's typed. See: https://reactnative.dev/docs/textinput#defaultvalue

We don't need to use "onChangeText" for the purpose of updating the input's text and can instead use it to invoke the "onChange" function.

We can also remove the useState and useEffect hooks, as they're not necessary to update the component's value.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Image Affects the Image Block [Feature] History History, undo, redo, revisions, autosave. Mobile App - i.e. Android or iOS Native mobile impl of the block editor. (Note: used in scripts, ping mobile folks to change) [Package] Block library /packages/block-library [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants