Skip to content

Commit

Permalink
Merge pull request #818 from MTES-MCT/main
Browse files Browse the repository at this point in the history
Mise en production 30/07/2024
  • Loading branch information
loicguillois authored Jul 30, 2024
2 parents cbe9472 + 48e556a commit 0c4393a
Show file tree
Hide file tree
Showing 45 changed files with 366 additions and 1,380 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,21 @@ name: "CodeQL"
on:
push:
branches: [ main ]
paths:
- frontend/**
- queue/**
- server/**
- shared/**
- packages/**
pull_request:
# The branches below must be a subset of the branches above
branches: [ main ]
paths:
- frontend/**
- queue/**
- server/**
- shared/**
- packages/**
schedule:
- cron: '21 21 * * 4'

Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,11 @@ jobs:
CYPRESS_BASE_URL: ${{ vars.HOST }}
CYPRESS_EMAIL: ${{ secrets.CYPRESS_EMAIL }}
CYPRESS_PASSWORD: ${{ secrets.CYPRESS_PASSWORD }}

- name: Upload screenshots
uses: actions/upload-artifact@v4
if: failure()
with:
name: cypress-screenshots
path: e2e/cypress/screenshots
retention-days: 7
9 changes: 8 additions & 1 deletion .github/workflows/github-actions.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
name: Node.js CI

on: [push]
on:
push:
paths:
- frontend/**
- queue/**
- server/**
- shared/**
- packages/**

jobs:
build:
Expand Down
15 changes: 14 additions & 1 deletion .github/workflows/review-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,18 @@ on:
pull_request_target:
types: [opened, closed, synchronize, reopened]
branches: [main]

paths:
- frontend/**
- queue/**
- server/**
- shared/**
- packages/**
paths:
- frontend/**
- queue/**
- server/**
- shared/**
- packages/**
env:
CLEVER_SECRET: ${{ secrets.CLEVER_SECRET }}
CLEVER_TOKEN: ${{ secrets.CLEVER_TOKEN }}
Expand Down Expand Up @@ -73,6 +84,8 @@ jobs:
clever env set CEREMA_TOKEN "unused" -a $APP_ALIAS
clever env set DATABASE_ENV "development" -a $APP_ALIAS
clever env set DATABASE_URL $POSTGRESQL_ADDON_URI -a $APP_ALIAS
clever env set E2E_EMAIL $E2E_EMAIL -a $APP_ALIAS
clever env set E2E_PASSWORD $E2E_PASSWORD -a $APP_ALIAS
clever env set HOST "https://$APP_ALIAS.cleverapps.io" -a $APP_ALIAS
clever env set METABASE_TOKEN "unused" -a $APP_ALIAS
clever env set PORT "8080" -a $APP_ALIAS
Expand Down
11 changes: 4 additions & 7 deletions .talismanrc
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
fileignoreconfig:
- filename: .github/workflows/deploy.yml
checksum: fe575a99e7ab0a3421ca14fcff7d4997cf2bf31ddf5619b7711233f5a4a316d3
- filename: .github/workflows/e2e.yml
checksum: 1994a562d1d57521c10078640cd49fdccf7b3baecbaf46f3ed383ada996b5c90
- filename: .github/workflows/github-actions.yml
checksum: b1a53b557b6b2ac4c57f6afce9e902582f5589f97762a963da587496a455c0c1
- filename: .github/workflows/review-app.yml
Expand Down Expand Up @@ -78,6 +74,8 @@ fileignoreconfig:
checksum: df71affe33700cb0a36ee0b4824ef60e7d8e5a08f3d4d16ca53c31e9085b45ae
- filename: queue/README.md
checksum: fe2ac5277a42e6bf8dfc1e0fe53cc3308bba9019d9091f4b8c291e4a2e4a4eb8
- filename: queue/src/.htpasswd
checksum: 7670652d46bed42247610009a41eadea1d18ff839db9fa831288cb6ab19792e1
- filename: queue/src/config.ts
checksum: 8ca4d9a0b6118457fb7dcea24e43645eb63bea92d9e0f1d0c4ae763ea55491a5
- filename: queue/src/events/index.ts
Expand Down Expand Up @@ -113,7 +111,7 @@ fileignoreconfig:
- filename: server/src/infra/database/scripts/002-load-establishments_direction_territoriale.sql
checksum: b2db25db2503ffb08d08e232fa5aa319caa0bacca03b5af067038154bb5393ca
- filename: server/src/infra/database/seeds/development/20240404235457_users.ts
checksum: f3fabfbe62c13a614236fd7c9474c78de726c44515e8f116f3532765907c218c
checksum: 85407878a244313b70b8a60b5c7d3e41c33df83629866437cbca3a309ab6e1bc
- filename: server/src/infra/database/seeds/development/20240627141242_e2e.ts
checksum: 56a46923a8cffefb7e70949b80718dc56ae2f3dd28f5057cb102461fe2fa10eb
- filename: server/src/routers/unprotected.ts
Expand All @@ -132,8 +130,7 @@ allowed_patterns:
- key=\{.+\}
- keyof
version: "1.0"
red/src/utils/s3.ts
checksum: 96fa9978f136699921498fe90d02c495d4c1d27f47c96e64b646b219f29204c1
85ac09fdcf3978c64ff996c2d0e8731431ecb2c0
scopeconfig:
- scope: node
allowed_patterns:
Expand Down
11 changes: 5 additions & 6 deletions e2e/cypress/e2e/campaign.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ describe('Campaign', () => {
cy.intercept('POST', Cypress.env('API') + '/housing/count').as(
'countHousings'
);
cy.intercept('POST', Cypress.env('API') + '/files').as('upload');

cy.logIn();
cy.get('button').contains('Bâtiment/DPE').click();
cy.get('label').contains('Nombre de logements').next().click();
cy.wait('@findHousings');
cy.wait('@countHousings');
cy.wait(['@findHousings', '@countHousings']);
cy.get('tbody')
.find('fieldset')
.then((checkboxes) => checkboxes.slice(0, 3))
Expand All @@ -29,6 +27,7 @@ describe('Campaign', () => {
cy.get('input[type="file"]')
.first()
.selectFile('cypress/fixtures/logo.png');
cy.wait('@upload');

cy.get('label')
.contains(/^En date du/)
Expand Down Expand Up @@ -69,7 +68,7 @@ describe('Campaign', () => {
cy.get('div[aria-labelledby="draft-body-label"]')
.type('Madame, Monsieur,{enter}')
.type(
'Marseille BB fait partie des lauréats du plan national de lutte contre les logements vacants du Ministère de la Transition écologique et de la Cohésion des Territoires. Ce plan a pour objectif d’accélérer, dans les territoires pilotes, la remise sur le marché immobilier (rénovation, location, vente, restructuration) du plus grand nombre possible de logements vacants. Dans ce cadre, l’ADIL 35 a été missionnée par Rennes Métropole pour assurer une mission d’information, de sensibilisation et d’accompagnement des propriétaires de logements vacants qui le souhaitent.{enter}'
'Marseille BB fait partie des lauréats du plan national de lutte contre les logements vacants du Ministère de la Transition écologique et de la Cohésion des Territoires. Ce plan a pour objectif d’accélérer, dans les territoires pilotes, la remise sur le marché immobilier (rénovation, location, vente, restructuration) du plus grand nombre possible de logements vacants. Dans ce cadre, l’ADIL 13 a été missionnée par Marseille BB pour assurer une mission d’information, de sensibilisation et d’accompagnement des propriétaires de logements vacants qui le souhaitent.{enter}'
)
.type(
'Un formulaire vous est proposé dans le cadre d’une enquête destinée à mieux comprendre les raisons de la vacance et s’inscrit dans une politique plus globale afin de construire l’aide qui vous sera la plus adaptée, et permettrait la remise des biens sur un marché en forte demande.{enter}'
Expand All @@ -78,7 +77,7 @@ describe('Campaign', () => {
'Depuis 2011, 960 propriétaires ont été accompagnés dans le cadre de l’opération Rennes Centre Ancien. Ce sont ainsi 300 logements vacants qui ont pu être réoccupés grâce à des aides publiques.{enter}'
)
.type(
'Votre logement situé au 123 rue bidon, à Marseille a été recensé comme vacant, c’est-à-dire qu’il aurait été déclaré comme inoccupé depuis « Nombre année vacance du logement » au 1er Janvier 2022. Si tel n’est pas le cas, votre retour permettra d’actualiser l’état réel de son occupation.{enter}'
'Votre logement situé au 123 rue bidon, à Marseille BB a été recensé comme vacant, c’est-à-dire qu’il aurait été déclaré comme inoccupé depuis « Nombre année vacance du logement » au 1er Janvier 2022. Si tel n’est pas le cas, votre retour permettra d’actualiser l’état réel de son occupation.{enter}'
)
.type(
'Un formulaire vous est proposé dans le cadre d’une enquête destinée à mieux comprendre les raisons de la vacance et s’inscrit dans une politique plus globale afin de construire l’aide qui vous sera la plus adaptée, et permettrait la remise des biens sur un marché en forte demande.{enter}'
Expand Down
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
]
},
"dependencies": {
"@codegouvfr/react-dsfr": "1.9.17",
"@codegouvfr/react-dsfr": "^1.9.20",
"@emotion/react": "^11.11.4",
"@emotion/styled": "^11.11.5",
"@faker-js/faker": "^8.4.1",
Expand Down
66 changes: 61 additions & 5 deletions frontend/src/components/Campaign/CampaignRecipients.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import Badge from '@codegouvfr/react-dsfr/Badge';
import Table from '@codegouvfr/react-dsfr/Table';
import { Pagination as DSFRPagination } from '../_dsfr';
import Typography from '@mui/material/Typography';
import Grid from '@mui/material/Unstable_Grid2';
import { ReactNode } from 'react';
import { ReactNode, useState } from 'react';

import { Campaign } from '../../models/Campaign';
import { useHousingList } from '../../hooks/useHousingList';
Expand All @@ -12,16 +13,33 @@ import AppLink from '../_app/AppLink/AppLink';
import { Housing } from '../../models/Housing';
import { useRemoveCampaignHousingMutation } from '../../services/campaign.service';
import ConfirmationModal from '../modals/ConfirmationModal/ConfirmationModal';
import { Pagination } from '@zerologementvacant/models';
import { DefaultPagination } from '../../store/reducers/housingReducer';
import { usePagination } from '../../hooks/usePagination';
import Button from '@codegouvfr/react-dsfr/Button';
import { useCountHousingQuery } from '../../services/housing.service';

interface Props {
campaign: Campaign;
}

function CampaignRecipients(props: Props) {
const [pagination, setPagination] = useState<Pagination>(DefaultPagination);
const filters = {
campaignIds: [props.campaign.id],
};
const { housingList } = useHousingList({
filters: {
campaignIds: [props.campaign.id],
},
filters,
pagination,
});

const { data: count } = useCountHousingQuery(filters);
const filteredCount = count?.housing ?? 0;

const { pageCount, hasPagination, changePerPage, changePage} = usePagination({
pagination,
setPagination,
count: filteredCount,
});

const [removeCampaignHousing] = useRemoveCampaignHousingMutation();
Expand Down Expand Up @@ -49,7 +67,7 @@ function CampaignRecipients(props: Props) {
null,
];
const data: ReactNode[][] = (housingList ?? []).map((housing, i) => [
`# ${i}`,
`# ${i + 1 + (pagination.page - 1) * pagination.perPage}`,
<AppLink
isSimple
key={`${housing.id}-address`}
Expand Down Expand Up @@ -103,6 +121,44 @@ function CampaignRecipients(props: Props) {
return (
<Grid container>
<Table data={data} headers={headers} />
{hasPagination && (
<>
<div className="fr-react-table--pagination-center nav">
<DSFRPagination
onClick={changePage}
currentPage={pagination.page}
pageCount={pageCount}
/>
</div>
<div style={{ textAlign: 'center' }}>
<Button
onClick={() => changePerPage(50)}
priority="secondary"
disabled={pagination.perPage === 50}
title="Afficher 50 résultats par page"
>
50 résultats par page
</Button>
<Button
onClick={() => changePerPage(200)}
className="fr-mx-3w"
priority="secondary"
disabled={pagination.perPage === 200}
title="Afficher 200 résultats par page"
>
200 résultats par page
</Button>
<Button
onClick={() => changePerPage(500)}
priority="secondary"
disabled={pagination.perPage === 500}
title="Afficher 500 résultats par page"
>
500 résultats par page
</Button>
</div>
</>
)}
</Grid>
);
}
Expand Down
20 changes: 3 additions & 17 deletions frontend/src/components/HousingList/HousingList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,26 +84,12 @@ const HousingList = ({
const { data: count } = useCountHousingQuery(filters);
const filteredCount = count?.housing ?? 0;

const { pageCount, rowNumber, hasPagination } = usePagination({
...pagination,
const { pageCount, hasPagination, rowNumber, changePerPage, changePage} = usePagination({
pagination,
setPagination,
count: filteredCount,
});

const changePerPage = (perPage: number) => {
setPagination({
...pagination,
page: 1,
perPage,
});
};

const changePage = (page: number) => {
setPagination({
...pagination,
page,
});
};

const onSort = (sort: HousingSort) => {
setSort(sort);
setPagination({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { Col, Pagination, Row, Table, Text } from '../../_dsfr';
import { Col, Pagination as DSFRPagination, Row, Table, Text } from '../../_dsfr';
import { format } from 'date-fns';
import { displayCount } from '../../../utils/stringUtils';
import { Owner } from '../../../models/Owner';
import { usePagination } from '../../../hooks/usePagination';
import { useFindOwnersQuery } from '../../../services/owner.service';
import { useAppDispatch, useAppSelector } from '../../../hooks/useStore';
import housingSlice from '../../../store/reducers/housingReducer';
import housingSlice, { DefaultPagination } from '../../../store/reducers/housingReducer';
import { useState } from 'react';
import { Pagination } from '@zerologementvacant/models';

interface Props {
onSelect: (owner: Owner) => void;
Expand All @@ -22,11 +24,12 @@ const HousingAdditionalOwnerSearchResults = ({ onSelect }: Props) => {
},
);

const [pagination, setPagination] = useState<Pagination>(DefaultPagination);

const { pageCount, rowNumber, hasPagination } = usePagination({
pagination,
setPagination,
count: additionalOwners?.filteredCount,
perPage: additionalOwners?.perPage,
page: additionalOwners?.page,
paginate: true,
});

const columns = () => [
Expand Down Expand Up @@ -96,7 +99,7 @@ const HousingAdditionalOwnerSearchResults = ({ onSelect }: Props) => {
/>
{hasPagination && (
<div className="fr-react-table--pagination-center nav">
<Pagination
<DSFRPagination
onClick={(page: number) =>
dispatch(
housingSlice.actions.fetchingAdditionalOwners({
Expand Down
22 changes: 20 additions & 2 deletions frontend/src/hooks/usePagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,40 @@ import { Pagination } from '@zerologementvacant/models';
import config from '../utils/config';

interface PaginationOptions extends Partial<Pagination> {
pagination: Pagination;
count?: number;
setPagination: React.Dispatch<React.SetStateAction<Pagination>>;
}

export function usePagination(opts: PaginationOptions) {
const count = opts.count ?? 0;
const page = opts.page ?? 1;
const perPage = opts.perPage ?? config.perPageDefault;
const page = opts.pagination.page ?? 1;
const perPage = opts.pagination.perPage ?? config.perPageDefault;
const pageCount = Math.ceil(count / perPage);

const rowNumber = (index: number) => (page - 1) * perPage + index + 1;

const hasPagination = count > perPage;

const changePerPage = (perPage: number) => {
opts.setPagination({
...opts.pagination,
page: 1,
perPage,
});
};

const changePage = (page: number) => {
opts.setPagination({
...opts.pagination,
page,
});
};
return {
pageCount,
rowNumber,
hasPagination,
changePerPage,
changePage,
};
}
Loading

0 comments on commit 0c4393a

Please sign in to comment.