Skip to content

Media picker: Fix image selection after upload when media picker presents multiple pages (closes #21115)#21117

Merged
kjac merged 2 commits intorelease/13.13from
v13/bugfix/fix-upload-with-paged-media-picker
Dec 17, 2025
Merged

Media picker: Fix image selection after upload when media picker presents multiple pages (closes #21115)#21117
kjac merged 2 commits intorelease/13.13from
v13/bugfix/fix-upload-with-paged-media-picker

Conversation

@AndyButland
Copy link
Contributor

Prerequisites

  • I have added steps to test this contribution in the description below

Fixes: #21115

Description

This PR fixes a regression introduced in #20202 that prevented correct automatic selection of an uploaded image when there were more images to display than a single page.

After the upload completes, the code now checks if there are multiple pages and if so, navigates to the last page and selects the newly uploaded image(s) from there.

Testing

To test this fix:

  • Have a media folder with > 100 items (or temporarily lower the page size configured in mediapicker.controller.js, line 87.
  • Upload a media file to the folder.
  • Verify that the last page of media items is displayed and the uploaded item is now automatically selected.

Copilot AI review requested due to automatic review settings December 11, 2025 07:05
@AndyButland AndyButland changed the title Media picker: Fix image selection after upload when media picker presents multiple pages Media picker: Fix image selection after upload when media picker presents multiple pages (closes #21115) Dec 11, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a regression where uploaded images were not automatically selected when the media picker displayed multiple pages. The fix adds logic to navigate to the last page after upload (where new items appear) before attempting to select the newly uploaded items.

Key changes:

  • After upload completion and folder refresh, check if there are multiple pages
  • If multiple pages exist, navigate to the last page where new uploads appear
  • Then proceed with existing selection logic for the uploaded items
Comments suppressed due to low confidence (1)

src/Umbraco.Web.UI.Client/src/views/common/infiniteeditors/mediapicker/mediapicker.controller.js:387

  • The selection logic fails when more files are uploaded than fit on the last page. For example, if uploading 10 files to a folder with 95 items (pageSize=100), the last page would have only 5 items (101-105), but files.length is 10. The calculation $scope.images.length - files.length becomes negative (5 - 10 = -5), causing _.rest() to return all 5 items instead of the correct subset. Additionally, this assumes newly uploaded items always have the highest IDs and appear on the last page, which may not be true if items are ordered differently or if IDs are not sequential. Consider tracking the actual uploaded file IDs returned from the upload operation and selecting items by matching those IDs.
                            var images = _.rest(_.sortBy($scope.images, 'id'), $scope.images.length - files.length);
                            images.forEach(image => selectMedia(image));

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Contributor

@kjac kjac left a comment

Choose a reason for hiding this comment

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

Good stuff. Works like a charm 💯

@kjac kjac merged commit 66d090b into release/13.13 Dec 17, 2025
18 checks passed
@kjac kjac deleted the v13/bugfix/fix-upload-with-paged-media-picker branch December 17, 2025 07:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants