Skip to content

Commit

Permalink
fix(Systems): THEEDGE-3474 - Fix tab selection (#1987)
Browse files Browse the repository at this point in the history
* initial fix

* adjust url behavior

* clean up

* add navidate support

* move to urlSearchParams

* add validation of status

* handle double click in same tab, clean up filter when switch tabs
  • Loading branch information
acosferreira authored Aug 29, 2023
1 parent a8e2655 commit d664411
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 42 deletions.
62 changes: 31 additions & 31 deletions src/routes/InventoryTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import React, { useEffect, useRef, useState } from 'react';
import PropTypes from 'prop-types';
import { shallowEqual, useDispatch, useSelector } from 'react-redux';
import { useLocation } from 'react-router-dom';
import { useLocation, useNavigate, useSearchParams } from 'react-router-dom';
import './inventory.scss';
import {
PageHeader,
Expand Down Expand Up @@ -31,8 +31,7 @@ import { InventoryTable as InventoryTableCmp } from '../components/InventoryTabl
import useChrome from '@redhat-cloud-services/frontend-components/useChrome';
import AddSelectedHostsToGroupModal from '../components/InventoryGroups/Modals/AddSelectedHostsToGroupModal';
import useFeatureFlag from '../Utilities/useFeatureFlag';
//TODO: re-enable when edge app migrates away from useHistory (THEEDGE-3488)
// import AsyncComponent from '@redhat-cloud-services/frontend-components/AsyncComponent';
import AsyncComponent from '@redhat-cloud-services/frontend-components/AsyncComponent';
import { useBulkSelectConfig } from '../Utilities/hooks/useBulkSelectConfig';
import RemoveHostsFromGroupModal from '../components/InventoryGroups/Modals/RemoveHostsFromGroupModal';
import { manageEdgeInventoryUrlName } from '../Utilities/edge';
Expand Down Expand Up @@ -151,6 +150,7 @@ const Inventory = ({
const navigate = useInsightsNavigate();
const chrome = useChrome();
const inventory = useRef(null);

const [isModalOpen, handleModalToggle] = useState(false);
const [currentSystem, setCurrentSystem] = useState({});
const [filters, onSetfilters] = useState(
Expand All @@ -166,23 +166,23 @@ const Inventory = ({
lastSeenFilter
)
);
const { pathname } = useLocation();
const tabsPath = [
resolveRelPath(''),
resolveRelPath(manageEdgeInventoryUrlName),
];
const initialActiveTabKey =
tabsPath.indexOf(pathname) >= 0 ? tabsPath.indexOf(pathname) : 0;
const [activeTabKey, setActiveTabKey] = useState(initialActiveTabKey);
useEffect(() => {
setActiveTabKey(initialActiveTabKey);
}, [pathname]);
const [searchParams, setSearchParams] = useSearchParams();
const [prm, setPrm] = useState('');
const [currentTab, setCurrentTab] = useState(searchParams.get('activeTab'));
const handleTabClick = (_event, tabIndex) => {
const tabPath = tabsPath[tabIndex];
if (tabPath !== undefined) {
navigate(`${tabPath}`);
setCurrentTab(tabIndex);
if (currentTab !== tabIndex) {
let currentParam = Object.fromEntries(searchParams);
if (currentParam !== '' || currentParam !== undefined) {
setPrm(currentParam);
setSearchParams({
...prm,
activeTab: tabIndex,
});
}

// }
}
setActiveTabKey(tabIndex);
};
const [ediOpen, onEditOpen] = useState(false);
const [addHostGroupModalOpen, setAddHostGroupModalOpen] = useState(false);
Expand Down Expand Up @@ -508,30 +508,30 @@ const Inventory = ({
{EdgeParityEnabled ? (
<Tabs
className="pf-m-light pf-c-table"
activeKey={activeTabKey}
activeKey={searchParams.get('activeTab') || 'conventional'}
onSelect={handleTabClick}
>
<Tab
eventKey={0}
eventKey={'conventional'}
title={<TabTitleText>Conventional (RPM-DNF)</TabTitleText>}
>
{traditionalDevices}
</Tab>
<Tab
eventKey={1}
eventKey={manageEdgeInventoryUrlName}
title={<TabTitleText>Immutable (OSTree)</TabTitleText>}
>
{/*
//TODO: re-enable when edge app migrates away from useHistory (THEEDGE-3488)
{
<AsyncComponent
appName="edge"
module="./Inventory"
historyProp={useHistory}
locationProp={useLocation}
showHeaderProp={false}
pathPrefix={resolveRelPath('')}
urlName={manageEdgeInventoryUrlName}
/> */}
appName="edge"
module="./Inventory"
navigateProp={useNavigate}
locationProp={useLocation}
showHeaderProp={false}
pathPrefix={resolveRelPath('')}
urlName={manageEdgeInventoryUrlName}
/>
}
</Tab>
</Tabs>
) : (
Expand Down
20 changes: 9 additions & 11 deletions src/routes/SystemUpdate.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
/* eslint-disable no-unused-vars */
import React, { useEffect } from 'react';
import useChrome from '@redhat-cloud-services/frontend-components/useChrome';
//TODO: re-enable when edge app migrates away from useHistory (THEEDGE-3488)
import AsyncComponent from '@redhat-cloud-services/frontend-components/AsyncComponent';
import { useLocation, useParams } from 'react-router-dom';
import { useLocation, useNavigate, useParams } from 'react-router-dom';

const SystemUpdate = () => {
const chrome = useChrome();
Expand All @@ -14,15 +13,14 @@ const SystemUpdate = () => {
const { inventoryId } = useParams();

return inventoryId !== null ? (
//TODO: re-enable when edge app migrates away from useHistory (THEEDGE-3488)
// <AsyncComponent
// appName="edge"
// module="./UpdateSystem"
// locationProp={useLocation}
// paramsProp={useParams}
// inventoryId={inventoryId}
// />
<div> removed edge update component</div>
<AsyncComponent
appName="edge"
module="./UpdateSystem"
navigateProp={useNavigate}
locationProp={useLocation}
paramsProp={useParams}
inventoryId={inventoryId}
/>
) : (
<></>
);
Expand Down

0 comments on commit d664411

Please sign in to comment.