-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9225 from nixocio/ui_issue_8670
Add relaunch against failed hosts Reviewed-by: Mat Wilson <[email protected]> https://github.com/one-t
- Loading branch information
Showing
14 changed files
with
313 additions
and
38 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
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
96 changes: 96 additions & 0 deletions
96
awx/ui_next/src/components/LaunchButton/ReLaunchDropDown.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,96 @@ | ||
import React, { useState } from 'react'; | ||
import { withI18n } from '@lingui/react'; | ||
import { t } from '@lingui/macro'; | ||
import { | ||
Dropdown, | ||
DropdownToggle, | ||
DropdownItem, | ||
DropdownPosition, | ||
DropdownSeparator, | ||
DropdownDirection, | ||
} from '@patternfly/react-core'; | ||
import { RocketIcon } from '@patternfly/react-icons'; | ||
|
||
function ReLaunchDropDown({ isPrimary = false, handleRelaunch, i18n }) { | ||
const [isOpen, setIsOPen] = useState(false); | ||
|
||
const onToggle = () => { | ||
setIsOPen(prev => !prev); | ||
}; | ||
|
||
const dropdownItems = [ | ||
<DropdownItem | ||
aria-label={i18n._(t`Relaunch on`)} | ||
key="relaunch_on" | ||
component="div" | ||
isPlainText | ||
> | ||
{i18n._(t`Relaunch on`)} | ||
</DropdownItem>, | ||
<DropdownSeparator key="separator" />, | ||
<DropdownItem | ||
key="relaunch_all" | ||
aria-label={i18n._(t`Relaunch all hosts`)} | ||
component="button" | ||
onClick={() => { | ||
handleRelaunch({ hosts: 'all' }); | ||
}} | ||
> | ||
{i18n._(t`All`)} | ||
</DropdownItem>, | ||
|
||
<DropdownItem | ||
key="relaunch_failed" | ||
aria-label={i18n._(t`Relaunch failed hosts`)} | ||
component="button" | ||
onClick={() => { | ||
handleRelaunch({ hosts: 'failed' }); | ||
}} | ||
> | ||
{i18n._(t`Failed hosts`)} | ||
</DropdownItem>, | ||
]; | ||
|
||
if (isPrimary) { | ||
return ( | ||
<Dropdown | ||
position={DropdownPosition.left} | ||
direction={DropdownDirection.up} | ||
isOpen={isOpen} | ||
dropdownItems={dropdownItems} | ||
toggle={ | ||
<DropdownToggle | ||
toggleIndicator={null} | ||
onToggle={onToggle} | ||
aria-label={i18n._(`relaunch jobs`)} | ||
id="relaunch_jobs" | ||
isPrimary | ||
> | ||
{i18n._(t`Relaunch`)} | ||
</DropdownToggle> | ||
} | ||
/> | ||
); | ||
} | ||
|
||
return ( | ||
<Dropdown | ||
isPlain | ||
position={DropdownPosition.right} | ||
isOpen={isOpen} | ||
dropdownItems={dropdownItems} | ||
toggle={ | ||
<DropdownToggle | ||
toggleIndicator={null} | ||
onToggle={onToggle} | ||
aria-label={i18n._(`relaunch jobs`)} | ||
id="relaunch_jobs" | ||
> | ||
<RocketIcon /> | ||
</DropdownToggle> | ||
} | ||
/> | ||
); | ||
} | ||
|
||
export default withI18n()(ReLaunchDropDown); |
55 changes: 55 additions & 0 deletions
55
awx/ui_next/src/components/LaunchButton/ReLaunchDropDown.test.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,55 @@ | ||
import React from 'react'; | ||
import { mountWithContexts } from '../../../testUtils/enzymeHelpers'; | ||
import ReLaunchDropDown from './ReLaunchDropDown'; | ||
|
||
describe('ReLaunchDropDown', () => { | ||
const handleRelaunch = jest.fn(); | ||
|
||
test('expected content is rendered on initialization', () => { | ||
const wrapper = mountWithContexts( | ||
<ReLaunchDropDown handleRelaunch={handleRelaunch} /> | ||
); | ||
|
||
expect(wrapper.find('Dropdown')).toHaveLength(1); | ||
}); | ||
|
||
test('dropdown have expected items and callbacks', () => { | ||
const wrapper = mountWithContexts( | ||
<ReLaunchDropDown handleRelaunch={handleRelaunch} /> | ||
); | ||
expect(wrapper.find('DropdownItem')).toHaveLength(0); | ||
wrapper.find('button').simulate('click'); | ||
wrapper.update(); | ||
expect(wrapper.find('DropdownItem')).toHaveLength(3); | ||
|
||
wrapper | ||
.find('DropdownItem[aria-label="Relaunch failed hosts"]') | ||
.simulate('click'); | ||
expect(handleRelaunch).toHaveBeenCalledWith({ hosts: 'failed' }); | ||
|
||
wrapper | ||
.find('DropdownItem[aria-label="Relaunch all hosts"]') | ||
.simulate('click'); | ||
expect(handleRelaunch).toHaveBeenCalledWith({ hosts: 'all' }); | ||
}); | ||
|
||
test('dropdown isPrimary have expected items and callbacks', () => { | ||
const wrapper = mountWithContexts( | ||
<ReLaunchDropDown isPrimary handleRelaunch={handleRelaunch} /> | ||
); | ||
expect(wrapper.find('DropdownItem')).toHaveLength(0); | ||
wrapper.find('button').simulate('click'); | ||
wrapper.update(); | ||
expect(wrapper.find('DropdownItem')).toHaveLength(3); | ||
|
||
wrapper | ||
.find('DropdownItem[aria-label="Relaunch failed hosts"]') | ||
.simulate('click'); | ||
expect(handleRelaunch).toHaveBeenCalledWith({ hosts: 'failed' }); | ||
|
||
wrapper | ||
.find('DropdownItem[aria-label="Relaunch all hosts"]') | ||
.simulate('click'); | ||
expect(handleRelaunch).toHaveBeenCalledWith({ hosts: 'all' }); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export { default } from './LaunchButton'; | ||
export { default as LaunchButton } from './LaunchButton'; | ||
export { default as ReLaunchDropDown } from './ReLaunchDropDown'; |
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
Oops, something went wrong.