diff --git a/awx/ui_next/src/screens/Host/shared/HostToggle.jsx b/awx/ui_next/src/components/HostToggle/HostToggle.jsx
similarity index 100%
rename from awx/ui_next/src/screens/Host/shared/HostToggle.jsx
rename to awx/ui_next/src/components/HostToggle/HostToggle.jsx
diff --git a/awx/ui_next/src/screens/Host/shared/HostToggle.test.jsx b/awx/ui_next/src/components/HostToggle/HostToggle.test.jsx
similarity index 100%
rename from awx/ui_next/src/screens/Host/shared/HostToggle.test.jsx
rename to awx/ui_next/src/components/HostToggle/HostToggle.test.jsx
diff --git a/awx/ui_next/src/components/HostToggle/index.js b/awx/ui_next/src/components/HostToggle/index.js
new file mode 100644
index 0000000000..4a772fa95e
--- /dev/null
+++ b/awx/ui_next/src/components/HostToggle/index.js
@@ -0,0 +1 @@
+export { default } from './HostToggle';
diff --git a/awx/ui_next/src/screens/Host/HostDetail/HostDetail.jsx b/awx/ui_next/src/screens/Host/HostDetail/HostDetail.jsx
index 7e03abc736..92924886b5 100644
--- a/awx/ui_next/src/screens/Host/HostDetail/HostDetail.jsx
+++ b/awx/ui_next/src/screens/Host/HostDetail/HostDetail.jsx
@@ -12,7 +12,7 @@ import { VariablesDetail } from '@components/CodeMirrorInput';
import Sparkline from '@components/Sparkline';
import DeleteButton from '@components/DeleteButton';
import { HostsAPI } from '@api';
-import HostToggle from '../shared/HostToggle';
+import HostToggle from '@components/HostToggle';
function HostDetail({ host, i18n, onUpdateHost }) {
const {
diff --git a/awx/ui_next/src/screens/Host/HostList/HostList.test.jsx b/awx/ui_next/src/screens/Host/HostList/HostList.test.jsx
index dbd6199a92..89bc038deb 100644
--- a/awx/ui_next/src/screens/Host/HostList/HostList.test.jsx
+++ b/awx/ui_next/src/screens/Host/HostList/HostList.test.jsx
@@ -121,7 +121,7 @@ describe('', () => {
expect(wrapper.find('HostListItem')).toHaveLength(3);
});
- test('should select single item', async () => {
+ test('should select and deselect a single item', async () => {
let wrapper;
await act(async () => {
wrapper = mountWithContexts();
@@ -141,6 +141,19 @@ describe('', () => {
.first()
.prop('isSelected')
).toEqual(true);
+ act(() => {
+ wrapper
+ .find('input#select-host-1')
+ .closest('DataListCheck')
+ .invoke('onChange')();
+ });
+ wrapper.update();
+ expect(
+ wrapper
+ .find('HostListItem')
+ .first()
+ .prop('isSelected')
+ ).toEqual(false);
});
test('should select all items', async () => {
diff --git a/awx/ui_next/src/screens/Host/HostList/HostListItem.jsx b/awx/ui_next/src/screens/Host/HostList/HostListItem.jsx
index 21c238fb23..fec58640a6 100644
--- a/awx/ui_next/src/screens/Host/HostList/HostListItem.jsx
+++ b/awx/ui_next/src/screens/Host/HostList/HostListItem.jsx
@@ -18,7 +18,7 @@ import { PencilAltIcon } from '@patternfly/react-icons';
import Sparkline from '@components/Sparkline';
import { Host } from '@types';
import styled from 'styled-components';
-import HostToggle from '../shared/HostToggle';
+import HostToggle from '@components/HostToggle';
const DataListAction = styled(_DataListAction)`
align-items: center;
diff --git a/awx/ui_next/src/screens/Host/HostList/HostListItem.test.jsx b/awx/ui_next/src/screens/Host/HostList/HostListItem.test.jsx
index c4958e11c2..a241f319cb 100644
--- a/awx/ui_next/src/screens/Host/HostList/HostListItem.test.jsx
+++ b/awx/ui_next/src/screens/Host/HostList/HostListItem.test.jsx
@@ -3,8 +3,6 @@ import { mountWithContexts } from '@testUtils/enzymeHelpers';
import HostsListItem from './HostListItem';
-const onToggleHost = jest.fn();
-
const mockHost = {
id: 1,
name: 'Host 1',
@@ -32,13 +30,12 @@ describe('', () => {
detailUrl="/host/1"
onSelect={() => {}}
host={mockHost}
- onToggleHost={onToggleHost}
/>
);
});
afterEach(() => {
- jest.clearAllMocks();
+ wrapper.unmount();
});
test('edit button shown to users with edit capabilities', () => {
@@ -54,7 +51,6 @@ describe('', () => {
detailUrl="/host/1"
onSelect={() => {}}
host={copyMockHost}
- onToggleHost={onToggleHost}
/>
);
expect(wrapper.find('PencilAltIcon').exists()).toBeFalsy();
diff --git a/awx/ui_next/src/screens/Inventory/InventoryHosts/InventoryHostItem.jsx b/awx/ui_next/src/screens/Inventory/InventoryHosts/InventoryHostItem.jsx
index cf7678f0e3..863b5fb168 100644
--- a/awx/ui_next/src/screens/Inventory/InventoryHosts/InventoryHostItem.jsx
+++ b/awx/ui_next/src/screens/Inventory/InventoryHosts/InventoryHostItem.jsx
@@ -10,11 +10,11 @@ import {
DataListItem,
DataListItemCells,
DataListItemRow,
- Switch,
Tooltip,
} from '@patternfly/react-core';
import { Link } from 'react-router-dom';
import { PencilAltIcon } from '@patternfly/react-icons';
+import HostToggle from '@components/HostToggle';
import Sparkline from '@components/Sparkline';
import { Host } from '@types';
import styled from 'styled-components';
@@ -27,16 +27,7 @@ const DataListAction = styled(_DataListAction)`
`;
function InventoryHostItem(props) {
- const {
- detailUrl,
- editUrl,
- host,
- i18n,
- isSelected,
- onSelect,
- toggleHost,
- toggleLoading,
- } = props;
+ const { detailUrl, editUrl, host, i18n, isSelected, onSelect } = props;
const recentPlaybookJobs = host.summary_fields.recent_jobs.map(job => ({
...job,
@@ -71,27 +62,7 @@ function InventoryHostItem(props) {
aria-labelledby={labelId}
id={labelId}
>
-
- toggleHost(host)}
- aria-label={i18n._(t`Toggle host`)}
- />
-
+
{host.summary_fields.user_capabilities?.edit && (