Skip to content

Commit

Permalink
chore: migrate to HDS v3 (#3466)
Browse files Browse the repository at this point in the history
* chore: upgrade to HDS v3

* fix(benefit): migrate to renamed euro sign

* feat(shared): introduce shared Header v3 component

* feat(benefit): use HDS v3 <Header>

* fix(benefit): reformat <Header>'s custom items

* chore(benefit): migrate to new footer

* chore: update hds-react to 3.11

* chore: update tet-youth

* chore: update tet-admin

* fix: headerV3 props

* fix: hds 3.11 was missing from yarn.lock

* fix: headerV3 types

* fix: tet-admin ssr issues

* fix: tet-youth ssr issues

* fix: remove desing tokens 3.11 that was accidentally in yarn.lock

* fix: add missing keys to loops

* fix: linter and unit tests

* fix: migrate to displaying primary languages as links

* chore: add translation to footer backToTop link

* chore: update hds in kesaseteli to v3

* fix: remove unused import

* fix: header language selection test

* chore: remove old shared header

* fix: linter issues in tests

* fix: adjust e2e test

* fix: e2e test selector

* fix: revert login links dynamic wrapper change

* fix: switch link to button

* fix: linter error

* chore: test what line fails

* chore: test what line fails

* fix: language change unit test

* fix: linter error and logout test

* fix: tet admin browser test

* fix: user aria-label test

* chore: rename HeaderV3 to Header

* fix: hds header import

* fix: login button selector

* chore: update hds design tokens

* fix: typos and array

---------

Co-authored-by: Mikko Riippi <[email protected]>
  • Loading branch information
sirtawast and Riippi authored Dec 16, 2024
1 parent 192dc77 commit 8bf6c73
Show file tree
Hide file tree
Showing 64 changed files with 676 additions and 501 deletions.
4 changes: 2 additions & 2 deletions frontend/benefit/applicant/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
"dotenv": "^16.0.0",
"finnish-ssn": "^2.1.2",
"formik": "^2.2.9",
"hds-design-tokens": "^2.17.1",
"hds-react": "^2.17.1",
"hds-design-tokens": "^3.11.0",
"hds-react": "^3.11.0",
"lodash": "^4.17.21",
"next": "14.2.12",
"next-router-mock": "0.9.12",
Expand Down
3 changes: 2 additions & 1 deletion frontend/benefit/applicant/public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,8 @@
"aboutTheService": "About the service",
"accessibilityStatementLink": "https://www.hel.fi/helsinki/en/administration/information/information/accessibility",
"aboutTheServiceLink": "https://www.hel.fi/en/business-and-work/employers/helsinki-benefit-for-employers",
"cookieSettings": "Cookie settings"
"cookieSettings": "Cookie settings",
"backToTop": "Back to top"
},
"notifications": {
"applicationSubmitted": {
Expand Down
3 changes: 2 additions & 1 deletion frontend/benefit/applicant/public/locales/fi/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,8 @@
"aboutTheService": "Tietoa palvelusta",
"accessibilityStatementLink": "https://www.hel.fi/helsinki/fi/kaupunki-ja-hallinto/tietoa-helsingista/tietoa-hel-fista/saavutettavuus/saavutettavuusselosteet",
"aboutTheServiceLink": "https://www.hel.fi/fi/yritykset-ja-tyo/tyonantajat/taloudelliset-tuet/tyonantajan-helsinki-lisa",
"cookieSettings": "Evästeasetukset"
"cookieSettings": "Evästeasetukset",
"backToTop": "Takaisin ylös"
},
"notifications": {
"applicationSubmitted": {
Expand Down
3 changes: 2 additions & 1 deletion frontend/benefit/applicant/public/locales/sv/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,8 @@
"aboutTheService": "Information om tjänsten",
"accessibilityStatementLink": "https://www.hel.fi/helsinki/sv/stad-och-forvaltning/information/information/tillganglighet",
"aboutTheServiceLink": "https://www.hel.fi/sv/foretag-och-arbete/arbetsgivare/arbetsgivarens-helsingforstillagg",
"cookieSettings": "Cookie -inställningar"
"cookieSettings": "Cookie -inställningar",
"backToTop": "Tillbaka till toppen"
},
"notifications": {
"applicationSubmitted": {
Expand Down
12 changes: 8 additions & 4 deletions frontend/benefit/applicant/src/components/footer/Footer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useTranslation } from 'benefit/applicant/i18n';
import { Footer } from 'hds-react';
import { Footer, Logo, logoFiDark } from 'hds-react';
import React from 'react';
import useLocale from 'shared/hooks/useLocale';

Expand All @@ -15,20 +15,24 @@ const FooterSection: React.FC = () => {
<Footer.Base
copyrightHolder={t('common:footer.copyrightText')}
copyrightText={t('common:footer.allRightsReservedText')}
backToTopLabel={t('common:footer.backToTop')}
logo={
<Logo src={logoFiDark} size="medium" alt="Helsingin kaupunki" />
}
>
<Footer.Item
<Footer.Link
as="a"
rel="noopener noreferrer"
target="_blank"
href={`/${locale}/accessibility-statement`}
label={t('common:footer.accessibilityStatement')}
/>
<Footer.Item
<Footer.Link
as="a"
href={`/${locale}/cookie-settings`}
label={t('common:footer.cookieSettings')}
/>
<Footer.Item
<Footer.Link
as="a"
rel="noopener noreferrer"
target="_blank"
Expand Down
16 changes: 4 additions & 12 deletions frontend/benefit/applicant/src/components/header/useHeader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ type ExtendedComponentProps = {
navigationItems: NavigationItem[];
isNavigationVisible: boolean;
hasMessenger: boolean;
handleLanguageChange: (
e: React.SyntheticEvent<unknown>,
newLanguage: OptionType<string>
) => void;
handleLanguageChange: (newLanguage: SUPPORTED_LANGUAGES) => void;
handleNavigationItemClick: (url: string) => void;
unreadMessagesCount: number | undefined | null;
setMessagesDrawerVisiblity: (state: boolean) => void;
Expand Down Expand Up @@ -141,18 +138,13 @@ const useHeader = (): ExtendedComponentProps => {
);
}, [status, setHasMessenger]);

const handleLanguageChange = (
e: React.SyntheticEvent<unknown>,
newLanguage: OptionType<string>
): void => {
e.preventDefault();

const handleLanguageChange = (newLanguage: SUPPORTED_LANGUAGES): void => {
void axios.get(BackendEndpoint.USER_OPTIONS, {
params: { lang: newLanguage.value },
params: { lang: newLanguage },
});

void router.push({ pathname, query }, asPath, {
locale: newLanguage.value,
locale: newLanguage,
});
};

Expand Down
4 changes: 2 additions & 2 deletions frontend/benefit/handler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
"finnish-ssn": "^2.1.2",
"formik": "^2.2.9",
"fuse.js": "^6.6.2",
"hds-design-tokens": "^2.17.1",
"hds-react": "^2.17.1",
"hds-design-tokens": "^3.11.0",
"hds-react": "^3.11.0",
"ibantools": "^4.3.4",
"lodash": "^4.17.21",
"next": "14.2.12",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ROUTES } from 'benefit/handler/constants';
import { UploadProps } from 'benefit/handler/types/application';
import { Button, IconGlyphEuro } from 'hds-react';
import { Button, IconEuroSign } from 'hds-react';
import { useRouter } from 'next/router';
import { useTranslation } from 'next-i18next';
import * as React from 'react';
Expand Down Expand Up @@ -33,7 +33,7 @@ const EmployeeActions: React.FC<UploadProps> = () => {
onClick={handleCloseClick}
theme="black"
variant="secondary"
iconLeft={<IconGlyphEuro />}
iconLeft={<IconEuroSign />}
>
{t(`${translationsBase}.addPreviouslyGrantedBenefit`)}
</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
CALCULATION_ROW_TYPES,
} from 'benefit-shared/constants';
import { Application } from 'benefit-shared/types/application';
import { Accordion, IconGlyphEuro, IconMoneyBag } from 'hds-react';
import { Accordion, IconEuroSign, IconMoneyBag } from 'hds-react';
import { useTranslation } from 'next-i18next';
import * as React from 'react';
import { $ViewField } from 'shared/components/benefit/summaryView/SummaryView.sc';
Expand Down Expand Up @@ -49,7 +49,7 @@ const DecisionCalculationAccordion: React.FC<Props> = ({ data }) => {
<>
<$DecisionCalculatorAccordion>
<$DecisionCalculatorAccordionIconContainer aria-hidden="true">
<IconGlyphEuro />
<IconEuroSign />
</$DecisionCalculatorAccordionIconContainer>
<Accordion
heading={t('common:applications.decision.calculation')}
Expand Down
5 changes: 4 additions & 1 deletion frontend/benefit/handler/src/components/footer/Footer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import AppContext from 'benefit/handler/context/AppContext';
import { Footer } from 'hds-react';
import { Footer, Logo, logoFiDark } from 'hds-react';
import { useTranslation } from 'next-i18next';
import React from 'react';

Expand All @@ -20,6 +20,9 @@ const FooterSection: React.FC = () => {
<Footer.Base
copyrightHolder={t('footer.copyrightText')}
copyrightText={t('footer.allRightsReservedText')}
logo={
<Logo src={logoFiDark} size="medium" alt="Helsingin kaupunki" />
}
/>
</Footer>
</$FooterWrapper>
Expand Down
11 changes: 11 additions & 0 deletions frontend/benefit/handler/src/components/header/Header.sc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ export const $BaseHeader = styled(BaseHeader)`
background: #1a1a1a;
`;

export const $HeaderCustomItems = styled.ul`
display: flex;
align-items: center;
margin-right: var(--spacing-s);
list-style-type: none;
margin: 0;
> li {
margin-right: var(--spacing-xs);
}
`;

export const $ToggleButton = styled.button`
all: initial;
border-radius: 50%;
Expand Down
22 changes: 15 additions & 7 deletions frontend/benefit/handler/src/components/header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as React from 'react';
import { getFullName } from 'shared/utils/application.utils';
import { DefaultTheme } from 'styled-components';

import { $BaseHeader } from './Header.sc';
import { $BaseHeader, $HeaderCustomItems } from './Header.sc';
import HeaderNotifier from './HeaderNotifier';
import { useHeader } from './useHeader';

Expand All @@ -34,15 +34,23 @@ const Header: React.FC = () => {
}
);

const customItems = (
<$HeaderCustomItems key="custom-items">
<li key="header-notifier">
<HeaderNotifier />
</li>
{process.env.NEXT_PUBLIC_SENTRY_ENVIRONMENT !== 'production' ? (
<li key="ahjo-mode-switch">
<TemporaryAhjoModeSwitch />
</li>
) : null}
</$HeaderCustomItems>
);

return (
<$BaseHeader
title={t('common:appName')}
customItems={[
process.env.NEXT_PUBLIC_SENTRY_ENVIRONMENT !== 'production' ? (
<TemporaryAhjoModeSwitch />
) : null,
<HeaderNotifier />,
]}
customItems={customItems}
titleUrl={ROUTES.HOME}
skipToContentLabel={t('common:header.linkSkipToContent')}
menuToggleAriaLabel={t('common:header.menuToggleAriaLabel')}
Expand Down
13 changes: 3 additions & 10 deletions frontend/benefit/handler/src/components/header/useHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ type ExtendedComponentProps = {
languageOptions: OptionType<string>[];
isNavigationVisible?: boolean;
navigationItems?: NavigationItem[];
handleLanguageChange: (
e: React.SyntheticEvent<unknown>,
newLanguage: OptionType<string>
) => void;
handleLanguageChange: (newLanguage: SUPPORTED_LANGUAGES) => void;
handleNavigationItemClick: (pathname: string) => void;
handleTitleClick: () => void;
};
Expand Down Expand Up @@ -108,12 +105,8 @@ const useHeader = (): ExtendedComponentProps => {
[items.default, items.newAhjo, isNewAhjoMode]
);

const handleLanguageChange = (
e: React.SyntheticEvent<unknown>,
newLanguage: OptionType<string>
): void => {
e.preventDefault();
void router.push('/', '/', { locale: newLanguage.value });
const handleLanguageChange = (newLanguage: SUPPORTED_LANGUAGES): void => {
void router.push('/', '/', { locale: newLanguage });
};

const handleNavigationItemClick = (pathname: string): void => {
Expand Down
2 changes: 1 addition & 1 deletion frontend/benefit/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"camelcase-keys": "^7.0.1",
"date-fns": "^2.24.0",
"formik": "^2.2.9",
"hds-react": "^2.17.1",
"hds-react": "^3.11.0",
"ibantools": "^4.1.5",
"next": "14.2.12",
"next-i18next": "^13.0.3",
Expand Down
2 changes: 1 addition & 1 deletion frontend/kesaseteli/employer/next-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
// see https://nextjs.org/docs/pages/building-your-application/configuring/typescript for more information.
4 changes: 2 additions & 2 deletions frontend/kesaseteli/employer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
"@sentry/nextjs": "^7.16.0",
"axios": "^0.27.2",
"dotenv": "^16.0.0",
"hds-design-tokens": "^2.17.1",
"hds-react": "^2.17.1",
"hds-design-tokens": "^3.11.0",
"hds-react": "^3.11.0",
"ibantools": "^4.1.5",
"lodash": "^4.17.21",
"next": "14.2.12",
Expand Down
3 changes: 2 additions & 1 deletion frontend/kesaseteli/employer/public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@
"accessibilityStatement": "Accessibility statement",
"accessibilityStatementLink": "https://www.hel.fi/helsinki/en/administration/information/information/accessibility",
"information": "Information on the service",
"informationLink": "https://kesaseteli.fi/en/"
"informationLink": "https://kesaseteli.fi/en/",
"backToTop": "Back to top"
},
"languages": {
"fi": "Suomeksi",
Expand Down
3 changes: 2 additions & 1 deletion frontend/kesaseteli/employer/public/locales/fi/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@
"accessibilityStatement": "Saavutettavuusseloste",
"accessibilityStatementLink": "https://www.hel.fi/helsinki/fi/kaupunki-ja-hallinto/tietoa-helsingista/tietoa-hel-fista/saavutettavuus/saavutettavuusselosteet",
"information": "Tietoa palvelusta",
"informationLink": "https://kesaseteli.fi/"
"informationLink": "https://kesaseteli.fi/",
"backToTop": "Takaisin ylös"
},
"languages": {
"fi": "Suomeksi",
Expand Down
3 changes: 2 additions & 1 deletion frontend/kesaseteli/employer/public/locales/sv/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@
"accessibilityStatement": "Tillgänglighetsutlåtande",
"accessibilityStatementLink": "https://www.hel.fi/helsinki/sv/stad-och-forvaltning/information/information/tillganglighet",
"information": "Information om servicen",
"informationLink": "https://kesaseteli.fi/sv/"
"informationLink": "https://kesaseteli.fi/sv/",
"backToTop": "Tillbaka till toppen"
},
"languages": {
"fi": "Suomeksi",
Expand Down
10 changes: 7 additions & 3 deletions frontend/kesaseteli/employer/src/components/footer/Footer.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Footer } from 'hds-react';
import { Footer, Logo, logoFiDark } from 'hds-react';
import { useTranslation } from 'next-i18next';
import React from 'react';

Expand All @@ -12,15 +12,19 @@ const FooterSection: React.FC = () => {
<Footer.Base
copyrightHolder={t('common:footer.copyrightText')}
copyrightText={t('common:footer.allRightsReservedText')}
backToTopLabel={t('common:footer.backToTop')}
logo={
<Logo src={logoFiDark} size="medium" alt="Helsingin kaupunki" />
}
>
<Footer.Item
<Footer.Link
as="a"
rel="noopener noreferrer"
target="_blank"
href={t('common:footer.informationLink')}
label={t('common:footer.information')}
/>
<Footer.Item
<Footer.Link
as="a"
rel="noopener noreferrer"
target="_blank"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@ const Header: React.FC = () => {
);

const handleLanguageChange = React.useCallback(
(
e: React.SyntheticEvent<unknown>,
{ value: lang }: OptionType<string>
): void => {
e.preventDefault();
(lang: string): void => {
void router.push(asPath, asPath, {
locale: lang,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import { DEFAULT_LANGUAGE, SUPPORTED_LANGUAGES } from 'shared/i18n/i18n';

const fakeObjectFactory = new FakeObjectFactory();

// Languages need to start with something else than 'fi' to avoid the default language
const REVERSED_LANGUAGES = [...SUPPORTED_LANGUAGES].reverse();

describe('frontend/kesaseteli/employer/src/components/header/Header.tsx', () => {
it('Redirects to backend when clicked login button', async () => {
expectUnauthorizedReply();
Expand Down Expand Up @@ -51,8 +54,8 @@ describe('frontend/kesaseteli/employer/src/components/header/Header.tsx', () =>
const spyRouterPush = jest.fn();
renderComponent(<Header />, { push: spyRouterPush });
await headerApi.expectations.userIsLoggedOut();
for (const lang of SUPPORTED_LANGUAGES) {
await headerApi.actions.changeLanguage('fi', lang);
for (const lang of REVERSED_LANGUAGES) {
await headerApi.actions.changeLanguage(lang);
await waitFor(() =>
expect(spyRouterPush).toHaveBeenCalledWith(undefined, undefined, {
locale: String(lang),
Expand Down
2 changes: 1 addition & 1 deletion frontend/kesaseteli/handler/next-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
// see https://nextjs.org/docs/pages/building-your-application/configuring/typescript for more information.
4 changes: 2 additions & 2 deletions frontend/kesaseteli/handler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
"axios": "^0.27.2",
"dotenv": "^16.0.0",
"finnish-ssn": "^2.1.2",
"hds-design-tokens": "^2.17.1",
"hds-react": "^2.17.1",
"hds-design-tokens": "^3.11.0",
"hds-react": "^3.11.0",
"lodash": "^4.17.21",
"next": "14.2.12",
"next-compose-plugins": "^2.2.1",
Expand Down
Loading

0 comments on commit 8bf6c73

Please sign in to comment.