Feature/plex collection sort#2856
Conversation
|
@00Scooby Thanks! Nice and tidy PR, appriciated! I'm reviewing this now. |
- Generate proper TypeORM migration for mediaServerSort column
(previous PR shipped the entity change without one — upgrades would
fail on the missing column).
- Extend collection sort comparator for addDate and releaseDate; the
UI offered seven sort options but four (addDate.{asc,desc},
releaseDate.{asc,desc}) fell through to the default branch and
silently preserved input order.
- Replace fake MediaServerCollectionSort union with a real template
literal (\${CollectionMediaSortField}.\${MediaSortOrder}); add
parseCollectionSortKey helper and remove \`as any\` casts.
- Add smart-collection guard before reorder (Plex rejects move on
smart) and membership-changed gate so we only push order to Plex
when newMedia.length > 0.
- Filter items with missing metadata before sorting; replace the
\`mediaData!\` non-null assertion.
- Move MEDIA_SERVER_FEATURES + supportsFeature into contracts and gate
the UI dropdown via supportsFeature(COLLECTION_SORT) so the feature
becomes available automatically if Jellyfin ever gains a boxset
reorder API.
- Add ICollection.mediaServerSort field; tighten zod-to-payload
parsing in AddModal.
- Revert unrelated edits introduced by this PR (rules.service return
values, scheduler defensive guards, cosmetic setContext changes).
- Tests: setCollectionCustomSort and moveCollectionItem URL shapes,
PlexAdapter.reorderCollectionItems orchestration, JellyfinAdapter
feature flag and reorder rejection.
8f74b00 to
a1874b7
Compare
|
Made some changes, please test that this still works. 🙏 |
|
Hey @enoch85, I just pulled your latest changes and did a hard reset on my local environment to clear the Vite cache. I ran a full end-to-end test again, and everything works flawlessly! The From my side, this is completely good to go and ready to be merged! 🚀 Thanks again for the review and the final tweaks! |
|
Congrats on your first PR to Maintainerr @00Scooby 🎉 |
|
This is great! I really like it. It would be awesome if, when day/date based sorting is selected, a secondary alphabetical sort was automatically applied as well. For example, let’s say we have these movies that are going to be deleted in 3 days: S, H, G, X and these movies that are going to be deleted in 5 days: C, Z, A The resulting order would be: G, H, S, X, A, C, Z So the primary sort would be “days to delete”, and then alphabetical when multiple movies share the same “days to delete” value. That’s how the current UI version of Maintainerr-Overlay-Helperr handles it. Sometimes there are 20+ movies scheduled for deletion on the same day, so having them sorted alphabetically within that group makes things much easier to browse. |
|
@MrLinford Are you up for the task? @timelordx Please create a seperate issue for this. |
* feat(storage-metrics): split potential reclaim into movie/show/season/episode panels (#2854) * fix(collections): credit reclaimed bytes when sizeBytes is not yet cached (#2855) * Feature/plex collection sort (#2856) * feat: implement plex adapter collection sorting logic * feat: apply collection sort orchestration in collections service * feat: add collection items sort dropdown to rule form * feat: complete UI and full stack implementation for collection sorting * fix(collections): address review feedback for collection sort - Generate proper TypeORM migration for mediaServerSort column (previous PR shipped the entity change without one — upgrades would fail on the missing column). - Extend collection sort comparator for addDate and releaseDate; the UI offered seven sort options but four (addDate.{asc,desc}, releaseDate.{asc,desc}) fell through to the default branch and silently preserved input order. - Replace fake MediaServerCollectionSort union with a real template literal (\${CollectionMediaSortField}.\${MediaSortOrder}); add parseCollectionSortKey helper and remove \`as any\` casts. - Add smart-collection guard before reorder (Plex rejects move on smart) and membership-changed gate so we only push order to Plex when newMedia.length > 0. - Filter items with missing metadata before sorting; replace the \`mediaData!\` non-null assertion. - Move MEDIA_SERVER_FEATURES + supportsFeature into contracts and gate the UI dropdown via supportsFeature(COLLECTION_SORT) so the feature becomes available automatically if Jellyfin ever gains a boxset reorder API. - Add ICollection.mediaServerSort field; tighten zod-to-payload parsing in AddModal. - Revert unrelated edits introduced by this PR (rules.service return values, scheduler defensive guards, cosmetic setContext changes). - Tests: setCollectionCustomSort and moveCollectionItem URL shapes, PlexAdapter.reorderCollectionItems orchestration, JellyfinAdapter feature flag and reorder rejection. --------- Co-authored-by: Steven Seitz <steven.seitz@omron.com> Co-authored-by: enoch85 <mailto@danielhansson.nu> * fix(collections): apply collection sort on save, harden Plex reorder (#2860) - Apply the collection sort immediately when a rule group is saved with a newly enabled or changed sort value, so users no longer see a configured sort that hasn't been pushed to Plex until a later add cycle. Previous behaviour gated the push on `newMedia.length > 0`, which left save-time changes unapplied indefinitely. - Continue past per-item move failures in the Plex adapter reorderCollectionItems loop. A single rejected move no longer aborts subsequent moves; failures are accumulated and logged in a summary warning so the rest of the collection still gets ordered. - Short-circuit the Plex reorder when the collection is already in the requested order. The adapter reads current child IDs first via PlexApiService.getCollectionChildren and returns early when they match `orderedItemIds`, skipping both the prefs PUT and every move PUT. The membership-changed gate in addToCollectionInternal is kept as a coarse pre-filter; the adapter check is the safety net. - Reuse the existing `case 'title':` branch in compareMediaItemsBySort as a tiebreaker for airDate / rating / watchCount / deleteSoonest, so items sharing the same primary value fall back to alphabetical ordering. Status sorts (manual / excluded) intentionally skip the fallback to preserve their partition contract. Affects every consumer of the comparator (Maintainerr UI overview/library/ collection display and the Plex collection-sort push) so on-disk Plex order matches what users see in Maintainerr for the same key. Tests: new sort-utils.spec covering the timelordx tiebreaker scenario, updated plex-adapter.service.spec for short-circuit and per-item failure paths, and rules.service.updateRules.spec covering the save-time apply transition. * fix(metadata): align Jellyfin retry id check with pre-filter (#2853) The metadata refresh retry path validated the verified id with isBlankMediaServerId, while the pre-filter used shouldRefreshMetadataItemId. When getMetadata returned an item with the Jellyfin empty GUID (00000000-0000-0000-0000-000000000000), the asymmetric check let the retry call refreshItemMetadata with that id, producing the "Guid can't be empty" spam in Jellyfin's ProviderManager queue. Use the same predicate in both places so foreign-shaped and empty-GUID ids are rejected consistently before any refresh request is issued. * Add Maintainerr architecture overview (#2817) --------- Co-authored-by: enoch85 <mailto@danielhansson.nu> Co-authored-by: 00Scooby <72069678+00Scooby@users.noreply.github.com> Co-authored-by: Steven Seitz <steven.seitz@omron.com> Co-authored-by: maintainerr-automation[bot] <261505141+maintainerr-automation[bot]@users.noreply.github.com> Co-authored-by: Kristian Matthews-Kennington <kristian@matthews-kennington.com>
|
@enoch85: https://github.com/Maintainerr/Maintainerr/issues/2861 Sorry about using the bug template; that seems to be the only one available. |
|
🎉 This PR is included in version 3.11.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Description & Design
Please include:
mediaServerSortcolumn is added to the Collection database entity.2. The UI (
AddModal) is updated with a dropdown to select the sort criteria (conditionally rendered for Plex).3. The
PlexApiServiceandPlexAdapterServiceare extended withsetCollectionCustomSortandmoveCollectionItemendpoints.4. In
collections.service.ts, after adding new items to the collection, the backend retrieves the hydrated metadata, sorts the items locally according to the chosen criteria, and pushes the exact new order to the media server.isPlexcheck, and the backend logic is protected bymediaServer.supportsFeature(MediaServerFeature.COLLECTION_SORT).Related issue
no related issue
AI-Assisted Development
If you used AI tools (e.g. ChatGPT, Copilot, Claude) while working on this PR, please describe:
collections.service.ts.ECONNREFUSEDand empty DB states), and rigorously tested the end-to-end flow on my local instance.IMediaServerService), hides Plex-specific logic behind feature flags, and seamlessly integrates into the existing UI components and Rule Executor lifecycle.Checklist
How to test
Please describe the steps to test your changes, including any setup required.
Additional context
Screenshot of the new UI configuration:
