-
Notifications
You must be signed in to change notification settings - Fork 356
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add embedded automate react component
- Loading branch information
1 parent
e252cf3
commit eef6e5b
Showing
7 changed files
with
152 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
app/javascript/components/automate-entry-points/index.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { Loading, Modal, ModalBody } from 'carbon-components-react'; | ||
import MiqDataTable from '../miq-data-table'; | ||
import { http } from '../../http_api'; | ||
|
||
const AutomateEntryPoints = ({ | ||
field, selected, type, setShowModal, setSelectedValue, | ||
}) => { | ||
const [data, setData] = useState({ | ||
isLoading: true, list: {}, selectedItemId: selected, | ||
}); | ||
|
||
const workflowTypes = { | ||
provision: __('Provision'), | ||
reconfigure: __('Reconfigure'), | ||
retire: __('Retirement'), | ||
}; | ||
|
||
useEffect(() => { | ||
http.post(`/catalog/ae_tree_load?typ=${type}`, {}, { headers: {}, skipJsonParsing: true }) | ||
.then((_data) => { | ||
console.log(data); | ||
API.get('/api/automate_domains?expand=resources') | ||
.then((response) => { | ||
console.log(response); | ||
// API.get('/api/automate_workspaces?expand=resources').then((response) => { | ||
// console.log(response); | ||
// }); | ||
setData({ | ||
...data, | ||
isLoading: false, | ||
}); | ||
}); | ||
}); | ||
}, []); | ||
|
||
/** Function to handle a row's click event. */ | ||
const onSelect = (selectedItemId) => { | ||
setData({ | ||
...data, | ||
selectedItemId: (data.selectedItemId === selectedItemId) ? undefined : selectedItemId, | ||
}); | ||
const params = `cfp-${encodeURIComponent(selectedItemId)}&tree=automate_catalog_tree&field=${field}`; | ||
window.miqJqueryRequest(`/catalog/ae_tree_select/?id=${params}&typ=${type}`); | ||
}; | ||
if (data.isLoading) { | ||
return (<Loading active small withOverlay={false} className="loading" />); | ||
} | ||
/** Function to handle the modal box close button click event. */ | ||
const onCloseModal = () => { | ||
if (setShowModal) { | ||
setShowModal(false); | ||
} else { | ||
document.getElementById(`${type}-workflows`).innerHTML = ''; | ||
http.post('/catalog/ae_tree_select_toggle?button=cancel', {}, { headers: {}, skipJsonParsing: true }); | ||
} | ||
}; | ||
/** Function to handle the modal box apply button click event. */ | ||
const onApply = () => { | ||
const seletedItem = data.list.rows.find((item) => item.id === data.selectedItemId); | ||
const name = seletedItem.name.text; | ||
if (seletedItem) { | ||
if (setShowModal && setSelectedValue) { | ||
setShowModal(false); | ||
setSelectedValue(seletedItem); | ||
} else { | ||
const nameField = document.getElementById(field); | ||
const selectedField = document.getElementById(`${type}_configuration_script_id`); | ||
|
||
if (nameField && selectedField) { | ||
nameField.value = name; | ||
selectedField.value = data.selectedItemId; | ||
http.post('/catalog/ae_tree_select_toggle?button=submit&automation_type=workflow', {}, { headers: {}, skipJsonParsing: true }) | ||
.then((_data) => { | ||
document.getElementById(`${type}-workflows`).innerHTML = ''; | ||
}); | ||
} | ||
} | ||
} | ||
}; | ||
return ( | ||
<Modal | ||
open | ||
modalHeading={sprintf(__('Select Embedded Workflow - %s Entry Point'), workflowTypes[type])} | ||
primaryButtonText={__('Apply')} | ||
secondaryButtonText={__('Cancel')} | ||
onRequestSubmit={onApply} | ||
onRequestClose={onCloseModal} | ||
className="workflows-entry-point-modal" | ||
> | ||
<ModalBody className="workflows-entry-point-modal-body"> | ||
<MiqDataTable | ||
headers={data.list.headers} | ||
rows={data.list.rows} | ||
onCellClick={(selectedRow) => onSelect(selectedRow.id)} | ||
showPagination={false} | ||
truncateText={false} | ||
mode="automated-workflow-entry-points" | ||
gridChecks={[data.selectedItemId]} | ||
size="md" | ||
/> | ||
</ModalBody> | ||
</Modal> | ||
); | ||
}; | ||
AutomateEntryPoints.propTypes = { | ||
field: PropTypes.string.isRequired, | ||
type: PropTypes.string.isRequired, | ||
selected: PropTypes.string, | ||
setShowModal: PropTypes.func, | ||
setSelectedValue: PropTypes.func, | ||
}; | ||
|
||
AutomateEntryPoints.defaultProps = { | ||
selected: '', | ||
setShowModal: undefined, | ||
setSelectedValue: undefined, | ||
}; | ||
|
||
export default AutomateEntryPoints; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters