Skip to content

Add upload UI and wire the uploader into the grid - #25622

Open
crazytonyli wants to merge 15 commits into
trunkfrom
task/media-v2-upload-ui
Open

crazytonyli wants to merge 15 commits into
trunkfrom
task/media-v2-upload-ui

Conversation

@crazytonyli

Copy link
Copy Markdown
Contributor

Note

This PR will be merged after #25621.

@dangermattic

dangermattic commented Jun 8, 2026 •

Copy link
Copy Markdown
Collaborator
2 Warnings
⚠️ View files have been modified, but no screenshot or video is included in the pull request. Consider adding some for clarity.
⚠️ This PR is larger than 500 lines of changes. Please consider splitting it into smaller PRs for easier and faster reviews.

Generated by 🚫 Danger

@wpmobilebot

wpmobilebot commented Jun 8, 2026 •

Copy link
Copy Markdown
Contributor

🤖 Build Failure Analysis

This build has failures. Claude has analyzed them - check the build annotations for details.

@crazytonyli
crazytonyli force-pushed the task/media-v2-upload-ui branch from 1e1fa49 to 90df03b Compare June 8, 2026 23:18
@wpmobilebot

wpmobilebot commented Jun 8, 2026 •

Copy link
Copy Markdown
Contributor
App Icon📲 You can test the changes from this Pull Request in WordPress by scanning the QR code below to install the corresponding build.
App NameWordPress
ConfigurationRelease-Alpha
Build Number34024
VersionPR #25622
Bundle IDorg.wordpress.alpha
Commit5bc6594
Installation URL5t4622h4lmc70
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@wpmobilebot

wpmobilebot commented Jun 8, 2026 •

Copy link
Copy Markdown
Contributor
App Icon📲 You can test the changes from this Pull Request in Jetpack by scanning the QR code below to install the corresponding build.
App NameJetpack
ConfigurationRelease-Alpha
Build Number34007
VersionPR #25622
Bundle IDcom.jetpack.alpha
Commit2afa80c
Installation URL2m1vlndtdk8f0
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@crazytonyli
crazytonyli force-pushed the task/media-v2-upload-ui branch from 90df03b to 362fcbe Compare June 11, 2026 00:32
@crazytonyli
crazytonyli force-pushed the task/media-v2-upload-ui branch from 362fcbe to 14694c9 Compare June 11, 2026 21:30
@crazytonyli
crazytonyli force-pushed the task/media-v2-upload-ui branch from 14694c9 to 5db0706 Compare June 12, 2026 00:50
@crazytonyli
crazytonyli force-pushed the task/media-v2-upload-ui branch 2 times, most recently from 80dac4b to 3206ce1 Compare June 16, 2026 03:43
@crazytonyli
crazytonyli force-pushed the task/media-v2-upload-ui branch from 3206ce1 to 9e91167 Compare June 16, 2026 08:28
@crazytonyli
crazytonyli force-pushed the task/media-v2-upload-ui branch from 9e91167 to 019a63c Compare June 17, 2026 23:51
@crazytonyli
crazytonyli force-pushed the task/media-v2-upload-ui branch from 019a63c to 8384343 Compare June 19, 2026 00:20
@crazytonyli
crazytonyli force-pushed the task/media-v2-upload-ui branch from 8384343 to 8682318 Compare July 7, 2026 22:09
@crazytonyli
crazytonyli force-pushed the task/media-v2-upload-ui branch 2 times, most recently from cb78b3b to 2afa80c Compare August 26, 2026 07:39
@crazytonyli
crazytonyli force-pushed the task/media-v2-upload-ui branch from 2afa80c to 5bc6594 Compare August 26, 2026 23:49
Base automatically changed from task/media-v2-upload-engine to trunk November 16, 2026 03:00
@crazytonyli
crazytonyli force-pushed the task/media-v2-upload-ui branch from bc45542 to b918305 Compare November 16, 2026 04:28
The folder symbol's built-in accessibility label is "move", which the filter menu exposed for documents. The doc symbol also matches the grid's document tile.
Fit as many tiles of at least 96 pt as the width allows, with a minimum of 4 columns, instead of a fixed 4 or 5. Tiles now stay about the size they are on a portrait iPhone in iPad split views, landscape, and full-width layouts.
Pending and failed entries carry the materialized temp file URL so the
Uploads screen can render a thumbnail. It is nil until materialization
completes and stays nil for non-retryable failures.
The registry caches one MediaUploader per blog so in-flight uploads
survive navigation, and pushes a freshly built policy into a cached
uploader on every vend so changed media settings apply to new enqueues.
The factory derives the policy from the blog's allowed types and the
user's media settings.
Add an add-menu with photo library, camera, file, and app-supplied
external pickers; a banner above the grid summarizing pending and failed
uploads; and an Uploads sheet with per-row cancel, retry, and remove plus
bulk actions. The view model observes the uploader's state publisher and
maps snapshots into row items. The routing vends the site's uploader from
the registry into the hosting controller.
The uploader drops entries as soon as they finish, so the open Uploads screen switched to "No Uploads" right after a success. It now shows "All uploaded" unless the user cancelled or removed the last rows.
The file name next to the icon already identifies the row. VoiceOver read the icon as a separate element with its symbol's built-in label.
Use a new key: the bundled English strings file maps the old key to the old text, which overrides the value in code until the next release regenerates it, and translators need to see the new text.
@crazytonyli
crazytonyli removed this pull request from stack #25910 November 16, 2026 17:40
@crazytonyli
crazytonyli force-pushed the task/media-v2-upload-ui branch from b918305 to f52092c Compare November 16, 2026 17:40
@crazytonyli
crazytonyli changed the base branch from trunk to task/media-v2-trunk-fixes November 16, 2026 17:41
@crazytonyli
crazytonyli added this pull request to stack #26407 November 16, 2026 17:41
@crazytonyli
crazytonyli requested a review from jkmassel November 16, 2026 17:52
@crazytonyli crazytonyli added this to the 27.5 milestone Nov 16, 2026
@crazytonyli
crazytonyli marked this pull request as ready for review November 16, 2026 17:52
@wpmobilebot wpmobilebot modified the milestones: 27.5, 27.6 Nov 20, 2026
@wpmobilebot

Copy link
Copy Markdown
Contributor

Version 27.5 has now entered code-freeze, so the milestone of this PR has been updated to 27.6.

Base automatically changed from task/media-v2-trunk-fixes to trunk November 27, 2026 00:37

@wpmobilebot wpmobilebot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approve. The upload flow works end to end. I found no Blockers, but please address the registry lifecycle suggestion before mediaLibraryV2 ships.

Tested on an iPhone 17 Pro simulator (iOS 26.5), Debug build of feb2737, signed in to the WordPress.com test site:

  • Add menu → Photo Library with 2 and then 6 photos. The banner showed "Uploading N items", the Uploads sheet showed live progress with thumbnails, and it switched to "All uploaded" when the queue drained while open. New items appeared at the top of the grid.
  • Choose File (security-scoped .fileImporter URL) with a file the server rejects. Checked the "1 upload failed" banner, the failed row, Retry, Remove (→ "No Uploads"), and the bulk menu, in light and dark mode. No layout, truncation, or color problems.

I also ran MediaUploaderRegistryTests, MediaUploaderTests and UploadsEmptyStateTrackerTests; the PR's tests all pass. Not covered: the camera items (no camera in the simulator), the pre-iOS 26 close button, self-hosted sites, and logging out mid-upload. External picker options aren't wired up in this PR.

// Blog on its main managed object context; only the Sendable policy
// value crosses into the update Task below.
let policy = MediaUploadPolicyFactory.make(from: blog)
if let existing = uploaders[id] {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggestion: A cached uploader keeps the WordPressClient it was first built with. WordPressClientFactory keys clients on blog and transport/credentials, and swaps them when a token or application password rotates or a WP.com site moves to direct access. #25852 also evicts them on logout and site removal. This registry keys on the blog only, and tearDown(blogID:) / tearDownAll() have no callers. After an in-place token refresh (AccountService.createOrUpdateAccountWithUserDetails sets account.authToken on the existing account), the grid uses the new client, but uploads keep sending the old credentials until the app relaunches. Uploaders for removed sites or logged-out accounts are also never cleaned up.

This test, added to MediaUploaderRegistryTests, fails on feb2737 with Expectation failed: uploadClient === current. The 3 existing registry tests pass.

@Test func uploaderFollowsRotatedCredentials() throws {
    let blog = makeBlog(siteId: 1)
    let registry = MediaUploaderRegistry()
    _ = try registry.uploader(for: blog)

    // Same Blog/WPAccount, new token (what the authtoken fixer in
    // AccountService.createOrUpdateAccountWithUserDetails does).
    blog.account?.authToken = "rotated-token"
    contextManager.saveContextAndWait(mainContext)

    let current = WordPressClientFactory.shared.instance(for: try WordPressSite(blog: blog))
    let uploader = try registry.uploader(for: blog)
    let transport = Mirror(reflecting: uploader).descendant("transport")
    let uploadClient = transport.flatMap { Mirror(reflecting: $0).descendant("client") } as? WordPressClient
    #expect(uploadClient === current)
}

Possible fix: rebuild the uploader, or swap its transport, when clientFactory.instance(for:) returns a different client. Then call tearDown/tearDownAll from the places that already call evictInstance/reset. I filed this as a Suggestion rather than a Blocker only because mediaLibraryV2 is debug-only today. It should be fixed before the flag ships.


switch item.mode {
case .uploading:
Button(action: onCancel) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggestion: This cancel button has no accessibility label, so VoiceOver reads the symbol's built-in name. On the simulator, each in-progress row's button is announced as "Close" (identifier: 'xmark.circle.fill', label: 'Close'), the same as the sheet's own Close button two elements earlier. The Retry and Remove buttons already have labels, so please add a localized one here too (e.g. "Cancel upload").

.buttonStyle(.plain)
case .failed(_, let isRetryable):
HStack(spacing: 16) {
if isRetryable {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggestion: Retry (and "Retry all failed") is offered for permanent server rejections. I uploaded a text file named .pdf through Choose File, and WordPress.com rejected it with "Sorry, you are not allowed to upload this file type." The row still shows Retry, and tapping it fails again within a second with the same error:

The root cause is MediaUploader.markFailed, which keeps the retry payload for any upload-stage error. This PR is the first place users can see it. Consider marking 4xx/permission rejections non-retryable so only Remove is offered.

// V2 uploads stage into persistent storage; clear anything a
// prior crash/force-quit orphaned there (no in-flight uploads
// survive process termination).
MediaUploader.sweepOrphanedStagingFiles()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: This sweep is already called on trunk, synchronously, near the top of didFinishLaunchingWithOptions (line 234), and its doc says to call it once. The second call is harmless because the cutoff is captured on the first call, but it looks like a leftover from before that call landed. It can be removed.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants