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

Correctly highlight the nav item for the legacy app. #616

Merged
merged 1 commit into from
Jan 6, 2020
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
4 changes: 4 additions & 0 deletions legacy/src/app/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,10 @@ const renderHeader = ($rootScope, $window, $http) => {
/>,
headerNode
);
$rootScope.$on("$routeChangeSuccess", function(event, next, current) {
// Update the header when the route changes.
renderHeader($rootScope, $window, $http);
});
};

const renderFooter = $window => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ exports[`Footer renders 1`] = `
className="u-remove-max-width"
>
©
2019
2020
Canonical Ltd. Ubuntu and Canonical are registered trademarks of Canonical Ltd.
</p>
</div>
Expand Down
8 changes: 5 additions & 3 deletions shared/src/components/Header/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export const Header = ({
});
window.ga("set", "dimension1", version);
window.ga("set", "dimension2", uuid);

const sendPageview = () => {
const path = window.location.pathname + window.location.hash;
window.ga("send", "pageview", path);
Expand Down Expand Up @@ -183,12 +184,12 @@ export const Header = ({
const generateNavItems = links => {
const hardwareLinks = links.filter(link => link.inHardwareMenu);
const hardwareMenu = generateHardwareMenu(hardwareLinks);
const path = location.pathname + location.hash;

const linkItems = links.map(link => (
<li
className={classNames("p-navigation__link", {
"is-selected": location.pathname.startsWith(
generateURL(link.url, link.isLegacy)
),
"is-selected": path.startsWith(generateURL(link.url, link.isLegacy)),
"u-hide--hardware-menu-threshold": link.inHardwareMenu
})}
key={link.url}
Expand Down Expand Up @@ -313,6 +314,7 @@ Header.propTypes = {
enableAnalytics: PropTypes.bool,
generateLocalLink: PropTypes.func,
location: PropTypes.shape({
hash: PropTypes.string,
pathname: PropTypes.string.isRequired
}).isRequired,
logout: PropTypes.func.isRequired,
Expand Down
46 changes: 45 additions & 1 deletion shared/src/components/Header/Header.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,51 @@ describe("Header", () => {
wrapper.findWhere(n => n.name() === "a" && n.text() === "Skip").exists()
).toBe(true);
expect(
wrapper.find(".p-navigation__links").at(0).props().children
wrapper
.find(".p-navigation__links")
.at(0)
.props().children
).toBe(false);
});

it("can highlight a new URL", () => {
const wrapper = shallow(
<Header
authUser={{
is_superuser: true,
username: "koala"
}}
basename="/MAAS"
completedIntro={true}
location={{
pathname: "/settings"
}}
logout={jest.fn()}
/>
);
const selected = wrapper.find(".p-navigation__link.is-selected");
expect(selected.exists()).toBe(true);
expect(selected.text()).toEqual("Settings");
});

it("can highlight a legacy URL", () => {
const wrapper = shallow(
<Header
authUser={{
is_superuser: true,
username: "koala"
}}
basename="/MAAS"
completedIntro={true}
location={{
hash: "#/machines",
pathname: "/MAAS/"
}}
logout={jest.fn()}
/>
);
const selected = wrapper.find(".p-navigation__link.is-selected");
expect(selected.exists()).toBe(true);
expect(selected.text()).toEqual("Machines");
});
});