Skip to content

Commit 741093d

Browse files
authored
Merge pull request ManageIQ#9548 from GilbertCherrie/workflow_entry_point_enhancements
Workflow entry point enhancements
2 parents 8ea4f5f + 0674fa5 commit 741093d

File tree

4 files changed

+69
-6
lines changed

4 files changed

+69
-6
lines changed

app/javascript/components/automate-entry-points/index.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ const AutomateEntryPoints = ({
177177

178178
return !isLoading && (
179179
<Modal
180+
modalHeading={__('Select Entry Point Instance')}
180181
open={showModal}
181182
primaryButtonText={__('OK')}
182183
secondaryButtonText={__('Cancel')}

app/javascript/components/terraform-template-catalog-form/terraform-template-catalog-form.schema.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,6 @@ const provisionTabSchema = (
237237
return schema;
238238
};
239239

240-
241240
const createSchema = ({
242241
data,
243242
setData,

app/javascript/components/workflows/helper.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,21 @@ import { rowData } from '../miq-data-table/helper';
22

33
/** Function to return the header information for the service catalog item's entry points. */
44
const entryPointsHeaderInfo = () => [
5-
{ header: __('Name'), key: 'name' },
5+
{ header: __('Repository'), key: 'configuration_script_source.name' },
6+
{ header: __('Workflow name'), key: 'name' },
67
];
78

89
/** Function to return the cell data for a row item. */
9-
const celInfo = (workflow) => [
10+
const cellInfo = (workflow) => [
11+
{ text: workflow.configuration_script_source ? workflow.configuration_script_source.name : '' },
1012
{ text: workflow.name },
1113
];
1214

1315
/** Function to return the row information for the list */
1416
const rowInfo = (headers, response) => {
1517
const headerKeys = headers.map((item) => item.key);
1618
const rows = response.resources.filter((item) => item.payload).map((workflow) => ({
17-
id: workflow.id.toString(), cells: celInfo(workflow), clickable: true,
19+
id: workflow.id.toString(), cells: cellInfo(workflow), clickable: true,
1820
}));
1921
const miqRows = rowData(headerKeys, rows, false);
2022
return miqRows.rowItems;

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

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,76 @@ const WorkflowEntryPoints = ({
99
field, selected, type, setShowModal, setSelectedValue,
1010
}) => {
1111
const [data, setData] = useState({
12-
isLoading: true, list: {}, selectedItemId: selected,
12+
isLoading: true, list: {}, selectedItemId: selected, key: 'workflow-entry-points',
1313
});
14+
const [prevSelectedHeader, setPrevSelectedHeader] = useState('');
15+
const [sortDirectionRepository, setSortDirectionRepository] = useState('DESC');
16+
const [sortDirectionName, setSortDirectionName] = useState('DESC');
1417

1518
const workflowTypes = {
1619
provision: __('Provision'),
1720
reconfigure: __('Reconfigure'),
1821
retire: __('Retirement'),
1922
};
2023

24+
const sortFunction = (selectedHeader, itemA, itemB) => {
25+
if (selectedHeader.key === 'name') {
26+
if (itemA.name.text === itemB.name.text) {
27+
return itemA.id - itemB.id;
28+
}
29+
return itemA.name.text.localeCompare(itemB.name.text, undefined, { sensitivity: 'base' });
30+
}
31+
if (itemA['configuration_script_source.name'] === undefined) {
32+
itemA['configuration_script_source.name'] = { text: '' };
33+
} else if (itemB['configuration_script_source.name'] === undefined) {
34+
itemB['configuration_script_source.name'] = { text: '' };
35+
}
36+
return itemA['configuration_script_source.name'].text.localeCompare(
37+
itemB['configuration_script_source.name'].text, undefined, { semsitivity: 'base' }
38+
);
39+
};
40+
41+
const onSort = (itemKey) => {
42+
const selectedHeader = data.list.headers.find((item) => item === itemKey);
43+
if (selectedHeader) {
44+
const sortedList = data.list;
45+
// FIXME: Try to only have 1 sort.
46+
// Need this sort or else you have to click the column names twice to resort when changing columns
47+
sortedList.rows.sort((a, b) => sortFunction(selectedHeader, a, b));
48+
if (prevSelectedHeader === selectedHeader.key) {
49+
if (selectedHeader.key === 'name') {
50+
if (sortDirectionName === 'ASC') {
51+
sortedList.rows.sort((a, b) => sortFunction(selectedHeader, a, b));
52+
} else {
53+
sortedList.rows.sort((a, b) => sortFunction(selectedHeader, b, a));
54+
}
55+
setSortDirectionName(sortDirectionName === 'ASC' ? 'DESC' : 'ASC');
56+
} else {
57+
if (sortDirectionRepository === 'ASC') {
58+
sortedList.rows.sort((a, b) => sortFunction(selectedHeader, a, b));
59+
} else {
60+
sortedList.rows.sort((a, b) => sortFunction(selectedHeader, b, a));
61+
}
62+
setSortDirectionRepository(sortDirectionRepository === 'ASC' ? 'DESC' : 'ASC');
63+
}
64+
} else {
65+
setSortDirectionName('DESC');
66+
setSortDirectionRepository('DESC');
67+
}
68+
const tempKey = `${data.key}-${sortedList.rows[0].id}`;
69+
setPrevSelectedHeader(selectedHeader.key);
70+
setData({
71+
...data, isLoading: false, list: sortedList, key: tempKey,
72+
});
73+
}
74+
};
75+
2176
useEffect(() => {
2277
http.post(`/catalog/ae_tree_select_toggle?typ=${type}`, {}, { headers: {}, skipJsonParsing: true })
2378
.then((_data) => {
24-
API.get('/api/configuration_script_payloads?expand=resources')
79+
const url = '/api/configuration_script_payloads/?expand=resources&attributes=configuration_script_source.name&'
80+
+ 'collection_class=ManageIQ::Providers::Workflows::AutomationManager::Workflow';
81+
API.get(url)
2582
.then((response) => {
2683
setData({
2784
...data,
@@ -81,6 +138,7 @@ const WorkflowEntryPoints = ({
81138
open
82139
modalHeading={sprintf(__('Select Embedded Workflow - %s Entry Point'), workflowTypes[type])}
83140
primaryButtonText={__('Apply')}
141+
primaryButtonDisabled={!data.selectedItemId}
84142
secondaryButtonText={__('Cancel')}
85143
onRequestSubmit={onApply}
86144
onRequestClose={onCloseModal}
@@ -90,6 +148,9 @@ const WorkflowEntryPoints = ({
90148
<MiqDataTable
91149
headers={data.list.headers}
92150
rows={data.list.rows}
151+
sortable
152+
onSort={onSort}
153+
key={data.key}
93154
onCellClick={(selectedRow) => onSelect(selectedRow.id)}
94155
showPagination={false}
95156
truncateText={false}

0 commit comments

Comments
 (0)