diff --git a/components/ThemeRegistry/theme.tsx b/components/ThemeRegistry/theme.tsx index 17ee831..24d3481 100644 --- a/components/ThemeRegistry/theme.tsx +++ b/components/ThemeRegistry/theme.tsx @@ -3,6 +3,7 @@ import { SvgIconProps } from "@mui/material/SvgIcon"; import { createTheme } from "@mui/material/styles"; import { MinusIcon } from "@/icons/MinusIcon"; import { PlusIcon } from "@/icons/PlusIcon"; +import type {} from "@mui/lab/themeAugmentation"; const AccordionIcon = (props: SvgIconProps) => ( <> @@ -159,6 +160,14 @@ const theme = createTheme({ }, }, }, + MuiTimelineDot: { + styleOverrides: { + root: { + marginLeft: "auto", + marginRight: "auto", + }, + }, + }, }, }); diff --git a/components/folders/TimelineCard.tsx b/components/folders/TimelineCard.tsx index 5bb9705..ecbd1b4 100644 --- a/components/folders/TimelineCard.tsx +++ b/components/folders/TimelineCard.tsx @@ -16,6 +16,7 @@ import StatusChip from "@/components/StatusChip"; import { ActeLegislatif, Document } from "@/repository/types"; import { Link } from "@mui/material"; import { getDocumentURL } from "@/domain/dataTransform"; +import { groupActs } from "@/repository/Acts"; export const TimelineCard = ({ acts, @@ -24,6 +25,8 @@ export const TimelineCard = ({ acts: ActeLegislatif[]; documents: Record; }) => { + const { actsStructure, actsLookup } = groupActs(acts); + return ( - {acts + {Object.values(actsStructure) + .sort((a, b) => + (a.date?.getTime() ?? 0) > (b.date?.getTime() ?? 0) ? 1 : -1 + ) + .flatMap(({ ids, date: groupDate, children: lvl1Group }) => { + return ids?.flatMap((id) => { + const actLvl0 = actsLookup[id]; + const title = actLvl0.nomCanonique || actLvl0.codeActe; + const date = actLvl0.dateActe ?? groupDate; + return [ + + + + {date + ? date.toLocaleDateString("fr-FR", { + year: "numeric", + month: "short", + day: "numeric", + }) + : "?"} + + + + + {actLvl0.codeActe} + + + + + + {title} + + + , + + ...Object.values(lvl1Group ?? {}) + .sort((a, b) => (a.date > b.date ? 1 : -1)) + .flatMap( + ({ + ids: lvl1Ids, + date: lvl1GroupDate, + children: lvl2Group, + }) => { + return lvl1Ids?.flatMap((id) => { + const actLvl1 = actsLookup[id]; + const title = + `${actLvl1.nomCanonique} (${actLvl1.codeActe})` || + actLvl1.codeActe; + const date = actLvl1.dateActe ?? lvl1GroupDate; + return [ + + + + + + + + {title} + + {date + ? date.toLocaleDateString("fr-FR", { + year: "numeric", + month: "short", + day: "numeric", + }) + : "?"} + + {Object.values(lvl2Group ?? {}) + .sort((a, b) => (a.date > b.date ? 1 : -1)) + .flatMap( + ({ + ids: lvl2Ids, + date: lvl2GroupDate, + children: lvl3Group, + }) => { + return lvl2Ids?.flatMap((id) => { + const actLvl2 = actsLookup[id]; + const date = actLvl2.dateActe; + const title = `${actLvl2.nomCanonique}${ + date + ? ` du ${date.toLocaleDateString( + "fr-FR", + { + year: "numeric", + month: "short", + day: "numeric", + } + )}` + : "" + }`; + + return ( + + {title} + + ); + }); + } + )} + + , + ]; + }); + } + ), + ]; + }); + })} + + {/* {acts .sort((a, b) => { if (!a.dateActe || !b.dateActe) { return 0; @@ -107,7 +229,7 @@ export const TimelineCard = ({ ); - })} + })} */} {/* Next lines are items from the figma. I keep them to be able to copy past them when needed. But commented to be sure I don't mix real data and the figma. */} diff --git a/repository/Acts.ts b/repository/Acts.ts index 61bbfd9..8777288 100644 --- a/repository/Acts.ts +++ b/repository/Acts.ts @@ -1,3 +1,5 @@ +// import { ActeLegislatif } from "./types"; + export type SN1_DEPOT = { codeActe: "SN1-DEPOT"; uid: string; @@ -412,7 +414,7 @@ export type ANLUNI_COM = { dossierRefUid: string; }; -export type ActeLegislatif = +export type ActLegislatif = | SN1_DEPOT | AN1 | SN1_COM @@ -479,210 +481,676 @@ export type ActWithDate = | CMP_SAISIE; const CONTEXT = { - "AN-APPLI": { lvl: 0, display: true }, - AN1: { lvl: 0, display: true }, - AN2: { lvl: 0, display: true }, - AN20: { lvl: 0, display: true }, - AN21: { lvl: 0, display: true }, - AN3: { lvl: 0, display: true }, - ANLDEF: { lvl: 0, display: true }, - ANLUNI: { lvl: 0, display: true }, - ANNLEC: { lvl: 0, display: true }, - CC: { lvl: 0, display: true }, - CMP: { lvl: 0, display: true }, - EU: { lvl: 0, display: true }, - PROM: { lvl: 0, display: true }, - SN1: { lvl: 0, display: true }, - SN2: { lvl: 0, display: true }, - SN3: { lvl: 0, display: true }, - SNNLEC: { lvl: 0, display: true }, - "AN-APPLI-RAPPORT": { lvl: 1, display: "?" }, - "AN1-ACIN": { lvl: 1, display: true }, - "AN1-AVCE": { lvl: 1, display: true }, - "AN1-COM": { lvl: 1, display: true }, - "AN1-DEBATS": { lvl: 1, display: true }, - "AN1-DEPOT": { lvl: 1, display: true }, - "AN1-DGVT": { lvl: 1, display: true }, - "AN1-DPTLETTRECT": { lvl: 1, display: true }, - "AN1-ETI": { lvl: 1, display: true }, - "AN1-MOTION": { lvl: 1, display: true }, - "AN1-PROCACC": { lvl: 1, display: true }, - "AN1-RECBUREAU": { lvl: 1, display: true }, - "AN1-RTRINI": { lvl: 1, display: true }, - "AN2-COM": { lvl: 1, display: true }, - "AN2-DEBATS": { lvl: 1, display: true }, - "AN2-DEPOT": { lvl: 1, display: true }, - "AN20-COMENQ": { lvl: 1, display: true }, - "AN20-MISINF": { lvl: 1, display: true }, - "AN20-RAPPORT": { lvl: 1, display: true }, - "AN21-APAN": { lvl: 1, display: true }, - "AN21-DEBATS": { lvl: 1, display: true }, - "AN21-DGVT": { lvl: 1, display: true }, - "AN21-MOTION": { lvl: 1, display: true }, - "AN21-MPR": { lvl: 1, display: true }, - "AN3-COM": { lvl: 1, display: true }, - "AN3-DEBATS": { lvl: 1, display: true }, - "AN3-DEPOT": { lvl: 1, display: true }, - "ANLDEF-COM": { lvl: 1, display: true }, - "ANLDEF-DEBATS": { lvl: 1, display: true }, - "ANLDEF-DEPOT": { lvl: 1, display: true }, - "ANLDEF-DGVT": { lvl: 1, display: true }, - "ANLDEF-MOTION": { lvl: 1, display: true }, - "ANLUNI-COM": { lvl: 1, display: true }, - "ANLUNI-DEBATS": { lvl: 1, display: true }, - "ANLUNI-DEPOT": { lvl: 1, display: true }, - "ANLUNI-RTRINI": { lvl: 1, display: true }, - "ANNLEC-COM": { lvl: 1, display: true }, - "ANNLEC-DEBATS": { lvl: 1, display: true }, - "ANNLEC-DEPOT": { lvl: 1, display: true }, - "ANNLEC-DGVT": { lvl: 1, display: true }, - "ANNLEC-MOTION": { lvl: 1, display: true }, - "CC-CONCLUSION": { lvl: 1, display: true }, - "CC-SAISIE-AN": { lvl: 1, display: true }, - "CC-SAISIE-DROIT": { lvl: 1, display: true }, - "CC-SAISIE-PAN": { lvl: 1, display: true }, - "CC-SAISIE-PM": { lvl: 1, display: true }, - "CC-SAISIE-PR": { lvl: 1, display: true }, - "CC-SAISIE-PSN": { lvl: 1, display: true }, - "CC-SAISIE-SN": { lvl: 1, display: true }, - "CMP-COM": { lvl: 1, display: true }, - "CMP-DEBATS-AN": { lvl: 1, display: true }, - "CMP-DEBATS-SN": { lvl: 1, display: true }, - "CMP-DEC": { lvl: 1, display: true }, - "CMP-DEPOT": { lvl: 1, display: true }, - "CMP-DGVT": { lvl: 1, display: true }, - "CMP-MOTION": { lvl: 1, display: true }, - "CMP-SAISIE": { lvl: 1, display: true }, - "EU-DEC": { lvl: 1, display: true }, - "PROM-PUB": { lvl: 1, display: true }, - "SN1-AVCE": { lvl: 1, display: true }, - "SN1-COM": { lvl: 1, display: true }, - "SN1-DEBATS": { lvl: 1, display: true }, - "SN1-DEPOT": { lvl: 1, display: true }, - "SN1-DPTLETTRECT": { lvl: 1, display: true }, - "SN1-ETI": { lvl: 1, display: true }, - "SN1-PROCACC": { lvl: 1, display: true }, - "SN1-RTRINI": { lvl: 1, display: true }, - "SN2-COM": { lvl: 1, display: true }, - "SN2-DEBATS": { lvl: 1, display: true }, - "SN2-DEPOT": { lvl: 1, display: true }, - "SN3-COM": { lvl: 1, display: true }, - "SN3-DEBATS": { lvl: 1, display: true }, - "SN3-DEPOT": { lvl: 1, display: true }, - "SNNLEC-COM": { lvl: 1, display: true }, - "SNNLEC-DEBATS": { lvl: 1, display: true }, - "SNNLEC-DEPOT": { lvl: 1, display: true }, - "AN1-COM-AVIS": { lvl: 2, display: true }, - "AN1-COM-FOND": { lvl: 2, display: true }, - "AN1-DEBATS-DEC": { lvl: 2, display: true }, - "AN1-DEBATS-MOTION": { lvl: 2, display: true }, - "AN1-DEBATS-MOTION-VOTE": { lvl: 2, display: true }, - "AN1-DEBATS-SEANCE": { lvl: 2, display: true }, - "AN2-COM-AVIS": { lvl: 2, display: true }, - "AN2-COM-FOND": { lvl: 2, display: true }, - "AN2-DEBATS-DEC": { lvl: 2, display: true }, - "AN2-DEBATS-SEANCE": { lvl: 2, display: true }, - "AN21-DEBATS-MOTION-VOTE": { lvl: 2, display: true }, - "AN21-DEBATS-SEANCE": { lvl: 2, display: true }, - "AN3-COM-FOND": { lvl: 2, display: true }, - "AN3-DEBATS-DEC": { lvl: 2, display: true }, - "AN3-DEBATS-SEANCE": { lvl: 2, display: true }, - "ANLDEF-COM-FOND": { lvl: 2, display: true }, - "ANLDEF-DEBATS-DEC": { lvl: 2, display: true }, - "ANLDEF-DEBATS-MOTION-VOTE": { lvl: 2, display: true }, - "ANLDEF-DEBATS-SEANCE": { lvl: 2, display: true }, - "ANLUNI-COM-CAE": { lvl: 2, display: true }, - "ANLUNI-COM-FOND": { lvl: 2, display: true }, - "ANLUNI-DEBATS-DEC": { lvl: 2, display: true }, - "ANLUNI-DEBATS-SEANCE": { lvl: 2, display: true }, - "ANNLEC-COM-AVIS": { lvl: 2, display: true }, - "ANNLEC-COM-FOND": { lvl: 2, display: true }, - "ANNLEC-DEBATS-DEC": { lvl: 2, display: true }, - "ANNLEC-DEBATS-MOTION-VOTE": { lvl: 2, display: true }, - "ANNLEC-DEBATS-SEANCE": { lvl: 2, display: true }, - "CMP-COM-NOMIN": { lvl: 2, display: true }, - "CMP-COM-RAPPORT-AN": { lvl: 2, display: true }, - "CMP-COM-RAPPORT-SN": { lvl: 2, display: true }, - "CMP-DEBATS-AN-DEC": { lvl: 2, display: true }, - "CMP-DEBATS-AN-SEANCE": { lvl: 2, display: true }, - "CMP-DEBATS-SN-DEC": { lvl: 2, display: true }, - "CMP-DEBATS-SN-SEANCE": { lvl: 2, display: true }, - "SN1-COM-AVIS": { lvl: 2, display: true }, - "SN1-COM-FOND": { lvl: 2, display: true }, - "SN1-DEBATS-DEC": { lvl: 2, display: true }, - "SN1-DEBATS-MOTION": { lvl: 2, display: true }, - "SN1-DEBATS-MOTION-VOTE": { lvl: 2, display: true }, - "SN1-DEBATS-SEANCE": { lvl: 2, display: true }, - "SN2-COM-AVIS": { lvl: 2, display: true }, - "SN2-COM-FOND": { lvl: 2, display: true }, - "SN2-DEBATS-DEC": { lvl: 2, display: true }, - "SN2-DEBATS-SEANCE": { lvl: 2, display: true }, - "SN3-COM-FOND": { lvl: 2, display: true }, - "SN3-DEBATS-DEC": { lvl: 2, display: true }, - "SN3-DEBATS-SEANCE": { lvl: 2, display: true }, - "SNNLEC-COM-FOND": { lvl: 2, display: true }, - "SNNLEC-DEBATS-DEC": { lvl: 2, display: true }, - "SNNLEC-DEBATS-SEANCE": { lvl: 2, display: true }, - "AN1-COM-AVIS-NOMIN": { lvl: 3, display: false }, - "AN1-COM-AVIS-RAPPORT": { lvl: 3, display: true }, - "AN1-COM-AVIS-REUNION": { lvl: 3, display: false }, - "AN1-COM-AVIS-SAISIE": { lvl: 3, display: false }, - "AN1-COM-FOND-NOMIN": { lvl: 3, display: false }, - "AN1-COM-FOND-RAPPORT": { lvl: 3, display: true }, - "AN1-COM-FOND-REUNION": { lvl: 3, display: false }, - "AN1-COM-FOND-SAISIE": { lvl: 3, display: false }, - "AN2-COM-AVIS-RAPPORT": { lvl: 3, display: true }, - "AN2-COM-AVIS-REUNION": { lvl: 3, display: false }, - "AN2-COM-AVIS-SAISIE": { lvl: 3, display: false }, - "AN2-COM-FOND-NOMIN": { lvl: 3, display: false }, - "AN2-COM-FOND-RAPPORT": { lvl: 3, display: true }, - "AN2-COM-FOND-REUNION": { lvl: 3, display: false }, - "AN2-COM-FOND-SAISIE": { lvl: 3, display: false }, - "AN20-COMENQ-CREA": { lvl: 3, display: false }, - "AN20-COMENQ-NOMIN": { lvl: 3, display: false }, - "AN20-COMENQ-RAPPORT": { lvl: 3, display: true }, - "AN20-MISINF-CREA": { lvl: 3, display: false }, - "AN20-MISINF-NOMIN": { lvl: 3, display: false }, - "AN20-MISINF-RAPPORT": { lvl: 3, display: true }, - "AN3-COM-FOND-NOMIN": { lvl: 3, display: false }, - "AN3-COM-FOND-RAPPORT": { lvl: 3, display: true }, - "AN3-COM-FOND-REUNION": { lvl: 3, display: false }, - "AN3-COM-FOND-SAISIE": { lvl: 3, display: false }, - "ANLDEF-COM-FOND-RAPPORT": { lvl: 3, display: true }, - "ANLDEF-COM-FOND-REUNION": { lvl: 3, display: false }, - "ANLDEF-COM-FOND-SAISIE": { lvl: 3, display: false }, - "ANLUNI-COM-CAE-DEC": { lvl: 3, display: false }, - "ANLUNI-COM-CAE-NOMIN": { lvl: 3, display: false }, - "ANLUNI-COM-CAE-RAPPORT": { lvl: 3, display: true }, - "ANLUNI-COM-CAE-REUNION": { lvl: 3, display: false }, - "ANLUNI-COM-CAE-SAISIE": { lvl: 3, display: false }, - "ANLUNI-COM-FOND-NOMIN": { lvl: 3, display: false }, - "ANLUNI-COM-FOND-RAPPORT": { lvl: 3, display: true }, - "ANLUNI-COM-FOND-REUNION": { lvl: 3, display: false }, - "ANLUNI-COM-FOND-SAISIE": { lvl: 3, display: false }, - "ANNLEC-COM-AVIS-NOMIN": { lvl: 3, display: false }, - "ANNLEC-COM-AVIS-RAPPORT": { lvl: 3, display: true }, - "ANNLEC-COM-AVIS-REUNION": { lvl: 3, display: false }, - "ANNLEC-COM-AVIS-SAISIE": { lvl: 3, display: false }, - "ANNLEC-COM-FOND-NOMIN": { lvl: 3, display: false }, - "ANNLEC-COM-FOND-RAPPORT": { lvl: 3, display: true }, - "ANNLEC-COM-FOND-REUNION": { lvl: 3, display: false }, - "ANNLEC-COM-FOND-SAISIE": { lvl: 3, display: false }, - "SN1-COM-AVIS-NOMIN": { lvl: 3, display: false }, - "SN1-COM-AVIS-RAPPORT": { lvl: 3, display: true }, - "SN1-COM-AVIS-SAISIE": { lvl: 3, display: false }, - "SN1-COM-FOND-NOMIN": { lvl: 3, display: false }, - "SN1-COM-FOND-RAPPORT": { lvl: 3, display: true }, - "SN1-COM-FOND-SAISIE": { lvl: 3, display: false }, - "SN2-COM-AVIS-NOMIN": { lvl: 3, display: false }, - "SN2-COM-AVIS-RAPPORT": { lvl: 3, display: true }, - "SN2-COM-AVIS-SAISIE": { lvl: 3, display: false }, - "SN2-COM-FOND-NOMIN": { lvl: 3, display: false }, - "SN2-COM-FOND-RAPPORT": { lvl: 3, display: true }, - "SN2-COM-FOND-SAISIE": { lvl: 3, display: false }, - "SN3-COM-FOND-RAPPORT": { lvl: 3, display: true }, - "SN3-COM-FOND-SAISIE": { lvl: 3, display: false }, - "SNNLEC-COM-FOND-NOMIN": { lvl: 3, display: false }, - "SNNLEC-COM-FOND-RAPPORT": { lvl: 3, display: true }, - "SNNLEC-COM-FOND-SAISIE": { lvl: 3, display: false }, + "AN-APPLI": { lvl: 0, display: true, parents: [] }, + AN1: { lvl: 0, display: true, parents: [] }, + AN2: { lvl: 0, display: true, parents: [] }, + AN20: { lvl: 0, display: true, parents: [] }, + AN21: { lvl: 0, display: true, parents: [] }, + AN3: { lvl: 0, display: true, parents: [] }, + ANLDEF: { lvl: 0, display: true, parents: [] }, + ANLUNI: { lvl: 0, display: true, parents: [] }, + ANNLEC: { lvl: 0, display: true, parents: [] }, + CC: { lvl: 0, display: true, parents: [] }, + CMP: { lvl: 0, display: true, parents: [] }, + EU: { lvl: 0, display: true, parents: [] }, + PROM: { lvl: 0, display: true, parents: [] }, + SN1: { lvl: 0, display: true, parents: [] }, + SN2: { lvl: 0, display: true, parents: [] }, + SN3: { lvl: 0, display: true, parents: [] }, + SNNLEC: { lvl: 0, display: true, parents: [] }, + "AN-APPLI-RAPPORT": { lvl: 1, display: "?", parents: ["AN-APPLI"] }, + "AN1-ACIN": { lvl: 1, display: true, parents: ["AN1"] }, + "AN1-AVCE": { lvl: 1, display: true, parents: ["AN1"] }, + "AN1-COM": { lvl: 1, display: true, parents: ["AN1"] }, + "AN1-DEBATS": { lvl: 1, display: true, parents: ["AN1"] }, + "AN1-DEPOT": { lvl: 1, display: true, parents: ["AN1"] }, + "AN1-DGVT": { lvl: 1, display: true, parents: ["AN1"] }, + "AN1-DPTLETTRECT": { lvl: 1, display: true, parents: ["AN1"] }, + "AN1-ETI": { lvl: 1, display: true, parents: ["AN1"] }, + "AN1-MOTION": { lvl: 1, display: true, parents: ["AN1"] }, + "AN1-PROCACC": { lvl: 1, display: true, parents: ["AN1"] }, + "AN1-RECBUREAU": { lvl: 1, display: true, parents: ["AN1"] }, + "AN1-RTRINI": { lvl: 1, display: true, parents: ["AN1"] }, + "AN2-COM": { lvl: 1, display: true, parents: ["AN2"] }, + "AN2-DEBATS": { lvl: 1, display: true, parents: ["AN2"] }, + "AN2-DEPOT": { lvl: 1, display: true, parents: ["AN2"] }, + "AN20-COMENQ": { lvl: 1, display: true, parents: ["AN20"] }, + "AN20-MISINF": { lvl: 1, display: true, parents: ["AN20"] }, + "AN20-RAPPORT": { lvl: 1, display: true, parents: ["AN20"] }, + "AN21-APAN": { lvl: 1, display: true, parents: ["AN21"] }, + "AN21-DEBATS": { lvl: 1, display: true, parents: ["AN21"] }, + "AN21-DGVT": { lvl: 1, display: true, parents: ["AN21"] }, + "AN21-MOTION": { lvl: 1, display: true, parents: ["AN21"] }, + "AN21-MPR": { lvl: 1, display: true, parents: ["AN21"] }, + "AN3-COM": { lvl: 1, display: true, parents: ["AN3"] }, + "AN3-DEBATS": { lvl: 1, display: true, parents: ["AN3"] }, + "AN3-DEPOT": { lvl: 1, display: true, parents: ["AN3"] }, + "ANLDEF-COM": { lvl: 1, display: true, parents: ["ANLDEF"] }, + "ANLDEF-DEBATS": { lvl: 1, display: true, parents: ["ANLDEF"] }, + "ANLDEF-DEPOT": { lvl: 1, display: true, parents: ["ANLDEF"] }, + "ANLDEF-DGVT": { lvl: 1, display: true, parents: ["ANLDEF"] }, + "ANLDEF-MOTION": { lvl: 1, display: true, parents: ["ANLDEF"] }, + "ANLUNI-COM": { lvl: 1, display: true, parents: ["ANLUNI"] }, + "ANLUNI-DEBATS": { lvl: 1, display: true, parents: ["ANLUNI"] }, + "ANLUNI-DEPOT": { lvl: 1, display: true, parents: ["ANLUNI"] }, + "ANLUNI-RTRINI": { lvl: 1, display: true, parents: ["ANLUNI"] }, + "ANNLEC-COM": { lvl: 1, display: true, parents: ["ANNLEC"] }, + "ANNLEC-DEBATS": { lvl: 1, display: true, parents: ["ANNLEC"] }, + "ANNLEC-DEPOT": { lvl: 1, display: true, parents: ["ANNLEC"] }, + "ANNLEC-DGVT": { lvl: 1, display: true, parents: ["ANNLEC"] }, + "ANNLEC-MOTION": { lvl: 1, display: true, parents: ["ANNLEC"] }, + "CC-CONCLUSION": { lvl: 1, display: true, parents: ["CC"] }, + "CC-SAISIE-AN": { lvl: 1, display: true, parents: ["CC"] }, + "CC-SAISIE-DROIT": { lvl: 1, display: true, parents: ["CC"] }, + "CC-SAISIE-PAN": { lvl: 1, display: true, parents: ["CC"] }, + "CC-SAISIE-PM": { lvl: 1, display: true, parents: ["CC"] }, + "CC-SAISIE-PR": { lvl: 1, display: true, parents: ["CC"] }, + "CC-SAISIE-PSN": { lvl: 1, display: true, parents: ["CC"] }, + "CC-SAISIE-SN": { lvl: 1, display: true, parents: ["CC"] }, + "CMP-COM": { lvl: 1, display: true, parents: ["CMP"] }, + "CMP-DEBATS-AN": { lvl: 1, display: true, parents: ["CMP"] }, + "CMP-DEBATS-SN": { lvl: 1, display: true, parents: ["CMP"] }, + "CMP-DEC": { lvl: 1, display: true, parents: ["CMP"] }, + "CMP-DEPOT": { lvl: 1, display: true, parents: ["CMP"] }, + "CMP-DGVT": { lvl: 1, display: true, parents: ["CMP"] }, + "CMP-MOTION": { lvl: 1, display: true, parents: ["CMP"] }, + "CMP-SAISIE": { lvl: 1, display: true, parents: ["CMP"] }, + "EU-DEC": { lvl: 1, display: true, parents: ["EU"] }, + "PROM-PUB": { lvl: 1, display: true, parents: ["PROM"] }, + "SN1-AVCE": { lvl: 1, display: true, parents: ["SN1"] }, + "SN1-COM": { lvl: 1, display: true, parents: ["SN1"] }, + "SN1-DEBATS": { lvl: 1, display: true, parents: ["SN1"] }, + "SN1-DEPOT": { lvl: 1, display: true, parents: ["SN1"] }, + "SN1-DPTLETTRECT": { lvl: 1, display: true, parents: ["SN1"] }, + "SN1-ETI": { lvl: 1, display: true, parents: ["SN1"] }, + "SN1-PROCACC": { lvl: 1, display: true, parents: ["SN1"] }, + "SN1-RTRINI": { lvl: 1, display: true, parents: ["SN1"] }, + "SN2-COM": { lvl: 1, display: true, parents: ["SN2"] }, + "SN2-DEBATS": { lvl: 1, display: true, parents: ["SN2"] }, + "SN2-DEPOT": { lvl: 1, display: true, parents: ["SN2"] }, + "SN3-COM": { lvl: 1, display: true, parents: ["SN3"] }, + "SN3-DEBATS": { lvl: 1, display: true, parents: ["SN3"] }, + "SN3-DEPOT": { lvl: 1, display: true, parents: ["SN3"] }, + "SNNLEC-COM": { lvl: 1, display: true, parents: ["SNNLEC"] }, + "SNNLEC-DEBATS": { lvl: 1, display: true, parents: ["SNNLEC"] }, + "SNNLEC-DEPOT": { lvl: 1, display: true, parents: ["SNNLEC"] }, + "AN1-COM-AVIS": { lvl: 2, display: true, parents: ["AN1", "AN1-COM"] }, + "AN1-COM-FOND": { lvl: 2, display: true, parents: ["AN1", "AN1-COM"] }, + "AN1-DEBATS-DEC": { lvl: 2, display: true, parents: ["AN1", "AN1-DEBATS"] }, + "AN1-DEBATS-MOTION": { + lvl: 2, + display: true, + parents: ["AN1", "AN1-DEBATS"], + }, + "AN1-DEBATS-MOTION-VOTE": { + lvl: 2, + display: true, + parents: ["AN1", "AN1-DEBATS", "AN1-DEBATS-MOTION"], + }, + "AN1-DEBATS-SEANCE": { + lvl: 2, + display: true, + parents: ["AN1", "AN1-DEBATS"], + }, + "AN2-COM-AVIS": { lvl: 2, display: true, parents: ["AN2", "AN2-COM"] }, + "AN2-COM-FOND": { lvl: 2, display: true, parents: ["AN2", "AN2-COM"] }, + "AN2-DEBATS-DEC": { lvl: 2, display: true, parents: ["AN2", "AN2-DEBATS"] }, + "AN2-DEBATS-SEANCE": { + lvl: 2, + display: true, + parents: ["AN2", "AN2-DEBATS"], + }, + "AN21-DEBATS-MOTION-VOTE": { + lvl: 2, + display: true, + parents: ["AN21", "AN21-DEBATS"], + }, + "AN21-DEBATS-SEANCE": { + lvl: 2, + display: true, + parents: ["AN21", "AN21-DEBATS"], + }, + "AN3-COM-FOND": { lvl: 2, display: true, parents: ["AN3", "AN3-COM"] }, + "AN3-DEBATS-DEC": { lvl: 2, display: true, parents: ["AN3", "AN3-DEBATS"] }, + "AN3-DEBATS-SEANCE": { + lvl: 2, + display: true, + parents: ["AN3", "AN3-DEBATS"], + }, + "ANLDEF-COM-FOND": { + lvl: 2, + display: true, + parents: ["ANLDEF", "ANLDEF-COM"], + }, + "ANLDEF-DEBATS-DEC": { + lvl: 2, + display: true, + parents: ["ANLDEF", "ANLDEF-DEBATS"], + }, + "ANLDEF-DEBATS-MOTION-VOTE": { + lvl: 2, + display: true, + parents: ["ANLDEF", "ANLDEF-DEBATS"], + }, + "ANLDEF-DEBATS-SEANCE": { + lvl: 2, + display: true, + parents: ["ANLDEF", "ANLDEF-DEBATS"], + }, + "ANLUNI-COM-CAE": { + lvl: 2, + display: true, + parents: ["ANLUNI", "ANLUNI-COM"], + }, + "ANLUNI-COM-FOND": { + lvl: 2, + display: true, + parents: ["ANLUNI", "ANLUNI-COM"], + }, + "ANLUNI-DEBATS-DEC": { + lvl: 2, + display: true, + parents: ["ANLUNI", "ANLUNI-DEBATS"], + }, + "ANLUNI-DEBATS-SEANCE": { + lvl: 2, + display: true, + parents: ["ANLUNI", "ANLUNI-DEBATS"], + }, + "ANNLEC-COM-AVIS": { + lvl: 2, + display: true, + parents: ["ANNLEC", "ANNLEC-COM"], + }, + "ANNLEC-COM-FOND": { + lvl: 2, + display: true, + parents: ["ANNLEC", "ANNLEC-COM"], + }, + "ANNLEC-DEBATS-DEC": { + lvl: 2, + display: true, + parents: ["ANNLEC", "ANNLEC-DEBATS"], + }, + "ANNLEC-DEBATS-MOTION-VOTE": { + lvl: 2, + display: true, + parents: ["ANNLEC", "ANNLEC-DEBATS"], + }, + "ANNLEC-DEBATS-SEANCE": { + lvl: 2, + display: true, + parents: ["ANNLEC", "ANNLEC-DEBATS"], + }, + "CMP-COM-NOMIN": { lvl: 2, display: true, parents: ["CMP", "CMP-COM"] }, + "CMP-COM-RAPPORT-AN": { lvl: 2, display: true, parents: ["CMP", "CMP-COM"] }, + "CMP-COM-RAPPORT-SN": { lvl: 2, display: true, parents: ["CMP", "CMP-COM"] }, + "CMP-DEBATS-AN-DEC": { + lvl: 2, + display: true, + parents: ["CMP", "CMP-DEBATS-AN"], + }, + "CMP-DEBATS-AN-SEANCE": { + lvl: 2, + display: true, + parents: ["CMP", "CMP-DEBATS-AN"], + }, + "CMP-DEBATS-SN-DEC": { + lvl: 2, + display: true, + parents: ["CMP", "CMP-DEBATS-SN"], + }, + "CMP-DEBATS-SN-SEANCE": { + lvl: 2, + display: true, + parents: ["CMP", "CMP-DEBATS-SN"], + }, + "SN1-COM-AVIS": { lvl: 2, display: true, parents: ["SN1", "SN1-COM"] }, + "SN1-COM-FOND": { lvl: 2, display: true, parents: ["SN1", "SN1-COM"] }, + "SN1-DEBATS-DEC": { lvl: 2, display: true, parents: ["SN1", "SN1-DEBATS"] }, + "SN1-DEBATS-MOTION": { + lvl: 2, + display: true, + parents: ["SN1", "SN1-DEBATS"], + }, + "SN1-DEBATS-MOTION-VOTE": { + lvl: 2, + display: true, + parents: ["SN1", "SN1-DEBATS", "SN1-DEBATS-MOTION"], + }, + "SN1-DEBATS-SEANCE": { + lvl: 2, + display: true, + parents: ["SN1", "SN1-DEBATS"], + }, + "SN2-COM-AVIS": { lvl: 2, display: true, parents: ["SN2", "SN2-COM"] }, + "SN2-COM-FOND": { lvl: 2, display: true, parents: ["SN2", "SN2-COM"] }, + "SN2-DEBATS-DEC": { lvl: 2, display: true, parents: ["SN2", "SN2-DEBATS"] }, + "SN2-DEBATS-SEANCE": { + lvl: 2, + display: true, + parents: ["SN2", "SN2-DEBATS"], + }, + "SN3-COM-FOND": { lvl: 2, display: true, parents: ["SN3", "SN3-COM"] }, + "SN3-DEBATS-DEC": { lvl: 2, display: true, parents: ["SN3", "SN3-DEBATS"] }, + "SN3-DEBATS-SEANCE": { + lvl: 2, + display: true, + parents: ["SN3", "SN3-DEBATS"], + }, + "SNNLEC-COM-FOND": { + lvl: 2, + display: true, + parents: ["SNNLEC", "SNNLEC-COM"], + }, + "SNNLEC-DEBATS-DEC": { + lvl: 2, + display: true, + parents: ["SNNLEC", "SNNLEC-DEBATS"], + }, + "SNNLEC-DEBATS-SEANCE": { + lvl: 2, + display: true, + parents: ["SNNLEC", "SNNLEC-DEBATS"], + }, + "AN1-COM-AVIS-NOMIN": { + lvl: 3, + display: false, + parents: ["AN1", "AN1-COM", "AN1-COM-AVIS"], + }, + "AN1-COM-AVIS-RAPPORT": { + lvl: 3, + display: true, + parents: ["AN1", "AN1-COM", "AN1-COM-AVIS"], + }, + "AN1-COM-AVIS-REUNION": { + lvl: 3, + display: false, + parents: ["AN1", "AN1-COM", "AN1-COM-AVIS"], + }, + "AN1-COM-AVIS-SAISIE": { + lvl: 3, + display: false, + parents: ["AN1", "AN1-COM", "AN1-COM-AVIS"], + }, + "AN1-COM-FOND-NOMIN": { + lvl: 3, + display: false, + parents: ["AN1", "AN1-COM", "AN1-COM-FOND"], + }, + "AN1-COM-FOND-RAPPORT": { + lvl: 3, + display: true, + parents: ["AN1", "AN1-COM", "AN1-COM-FOND"], + }, + "AN1-COM-FOND-REUNION": { + lvl: 3, + display: false, + parents: ["AN1", "AN1-COM", "AN1-COM-FOND"], + }, + "AN1-COM-FOND-SAISIE": { + lvl: 3, + display: false, + parents: ["AN1", "AN1-COM", "AN1-COM-FOND"], + }, + "AN2-COM-AVIS-RAPPORT": { + lvl: 3, + display: true, + parents: ["AN2", "AN2-COM", "AN2-COM-AVIS"], + }, + "AN2-COM-AVIS-REUNION": { + lvl: 3, + display: false, + parents: ["AN2", "AN2-COM", "AN2-COM-AVIS"], + }, + "AN2-COM-AVIS-SAISIE": { + lvl: 3, + display: false, + parents: ["AN2", "AN2-COM", "AN2-COM-AVIS"], + }, + "AN2-COM-FOND-NOMIN": { + lvl: 3, + display: false, + parents: ["AN2", "AN2-COM", "AN2-COM-FOND"], + }, + "AN2-COM-FOND-RAPPORT": { + lvl: 3, + display: true, + parents: ["AN2", "AN2-COM", "AN2-COM-FOND"], + }, + "AN2-COM-FOND-REUNION": { + lvl: 3, + display: false, + parents: ["AN2", "AN2-COM", "AN2-COM-FOND"], + }, + "AN2-COM-FOND-SAISIE": { + lvl: 3, + display: false, + parents: ["AN2", "AN2-COM", "AN2-COM-FOND"], + }, + "AN20-COMENQ-CREA": { + lvl: 3, + display: false, + parents: ["AN20", "AN20-COMENQ"], + }, + "AN20-COMENQ-NOMIN": { + lvl: 3, + display: false, + parents: ["AN20", "AN20-COMENQ"], + }, + "AN20-COMENQ-RAPPORT": { + lvl: 3, + display: true, + parents: ["AN20", "AN20-COMENQ"], + }, + "AN20-MISINF-CREA": { + lvl: 3, + display: false, + parents: ["AN20", "AN20-MISINF"], + }, + "AN20-MISINF-NOMIN": { + lvl: 3, + display: false, + parents: ["AN20", "AN20-MISINF"], + }, + "AN20-MISINF-RAPPORT": { + lvl: 3, + display: true, + parents: ["AN20", "AN20-MISINF"], + }, + "AN3-COM-FOND-NOMIN": { + lvl: 3, + display: false, + parents: ["AN3", "AN3-COM", "AN3-COM-FOND"], + }, + "AN3-COM-FOND-RAPPORT": { + lvl: 3, + display: true, + parents: ["AN3", "AN3-COM", "AN3-COM-FOND"], + }, + "AN3-COM-FOND-REUNION": { + lvl: 3, + display: false, + parents: ["AN3", "AN3-COM", "AN3-COM-FOND"], + }, + "AN3-COM-FOND-SAISIE": { + lvl: 3, + display: false, + parents: ["AN3", "AN3-COM", "AN3-COM-FOND"], + }, + "ANLDEF-COM-FOND-RAPPORT": { + lvl: 3, + display: true, + parents: ["ANLDEF", "ANLDEF-COM", "ANLDEF-COM-FOND"], + }, + "ANLDEF-COM-FOND-REUNION": { + lvl: 3, + display: false, + parents: ["ANLDEF", "ANLDEF-COM", "ANLDEF-COM-FOND"], + }, + "ANLDEF-COM-FOND-SAISIE": { + lvl: 3, + display: false, + parents: ["ANLDEF", "ANLDEF-COM", "ANLDEF-COM-FOND"], + }, + "ANLUNI-COM-CAE-DEC": { + lvl: 3, + display: false, + parents: ["ANLUNI", "ANLUNI-COM", "ANLUNI-COM-CAE"], + }, + "ANLUNI-COM-CAE-NOMIN": { + lvl: 3, + display: false, + parents: ["ANLUNI", "ANLUNI-COM", "ANLUNI-COM-CAE"], + }, + "ANLUNI-COM-CAE-RAPPORT": { + lvl: 3, + display: true, + parents: ["ANLUNI", "ANLUNI-COM", "ANLUNI-COM-CAE"], + }, + "ANLUNI-COM-CAE-REUNION": { + lvl: 3, + display: false, + parents: ["ANLUNI", "ANLUNI-COM", "ANLUNI-COM-CAE"], + }, + "ANLUNI-COM-CAE-SAISIE": { + lvl: 3, + display: false, + parents: ["ANLUNI", "ANLUNI-COM", "ANLUNI-COM-CAE"], + }, + "ANLUNI-COM-FOND-NOMIN": { + lvl: 3, + display: false, + parents: ["ANLUNI", "ANLUNI-COM", "ANLUNI-COM-FOND"], + }, + "ANLUNI-COM-FOND-RAPPORT": { + lvl: 3, + display: true, + parents: ["ANLUNI", "ANLUNI-COM", "ANLUNI-COM-FOND"], + }, + "ANLUNI-COM-FOND-REUNION": { + lvl: 3, + display: false, + parents: ["ANLUNI", "ANLUNI-COM", "ANLUNI-COM-FOND"], + }, + "ANLUNI-COM-FOND-SAISIE": { + lvl: 3, + display: false, + parents: ["ANLUNI", "ANLUNI-COM", "ANLUNI-COM-FOND"], + }, + "ANNLEC-COM-AVIS-NOMIN": { + lvl: 3, + display: false, + parents: ["ANNLEC", "ANNLEC-COM", "ANNLEC-COM-AVIS"], + }, + "ANNLEC-COM-AVIS-RAPPORT": { + lvl: 3, + display: true, + parents: ["ANNLEC", "ANNLEC-COM", "ANNLEC-COM-AVIS"], + }, + "ANNLEC-COM-AVIS-REUNION": { + lvl: 3, + display: false, + parents: ["ANNLEC", "ANNLEC-COM", "ANNLEC-COM-AVIS"], + }, + "ANNLEC-COM-AVIS-SAISIE": { + lvl: 3, + display: false, + parents: ["ANNLEC", "ANNLEC-COM", "ANNLEC-COM-AVIS"], + }, + "ANNLEC-COM-FOND-NOMIN": { + lvl: 3, + display: false, + parents: ["ANNLEC", "ANNLEC-COM", "ANNLEC-COM-FOND"], + }, + "ANNLEC-COM-FOND-RAPPORT": { + lvl: 3, + display: true, + parents: ["ANNLEC", "ANNLEC-COM", "ANNLEC-COM-FOND"], + }, + "ANNLEC-COM-FOND-REUNION": { + lvl: 3, + display: false, + parents: ["ANNLEC", "ANNLEC-COM", "ANNLEC-COM-FOND"], + }, + "ANNLEC-COM-FOND-SAISIE": { + lvl: 3, + display: false, + parents: ["ANNLEC", "ANNLEC-COM", "ANNLEC-COM-FOND"], + }, + "SN1-COM-AVIS-NOMIN": { + lvl: 3, + display: false, + parents: ["SN1", "SN1-COM", "SN1-COM-AVIS"], + }, + "SN1-COM-AVIS-RAPPORT": { + lvl: 3, + display: true, + parents: ["SN1", "SN1-COM", "SN1-COM-AVIS"], + }, + "SN1-COM-AVIS-SAISIE": { + lvl: 3, + display: false, + parents: ["SN1", "SN1-COM", "SN1-COM-AVIS"], + }, + "SN1-COM-FOND-NOMIN": { + lvl: 3, + display: false, + parents: ["SN1", "SN1-COM", "SN1-COM-FOND"], + }, + "SN1-COM-FOND-RAPPORT": { + lvl: 3, + display: true, + parents: ["SN1", "SN1-COM", "SN1-COM-FOND"], + }, + "SN1-COM-FOND-SAISIE": { + lvl: 3, + display: false, + parents: ["SN1", "SN1-COM", "SN1-COM-FOND"], + }, + "SN2-COM-AVIS-NOMIN": { + lvl: 3, + display: false, + parents: ["SN2", "SN2-COM", "SN2-COM-AVIS"], + }, + "SN2-COM-AVIS-RAPPORT": { + lvl: 3, + display: true, + parents: ["SN2", "SN2-COM", "SN2-COM-AVIS"], + }, + "SN2-COM-AVIS-SAISIE": { + lvl: 3, + display: false, + parents: ["SN2", "SN2-COM", "SN2-COM-AVIS"], + }, + "SN2-COM-FOND-NOMIN": { + lvl: 3, + display: false, + parents: ["SN2", "SN2-COM", "SN2-COM-FOND"], + }, + "SN2-COM-FOND-RAPPORT": { + lvl: 3, + display: true, + parents: ["SN2", "SN2-COM", "SN2-COM-FOND"], + }, + "SN2-COM-FOND-SAISIE": { + lvl: 3, + display: false, + parents: ["SN2", "SN2-COM", "SN2-COM-FOND"], + }, + "SN3-COM-FOND-RAPPORT": { + lvl: 3, + display: true, + parents: ["SN3", "SN3-COM", "SN3-COM-FOND"], + }, + "SN3-COM-FOND-SAISIE": { + lvl: 3, + display: false, + parents: ["SN3", "SN3-COM", "SN3-COM-FOND"], + }, + "SNNLEC-COM-FOND-NOMIN": { + lvl: 3, + display: false, + parents: ["SNNLEC", "SNNLEC-COM", "SNNLEC-COM-FOND"], + }, + "SNNLEC-COM-FOND-RAPPORT": { + lvl: 3, + display: true, + parents: ["SNNLEC", "SNNLEC-COM", "SNNLEC-COM-FOND"], + }, + "SNNLEC-COM-FOND-SAISIE": { + lvl: 3, + display: false, + parents: ["SNNLEC", "SNNLEC-COM", "SNNLEC-COM-FOND"], + }, } as const; + +type ActsStructure = Record< + string, + { + ids?: string[]; + date?: Date; + children?: ActsStructure; + } +>; + +function addDatesHelper( + item: { + ids?: string[]; + date?: Date; + children?: ActsStructure; + }, + lookup: Record +) { + const rep = {}; + + const idsDates = + item.ids?.map((id) => lookup[id].dateActe).filter((date) => date != null) ?? + ([] as Date[]); + + const idsMinDate = + idsDates?.length === 0 + ? undefined + : new Date(Math.min(...idsDates.map((d) => d.getTime()))); + + if (item.children === undefined) { + item.date = idsMinDate; + return idsMinDate; + } + + let childrenMinDate: Date | undefined = undefined; + Object.keys(item.children).forEach((key) => { + const date = addDatesHelper(item.children![key], lookup); + + childrenMinDate = + childrenMinDate === undefined || + (date !== undefined && childrenMinDate.getTime() > date.getTime()) + ? date + : childrenMinDate; + }); + + item.date = idsMinDate || childrenMinDate; + return item.date; +} + +function addDates( + structure: ActsStructure, + lookup: Record +) { + Object.keys(structure).forEach((key) => { + addDatesHelper(structure[key], lookup); + }); +} + +export function groupActs(acts: ActLegislatif[]) { + const actsStructure: ActsStructure = {}; + const actsLookup: Record = {}; + + acts.forEach((act) => { + const { codeActe, uid } = act; + let parentPointer: ActsStructure = actsStructure; + + CONTEXT[codeActe].parents.forEach((code) => { + if (parentPointer[code] === undefined) { + parentPointer[code] = { children: {} } as ActsStructure; + } + if (parentPointer[code].children === undefined) { + parentPointer[code].children = {} as ActsStructure; + } + parentPointer = parentPointer[code].children as ActsStructure; + }); + + if (parentPointer[codeActe] === undefined) { + parentPointer[codeActe] = { ids: [] }; + } + parentPointer[codeActe].ids?.push(uid); + actsLookup[uid] = act; + }); + + addDates(actsStructure, actsLookup); + + return { + actsStructure, + actsLookup, + }; +}