Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ const AutomateEntryPoints = ({

return !isLoading && (
<Modal
modalHeading={__('Select Entry Point Instance')}
open={showModal}
primaryButtonText={__('OK')}
secondaryButtonText={__('Cancel')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ const provisionTabSchema = (
return schema;
};


const createSchema = ({
data,
setData,
Expand Down
8 changes: 5 additions & 3 deletions app/javascript/components/workflows/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@ import { rowData } from '../miq-data-table/helper';

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

/** Function to return the cell data for a row item. */
const celInfo = (workflow) => [
const cellInfo = (workflow) => [
{ text: workflow.configuration_script_source ? workflow.configuration_script_source.name : '' },
{ text: workflow.name },
];

/** Function to return the row information for the list */
const rowInfo = (headers, response) => {
const headerKeys = headers.map((item) => item.key);
const rows = response.resources.filter((item) => item.payload).map((workflow) => ({
id: workflow.id.toString(), cells: celInfo(workflow), clickable: true,
id: workflow.id.toString(), cells: cellInfo(workflow), clickable: true,
}));
const miqRows = rowData(headerKeys, rows, false);
return miqRows.rowItems;
Expand Down
65 changes: 63 additions & 2 deletions app/javascript/components/workflows/workflow-entry-points.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,76 @@ const WorkflowEntryPoints = ({
field, selected, type, setShowModal, setSelectedValue,
}) => {
const [data, setData] = useState({
isLoading: true, list: {}, selectedItemId: selected,
isLoading: true, list: {}, selectedItemId: selected, key: 'workflow-entry-points',
});
const [prevSelectedHeader, setPrevSelectedHeader] = useState('');
const [sortDirectionRepository, setSortDirectionRepository] = useState('DESC');
const [sortDirectionName, setSortDirectionName] = useState('DESC');

const workflowTypes = {
provision: __('Provision'),
reconfigure: __('Reconfigure'),
retire: __('Retirement'),
};

const sortFunction = (selectedHeader, itemA, itemB) => {
if (selectedHeader.key === 'name') {
if (itemA.name.text === itemB.name.text) {
return itemA.id - itemB.id;
}
return itemA.name.text.localeCompare(itemB.name.text, undefined, { sensitivity: 'base' });
}
if (itemA['configuration_script_source.name'] === undefined) {
itemA['configuration_script_source.name'] = { text: '' };
} else if (itemB['configuration_script_source.name'] === undefined) {
itemB['configuration_script_source.name'] = { text: '' };
}
return itemA['configuration_script_source.name'].text.localeCompare(
itemB['configuration_script_source.name'].text, undefined, { semsitivity: 'base' }
);
};

const onSort = (itemKey) => {
const selectedHeader = data.list.headers.find((item) => item === itemKey);
if (selectedHeader) {
const sortedList = data.list;
// FIXME: Try to only have 1 sort.
// Need this sort or else you have to click the column names twice to resort when changing columns
sortedList.rows.sort((a, b) => sortFunction(selectedHeader, a, b));
if (prevSelectedHeader === selectedHeader.key) {
if (selectedHeader.key === 'name') {
if (sortDirectionName === 'ASC') {
sortedList.rows.sort((a, b) => sortFunction(selectedHeader, a, b));
} else {
sortedList.rows.sort((a, b) => sortFunction(selectedHeader, b, a));
}
setSortDirectionName(sortDirectionName === 'ASC' ? 'DESC' : 'ASC');
} else {
if (sortDirectionRepository === 'ASC') {
sortedList.rows.sort((a, b) => sortFunction(selectedHeader, a, b));
} else {
sortedList.rows.sort((a, b) => sortFunction(selectedHeader, b, a));
}
setSortDirectionRepository(sortDirectionRepository === 'ASC' ? 'DESC' : 'ASC');
}
} else {
setSortDirectionName('DESC');
setSortDirectionRepository('DESC');
}
const tempKey = `${data.key}-${sortedList.rows[0].id}`;
setPrevSelectedHeader(selectedHeader.key);
setData({
...data, isLoading: false, list: sortedList, key: tempKey,
});
}
};

useEffect(() => {
http.post(`/catalog/ae_tree_select_toggle?typ=${type}`, {}, { headers: {}, skipJsonParsing: true })
.then((_data) => {
API.get('/api/configuration_script_payloads?expand=resources')
const url = '/api/configuration_script_payloads/?expand=resources&attributes=configuration_script_source.name&'
+ 'collection_class=ManageIQ::Providers::Workflows::AutomationManager::Workflow';
API.get(url)
.then((response) => {
setData({
...data,
Expand Down Expand Up @@ -81,6 +138,7 @@ const WorkflowEntryPoints = ({
open
modalHeading={sprintf(__('Select Embedded Workflow - %s Entry Point'), workflowTypes[type])}
primaryButtonText={__('Apply')}
primaryButtonDisabled={!data.selectedItemId}
secondaryButtonText={__('Cancel')}
onRequestSubmit={onApply}
onRequestClose={onCloseModal}
Expand All @@ -90,6 +148,9 @@ const WorkflowEntryPoints = ({
<MiqDataTable
headers={data.list.headers}
rows={data.list.rows}
sortable
onSort={onSort}
key={data.key}
onCellClick={(selectedRow) => onSelect(selectedRow.id)}
showPagination={false}
truncateText={false}
Expand Down
Loading