Skip to content

Commit c3a7ef1

Browse files
committed
Include invalid workflows and disable them in the embedded workflow component
1 parent c2bd3bf commit c3a7ef1

File tree

6 files changed

+60
-12
lines changed

6 files changed

+60
-12
lines changed

app/javascript/components/miq-data-table/helper.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ export const rowData = (headerKeys, rows, hasCheckbox) => {
133133
const rowItems = [];
134134
const mergedStatus = [];
135135
rows.forEach(({
136-
cells, id, clickable, clickId,
136+
cells, id, clickable, clickId, disabled,
137137
}) => {
138138
const requiredCells = hasCheckbox ? (cells.filter((c) => !c.is_checkbox)) : cells;
139139
const { mergedCells, merged } = mergeIcons(requiredCells);
@@ -143,6 +143,7 @@ export const rowData = (headerKeys, rows, hasCheckbox) => {
143143
result.id = id;
144144
if (clickId) result.clickId = clickId;
145145
result.clickable = clickable;
146+
if (disabled !== undefined) result.disabled = disabled;
146147
return result;
147148
}, {});
148149
rowItems.push(reducedItems);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ const MiqDataTable = ({
128128
/** Function to identify if the row is clickable or not and the returns a class name */
129129
const classNameRow = (item) => {
130130
if (item) {
131-
const { clickable, id } = item;
131+
const { clickable, id, disabled } = item;
132+
if (disabled) return 'disabled-row';
132133
if (clickable === false) return 'simple-row';
133134
if (clickable === true || clickable === null) {
134135
return (gridChecks.includes(id)

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ const MiqTableCell = ({
2525
const alignClass = longText ? 'vertical_align_top' : '';
2626
const longerTextClass = veryLongText ? 'truncate_longer_text' : '';
2727

28+
const cellTitle = cell.data.title ? cell.data.title : cell.value;
2829
const truncateText = (
29-
<span title={cell.value} className={classNames('bx--front-line', wrapClass, longerTextClass)}>
30+
<span title={cellTitle} className={classNames('bx--front-line', wrapClass, longerTextClass)}>
3031
{cell.value}
3132
</span>
3233
);

app/javascript/components/workflows/helper.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,30 @@ const entryPointsHeaderInfo = () => [
77
];
88

99
/** Function to return the cell data for a row item. */
10-
const cellInfo = (workflow) => [
11-
{ text: workflow.configuration_script_source ? workflow.configuration_script_source.name : '' },
12-
{ text: workflow.name },
13-
];
10+
const cellInfo = (workflow) => {
11+
const isValid = workflow.payload_valid;
12+
const workflowNameTitle = !isValid ? `${workflow.name} (${__('Invalid Workflow')})` : workflow.name;
13+
14+
return [
15+
{ text: workflow.configuration_script_source ? workflow.configuration_script_source.name : '' },
16+
{ text: workflow.name, title: workflowNameTitle },
17+
];
18+
};
1419

1520
/** Function to return the row information for the list */
1621
const rowInfo = (headers, response) => {
1722
const headerKeys = headers.map((item) => item.key);
18-
const rows = response.resources.filter((item) => item.payload).map((workflow) => ({
19-
id: workflow.id.toString(), cells: cellInfo(workflow), clickable: true,
20-
}));
23+
const rows = response.resources.map((workflow) => {
24+
const isValid = workflow.payload_valid;
25+
return {
26+
id: workflow.id.toString(),
27+
name: workflow.name,
28+
cells: cellInfo(workflow),
29+
clickable: isValid,
30+
disabled: !isValid,
31+
};
32+
});
33+
2134
const miqRows = rowData(headerKeys, rows, false);
2235
return miqRows.rowItems;
2336
};

app/javascript/components/workflows/workflow-entry-points.jsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,14 @@ const WorkflowEntryPoints = ({
9191

9292
/** Function to handle a row's click event. */
9393
const onSelect = (selectedItemId) => {
94+
// Find the row to check if it's disabled
95+
const selectedRow = data.list.rows.find((row) => row.id === selectedItemId);
96+
97+
// Don't allow selection of disabled rows
98+
if (selectedRow && selectedRow.disabled) {
99+
return;
100+
}
101+
94102
setData({
95103
...data,
96104
selectedItemId: (data.selectedItemId === selectedItemId) ? undefined : selectedItemId,
@@ -110,6 +118,15 @@ const WorkflowEntryPoints = ({
110118
http.post('/catalog/ae_tree_select_toggle?button=cancel', {}, { headers: {}, skipJsonParsing: true });
111119
}
112120
};
121+
/** Function to check if a valid workflow is selected */
122+
const isValidSelection = () => {
123+
if (!data.selectedItemId) {
124+
return false;
125+
}
126+
const selectedRow = data.list.rows.find((row) => row.id === data.selectedItemId);
127+
return selectedRow && !selectedRow.disabled;
128+
};
129+
113130
/** Function to handle the modal box apply button click event. */
114131
const onApply = () => {
115132
const seletedItem = data.list.rows.find((item) => item.id === data.selectedItemId);
@@ -138,7 +155,7 @@ const WorkflowEntryPoints = ({
138155
open
139156
modalHeading={sprintf(__('Select Embedded Workflow - %s Entry Point'), workflowTypes[type])}
140157
primaryButtonText={__('Apply')}
141-
primaryButtonDisabled={!data.selectedItemId}
158+
primaryButtonDisabled={!isValidSelection()}
142159
secondaryButtonText={__('Cancel')}
143160
onRequestSubmit={onApply}
144161
onRequestClose={onCloseModal}

app/stylesheet/miq-data-table.scss

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,21 @@ table.miq_preview {
393393
.workflows-entry-point-modal-body {
394394
.miq-data-table {
395395
margin-top: 0px;
396+
397+
tbody tr.disabled-row {
398+
opacity: 0.5 !important;
399+
cursor: not-allowed !important;
400+
color: #8d8d8d !important;
401+
background-color: #f4f4f4 !important;
402+
403+
&:hover {
404+
background-color: #f4f4f4 !important;
405+
}
406+
407+
td {
408+
color: #8d8d8d !important;
409+
}
410+
}
396411
}
397412
}
398413
}
@@ -424,4 +439,4 @@ table.miq_preview {
424439
width: 50px;
425440
padding-left: 24px;
426441
}
427-
}
442+
}

0 commit comments

Comments
 (0)