Skip to content

Commit 307a963

Browse files
committed
fix(ws): update logic to expose active nav item in default view
1 parent b2bee1d commit 307a963

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

workspaces/frontend/src/app/AppRoutes.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import { Route, Routes } from 'react-router-dom';
2+
import { Route, Routes, Navigate } from 'react-router-dom';
33
import { AppRoutePaths } from '~/app/routes';
44
import { WorkspaceForm } from '~/app/pages/Workspaces/Form/WorkspaceForm';
55
import { NotFound } from './pages/notFound/NotFound';
@@ -64,7 +64,7 @@ const AppRoutes: React.FC = () => {
6464
<Route path={AppRoutePaths.workspaceEdit} element={<WorkspaceForm />} />
6565
<Route path={AppRoutePaths.workspaces} element={<Workspaces />} />
6666
<Route path={AppRoutePaths.workspaceKinds} element={<WorkspaceKinds />} />
67-
<Route path="/" element={<Workspaces />} />
67+
<Route path="/" element={<Navigate to={AppRoutePaths.workspaces} replace />} />
6868
<Route path="*" element={<NotFound />} />
6969
{
7070
// TODO: Remove the linter skip when we implement authentication

workspaces/frontend/src/app/NavSidebar.tsx

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import { NavLink } from 'react-router-dom';
2+
import { NavLink, useLocation } from 'react-router-dom';
33
import {
44
Brand,
55
Nav,
@@ -12,13 +12,20 @@ import {
1212
import { useNavData, isNavDataGroup, NavDataHref, NavDataGroup } from './AppRoutes';
1313
import { isMUITheme, LOGO_LIGHT } from './const';
1414

15-
const NavHref: React.FC<{ item: NavDataHref }> = ({ item }) => (
16-
<NavItem key={item.label} data-id={item.label} itemId={item.label}>
17-
<NavLink to={item.path} data-testid={`nav-link-${item.path}`}>
18-
{item.label}
19-
</NavLink>
20-
</NavItem>
21-
);
15+
const NavHref: React.FC<{ item: NavDataHref }> = ({ item }) => {
16+
const location = useLocation();
17+
18+
// With the redirect in place, we can now use a simple path comparison.
19+
const isActive = location.pathname === item.path;
20+
21+
return (
22+
<NavItem isActive={isActive} key={item.label} data-id={item.label} itemId={item.label}>
23+
<NavLink to={item.path} data-testid={`nav-link-${item.path}`}>
24+
{item.label}
25+
</NavLink>
26+
</NavItem>
27+
);
28+
};
2229

2330
const NavGroup: React.FC<{ item: NavDataGroup }> = ({ item }) => {
2431
const { children } = item;

workspaces/frontend/src/shared/style/MUI-theme.scss

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -543,10 +543,10 @@
543543
--pf-v6-c-nav__link--hover--Color: var(--kf-central-sidebar-default-color);
544544
--pf-v6-c-nav__link--FontSize: var(--pf-t--global--font--size--md);
545545

546-
&.active {
546+
&.pf-m-current {
547547
border-left: 3px solid var(--mui-palette-common-white);
548-
--pf-v6-c-nav__link--Color: var(--mui-palette-common-white);
549-
--pf-v6-c-nav__link--hover--Color: var(--mui-palette-common-white);
548+
--pf-v6-c-nav__link--m-current--BackgroundColor: #ffffff1b;
549+
--pf-v6-c-nav__link--m-current--Color: var(--mui-palette-common-white);
550550
}
551551

552552
&.pf-v6-c-brand {

0 commit comments

Comments
 (0)