diff --git a/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/waffle/waffle_inventory_switcher.tsx b/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/waffle/waffle_inventory_switcher.tsx index 6806fbd31d79a..4dea25bd6cf70 100644 --- a/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/waffle/waffle_inventory_switcher.tsx +++ b/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/waffle/waffle_inventory_switcher.tsx @@ -31,7 +31,7 @@ export const WaffleInventorySwitcher: React.FC = () => { } = useWaffleOptionsContext(); const [isOpen, setIsOpen] = useState(false); const closePopover = useCallback(() => setIsOpen(false), []); - const openPopover = useCallback(() => setIsOpen(true), []); + const togglePopover = useCallback(() => setIsOpen((currentIsOpen) => !currentIsOpen), []); const goToNodeType = useCallback( (targetNodeType: InventoryItemType) => { closePopover(); @@ -127,7 +127,7 @@ export const WaffleInventorySwitcher: React.FC = () => { const button = ( diff --git a/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/waffle/waffle_sort_controls.tsx b/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/waffle/waffle_sort_controls.tsx index 55cf18757f006..48c8b5f3c1dfb 100644 --- a/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/waffle/waffle_sort_controls.tsx +++ b/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/waffle/waffle_sort_controls.tsx @@ -25,20 +25,15 @@ const LABELS = { export const WaffleSortControls = ({ sort, onChange }: Props) => { const [isOpen, setIsOpen] = useState(false); - const showPopover = useCallback(() => { - setIsOpen(true); - }, [setIsOpen]); - - const closePopover = useCallback(() => { - setIsOpen(false); - }, [setIsOpen]); + const togglePopover = useCallback(() => setIsOpen((currentIsOpen) => !currentIsOpen), []); + const closePopover = useCallback(() => setIsOpen(false), []); const label = LABELS[sort.by]; const button = ( {label} diff --git a/x-pack/plugins/infra/public/pages/metrics/metrics_explorer/components/chart_context_menu.tsx b/x-pack/plugins/infra/public/pages/metrics/metrics_explorer/components/chart_context_menu.tsx index 217c5fdc7c0e8..ac91f16ff040c 100644 --- a/x-pack/plugins/infra/public/pages/metrics/metrics_explorer/components/chart_context_menu.tsx +++ b/x-pack/plugins/infra/public/pages/metrics/metrics_explorer/components/chart_context_menu.tsx @@ -181,7 +181,7 @@ export const MetricsExplorerChartContextMenu: React.FC = ({ ]; const handleClose = () => setPopoverState(false); - const handleOpen = () => setPopoverState(true); + const togglePopover = () => setPopoverState((currentIsOpen) => !currentIsOpen); const actionAriaLabel = i18n.translate('xpack.infra.metricsExplorer.actionsLabel.aria', { defaultMessage: 'Actions for {grouping}', values: { grouping: series.id }, @@ -193,7 +193,7 @@ export const MetricsExplorerChartContextMenu: React.FC = ({ { await pageObjects.infraHome.openTimeline(); await pageObjects.infraHome.closeTimeline(); }); + + it('toggles the inventory switcher', async () => { + await pageObjects.infraHome.toggleInventorySwitcher(); + }); }); describe('alerts flyouts', () => { diff --git a/x-pack/test/functional/page_objects/infra_home_page.ts b/x-pack/test/functional/page_objects/infra_home_page.ts index aed3558cfdcb4..34bcec45e7aa6 100644 --- a/x-pack/test/functional/page_objects/infra_home_page.ts +++ b/x-pack/test/functional/page_objects/infra_home_page.ts @@ -171,9 +171,16 @@ export function InfraHomePageProvider({ getService, getPageObjects }: FtrProvide return timelineSelectorsVisible.every((visible) => !visible); }, - async openInvenotrySwitcher() { + async openInventorySwitcher() { await testSubjects.click('openInventorySwitcher'); - return await testSubjects.find('goToHost'); + return await testSubjects.find('goToHost1'); + }, + + async toggleInventorySwitcher() { + await testSubjects.click('openInventorySwitcher'); + await testSubjects.find('goToHost'); + await testSubjects.click('openInventorySwitcher'); + return await testSubjects.missingOrFail('goToHost'); }, async goToHost() {