feat: update sorting (CM-1293)#4264
Merged
Merged
Conversation
Signed-off-by: Umberto Sgueglia <usgueglia@contractor.linuxfoundation.org>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR aligns sorting behavior in the Akrites/Ossprey packages list API with the admin dashboard’s expected contract by adjusting default sort direction behavior, improving health-score sorting consistency, and making NULL ordering depend on sort direction.
Changes:
- Default
sortDiris now derived fromsortBywhen omitted (ascforname/health, otherwisedesc). - Sorting by
healthnow uses a composite expression consistent with the API’s health scoring source fields. - ORDER BY now applies direction-based NULL placement (
NULLS FIRSTfor ASC,NULLS LASTfor DESC).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| services/libs/data-access-layer/src/osspckgs/api.ts | Updates health sort expression and makes NULL ordering depend on sort direction. |
| backend/src/api/public/v1/ossprey/packageList.ts | Changes query validation to make sortDir optional and derive a default based on sortBy. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
438
to
440
| } else if (opts.sortBy === 'health') { | ||
| sortExpr = 'r_sc.scorecard_score' | ||
| sortExpr = 'COALESCE(p.health_score, r_sc.scorecard_score * 10)' | ||
| } else if (opts.sortBy === 'risk') { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes sorting and health score consistency in the Akrites packages list API (
GET /akrites/packages) to match the contract expected by the LFX Akrites admin dashboard.Changes
sortDirdefault persortBy: the akrites handler was defaultingsortDirtodescglobally. Now whensortDiris omitted, it defaults toascfornameandhealth(matching the frontend's hard-coded directions) anddescfor all other sort keys (risk,impact,openVulns).healthwas using the rawr_sc.scorecard_score(0–10 scale), inconsistent with thehealth.scorefield returned in the response (which usesp.health_scorefirst, falling back toscorecard_score * 10). Now the sort uses the sameCOALESCE(p.health_score, r_sc.scorecard_score * 10)expression.nullsDirvariable that appliesNULLS FIRSTforASCsorts andNULLS LASTforDESCsorts. This ensures packages with missing health/impact data surface at the top when ordering worst-first, rather than being silently hidden at the end.Type of change
JIRA ticket
CM-1293
Note
Low Risk
Query-parameter and ORDER BY behavior only for the packages list endpoint; no auth or data mutation.
Overview
Aligns Akrites/Ossprey package list query sorting with what the admin UI expects when
sortDiris omitted or when ordering by health.sortDirdefaults are no longer alwaysdesc. After validation, missingsortDirbecomesascfornameandhealth, anddescforrisk,impact, andopenVulns.Health column sorting now uses the same composite score as the API response (
COALESCE(p.health_score, r_sc.scorecard_score * 10)), instead of raw scorecard on a 0–10 scale.NULL placement in
ORDER BYfollows sort direction:NULLS FIRSTfor ascending,NULLS LASTfor descending, so missing health/impact data is not always pushed to the end on ascending sorts.Reviewed by Cursor Bugbot for commit de8c27e. Bugbot is set up for automated code reviews on this repo. Configure here.