Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use NavLink in the navigation elements #623

Merged
merged 1 commit into from
Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 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,13 +87,15 @@ 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)
? 'border-l-4 border-jungle-green-500'
: 'hover:border-l-4 hover:border-jungle-green-500'
}`}
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'
}`
}
to={item.href}
>
<span className="text-left">
Expand All @@ -104,7 +104,7 @@ const Layout = () => {
<span className="mx-2 text-sm font-normal">
{item.name}
</span>
</Link>
</NavLink>
);
})}
</div>
Expand Down
6 changes: 6 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,12 @@ 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
5 changes: 5 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,11 @@ 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