-
Notifications
You must be signed in to change notification settings - Fork 8
✨ Page d'export avec lien pour exporter les données raccordement #3855
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5af5dfe
🚧 Basic page
HubM 23ed59a
🎨 Création d'une route pour l'export projet raccordement
HubM eeb0153
🎨 Retours reviews
HubM d9c4a87
🎨 Affichage entrée dans le menu
HubM 3195dd3
🎨 Ajout de label explicite dans les headers du csv
HubM f132bb2
🎨 matéraliser permission
HubM 63910b2
🎨 ajout lien vers "Tout les dossiers de raccordement" pour le role co…
HubM File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export const page = `/export`; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export * as Export from './export.routes'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import { FC } from 'react'; | ||
|
|
||
| import { Routes } from '@potentiel-applications/routes'; | ||
|
|
||
| import { PageTemplate } from '@/components/templates/Page.template'; | ||
| import { Heading1 } from '@/components/atoms/headings'; | ||
| import { LinkAction } from '@/components/atoms/LinkAction'; | ||
|
|
||
| export type ExportPageProps = { | ||
| actions: Array<'exporter-raccordement'>; | ||
| }; | ||
|
|
||
| export const ExportPage: FC<ExportPageProps> = ({ actions }) => ( | ||
| <PageTemplate banner={<Heading1>Exporter des données projets</Heading1>}> | ||
| <div className="mb-4"> | ||
| Cette page permet d'accéder à des liens pour exporter des données projets | ||
| </div> | ||
|
|
||
| {actions.includes('exporter-raccordement') && ( | ||
| <LinkAction label="Exporter les données raccordement" href={Routes.Raccordement.exporter} /> | ||
| )} | ||
| </PageTemplate> | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import type { Metadata } from 'next'; | ||
|
|
||
| import { PotentielUtilisateur } from '@potentiel-applications/request-context'; | ||
|
|
||
| import { PageWithErrorHandling } from '@/utils/PageWithErrorHandling'; | ||
| import { withUtilisateur } from '@/utils/withUtilisateur'; | ||
|
|
||
| import { ExportPage, ExportPageProps } from './export.page'; | ||
|
|
||
| export const metadata: Metadata = { | ||
| title: 'Export de données - Potentiel', | ||
| description: `Page d'export des données au format CSV`, | ||
| }; | ||
|
|
||
| export default async function Page() { | ||
| return PageWithErrorHandling(async () => | ||
| withUtilisateur(async (utilisateur) => { | ||
| return <ExportPage actions={mapToAction(utilisateur)} />; | ||
| }), | ||
| ); | ||
| } | ||
|
|
||
| type MapToAction = (utilisateur: PotentielUtilisateur) => ExportPageProps['actions']; | ||
|
|
||
| const mapToAction: MapToAction = (utilisateur) => { | ||
| if (utilisateur.rôle.aLaPermission('raccordement.listerDossierRaccordement')) { | ||
| return ['exporter-raccordement']; | ||
| } | ||
|
|
||
| return []; | ||
| }; |
85 changes: 85 additions & 0 deletions
85
packages/applications/ssr/src/app/reseaux/raccordements/exporter/route.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| import { Parser, ParserOptions } from '@json2csv/plainjs'; | ||
| import { mediator } from 'mediateur'; | ||
|
|
||
| import { Lauréat } from '@potentiel-domain/projet'; | ||
|
|
||
| import { withUtilisateur } from '@/utils/withUtilisateur'; | ||
| import { apiAction } from '@/utils/apiAction'; | ||
|
|
||
| export const GET = async (_: Request) => | ||
| apiAction(() => | ||
| withUtilisateur(async (utilisateur) => { | ||
| const dossiers = await mediator.send<Lauréat.Raccordement.ListerDossierRaccordementQuery>({ | ||
| type: 'Lauréat.Raccordement.Query.ListerDossierRaccordementQuery', | ||
| data: { | ||
| utilisateur: utilisateur.identifiantUtilisateur.email, | ||
| }, | ||
| }); | ||
|
|
||
| const fields: ParserOptions['fields'] = [ | ||
| { label: 'Identifiant projet', value: 'identifiantProjet' }, | ||
| { label: "Appel d'offre", value: 'appelOffre' }, | ||
| { label: 'Période', value: 'periode' }, | ||
| { label: 'Nom projet', value: 'nomProjet' }, | ||
| { label: 'Référence dossier', value: 'referenceDossier' }, | ||
| { label: 'Date demande complète raccordement', value: 'dateDemandeCompleteRaccordement' }, | ||
| { label: 'Date mise en service', value: 'dateMiseEnService' }, | ||
| { label: 'Gestionnaire réseau', value: 'gestionnaireReseau' }, | ||
| { label: 'Site de production', value: 'siteProduction' }, | ||
| { label: 'Société mère', value: 'societeMere' }, | ||
| { label: 'Puissance', value: 'puissance' }, | ||
| ]; | ||
|
|
||
| const utilisateurPeutVoirPrix = utilisateur.rôle.aLaPermission('projet.accèsDonnées.prix'); | ||
|
|
||
| if (utilisateurPeutVoirPrix) { | ||
| fields.push({ label: 'Prix de référence', value: 'prixReference' }); | ||
| } | ||
|
|
||
| const csvParser = new Parser({ fields, delimiter: ';', withBOM: true }); | ||
|
|
||
| const csv = csvParser.parse( | ||
| dossiers.items.map( | ||
| ({ | ||
| identifiantProjet, | ||
| nomProjet, | ||
| référenceDossier, | ||
| puissance, | ||
| unitéPuissance, | ||
| sociétéMère, | ||
| dateDemandeComplèteRaccordement, | ||
| dateMiseEnService, | ||
| raisonSocialeGestionnaireRéseau, | ||
| localité: { adresse1, adresse2, codePostal, commune, région, département }, | ||
| prixReference, | ||
| }) => ({ | ||
| identifiantProjet: identifiantProjet.formatter(), | ||
| appelOffre: identifiantProjet.appelOffre, | ||
| periode: identifiantProjet.période, | ||
| nomProjet, | ||
| referenceDossier: référenceDossier.formatter(), | ||
| dateDemandeCompleteRaccordement: dateDemandeComplèteRaccordement | ||
| ? dateDemandeComplèteRaccordement.date.toLocaleDateString('fr-FR') | ||
| : undefined, | ||
| dateMiseEnService: dateMiseEnService | ||
| ? dateMiseEnService.date.toLocaleDateString('fr-FR') | ||
| : undefined, | ||
| gestionnaireReseau: raisonSocialeGestionnaireRéseau, | ||
| siteProduction: `${adresse1} ${adresse2} ${codePostal} ${commune} - ${département} - ${région}`, | ||
| societeMere: sociétéMère, | ||
| puissance: `${puissance} ${unitéPuissance.formatter()}`, | ||
| prixReference: utilisateurPeutVoirPrix ? prixReference : undefined, | ||
| }), | ||
| ), | ||
| ); | ||
|
|
||
| const fileName = `export_projet_raccordement.csv`; | ||
HubM marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| return new Response(csv, { | ||
| headers: { | ||
| 'content-type': 'text/csv', | ||
| 'content-disposition': `attachment; filename=${fileName}`, | ||
| }, | ||
| }); | ||
| }), | ||
| ); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.