11import React , { useState , useEffect } from 'react' ;
22
33interface WorkflowStats {
4- name : string ;
4+ workflow_name : string ;
55 version : number ;
6- total_instances : string | number ;
7- completed : string | number ;
8- failed : string | number ;
9- running : string | number ;
10- avg_duration_seconds : string | number | null ;
6+ total_instances : number ;
7+ completed_instances : number ;
8+ failed_instances : number ;
9+ running_instances : number ;
10+ average_duration : number ;
1111}
1212
1313export const Stats : React . FC = ( ) => {
@@ -42,20 +42,20 @@ export const Stats: React.FC = () => {
4242 return < div className = "error" > Error: { error } </ div > ;
4343 }
4444
45- const formatDuration = ( seconds : string | number | null ) => {
46- if ( seconds === null || seconds === '' ) return '-' ;
47- const numSeconds = typeof seconds === 'string' ? parseFloat ( seconds ) : seconds ;
48- if ( isNaN ( numSeconds ) ) return '-' ;
49- if ( numSeconds < 60 ) return `${ numSeconds . toFixed ( 1 ) } s` ;
50- if ( numSeconds < 3600 ) return `${ ( numSeconds / 60 ) . toFixed ( 1 ) } m` ;
51- return `${ ( numSeconds / 3600 ) . toFixed ( 1 ) } h` ;
45+ const formatDuration = ( nanoseconds : number ) => {
46+ if ( nanoseconds === 0 || nanoseconds === null ) return '-' ;
47+
48+ // Convert nanoseconds to seconds
49+ const seconds = nanoseconds / 1000000000 ;
50+
51+ if ( seconds < 60 ) return `${ seconds . toFixed ( 1 ) } s` ;
52+ if ( seconds < 3600 ) return `${ ( seconds / 60 ) . toFixed ( 1 ) } m` ;
53+ return `${ ( seconds / 3600 ) . toFixed ( 1 ) } h` ;
5254 } ;
5355
54- const getSuccessRate = ( completed : string | number , total : string | number ) => {
55- const numCompleted = typeof completed === 'string' ? parseInt ( completed ) : completed ;
56- const numTotal = typeof total === 'string' ? parseInt ( total ) : total ;
57- if ( numTotal === 0 ) return '0.0' ;
58- return ( ( numCompleted / numTotal ) * 100 ) . toFixed ( 1 ) ;
56+ const getSuccessRate = ( completed : number , total : number ) => {
57+ if ( total === 0 ) return '0.0' ;
58+ return ( ( completed / total ) * 100 ) . toFixed ( 1 ) ;
5959 } ;
6060
6161 return (
@@ -81,17 +81,17 @@ export const Stats: React.FC = () => {
8181 </ thead >
8282 < tbody >
8383 { stats . map ( ( stat , index ) => (
84- < tr key = { `${ stat . name } -${ stat . version } ` } >
85- < td > { stat . name } </ td >
84+ < tr key = { `${ stat . workflow_name } -${ stat . version } ` } >
85+ < td > { stat . workflow_name } </ td >
8686 < td > v{ stat . version } </ td >
8787 < td > { stat . total_instances } </ td >
88- < td > { stat . completed } </ td >
89- < td > { stat . failed } </ td >
90- < td > { stat . running } </ td >
88+ < td > { stat . completed_instances } </ td >
89+ < td > { stat . failed_instances } </ td >
90+ < td > { stat . running_instances } </ td >
9191 < td >
92- { getSuccessRate ( stat . completed , stat . total_instances ) } %
92+ { getSuccessRate ( stat . completed_instances , stat . total_instances ) } %
9393 </ td >
94- < td > { formatDuration ( stat . avg_duration_seconds ) } </ td >
94+ < td > { formatDuration ( stat . average_duration ) } </ td >
9595 </ tr >
9696 ) ) }
9797 </ tbody >
@@ -104,37 +104,25 @@ export const Stats: React.FC = () => {
104104 < div className = "stats-grid" >
105105 < div className = "stat-card" >
106106 < div className = "stat-number" >
107- { stats . reduce ( ( sum , stat ) => {
108- const num = typeof stat . total_instances === 'string' ? parseInt ( stat . total_instances ) : stat . total_instances ;
109- return sum + ( isNaN ( num ) ? 0 : num ) ;
110- } , 0 ) }
107+ { stats . reduce ( ( sum , stat ) => sum + stat . total_instances , 0 ) }
111108 </ div >
112109 < div className = "stat-label" > Total Instances</ div >
113110 </ div >
114111 < div className = "stat-card" >
115112 < div className = "stat-number" >
116- { stats . reduce ( ( sum , stat ) => {
117- const num = typeof stat . completed === 'string' ? parseInt ( stat . completed ) : stat . completed ;
118- return sum + ( isNaN ( num ) ? 0 : num ) ;
119- } , 0 ) }
113+ { stats . reduce ( ( sum , stat ) => sum + stat . completed_instances , 0 ) }
120114 </ div >
121115 < div className = "stat-label" > Completed</ div >
122116 </ div >
123117 < div className = "stat-card" >
124118 < div className = "stat-number" >
125- { stats . reduce ( ( sum , stat ) => {
126- const num = typeof stat . failed === 'string' ? parseInt ( stat . failed ) : stat . failed ;
127- return sum + ( isNaN ( num ) ? 0 : num ) ;
128- } , 0 ) }
119+ { stats . reduce ( ( sum , stat ) => sum + stat . failed_instances , 0 ) }
129120 </ div >
130121 < div className = "stat-label" > Failed</ div >
131122 </ div >
132123 < div className = "stat-card" >
133124 < div className = "stat-number" >
134- { stats . reduce ( ( sum , stat ) => {
135- const num = typeof stat . running === 'string' ? parseInt ( stat . running ) : stat . running ;
136- return sum + ( isNaN ( num ) ? 0 : num ) ;
137- } , 0 ) }
125+ { stats . reduce ( ( sum , stat ) => sum + stat . running_instances , 0 ) }
138126 </ div >
139127 < div className = "stat-label" > Running</ div >
140128 </ div >
0 commit comments