Skip to content

Conversation

@dcalhoun
Copy link
Member

@dcalhoun dcalhoun commented Oct 29, 2024

Related

Description

Enable attaching media selected from the Media Library.

To test: See wordpress-mobile/GutenbergKit#35.

Regression Notes

  1. Potential unintended areas of impact
    Existing Media Library support in Gutenberg Mobile, Aztec, etc.
  2. What I did to test those areas of impact (or what existing automated tests I relied on)
    Manually tested Media Library support in alternative editors.
  3. What automated tests I added (or what prevented me from doing so)
    Not a priority for this experimental editor.

PR submission checklist:

  • I have completed the Regression Notes.
  • I have considered adding unit tests for my changes.
  • 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:

  • WordPress.com sites and self-hosted Jetpack sites.
  • Portrait and landscape orientations.
  • Light and dark modes.
  • Fonts: Larger, smaller and bold text.
  • High contrast.
  • VoiceOver.
  • 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)
  • iPhone and iPad.
  • Multi-tasking: Split view and Slide over. (iPad)

A single Media Library callback resulted in erroneously mutating
unselected blocks.
Unable to recreate the original erroneously replacement of media
attachments for unselected blocks. This now feels unnecessary.
Enable retaining selection for gallery addition/editing in the block
editor.
Reusing the `initialSelection` reduces complexity.
This no longer disrupts initial selection as the setting the initial
selection now occurs within `setEditing` rather than initialization.
This appears to be unnecessary with the latest implementation.
Without returning the initial selection, canceling cleared out media
attached to Gallery blocks in the web-based editor, as it presumes the
existing media will be returned as "selected."
Workaround existing logic that dismisses the dialog if `allowMuliple` is
true and selection is not empty. The existing logic allows for quickly
selecting a single media item, but inhibits the ability to showcase a
pre-existing selection for single-select contexts. This diverges from
the web experience, but is the easiest path forward to avoid a
significant refactor of the logic that would impact all other existing
use cases--Gutenberg Mobile, Aztec, etc.
Map the Media lookup results to the original array of media IDs so that
the sort order is preserved.
@dangermattic
Copy link
Collaborator

dangermattic commented Oct 29, 2024

2 Warnings
⚠️ Modules/Package.swift was changed without updating its corresponding Package.resolved. Please resolve the Swift packages as appropriate to your project setup (e.g. in Xcode or by running swift package resolve).
⚠️ PR is not assigned to a milestone.

Generated by 🚫 Danger

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Oct 29, 2024

WordPress Alpha📲 You can test the changes from this Pull Request in WordPress Alpha by scanning the QR code below to install the corresponding build.
App NameWordPress Alpha WordPress Alpha
ConfigurationRelease-Alpha
Build Numberpr23721-48be44a
Version25.4
Bundle IDorg.wordpress.alpha
Commit48be44a
App Center BuildWPiOS - One-Offs #11028
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Oct 29, 2024

Jetpack Alpha📲 You can test the changes from this Pull Request in Jetpack Alpha by scanning the QR code below to install the corresponding build.
App NameJetpack Alpha Jetpack Alpha
ConfigurationRelease-Alpha
Build Numberpr23721-48be44a
Version25.4
Bundle IDcom.jetpack.alpha
Commit48be44a
App Center Buildjetpack-installable-builds #10067
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

Comment on lines +178 to +182
if let selectedMedia = initialSelection, allowsMultipleSelection {
setInitialSelection(selectedMedia)
} else {
deselectAll()
}
Copy link
Member Author

@dcalhoun dcalhoun Oct 30, 2024

Choose a reason for hiding this comment

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

In order to support an initial selection for Gallery blocks—which is required by the web Gallery block implementation—we must now conditionally deselect all. Retaining an initial selection also improves the UX.

The restriction of initial selections to allowsMultipleSelection diverges from the web Media Library experience, but is a workaround for the native Media Library's current implementation that dismisses the dialog when a selection exists and multiple is disallowed.

The native approach creates a flow where tapping an image selects and dismisses the dialog for single-select contexts, reducing the number of taps to complete the flow. Rather than attempting a larger change to modify this behavior and align with web, I disabled initial selection when multiple selection is disabled—i.e., any block besides a Gallery.


private func buttonCancelTapped() {
delegate?.siteMediaPickerViewController(self, didFinishWithSelection: [])
delegate?.siteMediaPickerViewController(self, didFinishWithSelection: initialSelection)
Copy link
Member Author

Choose a reason for hiding this comment

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

Given initialSelection should be [] outside of the specific context of the "new" Gutenberg, this change should, in theory, have no negative impact on existing use case—e.g., Gutenberg Mobile, Aztec.

Copy link
Member Author

@dcalhoun dcalhoun Oct 30, 2024

Choose a reason for hiding this comment

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

This approach was copied and adapted from GutenbergViewController.

@dcalhoun dcalhoun marked this pull request as ready for review October 30, 2024 13:36
@dcalhoun dcalhoun requested a review from jkmassel October 30, 2024 13:36
.showSiteMediaPicker(blog: post.blog, delegate: self)
}

private func mapMediaIdsToMedia(_ mediaIds: [Int]) -> [Media] {
Copy link
Contributor

Choose a reason for hiding this comment

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

Any Media objects returned from this method aren't thread-safe – it looks like a lot of what's going on here should happen on the main thread, but can we add assertions to ensure that is the case?

We could also convert these to thread-safe objects, but that might be overkill at this point?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you for noting this. I am quite unfamiliar with the subject of thread safety, so I appreciate that inquiries and suggestions.

I added an assertion in 1867499 based on what I understand of your feedback. Please let me know if I misunderstood or you have alternatives to suggest.

Copy link
Contributor

@jkmassel jkmassel left a comment

Choose a reason for hiding this comment

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

I tested this and it works well. I have a few code-level suggestions, but I don't think this needs additional review if/when they're addressed

@dcalhoun dcalhoun enabled auto-merge November 11, 2024 20:12
@dcalhoun dcalhoun added this pull request to the merge queue Nov 12, 2024
Merged via the queue into trunk with commit 5b3871e Nov 12, 2024
24 checks passed
@dcalhoun dcalhoun deleted the feat/gutenberg-kit-media-library branch November 12, 2024 04:03
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] Enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants