From 6a7f7a0256a05c6e43a9e6f3291b101cd8616032 Mon Sep 17 00:00:00 2001 From: mabashian Date: Fri, 15 Jan 2021 14:50:41 -0500 Subject: [PATCH] Move smart inventory button out to it's own component to properly handle kebabification --- .../src/screens/Host/HostList/HostList.jsx | 31 +++-------- .../Host/HostList/SmartInventoryButton.jsx | 53 +++++++++++++++++++ .../HostList/SmartInventoryButton.test.jsx | 16 ++++++ 3 files changed, 75 insertions(+), 25 deletions(-) create mode 100644 awx/ui_next/src/screens/Host/HostList/SmartInventoryButton.jsx create mode 100644 awx/ui_next/src/screens/Host/HostList/SmartInventoryButton.test.jsx diff --git a/awx/ui_next/src/screens/Host/HostList/HostList.jsx b/awx/ui_next/src/screens/Host/HostList/HostList.jsx index d62bae0d32..0fabce1b60 100644 --- a/awx/ui_next/src/screens/Host/HostList/HostList.jsx +++ b/awx/ui_next/src/screens/Host/HostList/HostList.jsx @@ -2,7 +2,7 @@ import React, { useState, useEffect, useCallback } from 'react'; import { useHistory, useLocation, useRouteMatch } from 'react-router-dom'; import { withI18n } from '@lingui/react'; import { t } from '@lingui/macro'; -import { Button, Card, PageSection, Tooltip } from '@patternfly/react-core'; +import { Card, PageSection } from '@patternfly/react-core'; import { HostsAPI } from '../../../api'; import AlertModal from '../../../components/AlertModal'; @@ -20,6 +20,7 @@ import { } from '../../../util/qs'; import HostListItem from './HostListItem'; +import SmartInventoryButton from './SmartInventoryButton'; const QS_CONFIG = getQSConfig('host', { page: 1, @@ -183,30 +184,10 @@ function HostList({ i18n }) { />, ...(canAdd ? [ - -
- -
-
, + handleSmartInventoryClick()} + />, ] : []), ]} diff --git a/awx/ui_next/src/screens/Host/HostList/SmartInventoryButton.jsx b/awx/ui_next/src/screens/Host/HostList/SmartInventoryButton.jsx new file mode 100644 index 0000000000..9e90bbf531 --- /dev/null +++ b/awx/ui_next/src/screens/Host/HostList/SmartInventoryButton.jsx @@ -0,0 +1,53 @@ +import React from 'react'; +import { func } from 'prop-types'; +import { Button, DropdownItem, Tooltip } from '@patternfly/react-core'; +import { withI18n } from '@lingui/react'; +import { t } from '@lingui/macro'; +import { useKebabifiedMenu } from '../../../contexts/Kebabified'; + +function SmartInventoryButton({ onClick, i18n, isDisabled }) { + const { isKebabified } = useKebabifiedMenu(); + + if (isKebabified) { + return ( + + {i18n._(t`Smart Inventory`)} + + ); + } + + return ( + +
+ +
+
+ ); +} +SmartInventoryButton.propTypes = { + onClick: func.isRequired, +}; + +export default withI18n()(SmartInventoryButton); diff --git a/awx/ui_next/src/screens/Host/HostList/SmartInventoryButton.test.jsx b/awx/ui_next/src/screens/Host/HostList/SmartInventoryButton.test.jsx new file mode 100644 index 0000000000..b8f47725f5 --- /dev/null +++ b/awx/ui_next/src/screens/Host/HostList/SmartInventoryButton.test.jsx @@ -0,0 +1,16 @@ +import React from 'react'; +import { mountWithContexts } from '../../../../testUtils/enzymeHelpers'; +import SmartInventoryButton from './SmartInventoryButton'; + +describe('', () => { + test('should render button', () => { + const onClick = jest.fn(); + const wrapper = mountWithContexts( + + ); + const button = wrapper.find('button'); + expect(button).toHaveLength(1); + button.simulate('click'); + expect(onClick).toHaveBeenCalled(); + }); +});