@@ -12,16 +12,23 @@ import { isToolEnabled, smallUrl, slugifyUrl } from "../../src/utils";
1212import Link from "next/link" ;
1313import { GradeBadge , IconUnknown } from "../../src/components/GradeBadge" ;
1414import {
15+ phases ,
1516 getLatestPhase ,
1617 phaseSeverities ,
1718} from "../../src/components/BetagouvInfo" ;
1819
1920const report : DashLordReport = require ( "../../src/report.json" ) ;
2021
22+ type StatDef = {
23+ title : string ;
24+ value : ( any ) => number ;
25+ } ;
26+
2127type SummaryConfig = {
2228 title : string ;
2329 neededTool : DashlordTool ;
2430 columns : GridColDef [ ] ;
31+ stats : StatDef [ ] ;
2532} ;
2633
2734const defaultColumnsProps = {
@@ -70,6 +77,23 @@ const summaryConfigs: Record<string, SummaryConfig> = {
7077 accessibility : {
7178 title : "Accessibilité" ,
7279 neededTool : "declaration-a11y" ,
80+ stats : [
81+ {
82+ title : "Déclaration présente" ,
83+ value : ( rows ) =>
84+ rows . filter (
85+ ( row ) => row [ "declaration-a11y" ] && row [ "declaration-a11y" ] . mention
86+ ) . length ,
87+ } ,
88+ {
89+ title : "Déclaration absente" ,
90+ value : ( rows ) =>
91+ rows . filter (
92+ ( row ) =>
93+ ! ( row [ "declaration-a11y" ] && row [ "declaration-a11y" ] . mention )
94+ ) . length ,
95+ } ,
96+ ] ,
7397 columns : [
7498 {
7599 ...defaultColumnsProps ,
@@ -109,6 +133,18 @@ const summaryConfigs: Record<string, SummaryConfig> = {
109133 stats : {
110134 title : "Page de stats" ,
111135 neededTool : "stats" ,
136+ stats : [
137+ {
138+ title : "Stats publiées" ,
139+ value : ( rows ) =>
140+ rows . filter ( ( row ) => row . stats && row . stats . grade === "A" ) . length ,
141+ } ,
142+ {
143+ title : "Stats non publiées" ,
144+ value : ( rows ) =>
145+ rows . filter ( ( row ) => row . stats && row . stats . grade === "F" ) . length ,
146+ } ,
147+ ] ,
112148 columns : [
113149 {
114150 ...defaultColumnsProps ,
@@ -122,7 +158,8 @@ const summaryConfigs: Record<string, SummaryConfig> = {
122158 renderCell : ( params ) => {
123159 if ( params . value === "A" ) {
124160 return (
125- params . row . betagouv && (
161+ params . row . betagouv &&
162+ params . row . betagouv . attributes . stats_url && (
126163 < Link
127164 prefetch = { false }
128165 title = { `Voir la page de stats de l'url ${ slugifyUrl (
@@ -144,6 +181,23 @@ const summaryConfigs: Record<string, SummaryConfig> = {
144181 budget : {
145182 title : "Publication du budget" ,
146183 neededTool : "budget_page" ,
184+ stats : [
185+ {
186+ title : "Budget publié" ,
187+ value : ( rows ) =>
188+ rows . filter ( ( row ) => row . budget_page && row . budget_page . grade === "A" )
189+ . length ,
190+ } ,
191+ {
192+ title : "Budget non publié" ,
193+ value : ( rows ) =>
194+ rows . filter (
195+ ( row ) =>
196+ ! row . budget_page ||
197+ ( row . budget_page && row . budget_page . grade === "F" )
198+ ) . length ,
199+ } ,
200+ ] ,
147201 columns : [
148202 {
149203 ...defaultColumnsProps ,
@@ -157,7 +211,8 @@ const summaryConfigs: Record<string, SummaryConfig> = {
157211 renderCell : ( params ) => {
158212 if ( params . value === "A" ) {
159213 return (
160- params . row . betagouv && (
214+ params . row . betagouv &&
215+ params . row . betagouv . attributes . budget_url && (
161216 < Link
162217 prefetch = { false }
163218 title = { `Voir la page de budget de l'url ${ slugifyUrl (
@@ -166,7 +221,7 @@ const summaryConfigs: Record<string, SummaryConfig> = {
166221 href = { params . row . betagouv . attributes . budget_url }
167222 target = "_blank"
168223 >
169- / { params . row . betagouv . attributes . budget_url }
224+ { params . row . betagouv . attributes . budget_url }
170225 </ Link >
171226 )
172227 ) ;
@@ -180,13 +235,24 @@ const summaryConfigs: Record<string, SummaryConfig> = {
180235
181236const Summary = ( { id } : { id : string } ) => {
182237 const [ category , setCategory ] = useState ( null ) ;
238+ const [ phase , setPhase ] = useState ( null ) ;
183239 const summaryConfig = summaryConfigs [ id ] ;
184240 const categories = Array . from (
185241 new Set ( report . map ( ( url ) => url . category ) . filter ( Boolean ) )
186242 ) . sort ( ) ;
187243
188244 const tableData = (
189- category ? report . filter ( ( url ) => url . category === category ) : report
245+ category || phase
246+ ? report . filter ( ( url ) => {
247+ let matchCategory = category ? url . category === category : true ;
248+ let matchPhase = phase
249+ ? url . betagouv &&
250+ url . betagouv . attributes &&
251+ getLatestPhase ( url . betagouv . attributes . phases ) . id === phase
252+ : true ;
253+ return matchCategory && matchPhase ;
254+ } )
255+ : report
190256 ) . filter ( ( url ) =>
191257 summaryConfig . neededTool
192258 ? isToolEnabled ( summaryConfig . neededTool , url . url )
@@ -201,30 +267,33 @@ const Summary = ({ id }: { id: string }) => {
201267 field : "url" ,
202268 headerName : `URL` ,
203269 width : 400 ,
204- renderCell : ( params ) => (
205- < div
206- style = { {
207- width : "95%" ,
208- overflow : "hidden" ,
209- whiteSpace : "nowrap" ,
210- textOverflow : "ellipsis" ,
211- } }
212- >
213- < Link
214- prefetch = { false }
215- title = { `Voir les détails de l'url ${ slugifyUrl ( params . value ) } ` }
216- href = { `/url/${ encodeURIComponent ( slugifyUrl ( params . value ) ) } ` }
270+ renderCell : ( params ) =>
271+ params . value && (
272+ < div
273+ style = { {
274+ width : "95%" ,
275+ overflow : "hidden" ,
276+ whiteSpace : "nowrap" ,
277+ textOverflow : "ellipsis" ,
278+ } }
217279 >
218- < i className = { fr . cx ( "fr-icon-search-line" , "fr-icon--sm" ) } />
219-
220- { smallUrl ( params . value ) }
221- </ Link >
222- </ div >
223- ) ,
280+ < Link
281+ prefetch = { false }
282+ title = { `Voir les détails de l'url ${ slugifyUrl ( params . value ) } ` }
283+ href = { `/url/${ encodeURIComponent ( slugifyUrl ( params . value ) ) } ` }
284+ >
285+ < i className = { fr . cx ( "fr-icon-search-line" , "fr-icon--sm" ) } />
286+
287+ { smallUrl ( params . value ) }
288+ </ Link >
289+ </ div >
290+ ) ,
224291 } ,
225292 isToolEnabled ( "betagouv" ) && getPhaseColumn ( ) ,
226293 ...summaryConfig . columns ,
227294 ] . filter ( Boolean ) ;
295+
296+ // console.log(phases, report);
228297 return (
229298 < >
230299 < Head >
@@ -233,21 +302,61 @@ const Summary = ({ id }: { id: string }) => {
233302 </ title >
234303 </ Head >
235304 < h1 > { summaryConfig . title } </ h1 >
236- { categories . length > 1 && (
237- < Select
238- label = { null }
239- nativeSelectProps = { {
240- onChange : ( event ) => setCategory ( event . target . value ) ,
241- } }
242- >
243- < option value = "" > tous les incubateurs</ option >
244- { categories . map ( ( cat ) => (
245- < option value = { cat } key = { cat } >
246- { cat }
247- </ option >
248- ) ) }
249- </ Select >
250- ) }
305+
306+ < div className = { fr . cx ( "fr-grid-row" , "fr-grid-row--gutters" , "fr-mb-3w" ) } >
307+ { summaryConfig . stats . map ( ( stat ) => {
308+ const value = stat . value ( tableData ) ;
309+ return (
310+ < div
311+ className = { fr . cx ( "fr-col-3" , "fr-m-1w" , "fr-p-3w" ) }
312+ style = { { textAlign : "center" , border : "1px solid #ccc" } }
313+ >
314+ < div className = { fr . cx ( "fr-text--lead" , "fr-text--heavy" ) } >
315+ { stat . title }
316+ </ div >
317+ < div
318+ className = { fr . cx ( "fr-text--heavy" ) }
319+ style = { { fontSize : "2rem" } }
320+ >
321+ { value }
322+ </ div >
323+ </ div >
324+ ) ;
325+ } ) }
326+ </ div >
327+ < div className = { fr . cx ( "fr-grid-row" ) } >
328+ { categories . length > 1 && (
329+ < Select
330+ label = { null }
331+ nativeSelectProps = { {
332+ onChange : ( event ) => setCategory ( event . target . value ) ,
333+ } }
334+ >
335+ < option value = "" > tous les incubateurs</ option >
336+ { categories . map ( ( cat ) => (
337+ < option value = { cat } key = { cat } >
338+ { cat }
339+ </ option >
340+ ) ) }
341+ </ Select >
342+ ) }
343+ { isToolEnabled ( "betagouv" ) && (
344+ < Select
345+ className = { fr . cx ( "fr-ml-1w" ) }
346+ label = { null }
347+ nativeSelectProps = { {
348+ onChange : ( event ) => setPhase ( event . target . value ) ,
349+ } }
350+ >
351+ < option value = "" > toutes les phases</ option >
352+ { phases . map ( ( phase ) => (
353+ < option value = { phase . id } key = { phase . id } >
354+ { phase . label }
355+ </ option >
356+ ) ) }
357+ </ Select >
358+ ) }
359+ </ div >
251360 < DataGrid
252361 rows = { tableData }
253362 columns = { columns }
0 commit comments