-
Notifications
You must be signed in to change notification settings - Fork 366
Add current state to workflow states table and format duration time #9191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,13 +43,43 @@ const convertDate = (date) => { | |
| return formattedDate.toString(); | ||
| }; | ||
|
|
||
| // Converts the duration time in ms and returns a string in format: w days x hours y minutes z seconds | ||
| // duration: time in ms | ||
| const convertDuration = (duration) => { | ||
| const durationString = moment.duration(duration, 'milliseconds').toISOString().split('PT')[1]; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm very surprised this doesn't "throw away" the days, months, years component of the time |
||
| let startIndex = 0; | ||
| let resultString = ''; | ||
| if (durationString.indexOf('H') >= 0) { | ||
| resultString += `${durationString.slice(startIndex, durationString.indexOf('H'))}h `; | ||
| startIndex = durationString.indexOf('H') + 1; | ||
| } | ||
| if (durationString.indexOf('M') >= 0) { | ||
| resultString += `${durationString.slice(startIndex, durationString.indexOf('M'))}m `; | ||
| startIndex = durationString.indexOf('M') + 1; | ||
| } | ||
| if (durationString.indexOf('S') >= 0) { | ||
| resultString += `${durationString.slice(startIndex, durationString.indexOf('S'))}s`; | ||
| startIndex = durationString.indexOf('S') + 1; | ||
| } | ||
| return resultString; | ||
GilbertCherrie marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }; | ||
|
|
||
| const getItemIcon = (item) => { | ||
| if (item.RunnerContext && item.RunnerContext.success) { | ||
| return { icon: 'carbon--CheckmarkOutline' }; | ||
| } if (item.RunnerContext && item.RunnerContext.Error) { | ||
| return { icon: 'carbon--MisuseOutline' }; | ||
| } | ||
| return { icon: 'carbon--PlayOutline' }; | ||
| }; | ||
|
|
||
| /** Function to get the row data of workflow states table. */ | ||
| const rowData = ({ StateHistory }) => StateHistory.map((item) => ({ | ||
| id: item.Guid.toString(), | ||
| name: item.Name, | ||
| name: { text: item.Name, ...getItemIcon(item) }, | ||
| enteredTime: convertDate(item.EnteredTime.toString()), | ||
| finishedTime: convertDate(item.FinishedTime.toString()), | ||
| duration: item.Duration.toFixed(3).toString(), | ||
| duration: convertDuration(item.Duration * 1000), | ||
| })); | ||
|
|
||
| /** Function to return the header, row and status data required for the RequestWorkflowStatus component. */ | ||
|
|
@@ -59,6 +89,20 @@ export const workflowStatusData = (response) => { | |
| return undefined; | ||
| } | ||
| const rows = response.context ? rowData(response.context) : []; | ||
| if (response.context && response.context.State) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @agrare I think this code depends on nil-ing out the state when the flow is completed. Is that in yet?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No it isn't, started it but ran into some issues because we use
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @GilbertCherrie Since the "final" state might appear twice, I'm concerned this will double up the presentation of it. @agrare Thoughts on how we can avoid presenting the final state twice?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @agrare If we do a state retry or a state gets re-run in a loop, does each iteration get it's own GUID? If so, then yeah, an ID check might work. @GilbertCherrie You could also just check the very last state in the StatesHistory and if it's the same as the "current" state then don't show it.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Here is an example of the same state retried twice from floe specs: The State gets a Guid when it is started and a state that is retried multiple times is still the same state so it has the same Guid.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @agrare One more question. When the entire flow is done, does the "current" state have a "finished time"? If so, that might be the simplest check.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, |
||
| const state = response.context.State; | ||
| const currentTime = new Date(); // Date Object for current time | ||
| const oldTime = Date.parse(state.EnteredTime); // ms since start time to entered time in UTC | ||
| const durationTime = currentTime.getTime() - oldTime; // ms from entered time to current time | ||
|
|
||
| rows.push({ | ||
| id: state.Guid.toString(), | ||
| name: { text: state.Name, icon: 'carbon--PlayOutline' }, | ||
| enteredTime: convertDate(state.EnteredTime.toString()), | ||
| finishedTime: '', | ||
| duration: convertDuration(durationTime), | ||
| }); | ||
| } | ||
| const headers = headerData(); | ||
| const name = response.name || response.description; | ||
| return { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.