Skip to content

Commit

Permalink
fix(OCPADVISOR-89): Fix active tab handling (#565)
Browse files Browse the repository at this point in the history
  • Loading branch information
gkarat authored Apr 27, 2023
1 parent 30c287a commit b1717da
Showing 1 changed file with 9 additions and 19 deletions.
28 changes: 9 additions & 19 deletions src/Components/ClusterTabs/ClusterTabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { useIntl } from 'react-intl';
import { useParams, useSearchParams } from 'react-router-dom';
import messages from '../../Messages';
import { setSearchParameter } from '../../Utilities/Helpers';
import { useUpgradeRisksFeatureFlag } from '../../Utilities/useFeatureFlag';
import ClusterRules from '../ClusterRules/ClusterRules';
import { UpgradeRisksTable } from '../UpgradeRisksTable';
import { UpgradeRisksTracker } from '../UpgradeRisksTracker';
Expand All @@ -15,28 +14,19 @@ const CLUSTER_TABS = ['recommendations', 'upgrade_risks'];

const ClusterTabs = () => {
const intl = useIntl();
const upgradeRisksEnabled = useUpgradeRisksFeatureFlag();
const [searchParams] = useSearchParams();

const { clusterId } = useParams();
const areUpgradeRisksEnabled = useUpgradeRisksFeature(clusterId);
const upgradeRisksEnabled = useUpgradeRisksFeature(clusterId);

const [activeKey, setActiveKey] = useState(() => {
const activeTab = searchParams.get('active_tab');
return areUpgradeRisksEnabled
? CLUSTER_TABS.includes(activeTab)
? activeTab
: 'recommendations'
: 'recommendations';
});
const [activeKey, setActiveKey] = useState('recommendations');

useEffect(() => {
if (
areUpgradeRisksEnabled &&
searchParams.get('active_tab') === 'upgrade_risks'
) {
setActiveKey('upgrade_risks');
}
const tabKey = searchParams.get('active_tab');
setActiveKey(
upgradeRisksEnabled && CLUSTER_TABS.includes(tabKey)
? tabKey
: 'recommendations'
);
}, [upgradeRisksEnabled]);

return (
Expand All @@ -57,7 +47,7 @@ const ClusterTabs = () => {
>
{activeKey === 'recommendations' && <ClusterRules />}
</Tab>
{areUpgradeRisksEnabled && (
{upgradeRisksEnabled && (
<Tab
eventKey="upgrade_risks"
title={intl.formatMessage(messages.upgradeRisks)}
Expand Down

0 comments on commit b1717da

Please sign in to comment.