Skip to content

Commit 15154ed

Browse files
committed
Include invalid workflows and disable them in the embedded workflow component
1 parent 03e55ca commit 15154ed

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
@@ -13,10 +13,28 @@ const celInfo = (workflow) => [
1313
/** Function to return the row information for the list */
1414
const rowInfo = (headers, response) => {
1515
const headerKeys = headers.map((item) => item.key);
16-
const rows = response.resources.filter((item) => item.payload).map((workflow) => ({
17-
id: workflow.id.toString(), cells: celInfo(workflow), clickable: true,
18-
}));
19-
const miqRows = rowData(headerKeys, rows, false);
16+
const rows = response.resources.map((workflow) => {
17+
const isValid = !!workflow.payload;
18+
return {
19+
id: workflow.id.toString(),
20+
name: workflow.name,
21+
cells: celInfo(workflow),
22+
clickable: isValid,
23+
disabled: !isValid,
24+
};
25+
});
26+
27+
// Sort: valid workflows first (alphabetically), then invalid workflows (alphabetically)
28+
const sortedRows = rows.sort((a, b) => {
29+
// If both have same validity status, sort alphabetically by name
30+
if (a.disabled === b.disabled) {
31+
return a.name.localeCompare(b.name);
32+
}
33+
// Valid workflows come first
34+
return a.disabled ? 1 : -1;
35+
});
36+
37+
const miqRows = rowData(headerKeys, sortedRows, false);
2038
return miqRows.rowItems;
2139
};
2240

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ const WorkflowEntryPoints = ({
3434

3535
/** Function to handle a row's click event. */
3636
const onSelect = (selectedItemId) => {
37+
// Find the row to check if it's disabled
38+
const selectedRow = data.list.rows.find((row) => row.id === selectedItemId);
39+
40+
// Don't allow selection of disabled rows
41+
if (selectedRow && selectedRow.disabled) {
42+
return;
43+
}
44+
3745
setData({
3846
...data,
3947
selectedItemId: (data.selectedItemId === selectedItemId) ? undefined : selectedItemId,
@@ -53,6 +61,15 @@ const WorkflowEntryPoints = ({
5361
http.post('/catalog/ae_tree_select_toggle?button=cancel', {}, { headers: {}, skipJsonParsing: true });
5462
}
5563
};
64+
/** Function to check if a valid workflow is selected */
65+
const isValidSelection = () => {
66+
if (!data.selectedItemId) {
67+
return false;
68+
}
69+
const selectedRow = data.list.rows.find((row) => row.id === data.selectedItemId);
70+
return selectedRow && !selectedRow.disabled;
71+
};
72+
5673
/** Function to handle the modal box apply button click event. */
5774
const onApply = () => {
5875
const seletedItem = data.list.rows.find((item) => item.id === data.selectedItemId);
@@ -81,6 +98,7 @@ const WorkflowEntryPoints = ({
8198
open
8299
modalHeading={sprintf(__('Select Embedded Workflow - %s Entry Point'), workflowTypes[type])}
83100
primaryButtonText={__('Apply')}
101+
primaryButtonDisabled={!isValidSelection()}
84102
secondaryButtonText={__('Cancel')}
85103
onRequestSubmit={onApply}
86104
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)