Skip to content
This repository has been archived by the owner on Apr 5, 2024. It is now read-only.

Commit

Permalink
fix: header
Browse files Browse the repository at this point in the history
  • Loading branch information
maxgfr committed Mar 4, 2022
1 parent c3a1893 commit c9de1f0
Show file tree
Hide file tree
Showing 19 changed files with 206 additions and 188 deletions.
1 change: 1 addition & 0 deletions .env.development
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ NEXT_PUBLIC_SENTRY_DSN=""
NEXT_PUBLIC_SENTRY_ENV=""
NEXT_PUBLIC_MATOMO_URL=""
NEXT_PUBLIC_MATOMO_SITE_ID=""
NEXT_PUBLIC_APP_REPOSITORY_URL="https://github.com/SocialGouv/template"
3 changes: 2 additions & 1 deletion .env.production
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ NEXT_PUBLIC_SITE_URL="https://template.fabrique.social.gouv.fr/"
NEXT_PUBLIC_SENTRY_DSN="https://67a92c8c0f70486d9f36f2352eff1d19@sentry.fabrique.social.gouv.fr/68"
NEXT_PUBLIC_SENTRY_ENV="production"
NEXT_PUBLIC_MATOMO_URL="https://matomo.fabrique.social.gouv.fr"
NEXT_PUBLIC_MATOMO_SITE_ID=63
NEXT_PUBLIC_MATOMO_SITE_ID=63
NEXT_PUBLIC_APP_REPOSITORY_URL="https://github.com/SocialGouv/template"
1 change: 1 addition & 0 deletions .env.staging
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ NEXT_PUBLIC_SENTRY_DSN="https://67a92c8c0f70486d9f36f2352eff1d19@sentry.fabrique
NEXT_PUBLIC_SENTRY_ENV="development"
NEXT_PUBLIC_MATOMO_URL=""
NEXT_PUBLIC_MATOMO_SITE_ID=""
NEXT_PUBLIC_APP_REPOSITORY_URL="https://github.com/SocialGouv/template"
6 changes: 5 additions & 1 deletion .github/workflows/preproduction.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ jobs:
- name: Get project name
run: |
echo "project=${GITHUB_REPOSITORY#*/}" >> $GITHUB_ENV
- name: Get commit sha
run: |
echo "GITHUB_SHA=${GITHUB_SHA}" >> $GITHUB_ENV
- name: Use autodevops to deploy review branch
uses: SocialGouv/actions/autodevops-helm@v1
with:
Expand All @@ -28,3 +30,5 @@ jobs:
rancherId: ${{ secrets.RANCHER_PROJECT_ID }}
rancherProjectName: ${{ secrets.RANCHER_PROJECT_NAME }}
socialgouvBaseDomain: ${{ secrets.SOCIALGOUV_BASE_DOMAIN }}
dockerbuildargs: |
GITHUB_SHA=${{ env.GITHUB_SHA }}
4 changes: 4 additions & 0 deletions .github/workflows/production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ jobs:
- name: Get project name
run: |
echo "project=${GITHUB_REPOSITORY#*/}" >> $GITHUB_ENV
- name: Get commit sha
run: |
echo "GITHUB_SHA=${GITHUB_SHA}" >> $GITHUB_ENV
- name: Use autodevops to deploy production
uses: SocialGouv/actions/autodevops-helm@v1
id: autodevops
Expand All @@ -33,3 +36,4 @@ jobs:
socialgouvBaseDomain: ${{ secrets.SOCIALGOUV_BASE_DOMAIN }}
dockerbuildargs: |
PRODUCTION=true
GITHUB_SHA=${{ env.GITHUB_SHA }}
4 changes: 3 additions & 1 deletion .github/workflows/review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ jobs:
- name: Get project name
run: |
echo "project=${GITHUB_REPOSITORY#*/}" >> $GITHUB_ENV
- name: Get commit sha
run: |
echo "GITHUB_SHA=${GITHUB_SHA}" >> $GITHUB_ENV
- name: Use autodevops to deploy review branch
uses: SocialGouv/actions/autodevops-helm@v1
with:
Expand Down
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ RUN yarn install --frozen-lockfile

# Rebuild the source code only when needed
FROM node:$NODE_VERSION AS builder
ENV NODE_ENV production
ARG PRODUCTION
ENV NODE_ENV production
ARG GITHUB_SHA
ENV GITHUB_SHA $GITHUB_SHA
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
Expand Down
8 changes: 8 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
// https://docs.sentry.io/platforms/javascript/guides/nextjs/
const { withSentryConfig } = require("@sentry/nextjs");

const { version } = require("./package.json");

const commitSha = process.env.GITHUB_SHA || "dev";

/** @type {import('next').NextConfig} */
const moduleExports = {
reactStrictMode: true,
Expand All @@ -23,6 +27,10 @@ const sentryWebpackPluginOptions = {
silent: true, // Suppresses all logs
// For all available options, see:
// https://github.com/getsentry/sentry-webpack-plugin#options.
env: {
NEXT_PUBLIC_APP_VERSION: version,
NEXT_PUBLIC_APP_VERSION_COMMIT: commitSha,
},
};

// Make sure adding Sentry options is the last code to run before exporting, to
Expand Down
24 changes: 23 additions & 1 deletion src/components/footer/bottom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,28 @@ export const Bottom = (props: FooterBottomSectionProps): JSX.Element => (
{link.title}
</FooterLink>
))}
<FooterCopy>{props.copyright}</FooterCopy>
<FooterCopy>
<p>
Sauf mention contraire, tous les contenus de ce site sont sous{" "}
<a
href="https://github.com/etalab/licence-ouverte/blob/master/LO.md"
rel="noreferrer"
target="_blank"
>
licence etalab-2.0
</a>
</p>
<p>
Version {props.version} (
<a
target="_blank"
href={`${props.repositoryUrl}/tree/${props.commitHash}`}
rel="noreferrer"
>
{props.commitHash.substring(0, 8)}
</a>
)
</p>
</FooterCopy>
</FooterBottom>
);
4 changes: 3 additions & 1 deletion src/components/footer/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ export type FooterPartnerSectionProps = {

export type FooterBottomSectionProps = {
links: Array<Link>;
copyright: string;
version: string;
repositoryUrl: string;
commitHash: string;
};

export type FooterTopSectionProps = {
Expand Down
40 changes: 0 additions & 40 deletions src/components/header/body.tsx

This file was deleted.

15 changes: 2 additions & 13 deletions src/components/header/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from "react";
import { ComponentStory, ComponentMeta } from "@storybook/react";

import Header from ".";
import { headerBody, headerNav } from "@config";
import { headerProps } from "@config";

export default {
title: "Header",
Expand All @@ -13,16 +13,5 @@ const Template: ComponentStory<typeof Header> = args => <Header {...args} />;

export const Default = Template.bind({});
Default.args = {
bodySection: headerBody,
navSection: headerNav,
};

export const Body = Template.bind({});
Body.args = {
bodySection: headerBody,
};

export const Nav = Template.bind({});
Nav.args = {
navSection: headerNav,
...headerProps,
};
76 changes: 71 additions & 5 deletions src/components/header/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,78 @@
import { Header } from "@dataesr/react-dsfr";
import { Body } from "./body";
import { Nav } from "./nav";
import {
HeaderNav,
NavItem,
NavSubItem,
Header,
ToolItem,
Logo,
HeaderBody,
Service,
HeaderOperator,
ToolItemGroup,
Tool,
} from "@dataesr/react-dsfr";
import { MegaNav } from "./megaNav";
import { HeaderProps } from "./type";
import { SwitchThemeMode } from "./switch";

const Index = (props: HeaderProps): JSX.Element => (
<Header>
{props.bodySection && <Body {...props.bodySection} />}
{props.navSection && <Nav {...props.navSection} />}
<HeaderBody>
<Logo splitCharacter={props.splitTitleLength ?? 10}>
{props.mainTitle}
</Logo>
{props.image && (
<HeaderOperator>
<img
src={props.image.src}
alt={props.image.alt}
style={{ height: props.image.height, width: props.image.width }}
/>
</HeaderOperator>
)}
<Service
title={props.serviceTitle}
description={props.serviceDescription}
/>
<Tool {...props.closeButtonLabel}>
<ToolItemGroup>
{props.bodyItems?.map((item, index) => (
<ToolItem key={`${index}-${item.title}`} link={item.href}>
{item.title}
</ToolItem>
))}
{props.switchProps && <SwitchThemeMode {...props.switchProps} />}
</ToolItemGroup>
</Tool>
</HeaderBody>
<HeaderNav>
{props.navItems.map((item, index) => {
if ("headingLevel" in item) {
return <MegaNav key={`${index}-${item.title}`} {...item} />;
} else if ("items" in item) {
return (
<NavItem key={`${index}-${item.title}`} title={item.title}>
{item.items?.map((subItem, index) => (
<NavSubItem
key={`${index}-${subItem.title}`}
title={subItem.title}
link={subItem.href}
current={subItem.current}
/>
))}
</NavItem>
);
} else {
return (
<NavItem
key={`${index}-${item.title}`}
title={item.title}
link={item.href}
/>
);
}
})}
</HeaderNav>
</Header>
);

Expand Down
34 changes: 0 additions & 34 deletions src/components/header/nav.tsx

This file was deleted.

15 changes: 4 additions & 11 deletions src/components/header/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,16 @@ export type MegaNavProps = {
items: Array<NavItem>;
};

export type HeaderNavProps = {
items: Array<RegularNavProps | MegaNavProps>;
};

export type HeaderBodyProps = {
export type HeaderProps = {
mainTitle: string;
splitTitleLength?: number;
image?: Image;
serviceTitle: string;
serviceDescription: string;
items?: Array<Omit<Link, "name">>;
bodyItems?: Array<Omit<Link, "name">>;
switchProps?: SwitchProps;
};

export type HeaderProps = {
navSection?: HeaderNavProps;
bodySection: HeaderBodyProps;
closeButtonLabel?: string;
navItems: Array<RegularNavProps | MegaNavProps>;
};

export type SwitchProps = {
Expand Down
Loading

0 comments on commit c9de1f0

Please sign in to comment.