From 287d181af71e0ffb323e7f8b121d717a0a0b0e94 Mon Sep 17 00:00:00 2001 From: nixocio Date: Mon, 25 Jan 2021 16:50:26 -0500 Subject: [PATCH] Add tooltips to inventory sync status Add tooltips to inventory sync status on Inventory List. See: https://github.com/ansible/awx/issues/7676 --- .../components/StatusLabel/StatusLabel.jsx | 14 ++- .../InventoryList/InventoryListItem.jsx | 17 ++- .../InventoryList/InventoryListItem.test.jsx | 109 +++++++++++------- 3 files changed, 92 insertions(+), 48 deletions(-) diff --git a/awx/ui_next/src/components/StatusLabel/StatusLabel.jsx b/awx/ui_next/src/components/StatusLabel/StatusLabel.jsx index bd0466f5ce..9074deda1a 100644 --- a/awx/ui_next/src/components/StatusLabel/StatusLabel.jsx +++ b/awx/ui_next/src/components/StatusLabel/StatusLabel.jsx @@ -1,7 +1,7 @@ import 'styled-components/macro'; import React from 'react'; import { oneOf } from 'prop-types'; -import { Label } from '@patternfly/react-core'; +import { Label, Tooltip } from '@patternfly/react-core'; import { CheckCircleIcon, ExclamationCircleIcon, @@ -48,15 +48,19 @@ const icons = { canceled: ExclamationTriangleIcon, }; -export default function StatusLabel({ status }) { +export default function StatusLabel({ status, tooltipContent = '' }) { const label = status.charAt(0).toUpperCase() + status.slice(1); const color = colors[status] || 'grey'; const Icon = icons[status]; return ( - + <> + + + + ); } diff --git a/awx/ui_next/src/screens/Inventory/InventoryList/InventoryListItem.jsx b/awx/ui_next/src/screens/Inventory/InventoryList/InventoryListItem.jsx index d10dbf2a0a..aa0849313e 100644 --- a/awx/ui_next/src/screens/Inventory/InventoryList/InventoryListItem.jsx +++ b/awx/ui_next/src/screens/Inventory/InventoryList/InventoryListItem.jsx @@ -55,6 +55,19 @@ function InventoryListItem({ inventory.inventory_sources_with_failures > 0 ? 'error' : 'success'; } + let tooltipContent = ''; + if (inventory.has_inventory_sources) { + if (inventory.inventory_sources_with_failures > 0) { + tooltipContent = i18n._( + t`${inventory.inventory_sources_with_failures} sources with sync failures.` + ); + } else { + tooltipContent = i18n._(t`No inventory sync failures.`); + } + } else { + tooltipContent = i18n._(t`Not configured for inventory sync.`); + } + return ( - {inventory.kind !== 'smart' && } + {inventory.kind !== 'smart' && ( + + )} {inventory.kind === 'smart' diff --git a/awx/ui_next/src/screens/Inventory/InventoryList/InventoryListItem.test.jsx b/awx/ui_next/src/screens/Inventory/InventoryList/InventoryListItem.test.jsx index 6be246df39..179a089e52 100644 --- a/awx/ui_next/src/screens/Inventory/InventoryList/InventoryListItem.test.jsx +++ b/awx/ui_next/src/screens/Inventory/InventoryList/InventoryListItem.test.jsx @@ -7,24 +7,33 @@ import InventoryListItem from './InventoryListItem'; jest.mock('../../../api/models/Inventories'); describe('', () => { - test('initially renders succesfully', () => { + const inventory = { + id: 1, + name: 'Inventory', + kind: '', + has_active_failures: true, + total_hosts: 10, + hosts_with_active_failures: 4, + has_inventory_sources: true, + total_inventory_sources: 4, + inventory_sources_with_failures: 5, + summary_fields: { + organization: { + id: 1, + name: 'Default', + }, + user_capabilities: { + edit: true, + }, + }, + }; + + test('initially renders successfully', () => { mountWithContexts( {}} @@ -34,25 +43,50 @@ describe('', () => { ); }); + test('should render not configured tooltip', () => { + const wrapper = mountWithContexts( +
+ + {}} + /> + +
+ ); + + expect(wrapper.find('StatusLabel').prop('tooltipContent')).toBe( + 'Not configured for inventory sync.' + ); + }); + + test('should render success tooltip', () => { + const wrapper = mountWithContexts( + + + {}} + /> + +
+ ); + + expect(wrapper.find('StatusLabel').prop('tooltipContent')).toBe( + 'No inventory sync failures.' + ); + }); + test('should render prompt list item data', () => { const wrapper = mountWithContexts( {}} @@ -61,6 +95,9 @@ describe('', () => {
); expect(wrapper.find('StatusLabel').length).toBe(1); + expect(wrapper.find('StatusLabel').prop('tooltipContent')).toBe( + `${inventory.inventory_sources_with_failures} sources with sync failures.` + ); expect( wrapper .find('Td') @@ -72,7 +109,7 @@ describe('', () => { .find('Td') .at(2) .text() - ).toBe('Disabled'); + ).toBe('Error'); expect( wrapper .find('Td') @@ -92,19 +129,7 @@ describe('', () => { {}}