Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #34260 - add rex features dropdown to host page
- Loading branch information
1 parent
1eedf91
commit 1e337b8
Showing
10 changed files
with
124 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es6", | ||
"paths": { | ||
"foremanReact/*": ["../foreman/webpack/assets/javascripts/react_app/*"] | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { foremanUrl } from 'foremanReact/common/helpers'; | ||
import { sprintf, translate as __ } from 'foremanReact/common/I18n'; | ||
import { post } from 'foremanReact/redux/API'; | ||
|
||
export const runFeature = (hostId, feature, label) => dispatch => { | ||
const url = foremanUrl( | ||
`/job_invocations?feature=${feature}&host_ids%5B%5D=${hostId}` | ||
); | ||
|
||
const successToast = () => sprintf(__('%s job has been invoked'), label); | ||
const errorToast = ({ message }) => message; | ||
dispatch(post({ key: feature.toUpperCase(), url, successToast, errorToast })); | ||
}; |
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,2 @@ | ||
export const REX_FEATURES_API = '/api/remote_execution_features'; | ||
export const NEW_JOB_PAGE = '/job_invocations/new?host_ids%5B%5D'; |
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,73 @@ | ||
import PropTypes from 'prop-types'; | ||
import React, { useState } from 'react'; | ||
import { useDispatch } from 'react-redux'; | ||
import { | ||
DropdownItem, | ||
Dropdown, | ||
DropdownToggle, | ||
DropdownToggleAction, | ||
} from '@patternfly/react-core'; | ||
import { push } from 'connected-react-router'; | ||
|
||
import { useAPI } from 'foremanReact/common/hooks/API/APIHooks'; | ||
import { translate as __ } from 'foremanReact/common/I18n'; | ||
import { foremanUrl } from 'foremanReact/common/helpers'; | ||
import { STATUS } from 'foremanReact/constants'; | ||
|
||
import { REX_FEATURES_API, NEW_JOB_PAGE } from './constant'; | ||
import { runFeature } from './actions'; | ||
|
||
const FeaturesDropdown = ({ hostId }) => { | ||
const [isOpen, setIsOpen] = useState(false); | ||
const { | ||
response: { results: features }, | ||
status, | ||
} = useAPI('get', foremanUrl(REX_FEATURES_API)); | ||
const dispatch = useDispatch(); | ||
const dropdownItems = features | ||
?.filter(feature => feature.host_action_button) | ||
?.map(({ name, label, id, description }) => ( | ||
<DropdownItem | ||
onClick={() => dispatch(runFeature(hostId, label, name))} | ||
key={id} | ||
description={description} | ||
> | ||
{name} | ||
</DropdownItem> | ||
)); | ||
const scheduleJob = [ | ||
<DropdownToggleAction | ||
onClick={() => dispatch(push(`${NEW_JOB_PAGE}=${hostId}`))} | ||
key="schedule-job-action" | ||
> | ||
{__('Schedule a job')} | ||
</DropdownToggleAction>, | ||
]; | ||
|
||
return ( | ||
<Dropdown | ||
alignments={{ default: 'right' }} | ||
onSelect={() => setIsOpen(false)} | ||
toggle={ | ||
<DropdownToggle | ||
splitButtonItems={scheduleJob} | ||
toggleVariant="primary" | ||
onToggle={() => setIsOpen(prev => !prev)} | ||
isDisabled={status === STATUS.PENDING} | ||
splitButtonVariant="action" | ||
/> | ||
} | ||
isOpen={isOpen} | ||
dropdownItems={dropdownItems} | ||
/> | ||
); | ||
}; | ||
|
||
FeaturesDropdown.propTypes = { | ||
hostId: PropTypes.string, | ||
}; | ||
FeaturesDropdown.defaultProps = { | ||
hostId: undefined, | ||
}; | ||
|
||
export default FeaturesDropdown; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import React from 'react'; | ||
import { addGlobalFill } from 'foremanReact/components/common/Fill/GlobalFill'; | ||
import FeaturesDropdown from '../components/FeaturesDropdown'; | ||
|
||
export default () => | ||
addGlobalFill( | ||
'_rex-host-features', | ||
'_rex-host-features', | ||
<FeaturesDropdown key="_rex-host-features" />, | ||
1000 | ||
); |