33 * SPDX-License-Identifier: Apache-2.0
44 */
55
6- import React , { useState , useCallback , use , useEffect } from "react"
7- import { useNavigate , useRouteContext , useSearch } from "@tanstack/react-router"
6+ import React , { use , Suspense } from "react"
7+ import { useNavigate } from "@tanstack/react-router"
88import {
99 Stack ,
1010 DataGrid ,
@@ -18,23 +18,24 @@ import SectionContentHeading from "../../../common/SectionContentHeading"
1818import { CursorPagination } from "../../../common/CursorPagination"
1919import { ApolloQueryResult } from "@apollo/client"
2020import { GetVulnerabilitiesQuery } from "../../../../generated/graphql"
21- import { fetchVulnerabilities } from "../../../../api/fetchVulnerabilities"
2221import { getNormalizedVulnerabilitiesResponse , getNormalizedVulnerabilityServicesResponse } from "../../utils"
23- import { VulnerabilityService } from "../../utils"
2422
2523type VulnerabilityServicesListProps = {
2624 vulnerabilityName : string
2725 vulnerabilitiesPromise : Promise < ApolloQueryResult < GetVulnerabilitiesQuery > >
2826 onServiceClick ?: ( serviceCcrn : string ) => void
29- goToPage ? : ( after ?: string | null ) => void
27+ goToPage : ( after ?: string | null ) => void
3028}
3129
32- export const VulnerabilityServicesList = ( {
33- vulnerabilityName,
30+ const VulnerabilityServicesDataRows = ( {
3431 vulnerabilitiesPromise,
32+ vulnerabilityName,
3533 onServiceClick,
36- goToPage,
37- } : VulnerabilityServicesListProps ) => {
34+ } : {
35+ vulnerabilitiesPromise : Promise < ApolloQueryResult < GetVulnerabilitiesQuery > >
36+ vulnerabilityName : string
37+ onServiceClick ?: ( serviceCcrn : string ) => void
38+ } ) => {
3839 const navigate = useNavigate ( )
3940
4041 const handleServiceClick = ( serviceCcrn : string ) => {
@@ -48,15 +49,6 @@ export const VulnerabilityServicesList = ({
4849 }
4950 }
5051
51- const handlePageChange = useCallback (
52- ( after ?: string | null ) => {
53- if ( goToPage ) {
54- goToPage ( after )
55- }
56- } ,
57- [ goToPage ]
58- )
59-
6052 // Use the promise passed from the parent
6153 const { data } = use ( vulnerabilitiesPromise )
6254
@@ -76,24 +68,83 @@ export const VulnerabilityServicesList = ({
7668 }
7769
7870 return (
79- < Stack gap = "4" direction = "vertical" >
80- < SectionContentHeading > Services ({ totalCount } )</ SectionContentHeading >
71+ < >
72+ { services . map ( ( service , index ) => (
73+ < DataGridRow key = { index } className = "cursor-pointer" onClick = { ( ) => handleServiceClick ( service . ccrn ) } >
74+ < DataGridCell className = "whitespace-nowrap" > { service . ccrn } </ DataGridCell >
75+ </ DataGridRow >
76+ ) ) }
77+ </ >
78+ )
79+ }
80+
81+ const VulnerabilityServicesTotalCount = ( {
82+ vulnerabilitiesPromise,
83+ vulnerabilityName,
84+ } : {
85+ vulnerabilitiesPromise : Promise < ApolloQueryResult < GetVulnerabilitiesQuery > >
86+ vulnerabilityName : string
87+ } ) => {
88+ const { data } = use ( vulnerabilitiesPromise )
89+ const { vulnerabilities } = getNormalizedVulnerabilitiesResponse ( data )
90+ const vulnerabilityData = vulnerabilities . find ( ( vuln : Vulnerability ) => vuln . name === vulnerabilityName )
91+ const totalCount = vulnerabilityData ?. servicesCount || 0
92+
93+ return < > { totalCount } </ >
94+ }
95+
96+ export const VulnerabilityServicesList = ( {
97+ vulnerabilityName,
98+ vulnerabilitiesPromise,
99+ onServiceClick,
100+ goToPage,
101+ } : VulnerabilityServicesListProps ) => {
102+ return (
103+ < Suspense >
104+ < SectionContentHeading >
105+ Services
106+ < Suspense >
107+ (
108+ < VulnerabilityServicesTotalCount
109+ vulnerabilitiesPromise = { vulnerabilitiesPromise }
110+ vulnerabilityName = { vulnerabilityName }
111+ />
112+ )
113+ </ Suspense >
114+ </ SectionContentHeading >
81115
82116 < div className = "datagrid-hover" >
83117 < DataGrid columns = { 1 } >
84118 < DataGridRow >
85119 < DataGridHeadCell > Service CCRN</ DataGridHeadCell >
86120 </ DataGridRow >
87-
88- { services . map ( ( service , index ) => (
89- < DataGridRow key = { index } className = "cursor-pointer" onClick = { ( ) => handleServiceClick ( service . ccrn ) } >
90- < DataGridCell className = "whitespace-nowrap" > { service . ccrn } </ DataGridCell >
91- </ DataGridRow >
92- ) ) }
121+ < Suspense
122+ fallback = {
123+ < DataGridRow >
124+ < DataGridCell colSpan = { 1 } >
125+ < Stack gap = "2" alignment = "center" >
126+ < div > Loading</ div >
127+ < Spinner variant = "primary" > </ Spinner >
128+ </ Stack >
129+ </ DataGridCell >
130+ </ DataGridRow >
131+ }
132+ >
133+ < VulnerabilityServicesDataRows
134+ vulnerabilitiesPromise = { vulnerabilitiesPromise }
135+ vulnerabilityName = { vulnerabilityName }
136+ onServiceClick = { onServiceClick }
137+ />
138+ </ Suspense >
93139 </ DataGrid >
94140 </ div >
95-
96- { /* The CursorPagination component is removed as per the edit hint */ }
97- </ Stack >
141+ < Suspense >
142+ < CursorPagination
143+ dataNormalizationMethod = { getNormalizedVulnerabilityServicesResponse }
144+ dataPromise = { vulnerabilitiesPromise }
145+ goToPage = { goToPage }
146+ />
147+ </ Suspense >
148+ </ Suspense >
98149 )
99150}
0 commit comments