mirror of
https://github.com/ansible/awx.git
synced 2026-04-07 02:59:21 -02:30
Adds Promote Delete Modal To InventoryGroupDetails
It also removes a comment/reminder to remove some code after CredentialsLookUp refactor was completed. Now that it has been completed that code has been removed.
This commit is contained in:
@@ -9,9 +9,9 @@ import { VariablesDetail } from '@components/CodeMirrorInput';
|
|||||||
import { CardBody } from '@components/Card';
|
import { CardBody } from '@components/Card';
|
||||||
import ErrorDetail from '@components/ErrorDetail';
|
import ErrorDetail from '@components/ErrorDetail';
|
||||||
import AlertModal from '@components/AlertModal';
|
import AlertModal from '@components/AlertModal';
|
||||||
|
|
||||||
import { GroupsAPI } from '@api';
|
|
||||||
import { DetailList, Detail, UserDateDetail } from '@components/DetailList';
|
import { DetailList, Detail, UserDateDetail } from '@components/DetailList';
|
||||||
|
import InventoryGroupsDeleteModal from '../shared/InventoryGroupsDeleteModal';
|
||||||
|
import { GroupsAPI, InventoriesAPI } from '@api';
|
||||||
|
|
||||||
// TODO: extract this into a component for use in all relevant Detail views
|
// TODO: extract this into a component for use in all relevant Detail views
|
||||||
const ActionButtonWrapper = styled.div`
|
const ActionButtonWrapper = styled.div`
|
||||||
@@ -34,11 +34,14 @@ function InventoryGroupDetail({ i18n, history, match, inventoryGroup }) {
|
|||||||
} = inventoryGroup;
|
} = inventoryGroup;
|
||||||
const [error, setError] = useState(false);
|
const [error, setError] = useState(false);
|
||||||
const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false);
|
const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false);
|
||||||
|
const handleDelete = async option => {
|
||||||
const handleDelete = async () => {
|
|
||||||
setIsDeleteModalOpen(false);
|
setIsDeleteModalOpen(false);
|
||||||
try {
|
try {
|
||||||
await GroupsAPI.destroy(inventoryGroup.id);
|
if (option === 'delete') {
|
||||||
|
await GroupsAPI.destroy(inventoryGroup.id);
|
||||||
|
} else {
|
||||||
|
await InventoriesAPI.promoteGroup(match.params.id, inventoryGroup.id);
|
||||||
|
}
|
||||||
history.push(`/inventories/inventory/${match.params.id}/groups`);
|
history.push(`/inventories/inventory/${match.params.id}/groups`);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setError(err);
|
setError(err);
|
||||||
@@ -87,35 +90,12 @@ function InventoryGroupDetail({ i18n, history, match, inventoryGroup }) {
|
|||||||
</Button>
|
</Button>
|
||||||
</ActionButtonWrapper>
|
</ActionButtonWrapper>
|
||||||
{isDeleteModalOpen && (
|
{isDeleteModalOpen && (
|
||||||
<AlertModal
|
<InventoryGroupsDeleteModal
|
||||||
variant="danger"
|
groups={[inventoryGroup]}
|
||||||
title={i18n._(t`Delete Inventory Group`)}
|
|
||||||
isOpen={isDeleteModalOpen}
|
|
||||||
onClose={() => setIsDeleteModalOpen(false)}
|
onClose={() => setIsDeleteModalOpen(false)}
|
||||||
actions={[
|
isModalOpen={isDeleteModalOpen}
|
||||||
<Button
|
onDelete={handleDelete}
|
||||||
key="delete"
|
/>
|
||||||
variant="danger"
|
|
||||||
aria-label={i18n._(t`confirm delete`)}
|
|
||||||
onClick={handleDelete}
|
|
||||||
>
|
|
||||||
{i18n._(t`Delete`)}
|
|
||||||
</Button>,
|
|
||||||
<Button
|
|
||||||
key="cancel"
|
|
||||||
variant="secondary"
|
|
||||||
aria-label={i18n._(t`cancel delete`)}
|
|
||||||
onClick={() => setIsDeleteModalOpen(false)}
|
|
||||||
>
|
|
||||||
{i18n._(t`Cancel`)}
|
|
||||||
</Button>,
|
|
||||||
]}
|
|
||||||
>
|
|
||||||
{i18n._(t`Are you sure you want to delete:`)}
|
|
||||||
<br />
|
|
||||||
<strong>{inventoryGroup.name}</strong>
|
|
||||||
<br />
|
|
||||||
</AlertModal>
|
|
||||||
)}
|
)}
|
||||||
{error && (
|
{error && (
|
||||||
<AlertModal
|
<AlertModal
|
||||||
|
|||||||
@@ -44,7 +44,13 @@ describe('<InventoryGroupDetail />', () => {
|
|||||||
/>,
|
/>,
|
||||||
{
|
{
|
||||||
context: {
|
context: {
|
||||||
router: { history, route: { location: history.location } },
|
router: {
|
||||||
|
history,
|
||||||
|
route: {
|
||||||
|
location: history.location,
|
||||||
|
match: { params: { id: 1 } },
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -64,7 +70,13 @@ describe('<InventoryGroupDetail />', () => {
|
|||||||
await waitForElement(wrapper, 'Modal', el => el.length === 1);
|
await waitForElement(wrapper, 'Modal', el => el.length === 1);
|
||||||
expect(wrapper.find('Modal').length).toBe(1);
|
expect(wrapper.find('Modal').length).toBe(1);
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
wrapper.find('button[aria-label="confirm delete"]').simulate('click');
|
wrapper.find('Radio[id="radio-delete"]').invoke('onChange')();
|
||||||
|
});
|
||||||
|
wrapper.update();
|
||||||
|
await act(async () => {
|
||||||
|
wrapper
|
||||||
|
.find('ModalBoxFooter Button[aria-label="Delete"]')
|
||||||
|
.invoke('onClick')();
|
||||||
});
|
});
|
||||||
expect(GroupsAPI.destroy).toBeCalledWith(1);
|
expect(GroupsAPI.destroy).toBeCalledWith(1);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -91,14 +91,9 @@ function InventoryForm({
|
|||||||
<CredentialLookup
|
<CredentialLookup
|
||||||
label={i18n._(t`Insights Credential`)}
|
label={i18n._(t`Insights Credential`)}
|
||||||
credentialTypeId={credentialTypeId}
|
credentialTypeId={credentialTypeId}
|
||||||
onChange={value => {
|
onChange={value =>
|
||||||
// TODO: BELOW SHOULD BE REFACTORED AND REMOVED ONCE THE LOOKUP REFACTOR
|
form.setFieldValue('insights_credential', value)
|
||||||
// GOES INTO PLACE.
|
}
|
||||||
if (value[0] === field.value) {
|
|
||||||
return form.setFieldValue('insights_credential', null);
|
|
||||||
}
|
|
||||||
return form.setFieldValue('insights_credential', value);
|
|
||||||
}}
|
|
||||||
value={field.value}
|
value={field.value}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|||||||
Reference in New Issue
Block a user