From 3ea37e1c798c6d316746e7ac19e56a9ea17d2867 Mon Sep 17 00:00:00 2001 From: Alex Corey Date: Tue, 3 Dec 2019 15:49:36 -0500 Subject: [PATCH] Addresses PR issues Adds Delete Modal for deleting from Details view Adds test for delete modal Addresses styling for Variables label Removes X close button from form --- .../InventoryGroup/InventoryGroup.jsx | 14 ++- .../InventoryGroupDetail.jsx | 86 ++++++++++++++++--- .../InventoryGroupDetail.test.jsx | 18 ++-- .../InventoryGroupForm/InventoryGroupForm.jsx | 9 +- 4 files changed, 95 insertions(+), 32 deletions(-) diff --git a/awx/ui_next/src/screens/Inventory/InventoryGroups/InventoryGroup/InventoryGroup.jsx b/awx/ui_next/src/screens/Inventory/InventoryGroups/InventoryGroup/InventoryGroup.jsx index 9a4994c8fe..d665c19176 100644 --- a/awx/ui_next/src/screens/Inventory/InventoryGroups/InventoryGroup/InventoryGroup.jsx +++ b/awx/ui_next/src/screens/Inventory/InventoryGroups/InventoryGroup/InventoryGroup.jsx @@ -51,14 +51,24 @@ function InventoryGroups({ i18n, match, setBreadcrumb, inventory }) { key="edit" path="/inventories/inventory/:id/groups/:groupId/edit" render={() => { - return ; + return ( + + ); }} />, { - return ; + return ( + + ); }} />, { try { await GroupsAPI.destroy(inventoryGroup.id); @@ -29,10 +33,42 @@ function InventoryGroupDetail({ i18n, history, match, inventoryGroup }) { setError(err); } }; - if (error) { return ; } + if (isDeleteModalOpen) { + return ( + setIsDeleteModalOpen(false)} + actions={[ + , + , + ]} + > + {i18n._(t`Are you sure you want to delete:`)} +
+ {inventoryGroup.name} +
+
+ ); + } return ( @@ -41,23 +77,47 @@ function InventoryGroupDetail({ i18n, history, match, inventoryGroup }) { label={i18n._(t`Description`)} value={inventoryGroup.description} /> + + } + /> - + {i18n._(t`${formatDateString(inventoryGroup.created)} by`)}{' '} + + {inventoryGroup.summary_fields.created_by.username} + + + } /> + {i18n._(t`${formatDateString(inventoryGroup.modified)} by`)}{' '} + + {inventoryGroup.summary_fields.modified_by.username} + + + } /> @@ -75,7 +135,7 @@ function InventoryGroupDetail({ i18n, history, match, inventoryGroup }) { diff --git a/awx/ui_next/src/screens/Inventory/InventoryGroups/InventoryGroupDetail/InventoryGroupDetail.test.jsx b/awx/ui_next/src/screens/Inventory/InventoryGroups/InventoryGroupDetail/InventoryGroupDetail.test.jsx index d1803d1928..2a762aa435 100644 --- a/awx/ui_next/src/screens/Inventory/InventoryGroups/InventoryGroupDetail/InventoryGroupDetail.test.jsx +++ b/awx/ui_next/src/screens/Inventory/InventoryGroups/InventoryGroupDetail/InventoryGroupDetail.test.jsx @@ -13,14 +13,16 @@ const inventoryGroup = { description: 'Bar', variables: 'bizz: buzz', id: 1, - created: '10:00', - modified: '12:00', + created: '2019-12-02T15:58:16.276813Z', + modified: '2019-12-03T20:33:46.207654Z', summary_fields: { created_by: { username: 'James', + id: 13, }, modified_by: { username: 'Bond', + id: 14, }, }, }; @@ -49,8 +51,10 @@ describe('', () => { test('InventoryGroupDetail renders successfully', () => { expect(wrapper.length).toBe(1); }); - test('should call api to delete the group', () => { + test('should open delete modal and then call api to delete the group', () => { wrapper.find('button[aria-label="Delete"]').simulate('click'); + expect(wrapper.find('Modal').length).toBe(1); + wrapper.find('button[aria-label="confirm delete"]').simulate('click'); expect(GroupsAPI.destroy).toBeCalledWith(1); }); test('should navigate user to edit form on edit button click', async () => { @@ -67,12 +71,8 @@ describe('', () => { expect(wrapper.find('Detail[label="Description"]').prop('value')).toBe( 'Bar' ); - expect(wrapper.find('Detail[label="Created"]').prop('value')).toBe( - '10:00 by James' - ); - expect(wrapper.find('Detail[label="Modified"]').prop('value')).toBe( - '12:00 by Bond' - ); + expect(wrapper.find('Detail[label="Created"]').length).toBe(1); + expect(wrapper.find('Detail[label="Modified"]').length).toBe(1); expect(wrapper.find('VariablesInput').prop('value')).toBe('bizz: buzz'); }); }); diff --git a/awx/ui_next/src/screens/Inventory/InventoryGroups/InventoryGroupForm/InventoryGroupForm.jsx b/awx/ui_next/src/screens/Inventory/InventoryGroups/InventoryGroupForm/InventoryGroupForm.jsx index 0ae49c22d4..f6dea49aee 100644 --- a/awx/ui_next/src/screens/Inventory/InventoryGroups/InventoryGroupForm/InventoryGroupForm.jsx +++ b/awx/ui_next/src/screens/Inventory/InventoryGroups/InventoryGroupForm/InventoryGroupForm.jsx @@ -2,10 +2,9 @@ import React from 'react'; import { withRouter } from 'react-router-dom'; import { withI18n } from '@lingui/react'; import { Formik } from 'formik'; -import { Form, Card, CardBody, CardHeader } from '@patternfly/react-core'; +import { Form, Card, CardBody } from '@patternfly/react-core'; import { t } from '@lingui/macro'; -import CardCloseButton from '@components/CardCloseButton'; import FormRow from '@components/FormRow'; import FormField from '@components/FormField'; import FormActionGroup from '@components/FormActionGroup/FormActionGroup'; @@ -18,7 +17,6 @@ function InventoryGroupForm({ group = {}, handleSubmit, handleCancel, - match, }) { const initialValues = { name: group.name || '', @@ -28,11 +26,6 @@ function InventoryGroupForm({ return ( - - -