mirror of
https://github.com/ansible/awx.git
synced 2026-04-10 04:29:21 -02:30
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.
This commit is contained in:
@@ -1,19 +1,20 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { shape, string, number, arrayOf, node, oneOfType } from 'prop-types';
|
import { shape, string, number, arrayOf, node, oneOfType } from 'prop-types';
|
||||||
import { Tab, Tabs, TabTitleText } from '@patternfly/react-core';
|
import { Tab, Tabs, TabTitleText } from '@patternfly/react-core';
|
||||||
import { useHistory } from 'react-router-dom';
|
import { useHistory, useLocation } from 'react-router-dom';
|
||||||
|
|
||||||
function RoutedTabs(props) {
|
function RoutedTabs(props) {
|
||||||
const { tabsArray } = props;
|
const { tabsArray } = props;
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
|
const location = useLocation();
|
||||||
|
|
||||||
const getActiveTabId = () => {
|
const getActiveTabId = () => {
|
||||||
const match = tabsArray.find(tab => tab.link === history.location.pathname);
|
const match = tabsArray.find(tab => tab.link === location.pathname);
|
||||||
if (match) {
|
if (match) {
|
||||||
return match.id;
|
return match.id;
|
||||||
}
|
}
|
||||||
const subpathMatch = tabsArray.find(tab =>
|
const subpathMatch = tabsArray.find(tab =>
|
||||||
history.location.pathname.startsWith(tab.link)
|
location.pathname.startsWith(tab.link)
|
||||||
);
|
);
|
||||||
if (subpathMatch) {
|
if (subpathMatch) {
|
||||||
return subpathMatch.id;
|
return subpathMatch.id;
|
||||||
|
|||||||
Reference in New Issue
Block a user