Fix non-Linux not displaying all OS version. (#35220)

<!-- Add the related story/sub-task/bug number, like Resolves #123, or
remove if NA -->
**Related issue:** Resolves #35166

Fix
- For an OS version, we first fetch the version with
max_vulnerabilities=0.
- If the OS version has vulnerabilities and it is non-Linux, then we
refetch the OS version without specifying the `max_vulnerabilities`
parameter, which fetches all vulnerabilities.

# Checklist for submitter

## Testing

- [x] QA'd all new/changed functionality manually

For unreleased bug fixes in a release candidate, one of:

- [x] Confirmed that the fix is not expected to adversely impact load
test results

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Improvements**
* Optimized vulnerability data loading for operating system details with
enhanced fetching strategy
* Improved loading state management for clearer visibility during data
retrieval on OS version pages

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Jacob Shandling <jacob@shandling.dev>
This commit is contained in:
Victor Lyuboslavsky 2025-11-05 17:02:55 -06:00 committed by GitHub
parent b4cf896545
commit e5c5992cda
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 23 additions and 2 deletions

View file

@ -1,6 +1,6 @@
/** software/os/:id */
import React, { useCallback, useContext } from "react";
import React, { useCallback, useContext, useState } from "react";
import { useQuery } from "react-query";
import { useErrorHandler } from "react-error-boundary";
import { InjectedRouter, RouteComponentProps } from "react-router";
@ -169,6 +169,11 @@ const SoftwareOSDetailsPage = ({
includeNoTeam: true,
});
// Track whether we need to fetch all vulnerabilities
const [maxVulnerabilities, setMaxVulnerabilities] = useState<
number | undefined
>(0);
const {
data: { os_version: osVersionDetails, counts_updated_at } = {},
isLoading,
@ -184,6 +189,7 @@ const SoftwareOSDetailsPage = ({
scope: "osVersionDetails",
os_version_id: osVersionIdFromURL,
teamId: teamIdForApi,
max_vulnerabilities: maxVulnerabilities,
},
],
({ queryKey }) => osVersionsAPI.getOSVersion(queryKey[0]),
@ -200,6 +206,19 @@ const SoftwareOSDetailsPage = ({
handlePageError(error);
}
},
onSuccess: (data) => {
const {
os_version: { platform, vulnerabilities_count },
} = data;
if (
!isLinuxLike(platform) &&
vulnerabilities_count &&
vulnerabilities_count > 0 &&
maxVulnerabilities === 0
) {
setMaxVulnerabilities(undefined);
}
},
}
);

View file

@ -42,6 +42,7 @@ export interface IOSVersionsResponse {
interface IGetOsVersionOptions {
os_version_id: number;
teamId?: number;
max_vulnerabilities?: number;
}
export interface IGetOsVersionQueryKey extends IGetOsVersionOptions {
@ -94,11 +95,12 @@ export const getOSVersions = ({
const getOSVersion = ({
os_version_id,
teamId,
max_vulnerabilities,
}: IGetOsVersionOptions): Promise<IOSVersionResponse> => {
const endpoint = endpoints.OS_VERSION(os_version_id);
const queryString = buildQueryStringFromParams({
team_id: teamId,
max_vulnerabilities: 3, // Limit CVEs to first 3, use vulnerabilities_count for total
max_vulnerabilities,
});
const path = queryString ? `${endpoint}?${queryString}` : endpoint;