Skip to content

Commit

Permalink
Use NavLink in the navigation elements
Browse files Browse the repository at this point in the history
  • Loading branch information
arbulu89 committed Jun 2, 2022
1 parent 7b3101f commit 8df874e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
12 changes: 5 additions & 7 deletions assets/js/components/Layout/Layout.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState, useCallback } from 'react';
import { Link, Outlet, useLocation } from 'react-router-dom';
import { NavLink, Outlet } from 'react-router-dom';

import {
EOS_HOME_OUTLINED,
Expand Down Expand Up @@ -52,8 +52,6 @@ const navigation = [
];

const Layout = () => {
const { pathname } = useLocation();
const isCurrentRoute = (route) => pathname === route;
const [isCollapsed, setCollapsed] = useState(
localStorage.getItem('sidebar-collapsed')
);
Expand Down Expand Up @@ -89,10 +87,10 @@ const Layout = () => {
<div>
{navigation.map((item, index) => {
return (
<Link
<NavLink
key={index}
className={`tn-menu-item w-full text-gray-800 dark:text-white flex items-center pl-6 p-2 my-2 transition-colors duration-200 justify-start ${
isCurrentRoute(item.href)
className={({ isActive }) => `tn-menu-item w-full text-gray-800 dark:text-white flex items-center pl-6 p-2 my-2 transition-colors duration-200 justify-start ${
isActive
? 'border-l-4 border-jungle-green-500'
: 'hover:border-l-4 hover:border-jungle-green-500'
}`}
Expand All @@ -104,7 +102,7 @@ const Layout = () => {
<span className="mx-2 text-sm font-normal">
{item.name}
</span>
</Link>
</NavLink>
);
})}
</div>
Expand Down
4 changes: 4 additions & 0 deletions test/e2e/cypress/integration/host_details.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ context('Host Details', () => {
});

describe('Detailed view for a specific host should be available', () => {
it('should highlight the hosts sidebar entry', () => {
cy.get('.tn-menu-item[href="/hosts"]').invoke('attr', 'aria-current').should('eq', 'page');
});

it('should show the host I clicked on in the overview', () => {
cy.get('.grid-flow-col > :nth-child(1) > :nth-child(2) > span').should(
'contain',
Expand Down
3 changes: 3 additions & 0 deletions test/e2e/cypress/integration/hosts_overview.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ context('Hosts Overview', () => {
});

describe('Registered Hosts are shown in the list', () => {
it('should highlight the hosts sidebar entry', () => {
cy.get('.tn-menu-item[href="/hosts"]').invoke('attr', 'aria-current').should('eq', 'page');
});
it('should show 10 of the 27 registered hosts', () => {
cy.get('.tn-hostname').its('length').should('eq', 10);
});
Expand Down

0 comments on commit 8df874e

Please sign in to comment.