@@ -43,13 +43,43 @@ const convertDate = (date) => {
4343 return formattedDate . toString ( ) ;
4444} ;
4545
46+ // Converts the duration time in ms and returns a string in format: w days x hours y minutes z seconds
47+ // duration: time in ms
48+ const convertDuration = ( duration ) => {
49+ const durationString = moment . duration ( duration , 'milliseconds' ) . toISOString ( ) . split ( 'PT' ) [ 1 ] ;
50+ let startIndex = 0 ;
51+ let resultString = '' ;
52+ if ( durationString . indexOf ( 'H' ) >= 0 ) {
53+ resultString += `${ durationString . slice ( startIndex , durationString . indexOf ( 'H' ) ) } h ` ;
54+ startIndex = durationString . indexOf ( 'H' ) + 1 ;
55+ }
56+ if ( durationString . indexOf ( 'M' ) >= 0 ) {
57+ resultString += `${ durationString . slice ( startIndex , durationString . indexOf ( 'M' ) ) } m ` ;
58+ startIndex = durationString . indexOf ( 'M' ) + 1 ;
59+ }
60+ if ( durationString . indexOf ( 'S' ) >= 0 ) {
61+ resultString += `${ durationString . slice ( startIndex , durationString . indexOf ( 'S' ) ) } s` ;
62+ startIndex = durationString . indexOf ( 'S' ) + 1 ;
63+ }
64+ return resultString ;
65+ } ;
66+
67+ const getItemIcon = ( item ) => {
68+ if ( item . RunnerContext && item . RunnerContext . success ) {
69+ return { icon : 'carbon--CheckmarkOutline' } ;
70+ } if ( item . RunnerContext && item . RunnerContext . Error ) {
71+ return { icon : 'carbon--MisuseOutline' } ;
72+ }
73+ return { icon : 'carbon--PlayOutline' } ;
74+ } ;
75+
4676/** Function to get the row data of workflow states table. */
4777const rowData = ( { StateHistory } ) => StateHistory . map ( ( item ) => ( {
4878 id : item . Guid . toString ( ) ,
49- name : item . Name ,
79+ name : { text : item . Name , ... getItemIcon ( item ) } ,
5080 enteredTime : convertDate ( item . EnteredTime . toString ( ) ) ,
5181 finishedTime : convertDate ( item . FinishedTime . toString ( ) ) ,
52- duration : item . Duration . toFixed ( 3 ) . toString ( ) ,
82+ duration : convertDuration ( item . Duration * 1000 ) ,
5383} ) ) ;
5484
5585/** Function to return the header, row and status data required for the RequestWorkflowStatus component. */
@@ -59,6 +89,20 @@ export const workflowStatusData = (response) => {
5989 return undefined ;
6090 }
6191 const rows = response . context ? rowData ( response . context ) : [ ] ;
92+ if ( response . context && response . context . State ) {
93+ const state = response . context . State ;
94+ const currentTime = new Date ( ) ; // Date Object for current time
95+ const oldTime = Date . parse ( state . EnteredTime ) ; // ms since start time to entered time in UTC
96+ const durationTime = currentTime . getTime ( ) - oldTime ; // ms from entered time to current time
97+
98+ rows . push ( {
99+ id : state . Guid . toString ( ) ,
100+ name : { text : state . Name , icon : 'carbon--PlayOutline' } ,
101+ enteredTime : convertDate ( state . EnteredTime . toString ( ) ) ,
102+ finishedTime : '' ,
103+ duration : convertDuration ( durationTime ) ,
104+ } ) ;
105+ }
62106 const headers = headerData ( ) ;
63107 const name = response . name || response . description ;
64108 return {
0 commit comments