diff --git a/awx/ui_next/src/components/AddDropDownButton/AddDropDownButton.jsx b/awx/ui_next/src/components/AddDropDownButton/AddDropDownButton.jsx index bd56d3d1a4..9296fc1f17 100644 --- a/awx/ui_next/src/components/AddDropDownButton/AddDropDownButton.jsx +++ b/awx/ui_next/src/components/AddDropDownButton/AddDropDownButton.jsx @@ -1,10 +1,9 @@ import React, { useState, useRef, useEffect } from 'react'; -import { Link, withRouter } from 'react-router-dom'; -import { withI18n } from '@lingui/react'; +import { Link } from 'react-router-dom'; import { Dropdown, DropdownPosition } from '@patternfly/react-core'; import { ToolbarAddButton } from '@components/PaginatedDataList'; -function AddDropDownButton({ topUrl, bottomUrl, topLabel, bottomLabel }) { +function AddDropDownButton({ dropdownItems }) { const [isOpen, setIsOpen] = useState(false); const element = useRef(null); @@ -28,22 +27,19 @@ function AddDropDownButton({ topUrl, bottomUrl, topLabel, bottomLabel }) { isOpen={isOpen} position={DropdownPosition.right} toggle={ setIsOpen(!isOpen)} />} - dropdownItems={[ - - {`${topLabel}`} - , + dropdownItems={dropdownItems.map(item => ( - {`${bottomLabel}`} - , - ]} + {item.label} + + ))} /> ); } export { AddDropDownButton as _AddDropDownButton }; -export default withI18n()(withRouter(AddDropDownButton)); +export default AddDropDownButton; diff --git a/awx/ui_next/src/components/AddDropDownButton/AddDropDownButton.test.jsx b/awx/ui_next/src/components/AddDropDownButton/AddDropDownButton.test.jsx index a6e4c1b1a3..a30e3f9cd8 100644 --- a/awx/ui_next/src/components/AddDropDownButton/AddDropDownButton.test.jsx +++ b/awx/ui_next/src/components/AddDropDownButton/AddDropDownButton.test.jsx @@ -3,20 +3,33 @@ import { mountWithContexts } from '@testUtils/enzymeHelpers'; import AddDropDownButton from './AddDropDownButton'; describe('', () => { + const dropdownItems = [ + { + key: 'inventory', + label: 'Inventory', + url: `inventory/inventory/add/`, + }, + ]; test('should be closed initially', () => { - const wrapper = mountWithContexts(); + const wrapper = mountWithContexts( + + ); expect(wrapper.find('Dropdown').prop('isOpen')).toEqual(false); }); test('should render two links', () => { - const wrapper = mountWithContexts(); + const wrapper = mountWithContexts( + + ); wrapper.find('button').simulate('click'); expect(wrapper.find('Dropdown').prop('isOpen')).toEqual(true); - expect(wrapper.find('Link')).toHaveLength(2); + expect(wrapper.find('Link')).toHaveLength(dropdownItems.length); }); test('should close when button re-clicked', () => { - const wrapper = mountWithContexts(); + const wrapper = mountWithContexts( + + ); wrapper.find('button').simulate('click'); expect(wrapper.find('Dropdown').prop('isOpen')).toEqual(true); wrapper.find('button').simulate('click'); diff --git a/awx/ui_next/src/components/AddDropDownButton/index.js b/awx/ui_next/src/components/AddDropDownButton/index.js index 1ba2828957..8c87c7df31 100644 --- a/awx/ui_next/src/components/AddDropDownButton/index.js +++ b/awx/ui_next/src/components/AddDropDownButton/index.js @@ -1,4 +1 @@ -export { - default -} -from './AddDropDownButton' +export { default } from './AddDropDownButton'; diff --git a/awx/ui_next/src/screens/Inventory/InventoryList/InventoryList.jsx b/awx/ui_next/src/screens/Inventory/InventoryList/InventoryList.jsx index fa8ac6e584..da87e832b9 100644 --- a/awx/ui_next/src/screens/Inventory/InventoryList/InventoryList.jsx +++ b/awx/ui_next/src/screens/Inventory/InventoryList/InventoryList.jsx @@ -36,7 +36,6 @@ class InventoriesList extends Component { selected: [], inventories: [], itemCount: 0, - isAddOpen: false, }; this.loadInventories = this.loadInventories.bind(this); @@ -44,7 +43,6 @@ class InventoriesList extends Component { this.handleSelect = this.handleSelect.bind(this); this.handleInventoryDelete = this.handleInventoryDelete.bind(this); this.handleDeleteErrorClose = this.handleDeleteErrorClose.bind(this); - this.handleAddToggle = this.handleAddToggle.bind(this); } componentDidMount() { @@ -78,18 +76,6 @@ class InventoriesList extends Component { } } - handleAddToggle(e) { - const { isAddOpen } = this.state; - - if (this.node && this.node.contains(e.target) && isAddOpen) { - this.setState({ isAddOpen: false }); - } else if (this.node && this.node.contains(e.target) && !isAddOpen) { - this.setState({ isAddOpen: true }); - } else { - this.setState({ isAddOpen: false }); - } - } - async handleInventoryDelete() { const { selected, itemCount } = this.state; @@ -155,14 +141,29 @@ class InventoriesList extends Component { inventories, itemCount, selected, - isAddOpen, actions, } = this.state; const { match, i18n } = this.props; const canAdd = actions && Object.prototype.hasOwnProperty.call(actions, 'POST'); - const isAllSelected = - selected.length > 0 && selected.length === inventories.length; + const isAllSelected = selected.length === inventories.length; + const addButton = ( + + ); return ( @@ -208,15 +209,7 @@ class InventoriesList extends Component { itemsToDelete={selected} pluralizedItemName="Inventories" />, - canAdd && ( - - ), + canAdd && addButton, ]} /> )} @@ -234,17 +227,7 @@ class InventoriesList extends Component { isSelected={selected.some(row => row.id === inventory.id)} /> )} - emptyStateControls={ - canAdd && ( - - ) - } + emptyStateControls={canAdd && addButton} /> 0; + const addButton = ( + + ); return ( @@ -206,15 +223,7 @@ class TemplatesList extends Component { itemsToDelete={selected} pluralizedItemName="Templates" />, - canAdd && ( - - ), + canAdd && addButton, ]} /> )} @@ -228,17 +237,7 @@ class TemplatesList extends Component { isSelected={selected.some(row => row.id === template.id)} /> )} - emptyStateControls={ - canAdd && ( - - ) - } + emptyStateControls={canAdd && addButton} />