Skip to content

Commit b8e151c

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

File tree

5 files changed

+61
-7
lines changed

5 files changed

+61
-7
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/workflows/helper.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,28 @@ const cellInfo = (workflow) => [
1515
/** Function to return the row information for the list */
1616
const rowInfo = (headers, response) => {
1717
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-
}));
21-
const miqRows = rowData(headerKeys, rows, false);
18+
const rows = response.resources.map((workflow) => {
19+
const isValid = !!workflow.payload;
20+
return {
21+
id: workflow.id.toString(),
22+
name: workflow.name,
23+
cells: cellInfo(workflow),
24+
clickable: isValid,
25+
disabled: !isValid,
26+
};
27+
});
28+
29+
// Sort: valid workflows first (alphabetically), then invalid workflows (alphabetically)
30+
const sortedRows = rows.sort((a, b) => {
31+
// If both have same validity status, sort alphabetically by name
32+
if (a.disabled === b.disabled) {
33+
return a.name.localeCompare(b.name);
34+
}
35+
// Valid workflows come first
36+
return a.disabled ? 1 : -1;
37+
});
38+
39+
const miqRows = rowData(headerKeys, sortedRows, false);
2240
return miqRows.rowItems;
2341
};
2442

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

Lines changed: 18 additions & 0 deletions
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);
@@ -139,6 +156,7 @@ const WorkflowEntryPoints = ({
139156
modalHeading={sprintf(__('Select Embedded Workflow - %s Entry Point'), workflowTypes[type])}
140157
primaryButtonText={__('Apply')}
141158
primaryButtonDisabled={!data.selectedItemId}
159+
// primaryButtonDisabled={!isValidSelection()}
142160
secondaryButtonText={__('Cancel')}
143161
onRequestSubmit={onApply}
144162
onRequestClose={onCloseModal}

app/stylesheet/miq-data-table.scss

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,22 @@ 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+
pointer-events: none !important;
401+
color: #8d8d8d !important;
402+
background-color: #f4f4f4 !important;
403+
404+
&:hover {
405+
background-color: #f4f4f4 !important;
406+
}
407+
408+
td {
409+
color: #8d8d8d !important;
410+
}
411+
}
396412
}
397413
}
398414
}
@@ -424,4 +440,4 @@ table.miq_preview {
424440
width: 50px;
425441
padding-left: 24px;
426442
}
427-
}
443+
}

0 commit comments

Comments
 (0)