Skip to content

Commit

Permalink
fix(header): prevent some exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
revolunet committed Feb 16, 2024
1 parent 1d61e08 commit a3db705
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 82 deletions.
42 changes: 4 additions & 38 deletions report/www/src/__tests__/__snapshots__/Header.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -401,46 +401,12 @@ exports[`Should render HeaderSite 1`] = `
aria-expanded="false"
class="fr-nav__btn"
id="fr-header-main-navigation-button-2"
>
Incubateurs
</button>
</li>
<li
class="fr-nav__item"
>
<button
aria-controls="fr-header-main-navigation-menu-3"
aria-expanded="false"
class="fr-nav__btn"
id="fr-header-main-navigation-button-3"
/>
</li>
<li
class="fr-nav__item"
>
<button
aria-controls="fr-header-main-navigation-menu-4"
aria-expanded="false"
class="fr-nav__btn"
id="fr-header-main-navigation-button-4"
>
Startups
</button>
</li>
<li
class="fr-nav__item"
>
<button
aria-controls="fr-header-main-navigation-menu-5"
aria-expanded="false"
class="fr-nav__btn"
id="fr-header-main-navigation-button-5"
>
Vues
</button>
<div
class="fr-menu fr-collapse"
id="fr-header-main-navigation-menu-5"
id="fr-header-main-navigation-menu-2"
>
<ul
class="fr-menu__list"
Expand All @@ -449,7 +415,7 @@ exports[`Should render HeaderSite 1`] = `
<a
class="fr-nav__link"
href="/wappalyzer"
id="fr-header-main-navigation-menu-5-link-Technologies_wappalyzer_-0"
id="fr-header-main-navigation-menu-2-link-Technologies_wappalyzer_-0"
>
Technologies (wappalyzer)
</a>
Expand All @@ -458,7 +424,7 @@ exports[`Should render HeaderSite 1`] = `
<a
class="fr-nav__link"
href="/updownio"
id="fr-header-main-navigation-menu-5-link-Disponibilit__updown_io_-1"
id="fr-header-main-navigation-menu-2-link-Disponibilit__updown_io_-1"
>
Disponibilité (updown.io)
</a>
Expand All @@ -472,7 +438,7 @@ exports[`Should render HeaderSite 1`] = `
<a
class="fr-nav__link"
href="/about"
id="fr-header-main-navigation-link-6"
id="fr-header-main-navigation-link-3"
>
A propos
</a>
Expand Down
88 changes: 44 additions & 44 deletions report/www/src/components/HeaderSite.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,38 @@ export const HeaderSite: React.FC<HeaderSiteProps> = ({ report }) => {

const { t } = useTranslation();

const betaStartups =
(isToolEnabled("betagouv") &&
sortedReport
.filter((url) => url.betaId)
.filter(
(url, i, all) =>
!all
.map((u) => u.betaId)
.slice(i + 1)
.includes(url.betaId)
)
.map((url) => url.betaId)
.sort()) ||
[];

const views = [
isToolEnabled("wappalyzer") && {
linkProps: {
href: "/wappalyzer",
},
text: t("wappalyzer"),
isActive: router.asPath === "/wappalyzer/",
},
isToolEnabled("updownio") && {
linkProps: {
href: "/updownio",
},
text: t("updownio"),
isActive: router.asPath === "/updownio/",
},
].filter(Boolean);

return (
<>
<Header
Expand Down Expand Up @@ -76,7 +108,7 @@ export const HeaderSite: React.FC<HeaderSiteProps> = ({ report }) => {
},
isActive: router.asPath === "/",
},
{
categories.length > 1 && {
text: t("categories"),
menuLinks: [
...categories.map((category) => ({
Expand All @@ -102,61 +134,29 @@ export const HeaderSite: React.FC<HeaderSiteProps> = ({ report }) => {
],
isActive: router.asPath.startsWith("/tag/"),
},
isToolEnabled("betagouv") && {
betaStartups.length > 1 && {
text: t("startups"),
menuLinks: [
...sortedReport
.filter((url) => url.betaId)
.filter(
(url, i, all) =>
!all
.map((u) => u.betaId)
.slice(i + 1)
.includes(url.betaId)
)
.map((url) => url.betaId)
.sort()
.map((startup) => {
return {
linkProps: {
href: `/startup/${startup}`,
},
text: startup,
isActive: router.asPath === `/startup/${startup}`,
};
}),
],
menuLinks: betaStartups.map((startup) => ({
linkProps: {
href: `/startup/${startup}`,
},
text: startup,
isActive: router.asPath === `/startup/${startup}`,
})),
isActive: router.asPath.startsWith("/startup/"),
},

{
views.length && {
text: "Vues",
menuLinks: [
isToolEnabled("wappalyzer") && {
linkProps: {
href: "/wappalyzer",
},
text: t("wappalyzer"),
isActive: router.asPath === "/wappalyzer/",
},
isToolEnabled("updownio") && {
linkProps: {
href: "/updownio",
},
text: t("updownio"),
isActive: router.asPath === "/updownio/",
},
],
menuLinks: views,
},

{
text: t("about"),
linkProps: {
href: "/about",
},
isActive: router.asPath === "/about/",
},
]}
].filter(Boolean)}
serviceTagline={dashlordConfig.description}
serviceTitle={dashlordConfig.title}
/>
Expand Down

0 comments on commit a3db705

Please sign in to comment.