From fa1ef87f20fad0b77f21626232aa9f515945df56 Mon Sep 17 00:00:00 2001 From: Jake McDermott Date: Fri, 18 Dec 2020 09:36:25 -0500 Subject: [PATCH] Use location hook in routed tabs Fix a unit test that is failing due to history.location not updating as expected when a routed tab is selected. --- awx/ui_next/src/components/RoutedTabs/RoutedTabs.jsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/awx/ui_next/src/components/RoutedTabs/RoutedTabs.jsx b/awx/ui_next/src/components/RoutedTabs/RoutedTabs.jsx index 3b93990417..c995404ddd 100644 --- a/awx/ui_next/src/components/RoutedTabs/RoutedTabs.jsx +++ b/awx/ui_next/src/components/RoutedTabs/RoutedTabs.jsx @@ -1,19 +1,20 @@ import React from 'react'; import { shape, string, number, arrayOf, node, oneOfType } from 'prop-types'; import { Tab, Tabs, TabTitleText } from '@patternfly/react-core'; -import { useHistory } from 'react-router-dom'; +import { useHistory, useLocation } from 'react-router-dom'; function RoutedTabs(props) { const { tabsArray } = props; const history = useHistory(); + const location = useLocation(); const getActiveTabId = () => { - const match = tabsArray.find(tab => tab.link === history.location.pathname); + const match = tabsArray.find(tab => tab.link === location.pathname); if (match) { return match.id; } const subpathMatch = tabsArray.find(tab => - history.location.pathname.startsWith(tab.link) + location.pathname.startsWith(tab.link) ); if (subpathMatch) { return subpathMatch.id;