Skip to content

feat: update sorting (CM-1293)#4264

Merged
ulemons merged 1 commit into
mainfrom
feat/improve-packages-filter
Jun 25, 2026
Merged

feat: update sorting (CM-1293)#4264
ulemons merged 1 commit into
mainfrom
feat/improve-packages-filter

Conversation

@ulemons

@ulemons ulemons commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

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

  • sortDir default per sortBy: the akrites handler was defaulting sortDir to desc globally. Now when sortDir is omitted, it defaults to asc for name and health (matching the frontend's hard-coded directions) and desc for all other sort keys (risk, impact, openVulns).
  • Health sort expression: sorting by health was using the raw r_sc.scorecard_score (0–10 scale), inconsistent with the health.score field returned in the response (which uses p.health_score first, falling back to scorecard_score * 10). Now the sort uses the same COALESCE(p.health_score, r_sc.scorecard_score * 10) expression.
  • NULL handling for ascending sorts: added a nullsDir variable that applies NULLS FIRST for ASC sorts and NULLS LAST for DESC sorts. 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

  • Bug fix
  • New feature
  • Refactor / cleanup
  • Performance improvement
  • Chore / dependency update
  • Documentation

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 sortDir is omitted or when ordering by health.

sortDir defaults are no longer always desc. After validation, missing sortDir becomes asc for name and health, and desc for risk, impact, and openVulns.

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 BY follows sort direction: NULLS FIRST for ascending, NULLS LAST for 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.

Signed-off-by: Umberto Sgueglia <usgueglia@contractor.linuxfoundation.org>
@ulemons ulemons self-assigned this Jun 25, 2026
Copilot AI review requested due to automatic review settings June 25, 2026 11:12
@ulemons ulemons added the Bug Created by Linear-GitHub Sync label Jun 25, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 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 sortDir is now derived from sortBy when omitted (asc for name/health, otherwise desc).
  • Sorting by health now uses a composite expression consistent with the API’s health scoring source fields.
  • ORDER BY now applies direction-based NULL placement (NULLS FIRST for ASC, NULLS LAST for 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') {
@ulemons ulemons merged commit 014ddc7 into main Jun 25, 2026
22 checks passed
@ulemons ulemons deleted the feat/improve-packages-filter branch June 25, 2026 11:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Created by Linear-GitHub Sync

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants