Respect the custom order of playlists and favorites#207
Conversation
The app always re-sorted playlist songs (default by title), discarding the order the server returns — which for a regular playlist is the custom order defined on the web (pivot `position`). Add a "Custom order" sort that preserves the fetched order (reversible), make it the default for playlists, and make `$sort` return a new list so it no longer mutates the cached playlist in place.
|
Warning Review limit reached
Next review available in: 6 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughPlaylist and favorites sorting now support server-defined custom order. API-version feature flags gate the controls, ascending position sorting preserves server order, descending sorting reverses it, and tests cover feature support and sorting behavior. ChangesCustom ordering
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant AppState
participant FeatureSupport
participant PlaylistOrFavoritesScreen
participant SortButton
participant PlayableSort
AppState->>FeatureSupport: check API version
FeatureSupport-->>PlaylistOrFavoritesScreen: report custom ordering support
PlaylistOrFavoritesScreen->>SortButton: provide position field when supported
SortButton->>PlayableSort: select position and direction
PlayableSort-->>PlaylistOrFavoritesScreen: preserve or reverse server order
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Favorites carry a server-side custom order (favorites.position, with a favorites/move endpoint) just like playlists. Default the Favorites screen to Custom order and offer it in the sort button.
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
test/extensions/playable_list_test.dart (1)
8-8: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueUse descriptive variable names instead of single-letter identifiers.
a,b,cviolate the coding guideline for**/*.dartfiles: single-letter names are only permitted for loop counters (i,j) and the test harness (h). ConsidersongA,songB,songCor names reflecting their role in the test.As per coding guidelines: "Don't use single-letter variable names except for:
iandjfor loop counters, andhfor the test harness. For all other cases (callback params, destructured fields, lambda args, etc.), pick a descriptive name that says what it is."🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@test/extensions/playable_list_test.dart` at line 8, Replace the single-letter Song fields a, b, and c in the playable list tests with descriptive names such as songA, songB, and songC, and update every reference consistently while preserving the existing test behavior.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@test/extensions/playable_list_test.dart`:
- Around line 38-41: Extend the existing “does not mutate the original list”
test to also exercise sorting via the position field, using the position sort
configuration and asserting the original list remains unchanged. Keep the
current title immutability assertion intact.
---
Nitpick comments:
In `@test/extensions/playable_list_test.dart`:
- Line 8: Replace the single-letter Song fields a, b, and c in the playable list
tests with descriptive names such as songA, songB, and songC, and update every
reference consistently while preserving the existing test behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 1c4551d5-5e2c-499d-a052-73abfa2e0f7b
📒 Files selected for processing (4)
lib/extensions/playable_list.dartlib/ui/screens/playlist_details.dartlib/ui/widgets/playable_list_sort_button.darttest/extensions/playable_list_test.dart
| test('does not mutate the original list', () { | ||
| final original = customOrder(); | ||
| original.$sort(config('title', SortOrder.asc)); | ||
| expect(original, [c, a, b]); |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Add an immutability assertion for the position sort path.
The immutability test only covers the title field. Since position is the primary new feature, explicitly verifying that it also doesn't mutate the original list would close the coverage gap.
🧪 Suggested additional test
test('does not mutate the original list', () {
final original = customOrder();
original.$sort(config('title', SortOrder.asc));
+ original.$sort(config('position', SortOrder.asc));
+ original.$sort(config('position', SortOrder.desc));
expect(original, [c, a, b]);
});📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| test('does not mutate the original list', () { | |
| final original = customOrder(); | |
| original.$sort(config('title', SortOrder.asc)); | |
| expect(original, [c, a, b]); | |
| test('does not mutate the original list', () { | |
| final original = customOrder(); | |
| original.$sort(config('title', SortOrder.asc)); | |
| original.$sort(config('position', SortOrder.asc)); | |
| original.$sort(config('position', SortOrder.desc)); | |
| expect(original, [c, a, b]); |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@test/extensions/playable_list_test.dart` around lines 38 - 41, Extend the
existing “does not mutate the original list” test to also exercise sorting via
the position field, using the position sort configuration and asserting the
original list remains unchanged. Keep the current title immutability assertion
intact.
Playlist ordering landed in koel 7.0.2 and favorites ordering in 9.0.0. On older servers the returned order isn't a custom order, so gate the "Custom order" default (and menu entry) behind the server version, falling back to the previous Title default. Nothing reads a per-song position field, so the sort itself was already safe on any server.
Rename songA/B/C and also assert $sort doesn't mutate the original list when sorting by position.
Fixes #202.
Problem
On mobile, playlist and favorites songs were always re-sorted — defaulting to Title, with only Title / Artist / Recently added available. That discarded the user-defined order the server returns:
playlists/{id}/songs→->orderByPivot('position')(since koel 7.0.2)songs/favorites→->orderBy('favorites.position'), with afavorites/moveendpoint (since koel 9.0.0)So the app couldn't play them in their intended order, and "Recently added" sorts by the song's date rather than the add order.
Changes
$sort: a'position'field preserves the server-provided order (reversible via the sort direction) instead of comparing a field. It also returns a new list rather than sorting in place, so it no longer mutates the cached list.Custom order.Custom orderand offer it in the sort button.Older servers
'position'is a sort-mode sentinel, not a per-song field — nothing is read from the response, so the sort can't break on any server. But an older server returns a raw (non-custom) order, so theCustom orderdefault and menu entry are gated behind the server version (Feature.customPlaylistOrder= 7.0.2,Feature.customFavoritesOrder= 9.0.0); older servers keep the previous Title default.Tests
playable_list_test.dart:Custom orderkeeps the server order; descending reverses it; other fields still sort;$sortdoesn't mutate the original.features_test.dart: version thresholds for the two new features.Summary by CodeRabbit