Skip to content

Commit 17c1e3b

Browse files
authored
Merge pull request #99 from samuel-gomez/refactor/update-custom-table-accessibility
Refactor/update custom table accessibility
2 parents 9640e41 + f3e7459 commit 17c1e3b

File tree

34 files changed

+186
-597
lines changed

34 files changed

+186
-597
lines changed

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,8 @@
99
},
1010
"[feature]": {
1111
"editor.defaultFormatter": "alexkrechik.cucumberautocomplete"
12+
},
13+
"editor.codeActionsOnSave": {
14+
"source.organizeImports": "always"
1215
}
1316
}

src/pages/Demos/Members/Members.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { Paging } from '@axa-fr/react-toolkit-all';
2-
import Resilience from 'shared/components/Resilience';
32
import Layout, { type TLayoutPage } from 'Layout';
4-
import { Tanomaly } from 'shared/types';
53
import Loader, { type TLoader } from 'shared/components/Loader';
4+
import Resilience from 'shared/components/Resilience';
65
import Table from 'shared/components/Table';
7-
import { TITLE_BAR, TITLE, TABLE_HEADERS_MEMBERS } from './constants';
6+
import type { Tanomaly } from 'shared/types';
87
import type { TReturnUseMembers } from './Members.hook';
8+
import { TABLE_HEADERS_MEMBERS, TABLE_ITEMS_TYPE, TITLE, TITLE_BAR } from './constants';
99

1010
export type TMembers = TLayoutPage & {
1111
loaderMode: TLoader['mode'];
@@ -16,6 +16,7 @@ export type TMembers = TLayoutPage & {
1616
sorting: TReturnUseMembers['sorting'];
1717
members: TReturnUseMembers['members'];
1818
anomaly: Tanomaly | null;
19+
title?: string;
1920
headers?: typeof TABLE_HEADERS_MEMBERS;
2021
};
2122

@@ -36,7 +37,7 @@ const Members = ({
3637
<h1 className="af-title--content">{title}</h1>
3738
<Loader mode={loaderMode}>
3839
<Resilience anomaly={anomaly} refetch={refetch as React.MouseEventHandler<HTMLButtonElement>}>
39-
<Table items={members} headers={headers} onSort={onChangeSorting} sorting={sorting} aria-label={`Tableau ${title}`} />
40+
<Table title={title} items={members} itemsType={TABLE_ITEMS_TYPE} headers={headers} onSort={onChangeSorting} sorting={sorting} />
4041
<Paging {...pagination} onChange={onChangePaging} id="paging" />
4142
</Resilience>
4243
</Loader>

src/pages/Demos/Members/__tests__/Members.spec.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ import { render, screen } from 'shared/testsUtils/customRender';
33
import { serverUseGet } from 'shared/testsUtils/msw';
44
import {
55
JeSuisUnUtilisateurConnuEtConnecteAvecleProfil,
6+
LaPageContientUnTableau,
67
LeTableauContientLesLignesCorrespondantAuxDonneesRecues,
78
LeTableauPresenteDesEntetesDeTriDeColonnesDansLOrdreSuivant,
8-
LaPageContientUnTableau,
99
} from 'shared/testsUtils/sharedScenarios';
1010
import Members from '..';
11-
import { totals } from './Members.mock';
1211
import type { TresponseBody } from '../Members.hook';
12+
import { totals } from './Members.mock';
1313

1414
const feature = loadFeature('features/Demos/Members/Members.feature');
15-
const tableAriaLabel = 'Tableau Liste des membres';
15+
const tableItemsType = 'membres';
1616

1717
defineFeature(feature, test => {
1818
let role: string;
@@ -31,18 +31,18 @@ defineFeature(feature, test => {
3131
expect(await screen.findByText('Samuel')).toBeInTheDocument();
3232
});
3333

34-
LaPageContientUnTableau(then, 'la page contient un tableau répertoriant la liste des membres', tableAriaLabel);
34+
LaPageContientUnTableau(then, 'la page contient un tableau répertoriant la liste des membres', tableItemsType);
3535

3636
LeTableauPresenteDesEntetesDeTriDeColonnesDansLOrdreSuivant(
3737
and,
3838
/^le tableau présente des entêtes de tri de colonnes dans lordre suivant : "(.*)", "(.*)", "(.*)", "(.*)"$/,
39-
tableAriaLabel,
39+
tableItemsType,
4040
);
4141

4242
LeTableauContientLesLignesCorrespondantAuxDonneesRecues(
4343
and,
4444
/^le tableau contient (\d+) lignes avec (\d+) colonnes dans l'ordre suivant :$/,
45-
tableAriaLabel,
45+
tableItemsType,
4646
);
4747
});
4848
});

src/pages/Demos/Members/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { ASCENDING, Torder } from 'shared/components/Table';
33
export const TITLE_BAR = 'Gestion des membres';
44
export const TITLE = 'Liste des membres';
55
export const ROUTE_URL_MEMBERS = 'members';
6+
export const TABLE_ITEMS_TYPE = 'membres';
67

78
export const TABLE_HEADERS_MEMBERS = [
89
{ label: 'Prénom', field: 'firstname', id: 'firstname', key: 'firstname' },

src/pages/Demos/SearchMembers/SearchMembers.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Resilience from 'shared/components/Resilience';
55
import Table from 'shared/components/Table';
66
import DownloadLink from 'shared/components/DownloadLink';
77
import { formatDate } from 'shared/helpers/formatDate';
8-
import { TITLE_BAR, TITLE, SUBTITLE, TABLE_HEADERS_SEARCHMEMBERS } from './constants';
8+
import { TITLE_BAR, TITLE, SUBTITLE, TABLE_HEADERS_SEARCHMEMBERS, TABLE_ITEMS_TYPE } from './constants';
99
import SearchForm from './SearchForm';
1010
import type { TReturnUseFormSearchMembers, TReturnUseSearchMembers } from './SearchMembers.hook';
1111

@@ -36,6 +36,7 @@ type TSearchMembers = TLayoutPage &
3636
Omit<TReturnUseSearchMembers, 'isLoading'> & {
3737
loaderMode: TLoader['mode'];
3838
submitFormSearchMembers: TReturnUseFormSearchMembers['submitFormSearchMembers'];
39+
title?: string;
3940
};
4041

4142
const SearchMembers = ({ titleBar = TITLE_BAR, title = TITLE, loaderMode, searchMembers, anomaly, submitFormSearchMembers }: TSearchMembers) => (
@@ -54,7 +55,7 @@ const SearchMembers = ({ titleBar = TITLE_BAR, title = TITLE, loaderMode, search
5455
<Loader message="Recherche des membres en cours..." mode={loaderMode}>
5556
<Resilience anomaly={anomaly}>
5657
<h2 className="af-title">{SUBTITLE}</h2>
57-
<Table items={searchMembers} headers={TABLE_HEADERS_SEARCHMEMBERS} />
58+
<Table itemsType={TABLE_ITEMS_TYPE} title={title} items={searchMembers} headers={TABLE_HEADERS_SEARCHMEMBERS} />
5859
</Resilience>
5960
</Loader>
6061
</Layout>

src/pages/Demos/SearchMembers/__tests__/SearchMembers.test.tsx

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { screen } from '@testing-library/react';
22
import { MODES } from 'shared/components/Loader';
33
import { emptyFunction, render } from 'shared/testsUtils';
4-
import SearchMembers, { getDownloadPath, setFileName, DownloadLinkEnhanced } from '../SearchMembers';
4+
import SearchMembers, { DownloadLinkEnhanced, getDownloadPath, setFileName } from '../SearchMembers';
55

66
describe('getDownloadPath', () => {
77
it('Should return "members/0064962455/download-detail" When getDownloadPath with memberId "0064962455"', () => {
@@ -40,18 +40,11 @@ describe('<DownloadLinkEnhanced />', () => {
4040
firstname: 'samuel',
4141
lastname: 'gomez',
4242
};
43-
it('Should call getDownloadPathFn and setFileNameFn with proper params', () => {
44-
const { asFragment } = render(
45-
<DownloadLinkEnhanced {...defaultDownloadProps} getDownloadPathFn={getDownloadPathFnMock} setFileNameFn={setFileNameFnMock} />,
46-
);
47-
expect(asFragment()).toMatchSnapshot();
48-
expect(getDownloadPathFnMock).toBeCalledWith('09878817');
49-
expect(setFileNameFnMock).toBeCalledWith({ memberId: '09878817', name: 'samuel-gomez' });
50-
});
5143

52-
it('Should call getDownloadPathFn and setFileNameFn with proper params 2 ', () => {
53-
const { asFragment } = render(<DownloadLinkEnhanced {...defaultDownloadProps} />);
54-
expect(asFragment()).toMatchSnapshot();
44+
it('Should call getDownloadPathFn and setFileNameFn with proper params', () => {
45+
render(<DownloadLinkEnhanced {...defaultDownloadProps} getDownloadPathFn={getDownloadPathFnMock} setFileNameFn={setFileNameFnMock} />);
46+
expect(getDownloadPathFnMock).toHaveBeenCalledWith('09878817');
47+
expect(setFileNameFnMock).toHaveBeenCalledWith({ memberId: '09878817', name: 'samuel-gomez' });
5548
});
5649
});
5750

src/pages/Demos/SearchMembers/__tests__/__snapshots__/SearchMembers.test.tsx.snap

Lines changed: 0 additions & 59 deletions
This file was deleted.

src/pages/Demos/SearchMembers/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export const TITLE_BAR = 'Recherche de membres';
22
export const TITLE = 'Recherche par Nom';
33
export const SUBTITLE = 'Tableau des membres';
44
export const ROUTE_URL_SEARCHMEMBERS = 'search-members';
5+
export const TABLE_ITEMS_TYPE = 'membres';
56

67
export const TABLE_HEADERS_SEARCHMEMBERS = [
78
{ label: 'Prénom du membre', key: 'firstname' },

src/shared/components/Table/Body/Body.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { ReactNode } from 'react';
21
import { Table as TableTk } from '@axa-fr/react-toolkit-all';
2+
import type { ReactNode } from 'react';
33
import Line from './Line';
44

55
export type Tcol = {
@@ -20,13 +20,12 @@ type TItems = {
2020
};
2121

2222
export type TBody = {
23-
ariaLabel?: string;
2423
items?: TItems[];
2524
children?: ReactNode;
2625
};
2726

28-
const Body = ({ items = [], children, ariaLabel = 'table-body' }: TBody) => (
29-
<TableTk.Body aria-label={ariaLabel}>
27+
const Body = ({ items = [], children }: TBody) => (
28+
<TableTk.Body>
3029
{items.map(({ key, classModifier, cols }) => (
3130
<Line key={key} classModifier={classModifier} cols={Object.entries({ ...cols })} />
3231
))}

src/shared/components/Table/Body/Line/Line.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
import { ComponentPropsWithoutRef } from 'react';
21
import { Table as TableTk } from '@axa-fr/react-toolkit-all';
2+
import { ComponentPropsWithoutRef } from 'react';
33
import Td, { TTdContainer } from './Td';
44

55
export type TLine = ComponentPropsWithoutRef<typeof TableTk.Tr> & {
66
columns: (TTdContainer & { keyCol: string })[];
7-
ariaLabel?: string;
87
};
98

10-
const Line = ({ className, columns = [], classModifier = '', children, ariaLabel = 'table-body-line' }: TLine) => (
11-
<TableTk.Tr classModifier={classModifier} className={className} aria-label={ariaLabel}>
9+
const Line = ({ className, columns = [], classModifier = '', children }: TLine) => (
10+
<TableTk.Tr classModifier={classModifier} className={className}>
1211
<>
1312
{columns.map(({ keyCol, ...restTd }) => (
1413
<Td key={keyCol} {...restTd} />

0 commit comments

Comments
 (0)