@@ -9,32 +9,16 @@ import { getDurationString, isoDateString } from '@/utils/date';
9
9
10
10
type DeploymentCardType = 'Longest' | 'Shortest' ;
11
11
12
- interface DeploymentWithValidDuration extends Deployment {
13
- duration : number ;
14
- }
15
12
16
13
interface DeploymentCardProps {
17
- deployment : DeploymentWithValidDuration ;
14
+ deployment : Deployment ;
18
15
type : DeploymentCardType ;
19
16
}
20
17
21
18
interface DoraMetricsDurationProps {
22
19
deployments : Deployment [ ] ;
23
20
}
24
21
25
- const calculateDurationFromConductedAt = ( conductedAt : string ) : number | undefined => {
26
- try {
27
- const deploymentDate = new Date ( conductedAt ) ;
28
- if ( isNaN ( deploymentDate . getTime ( ) ) ) {
29
- return undefined ;
30
- }
31
- const now = new Date ( ) ;
32
- return Math . floor ( ( now . getTime ( ) - deploymentDate . getTime ( ) ) / 1000 ) ;
33
- } catch ( error ) {
34
- console . error ( 'Error calculating duration:' , error ) ;
35
- return undefined ;
36
- }
37
- } ;
38
22
39
23
const formatDeploymentDate = ( dateString : string ) : string => {
40
24
if ( ! dateString ) return 'Unknown Date' ;
@@ -112,9 +96,17 @@ const DeploymentCard: FC<DeploymentCardProps> = ({ deployment }) => {
112
96
{ deployment . head_branch || 'Unknown Branch' }
113
97
</ Line >
114
98
< AccessTimeRounded fontSize = "small" />
115
- < Line sx = { { color : theme . palette . primary . light } } > { getDurationString ( deployment . duration ) } </ Line >
99
+ < Line sx = { { color : theme . palette . primary . light } } >
100
+ { getDurationString ( deployment . run_duration ) }
101
+ </ Line >
116
102
</ FlexBox >
117
103
< ArrowForwardIosRounded
104
+ sx = { {
105
+ position : 'absolute' ,
106
+ right : 0 ,
107
+ top : '35%' ,
108
+ bottom : '35%' ,
109
+ } }
118
110
fontSize = "medium"
119
111
/>
120
112
</ FlexBox >
@@ -130,27 +122,20 @@ export const DoraMetricsDuration: FC<DoraMetricsDurationProps> = ({ deployments
130
122
}
131
123
132
124
const validDeployments = deployments
133
- . filter ( ( d ) : d is Deployment => Boolean ( d . conducted_at ) )
134
- . map ( deployment => ( {
135
- ...deployment ,
136
- duration : calculateDurationFromConductedAt ( deployment . conducted_at )
137
- } ) )
138
- . filter ( ( d ) : d is DeploymentWithValidDuration =>
139
- typeof d . duration === 'number' &&
140
- d . duration >= 0
141
- ) ;
125
+ . filter ( ( d ) : d is Deployment => Boolean ( d . conducted_at && typeof d . run_duration === 'number' ) )
126
+ . filter ( ( d ) => d . run_duration >= 0 ) ;
142
127
143
128
if ( ! validDeployments . length ) {
144
129
return { longestDeployment : null , shortestDeployment : null } ;
145
130
}
146
131
147
132
// Function to calculate Longest and shortest deployments
148
133
const { longest, shortest } = validDeployments . reduce ( ( acc , current ) => ( {
149
- longest : ! acc . longest || current . duration > acc . longest . duration ? current : acc . longest ,
150
- shortest : ! acc . shortest || current . duration < acc . shortest . duration ? current : acc . shortest
134
+ longest : ! acc . longest || current . run_duration > acc . longest . run_duration ? current : acc . longest ,
135
+ shortest : ! acc . shortest || current . run_duration < acc . shortest . run_duration ? current : acc . shortest
151
136
} ) , {
152
- longest : null as DeploymentWithValidDuration | null ,
153
- shortest : null as DeploymentWithValidDuration | null
137
+ longest : null as Deployment | null ,
138
+ shortest : null as Deployment | null
154
139
} ) ;
155
140
156
141
return { longestDeployment : longest , shortestDeployment : shortest } ;
@@ -160,15 +145,15 @@ export const DoraMetricsDuration: FC<DoraMetricsDurationProps> = ({ deployments
160
145
< FlexBox col gap = {
9E12
1.5 } >
161
146
< FlexBox gap = { 3 } >
162
147
< FlexBox col gap = { 1 } >
163
- < Line white sx = { { fontSize : '1.1rem ' } } bold > Longest Deployment</ Line >
148
+ < Line white sx = { { fontSize : '1.0rem ' } } semibold > Longest Deployment</ Line >
164
149
< DeploymentCard
165
150
deployment = { longestDeployment }
166
151
type = "Longest"
167
152
/>
168
153
</ FlexBox >
169
154
170
155
< FlexBox col gap = { 1 } >
171
- < Line white sx = { { fontSize : '1.1rem ' } } bold > Shortest Deployment</ Line >
156
+ < Line white sx = { { fontSize : '1.0rem ' } } semibold > Shortest Deployment</ Line >
172
157
< DeploymentCard
173
158
deployment = { shortestDeployment }
174
159
type = "Shortest"
0 commit comments