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

refactor: Separate Gutenberg editor implementations #21493

Merged
merged 8 commits into from
Nov 26, 2024

Conversation

dcalhoun
Copy link
Member

@dcalhoun dcalhoun commented Nov 25, 2024

Closes https://github.com/Automattic/dotcom-forge/issues/9831.

Separate the Gutenberg Mobile and GutenbergKit fragments to reduce regression risk when modifying one of the two editors. While the editors do share commonalities, there are also significant differences. We also do not iterate on the editors simultaneously or at the same pace.

Testing Instructions

Test both the Gutenberg Mobile and GutenbergKit editors, attempting to find regressions with foundational features—text editing, media uploads, etc. Toggle the "experimental block editor" feature flags to switch between the two editors.

Regression Notes

  1. Potential unintended areas of impact
    Regressions in either of the block editors.
  2. What I did to test those areas of impact (or what existing automated tests I relied on)
    Manually tested both editors.
  3. What automated tests I added (or what prevented me from doing so)
    None, deemed unnecessary for the experimental editor.

PR Submission Checklist:

  • I have completed the Regression Notes.
  • I have considered adding accessibility improvements for my changes.
  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

Testing Checklist (strike-out the not-applying and unnecessary ones):

  • WordPress.com sites and self-hosted Jetpack sites.
  • Portrait and landscape orientations.
  • Light and dark modes.
  • Fonts: Larger, smaller and bold text.
  • High contrast.
  • Talkback.
  • Languages with large words or with letters/accents not frequently used in English.
  • Right-to-left languages. (Even if translation isn’t complete, formatting should still respect the right-to-left layout)
  • Large and small screen sizes. (Tablet and smaller phones)
  • Multi-tasking: Split screen and Pop-up view. (Android 10 or higher)

@dcalhoun dcalhoun added [Type] Task Gutenberg Editing and display of Gutenberg blocks. labels Nov 25, 2024
@dangermattic
Copy link
Collaborator

dangermattic commented Nov 25, 2024

3 Warnings
⚠️ This PR is larger than 300 lines of changes. Please consider splitting it into smaller PRs for easier and faster reviews.
⚠️ Class GutenbergKitEditorFragment is missing tests, but unit-tests-exemption label was set to ignore this.
⚠️ PR is not assigned to a milestone.

Generated by 🚫 Danger

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Nov 25, 2024

Jetpack📲 You can test the changes from this Pull Request in Jetpack by scanning the QR code below to install the corresponding build.
App NameJetpack Jetpack
FlavorJalapeno
Build TypeDebug
Versionpr21493-e862f40
Commite862f40
Direct Downloadjetpack-prototype-build-pr21493-e862f40.apk
Note: Google Login is not supported on these builds.

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Nov 25, 2024

WordPress📲 You can test the changes from this Pull Request in WordPress by scanning the QR code below to install the corresponding build.
App NameWordPress WordPress
FlavorJalapeno
Build TypeDebug
Versionpr21493-e862f40
Commite862f40
Direct Downloadwordpress-prototype-build-pr21493-e862f40.apk
Note: Google Login is not supported on these builds.

Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

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

Android Lint found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

Enable simple checking for both GBM and GBK.
There are now separate fragments for "new" and "old" Gutenberg, negating
the need for branching logic within the fragments themselves.
The majority--if not all--of this code is unused by GutenbergKit. No-op
methods were retained to satisfy the requirements of the class shared
between Gutenberg Mobile and GutenbergKit.
The use of "new" to uniquely describe something is problematic, as it
provides little context and could become incorrect at some future time.
@dcalhoun dcalhoun force-pushed the refactor/separate-editor-implementations branch from c100ab2 to e862f40 Compare November 26, 2024 14:46
Copy link

sonarcloud bot commented Nov 26, 2024

Please retry analysis of this Pull-Request directly on SonarQube Cloud

Copy link

codecov bot commented Nov 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 39.44%. Comparing base (0ceef78) to head (e862f40).
Report is 17 commits behind head on trunk.

Additional details and impacted files
@@            Coverage Diff             @@
##            trunk   #21493      +/-   ##
==========================================
- Coverage   39.44%   39.44%   -0.01%     
==========================================
  Files        2121     2119       -2     
  Lines       99564    99556       -8     
  Branches    15313    15313              
==========================================
- Hits        39277    39269       -8     
  Misses      56806    56806              
  Partials     3481     3481              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member Author

@dcalhoun dcalhoun left a comment

Choose a reason for hiding this comment

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

I consider the failed SonarQube Cloud result irrelevant as previous failed runs originated from crossing a code duplication threshold. However, the point of these changes is to duplicate code in order to reduce unnecessary risk associated with modifying code shared between two very different implementations.

@@ -180,8 +180,8 @@ android {
buildConfigField "boolean", "ENABLE_SITE_MONITORING", "false"
buildConfigField "boolean", "SYNC_PUBLISHING", "false"
buildConfigField "boolean", "ENABLE_IN_APP_UPDATES", "false"
buildConfigField "boolean", "ENABLE_NEW_GUTENBERG", "false"
buildConfigField "boolean", "ENABLE_NEW_GUTENBERG_THEME_STYLES", "false"
buildConfigField "boolean", "ENABLE_GUTENBERG_KIT", "false"
Copy link
Member Author

Choose a reason for hiding this comment

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

The term "new" is problematic, as it provides little context and can become outdated/incorrect in the future. I replaced it with a more meaningful name.

when {
htmlModeMenuStateOn -> PostEditorAnalyticsSession.Editor.HTML
isGutenberg -> PostEditorAnalyticsSession.Editor.GUTENBERG
isGutenbergKit -> PostEditorAnalyticsSession.Editor.GUTENBERG_KIT
Copy link
Member Author

Choose a reason for hiding this comment

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

Introduced a new GutenbergKit-specific analytic indicator to denote the different Gutenberg editors.

Comment on lines +2404 to +2405
if (isGutenbergKitEditor && showGutenbergEditor) {
createGutenbergKitEditorFragment()
Copy link
Member Author

Choose a reason for hiding this comment

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

This—along with the related fragment files—is the predominant change proposed. The separation is proposed to reduce risk associated with modifying shared logic between the Gutenberg editors, which are diverging and not progressing forward at the same rate.

Copy link
Member Author

Choose a reason for hiding this comment

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

These changes should, in theory, restore this file to its state prior to 93c47b1, where it was heavily modified for the addition of GutenbergKit. This theory can be validated in the form of copying and pasting the implementation from the parent commit.

I.e., checking out this branch and pasting the previous implementation into this file in your editor should result in Git showing little-to-no modifications1 via git diff.

Footnotes

  1. There are a few stylistic changes—spacing, ordering, etc.

Copy link
Contributor

Choose a reason for hiding this comment

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

checking out this branch and pasting the previous implementation into this file in your editor should result in Git showing little-to-no modifications1

Just an FYI that I had to implement onEditorContentChanged and onOpenMediaLibrary for the previous code to work.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks. That is expected given the current version of the shared interface requires those methods.

Copy link
Member Author

Choose a reason for hiding this comment

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

This new GutenbergKit implementation is devoid of all Gutenberg Mobile-specific logic. Hence, the smaller line numbers and several no-ops satisfying the shared interface. Long term, we might consider severing the shared interface.

Copy link
Member Author

Choose a reason for hiding this comment

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

Long term, we might also consider how this implementation could be simplified, creating clear and useful separation between Aztec, Gutenberg Mobile, and GutenbergKit.

@dcalhoun dcalhoun marked this pull request as ready for review November 26, 2024 16:43
@nbradbury nbradbury self-assigned this Nov 26, 2024
@nbradbury
Copy link
Contributor

@dcalhoun This is unrelated to this PR but wanted to mention it. While testing I noticed the tool buttons don't always appear correctly. Here I've enabled both bold and italic, but the italic button is solid black.

buttons

@dcalhoun
Copy link
Member Author

While testing I noticed the tool buttons don't always appear correctly. Here I've enabled both bold and italic, but the italic button is solid black.

Thanks for the note. This relates to the way mobile web browsers apply hover styles and will be addressed within https://github.com/Automattic/dotcom-forge/issues/8678.

Copy link
Contributor

@nbradbury nbradbury left a comment

Choose a reason for hiding this comment

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

Changes look good and I'm glad for the separation :shipit:

@dcalhoun dcalhoun changed the title refactor: Separate editor implementations refactor: Separate Gutenberg editor implementations Nov 26, 2024
@dcalhoun dcalhoun merged commit 817841f into trunk Nov 26, 2024
27 of 29 checks passed
@dcalhoun dcalhoun deleted the refactor/separate-editor-implementations branch November 26, 2024 19:50
Copy link

sentry-io bot commented Nov 29, 2024

Suspect Issues

This pull request was deployed and Sentry observed the following issues:

  • ‼️ CursorWindowAllocationException: Could not allocate CursorWindow '' of size 20971520 due to error -12. org.wordpress.android.fluxc.persistence.EditorT... View Issue

Did you find this useful? React with a 👍 or 👎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Gutenberg Editing and display of Gutenberg blocks. [Type] Task unit-tests-exemption
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants