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

Upgrade @codegouvfr/react-dsfr from 1.9.16 to 1.16 #933

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
e85cb1f
fix: upgrade @codegouvfr/react-dsfr from 1.9.16 to 1.13.2
snyk-bot Oct 3, 2024
a75d8b4
chore: upgrade @codegouvfr/react-dsfr
Falinor Nov 28, 2024
7ad3cad
chore: upgrade @codegouvfr/react-dsfr to v1.15.0
Falinor Dec 4, 2024
2a18cf8
feat(frontend): add OccupancyTag
Falinor Dec 11, 2024
b9b5939
chore(frontend): add @tanstack/react-table
Falinor Dec 11, 2024
ee48a31
feat(frontend): create a new table using @tanstack/react-table
Falinor Dec 11, 2024
6077e99
feat(frontend): cut campaign name if it is too long
Falinor Dec 12, 2024
2e04ccc
feat(frontend): select all housings
Falinor Dec 12, 2024
f1eec0a
feat(frontend): add items per page select
Falinor Dec 12, 2024
9bb1621
feat(frontend): add sort to the housing table
Falinor Dec 16, 2024
e585f0d
fix(frontend): select housings correctly
Falinor Dec 16, 2024
6119a19
refactor: rework campaign list view and its table
Falinor Dec 17, 2024
fc5dd5d
fix(frontend): fix imports
Falinor Dec 17, 2024
ba51e7d
refactor(frontend): extract CampaignTable
Falinor Dec 17, 2024
324bf78
feat(frontend): extract AdvancedTableHeader
Falinor Dec 17, 2024
d2c0445
refactor(frontend): use the new AdvancedTable in CampaignRecipients
Falinor Dec 17, 2024
2069e4c
fix(frontend): use a Stack instead of a ButtonsGroup
Falinor Dec 18, 2024
fcb8dce
refactor(frontend): use AdvancedTable in HousingList
Falinor Dec 18, 2024
ecbd27a
fix(frontend): fix header alignment
Falinor Dec 18, 2024
18a081d
build: fix a build error because of the pnpm linker
Falinor Dec 18, 2024
1033df8
build(queue): fix type error
Falinor Dec 18, 2024
609eedd
build: fix a build error because of the pnpm linker
Falinor Dec 18, 2024
d32649f
chore(server): remove useless type definition
Falinor Dec 18, 2024
5df1bd5
chore: revert jest
Falinor Dec 18, 2024
1f25a1f
chore(frontend): polyfill jest to run tests
Falinor Dec 19, 2024
01a64d7
test(frontend): fix failing test
Falinor Dec 19, 2024
604c677
build(server): fix build error
Falinor Jan 6, 2025
2925fb6
fix(frontend): fix action table header
Falinor Jan 15, 2025
e93fa17
fix(frontend): stack campaigns in the housing table
Falinor Jan 15, 2025
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
3 changes: 2 additions & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ nodeLinker: pnpm
packageExtensions:
"@codegouvfr/react-dsfr@*":
dependencies:
react: "*"
"@types/react": "^18"
"react": "^18"
"@turf/dissolve@*":
dependencies:
"@turf/flatten": "*"
Expand Down
6 changes: 4 additions & 2 deletions frontend/jest.polyfills.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

const { TextDecoder, TextEncoder } = require('node:util');
const { ReadableStream, TransformStream } = require('node:stream/web');
const { BroadcastChannel } = require('node:worker_threads')

Object.defineProperties(globalThis, {
ReadableStream: { value: ReadableStream },
Expand All @@ -22,13 +23,14 @@ const { Blob, File } = require('node:buffer');
const { fetch, Headers, FormData, Request, Response } = require('undici');

Object.defineProperties(globalThis, {
fetch: { value: fetch, writable: true },
fetch: { value: fetch, writable: true, configurable: true },
Blob: { value: Blob },
File: { value: File },
Headers: { value: Headers },
FormData: { value: FormData },
Request: { value: Request, configurable: true },
Response: { value: Response, configurable: true }
Response: { value: Response, configurable: true },
BroadcastChannel: { value: BroadcastChannel },
});

Object.defineProperty(window, 'matchMedia', {
Expand Down
12 changes: 7 additions & 5 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
]
},
"dependencies": {
"@codegouvfr/react-dsfr": "1.9.16",
"@codegouvfr/react-dsfr": "1.16.0",
"@emotion/react": "^11.13.3",
"@emotion/styled": "^11.13.0",
"@hookform/resolvers": "^3.9.1",
Expand All @@ -36,6 +36,7 @@
"@maplibre/maplibre-gl-style-spec": "^20.3.1",
"@mui/material": "^5.16.7",
"@reduxjs/toolkit": "^1.9.7",
"@tanstack/react-table": "^8.20.5",
"@turf/turf": "^7.1.0",
"@typeform/embed-react": "^2.31.0",
"@zerologementvacant/models": "workspace:*",
Expand Down Expand Up @@ -77,8 +78,8 @@
"@craco/craco": "^7.1.0",
"@faker-js/faker": "^8.4.1",
"@testing-library/dom": "^10.4.0",
"@testing-library/jest-dom": "^6.5.0",
"@testing-library/react": "^16.0.1",
"@testing-library/jest-dom": "^6.6.3",
"@testing-library/react": "^16.1.0",
"@testing-library/user-event": "^14.5.2",
"@tsconfig/create-react-app": "^2.0.5",
"@types/async": "^3.2.24",
Expand All @@ -89,12 +90,13 @@
"@types/prop-types": "^15.7.13",
"@types/qs": "^6",
"@types/randomstring": "^1.3.0",
"@types/react": "^18.3.11",
"@types/react-dom": "^18.3.0",
"@types/react": "^18.3.17",
"@types/react-dom": "^18.3.5",
"@types/uuid": "^9.0.8",
"identity-obj-proxy": "^3.0.0",
"jest": "^29.7.0",
"jest-extended": "^4.0.2",
"jest-sorted": "^1.0.15",
"jest-watch-typeahead": "^2.2.2",
"randomstring": "^1.3.0",
"react-dev-utils": "^12.0.1",
Expand Down
12 changes: 6 additions & 6 deletions frontend/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
href="https://unpkg.com/[email protected]/dist/maplibre-gl.css"
rel="stylesheet"
/>
<link rel="apple-touch-icon" href="/dsfr/favicon/apple-touch-icon.png" />
<link rel="icon" href="/dsfr/favicon/favicon.svg" type="image/svg+xml" />
<link rel="shortcut icon" href="/dsfr/favicon/favicon.ico" type="image/x-icon" />
<link rel="manifest" href="/dsfr/favicon/manifest.webmanifest" crossorigin="use-credentials" />
<link rel="apple-touch-icon" href="/dsfr/favicon/apple-touch-icon.png?v=1.12.1" />
<link rel="icon" href="/dsfr/favicon/favicon.svg?v=1.12.1" type="image/svg+xml" />
<link rel="shortcut icon" href="/dsfr/favicon/favicon.ico?v=1.12.1" type="image/x-icon" />
<link rel="manifest" href="/dsfr/favicon/manifest.webmanifest?v=1.12.1" crossorigin="use-credentials" />

<link rel="stylesheet" href="/dsfr/utility/icons/icons.min.css" />
<link rel="stylesheet" href="/dsfr/dsfr.min.css" />
<link rel="stylesheet" href="/dsfr/utility/icons/icons.min.css?hash=7e4f55f5" />
<link rel="stylesheet" href="/dsfr/dsfr.min.css?v=1.12.1" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import AuthenticatedLayout from './layouts/AuthenticatedLayout';
import HousingListView from './views/HousingList/HousingListView';
import CampaignView from './views/Campaign/CampaignView';
import GroupView from './views/Group/GroupView';
import CampaignsListView from './views/Campaign/CampaignListView';
import CampaignListView from './views/Campaign/CampaignListView';
import HousingView from './views/Housing/HousingView';
import OwnerView from './views/Owner/OwnerView';
import StatusView from './views/Resources/StatusView';
Expand Down Expand Up @@ -44,7 +44,7 @@ const router = createBrowserRouter(
/>
<Route path="/analyses" element={<AnalysisView />} />
<Route path="/groupes/:id" element={<GroupView />} />
<Route path="/campagnes" element={<CampaignsListView />} />
<Route path="/campagnes" element={<CampaignListView />} />
<Route path="/campagnes/:id" element={<CampaignView />} />
<Route
path="/proprietaires/:ownerId/logements/:housingId"
Expand Down
121 changes: 121 additions & 0 deletions frontend/src/components/AdvancedTable/AdvancedTable.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import { fr } from '@codegouvfr/react-dsfr';
import {
Pagination as TablePagination,
PaginationProps as TablePaginationProps
} from '@codegouvfr/react-dsfr/Pagination';
import Select, { SelectProps } from '@codegouvfr/react-dsfr/SelectNext';
import { Table, TableProps } from '@codegouvfr/react-dsfr/Table';
import Skeleton from '@mui/material/Skeleton';
import Stack from '@mui/material/Stack';
import {
flexRender,
getCoreRowModel,
TableOptions,
useReactTable
} from '@tanstack/react-table';
import { MouseEvent, ReactNode } from 'react';

interface AdvancedTableProps<Data extends object>
extends Omit<TableOptions<Data>, 'data' | 'getCoreRowModel'>,
PaginationProps {
data?: Data[];
isLoading?: boolean;
paginationProps?: Omit<
TablePaginationProps,
'count' | 'defaultPage' | 'getPageLinkProps'
>;
tableProps?: Omit<TableProps, 'headers' | 'data'>;
}

interface PaginationProps {
/**
* @default true
*/
paginate?: boolean;
page?: number;
pageCount?: number;
perPage?: number;
onPageChange?(page: number): void;
onPerPageChange?(perPage: number): void;
}

const ROW_SIZE = 64;
const PER_PAGE_OPTIONS: SelectProps.Option[] = [
'50',
'200',
'500'
].map<SelectProps.Option>((nb) => {
return { label: `${nb} résultats par page`, value: nb };
});

function AdvancedTable<Data extends object>(props: AdvancedTableProps<Data>) {
const table = useReactTable<Data>({
manualPagination: true,
manualSorting: true,
...props,
data: props.data ?? [],
getCoreRowModel: getCoreRowModel()
});
const headers: ReactNode[] = table
.getLeafHeaders()
.map((header) =>
flexRender(header.column.columnDef.header, header.getContext())
);
const data: ReactNode[][] = table
.getRowModel()
.rows.map((row) => row.getVisibleCells())
.map((cells) =>
cells.map((cell) =>
flexRender(cell.column.columnDef.cell, cell.getContext())
)
);

const paginate = props.paginate ?? true;

if (props?.isLoading) {
return (
<Skeleton
animation="wave"
variant="rectangular"
width="100%"
height={ROW_SIZE * 6}
/>
);
}

return (
<Stack>
<Table {...props.tableProps} headers={headers} data={data} />
{paginate ? (
<Stack direction="row" justifyContent="center">
<Select
className={fr.cx('fr-mr-2w')}
label={null}
nativeSelectProps={{
value: props.perPage?.toString(),
onChange: (event) => {
props.onPerPageChange?.(Number(event.target.value));
}
}}
options={PER_PAGE_OPTIONS}
/>
<TablePagination
{...props.paginationProps}
count={props.pageCount ?? 1}
defaultPage={props.page}
getPageLinkProps={(page: number) => ({
to: '#',
onClick: (event: MouseEvent) => {
event.preventDefault();
props.onPageChange?.(page);
}
})}
showFirstLast
/>
</Stack>
) : null}
</Stack>
);
}

export default AdvancedTable;
25 changes: 25 additions & 0 deletions frontend/src/components/AdvancedTable/AdvancedTableHeader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import Stack from '@mui/material/Stack';
import Typography from '@mui/material/Typography';
import { ReactNode } from 'react';

interface AdvancedTableHeaderProps {
title: string;
sort?: ReactNode;
}

function AdvancedTableHeader(props: AdvancedTableHeaderProps) {
return (
<Stack
direction="row"
sx={{ alignItems: 'center', justifyContent: 'space-between' }}
spacing={1}
>
<Typography variant="body2" sx={{ fontWeight: 700 }}>
{props.title}
</Typography>
{props.sort}
</Stack>
);
}

export default AdvancedTableHeader;
Loading
Loading