Skip to content

Commit a9b704b

Browse files
authored
Merge pull request #9191 from GilbertCherrie/fix_workflow_states_table
Add current state to workflow states table and format duration time
2 parents d5a4682 + 87d7593 commit a9b704b

File tree

3 files changed

+87
-5
lines changed

3 files changed

+87
-5
lines changed

app/javascript/components/miq-data-table/miq-table-cell.jsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
CellAction, hasIcon, hasImage, hasButton, hasTextInput, hasToggle, hasLink, isObject, isArray, isNumber, decimalCount,
1111
} from './helper';
1212
import { customOnClickHandler } from '../../helpers/custom-click-handler';
13+
import { carbonizeIcon } from '../../menu/icon';
1314

1415
const MiqTableCell = ({
1516
cell, onCellClick, row, truncate,
@@ -74,6 +75,20 @@ const MiqTableCell = ({
7475
);
7576
};
7677

78+
const returnIcon = (icon, style, styledIconClass, longerTextClass, index = undefined) => {
79+
const extraProps = {};
80+
if (index !== undefined) {
81+
extraProps.key = index.toString();
82+
}
83+
if (icon.startsWith('carbon--')) {
84+
const IconElement = carbonizeIcon(icon);
85+
return (
86+
<IconElement aria-label={icon} className={classNames('icon', 'carbon-icons-style', icon)} style={style} {...extraProps} />
87+
);
88+
}
89+
return (<i className={classNames('fa-lg', 'icon', icon, styledIconClass, longerTextClass)} style={style} {...extraProps} />);
90+
};
91+
7792
/** Function to render icon(s) in cell. */
7893
const renderIcon = (icon, style, showText) => {
7994
const hasBackground = Object.keys(style).includes('background');
@@ -83,8 +98,8 @@ const MiqTableCell = ({
8398
<div className={cellClass}>
8499
{
85100
typeof (icon) === 'string'
86-
? <i className={classNames('fa-lg', 'icon', icon, styledIconClass, longerTextClass)} style={style} />
87-
: icon.map((i, index) => <i className={classNames('fa-lg', 'icon', i)} key={index.toString()} />)
101+
? returnIcon(icon, style, styledIconClass, longerTextClass)
102+
: icon.map((i, index) => returnIcon(i, style, styledIconClass, longerTextClass, index))
88103
}
89104
{showText && truncateText}
90105
</div>

app/javascript/components/request-workflow-status/data.js

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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. */
4777
const 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 {

app/stylesheet/miq-data-table.scss

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
:root {
2+
--green: #2d7623;
3+
--red: #cc0000;
4+
--yellow: #ec7a08;
5+
}
6+
17
.tenant-quota-data-table {
28
.miq-data-table {
39
margin-bottom: 32px;
@@ -113,7 +119,7 @@
113119
}
114120

115121
.icon.fa-ruby {
116-
color: #cc0000 !important;
122+
color: var(--red) !important;
117123
}
118124

119125
span {
@@ -387,3 +393,20 @@ table.miq_preview {
387393
}
388394
}
389395

396+
.request-workflow-status {
397+
.carbon-icons-style {
398+
margin-right: 5px;
399+
}
400+
401+
.carbon--CheckmarkOutline {
402+
color: var(--green);
403+
}
404+
405+
.carbon--MisuseOutline {
406+
color: var(--red);
407+
}
408+
409+
.carbon--PlayOutline {
410+
color: var(--yellow)
411+
}
412+
}

0 commit comments

Comments
 (0)