Skip to content

Commit

Permalink
Améliore les pages deputés (#54)
Browse files Browse the repository at this point in the history
* Improve amendements for deputes

* Ajouter la page sur les travaux parlementaire

* remove duplicated mandats

* fix mandats

* reshape depute tabs

* use relative path

* get update from ORM

* Ajout des questions au gouvernements
  • Loading branch information
alexfauquette authored Aug 25, 2024
1 parent b6de5bd commit 5e9ab21
Show file tree
Hide file tree
Showing 34 changed files with 1,191 additions and 192 deletions.
10 changes: 9 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# .env.local

## settings to the DB for knext (will be removed)
DB_HOST=51.159.207.103
DB_PORT=1695
DB_USER=default_user
DB_PASSWORD=...
DB_DATABASE=tricoteuses
DB_DATABASE=tricoteuses

## setting to the prisma db
TRICOTEUSES_ASSEMBLEE_API_DB_URL="postgresql://username:password@host:port/dbname?schema=public"

## Path to tricoteuses-api-assemblee-orm
TRICOTEUSES_ASSEMBLEE_API_REPO="/home/.../tricoteuses-api-assemblee-orm"
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ export const DebateTimeline = ({ paragraphs }: DebateTimelineProps) => (
},
}}
>
{paragraphs.map(({ hash, codeGrammaire, acteur, roleDebat, texte }) => {
{paragraphs.map(({ hash, codeGrammaire, acteurRef, roleDebat, texte }) => {
switch (codeGrammaire) {
case "PAROLE_GENERIQUE":
case "INTERRUPTION_1_10":
return (
<ParoleItem
key={hash}
acteur={acteur}
acteur={acteurRef}
roleDebat={roleDebat}
texte={texte}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { WORDS_PER_MINUTES } from "@/components/const";
import { Acteur, Organe, Paragraphe } from "@prisma/client";

export type ParagrapheWithActeur = Paragraphe & {
acteur: null | (Acteur & { groupeParlementaire: null | Organe });
acteurRef: null | (Acteur & { groupeParlementaire: null | Organe });
};

function getWordsPerGroup(paragraphs: ParagrapheWithActeur[]) {
Expand All @@ -30,18 +30,18 @@ function getWordsPerGroup(paragraphs: ParagrapheWithActeur[]) {
}
> = {};
paragraphs.forEach((paragraphe) => {
const { codeGrammaire, acteur, texte } = paragraphe;
const { codeGrammaire, acteurRef, texte } = paragraphe;

if (
codeGrammaire !== "PAROLE_GENERIQUE" ||
!acteur ||
!acteur.groupeParlementaire ||
!acteur.groupeParlementaireUid ||
!acteurRef ||
!acteurRef.groupeParlementaire ||
!acteurRef.groupeParlementaireUid ||
!texte
) {
return;
}
const groupeParlementaire = acteur.groupeParlementaire;
const groupeParlementaire = acteurRef.groupeParlementaire;

const wordCount = texte.split(" ").length;
if (groups[groupeParlementaire.uid]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async function getParagraphesUnCached(
valeurPtsOdj: index.toString(),
},
include: {
acteur: {
acteurRef: {
include: { groupeParlementaire: true },
},
},
Expand Down
35 changes: 25 additions & 10 deletions app/depute/[slug]/Mandats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ const order = ["COMPER", "COMNL", "GE", "GA"];

type MandatsPerType = Record<
string,
(Pick<Organe, "libelle"> & Pick<Mandat, "libQualiteSex">)[]
(Pick<Organe, "libelle"> &
Pick<Mandat, "libQualiteSex" | "organeRefUid" | "dateFin">)[]
>;

export default function Mandats({
Expand All @@ -34,15 +35,17 @@ export default function Mandats({
if (!organe) {
return acc;
}
const { libQualiteSex, typeOrgane } = mandat;
const { libQualiteSex, typeOrgane, organeRefUid, dateFin } = mandat;

return {
...acc,
[typeOrgane]: [
...(acc[typeOrgane] ?? []),
{
organeRefUid,
libelle: organe?.libelle,
libQualiteSex,
dateFin,
},
],
};
Expand All @@ -64,14 +67,26 @@ export default function Mandats({
<InfoOutlinedIcon fontSize="inherit" />
</Typography>
<List>
{mandatsPerType[type].map(({ libelle, libQualiteSex }) => (
<ListItem key={libelle} disablePadding>
<Typography variant="body2">
{libelle}
{libQualiteSex && ` (${libQualiteSex})`}
</Typography>
</ListItem>
))}
{mandatsPerType[type]
.filter(({ libQualiteSex, organeRefUid }) => {
if (libQualiteSex !== "Membre") {
return true;
}
return (
// Display "Membre" mandat if it's the unique mandat in the organe (avoid duplicate with membre + president, or secretaire, ...)
mandatsPerType[type].filter(
(item) => item.organeRefUid === organeRefUid
).length === 1
);
})
.map(({ libelle, libQualiteSex }) => (
<ListItem key={libelle} disablePadding>
<Typography variant="body2">
{libelle}
{libQualiteSex && ` (${libQualiteSex})`}
</Typography>
</ListItem>
))}
</List>
</Box>
))}
Expand Down
6 changes: 6 additions & 0 deletions app/depute/[slug]/Tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ export default function DeputeTabs({ slug }: { slug: string }) {
component={Link}
href={`/depute/${slug}/votes`}
/>
<Tab
value="qag"
label="Questions"
component={Link}
href={`/depute/${slug}/qag`}
/>
</Tabs>
);
}
5 changes: 0 additions & 5 deletions app/depute/[slug]/[tab]/Activites.tsx

This file was deleted.

49 changes: 0 additions & 49 deletions app/depute/[slug]/[tab]/Amendements.tsx

This file was deleted.

20 changes: 0 additions & 20 deletions app/depute/[slug]/[tab]/Travaux.tsx

This file was deleted.

22 changes: 0 additions & 22 deletions app/depute/[slug]/[tab]/page.tsx

This file was deleted.

74 changes: 74 additions & 0 deletions app/depute/[slug]/amendements/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import React from "react";

import Stack from "@mui/material/Stack";

import AmendementCard from "@/components/folders/AmendementCard";
import { prisma } from "@/prisma";

async function getDeputeAmendementUnCached(slug: string) {
try {
return await prisma.acteur.findFirst({
where: { slug },
select: {
amendements: {
include: { texteLegislatifRef: { select: { numNotice: true } } },
},
},
});
} catch (error) {
console.error(`Error fetching amendement from depute ${slug}:`, error);
throw error;
}
}

const getDeputeAmendement = React.cache(getDeputeAmendementUnCached);

export default async function Amendements({
params,
}: {
params: { slug: string };
}) {
const deputeWithAmendements = await getDeputeAmendement(params.slug);

const { amendements } = deputeWithAmendements!;

return (
<Stack>
<p>Amendements</p>
{amendements &&
amendements
.sort((a, b) =>
Number.parseInt(a.numeroOrdreDepot || "") <
Number.parseInt(b.numeroOrdreDepot || "")
? -1
: 1
)
.map((amendement) => {
const numeroNotice = amendement.texteLegislatifRef?.numNotice;
const section = amendement.divisionArticleDesignationCourte;
// const subSection = amendement.alineaDesignation;

const article = [
section,
// subSection
]
.filter((item) => item !== null)
.join(" ");

const titre = `Amendement N°${amendement.numeroOrdreDepot}${
numeroNotice == null
? ""
: ` au text N°${numeroNotice}${article ? ` - ${article}` : ""}`
}`;
return (
<AmendementCard
key={amendement.uid}
amendement={amendement}
depute={null}
titre={titre}
/>
);
})}
</Stack>
);
}
4 changes: 2 additions & 2 deletions app/depute/[slug]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default async function Page({
// A décider: Faut il afficher les mandats passé?
// Exemple: la partissipation à des commission d'enquête
const mandasEnCours = depute.mandats?.filter(
(mandat) => true //mandat.dateFin === null
(mandat) => mandat.dateFin === null
);

return (
Expand Down Expand Up @@ -78,7 +78,7 @@ export default async function Page({
<>
<br />
Fin de mandat le{" "}
{new Date(circonscription.dateFin).toLocaleDateString()}
{new Date(circonscription.dateFin).toLocaleDateString("fr-FR")}
</>
)}
</Typography>
Expand Down
9 changes: 2 additions & 7 deletions app/depute/[slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import React from "react";
import Activites from "./[tab]/Activites";

export default function Page({
params,
}: {
params: { slug: string; tab: string };
}) {
return <Activites deputeSlug={params.slug} />;
export default function Page({ params }: { params: { slug: string } }) {
return <p>Activités</p>;
}
Loading

0 comments on commit 5e9ab21

Please sign in to comment.