@@ -13,12 +13,15 @@ import {
1313 Policy ,
1414 SelectPolicyTestResult ,
1515 UrlTestPolicyTestResult ,
16+ PolicyBenchmarkResults ,
1617} from '../../../types'
1718import fetcher from '../../../utils/fetcher'
19+ import { mutatePolicyPerformanceResults } from '../usePolicyPerformance'
1820
1921interface PolicyGroupProps {
2022 policyGroupName : string
2123 policyGroup : Policy [ ]
24+ policyPerformanceResults ?: PolicyBenchmarkResults
2225}
2326
2427const LoadingOverlay = styled . div `
@@ -42,6 +45,7 @@ const latencyResultStyle = (latency: number) => {
4245const PolicyGroup : React . FC < PolicyGroupProps > = ( {
4346 policyGroupName,
4447 policyGroup,
48+ policyPerformanceResults,
4549} ) => {
4650 const { t } = useTranslation ( )
4751 const [ isInViewport , targetRef ] = useIsInViewport ( { threshold : 10 } )
@@ -97,6 +101,11 @@ const PolicyGroup: React.FC<PolicyGroupProps> = ({
97101 [ name : string ] : number
98102 } = { }
99103
104+ if ( policyPerformanceResults ) {
105+ mutatePolicyPerformanceResults ( )
106+ return
107+ }
108+
100109 if ( res . winner ) {
101110 const testResult = ( res as UrlTestPolicyTestResult ) . results [ 0 ] . data
102111 Object . keys ( testResult ) . forEach ( ( key ) => {
@@ -134,6 +143,31 @@ const PolicyGroup: React.FC<PolicyGroupProps> = ({
134143 } ) . then ( ( res ) => res . policy )
135144 } , [ policyGroupName ] )
136145
146+ useEffect ( ( ) => {
147+ if ( ! policyPerformanceResults ) {
148+ return
149+ }
150+
151+ const latencies : {
152+ [ name : string ] : number
153+ } = { }
154+
155+ policyGroup . forEach ( ( policy ) => {
156+ Object . keys ( policyPerformanceResults ) . forEach ( ( key ) => {
157+ if ( policy . lineHash === key ) {
158+ latencies [ policy . name ] =
159+ policyPerformanceResults [ key ] . lastTestScoreInMS === 0
160+ ? - 1
161+ : Number (
162+ policyPerformanceResults [ key ] . lastTestScoreInMS . toFixed ( 0 ) ,
163+ )
164+ }
165+ } )
166+ } )
167+
168+ setLatencies ( latencies )
169+ } , [ policyGroup , policyPerformanceResults ] )
170+
137171 useEffect ( ( ) => {
138172 let isMounted = true
139173
@@ -152,7 +186,7 @@ const PolicyGroup: React.FC<PolicyGroupProps> = ({
152186
153187 return (
154188 < div ref = { targetRef } >
155- < Card shadow = "single" tw = "relative overflow-hidden px-3 md:px-4" >
189+ < Card tw = "relative overflow-hidden px-3 md:px-4" >
156190 { isLoading && (
157191 < LoadingOverlay >
158192 < Spinner />
0 commit comments