fix: change default sorting to downloads-week-desc as in parseSortOption#2477
fix: change default sorting to downloads-week-desc as in parseSortOption#2477t128n wants to merge 2 commits intonpmx-dev:mainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
2 Skipped Deployments
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
📝 WalkthroughSummary by CodeRabbit
WalkthroughThe default sorting option on the organisation page has been changed from Changes
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
app/pages/org/[org].vue (1)
84-90:⚠️ Potential issue | 🟠 MajorDefault sort is still inconsistent on org-switch flow (Line 115).
Line 89 now treats
'downloads-week-desc'as default for URL sync, but Line 115 still resets to'updated-desc'. On client-side org navigation, that can reintroduce mismatch and persistsort=updated-descunexpectedly.Suggested fix
+const ORG_DEFAULT_SORT: SortOption = 'downloads-week-desc' @@ - initialSort: parseSortOption(normalizeSearchParam(route.query.sort)), + initialSort: parseSortOption(normalizeSearchParam(route.query.sort)) ?? ORG_DEFAULT_SORT, @@ - sort: updates.sort && updates.sort !== 'downloads-week-desc' ? updates.sort : undefined, + sort: updates.sort && updates.sort !== ORG_DEFAULT_SORT ? updates.sort : undefined, @@ - setSort('updated-desc') + setSort(ORG_DEFAULT_SORT)
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 0f107d08-ee6f-4ae7-99d4-b0343f9ad45b
📒 Files selected for processing (1)
app/pages/org/[org].vue
| } = useStructuredFilters({ | ||
| packages, | ||
| initialSort: (normalizeSearchParam(route.query.sort) as SortOption) ?? 'updated-desc', | ||
| initialSort: (normalizeSearchParam(route.query.sort) as SortOption) ?? 'downloads-week-desc', | ||
| }) |
There was a problem hiding this comment.
Use parseSortOption (not a direct cast) for query-derived sort.
(normalizeSearchParam(route.query.sort) as SortOption) trusts arbitrary query input. An invalid ?sort= value can enter state and bypass the normal defaulting/parsing behaviour described in the PR objective.
Suggested fix
-import type { FilterChip, SortOption } from '#shared/types/preferences'
+import { parseSortOption, type FilterChip, type SortOption } from '#shared/types/preferences'
@@
- initialSort: (normalizeSearchParam(route.query.sort) as SortOption) ?? 'downloads-week-desc',
+ initialSort: parseSortOption(normalizeSearchParam(route.query.sort)),As per coding guidelines: "Ensure you write strictly type-safe code."
📝 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.
| } = useStructuredFilters({ | |
| packages, | |
| initialSort: (normalizeSearchParam(route.query.sort) as SortOption) ?? 'updated-desc', | |
| initialSort: (normalizeSearchParam(route.query.sort) as SortOption) ?? 'downloads-week-desc', | |
| }) | |
| } = useStructuredFilters({ | |
| packages, | |
| initialSort: parseSortOption(normalizeSearchParam(route.query.sort)), | |
| }) |
ghostdevv
left a comment
There was a problem hiding this comment.
could you take a look at code rabbit's comment?
Totally missed that 2nd comment - just added another commit that fixes it |
🔗 Linked issue
Resolves #2471
🧭 Context
Describe the bug
https://npmx.dev/org/arnaud-barre-> Sort dropdown isDownloads/wkLast published, no URL changeDownloads/wk,?sort=downloads-week-descis append to the URLThe makes it annoying in the following flow:
Changed default sorting on
/org/pages to match the default sorting method used innpmx.dev/shared/types/preferences.ts
Lines 133 to 149 in 0164064
📚 Description
/org/[org]pages usedupdated-descas the default sorting methodnpmx.dev/app/pages/org/[org].vue
Line 60 in 0164064
The
ListToolbarcomponent used on that page, relies on the fnparseSortOption, which usesdownloads-week-descas the default sorting method though, as defined innpmx.dev/shared/types/preferences.ts
Lines 133 to 149 in 0164064
So when
/org/used the default sorting method, it didn't save it in the URL query params. The/org/page thought thatupdated-desc iwas used, butListToolbarthought thatdownloads-weeks-desc iwas used. This caused the desync as outlined in the issue.I adjusted the default on the
/org/page to align with the default set inshared/types/preferences.ts.