@@ -2,15 +2,16 @@ import { useLang } from "ui/i18n";
22import { Trans , useTranslation } from "react-i18next" ;
33import { fr } from "@codegouvfr/react-dsfr" ;
44import { tss } from "tss-react" ;
5- import { shortEndMonthDate , monthDate } from "ui/useMoment" ;
5+ import { shortEndMonthDate , monthDate , useFormattedDate } from "ui/useMoment" ;
66import Tooltip from "@mui/material/Tooltip" ;
77import { capitalize } from "tsafe/capitalize" ;
88import { CnllServiceProviderModal } from "./CnllServiceProviderModal" ;
99import { assert , type Equals } from "tsafe/assert" ;
1010import config from "../../config-ui.json" ;
11- import { SILL , SoftwareType } from "api/dist/src/lib/ApiTypes " ;
11+ import type { ApiTypes } from "api" ;
1212import { SoftwareTypeTable } from "ui/shared/SoftwareTypeTable" ;
1313import { LogoURLButton } from "ui/shared/LogoURLButton" ;
14+ import { Chip } from "@mui/material" ;
1415
1516//TODO: Do not use optional props (?) use ( | undefined ) instead
1617// so we are sure that we don't forget to provide some props
@@ -39,8 +40,9 @@ export type Props = {
3940 programmingLanguages : string [ ] ;
4041 keywords ?: string [ ] ;
4142 applicationCategories : string [ ] ;
42- softwareType : SoftwareType ;
43- identifiers : SILL . Identification [ ] ;
43+ softwareType : ApiTypes . SoftwareType ;
44+ identifiers : ApiTypes . SILL . Identification [ ] ;
45+ repoMetadata ?: ApiTypes . SILL . RepoMetadata ;
4446} ;
4547export const PreviewTab = ( props : Props ) => {
4648 const {
@@ -64,14 +66,22 @@ export const PreviewTab = (props: Props) => {
6466 keywords,
6567 applicationCategories,
6668 softwareType,
67- identifiers
69+ identifiers,
70+ repoMetadata
6871 } = props ;
6972
7073 const { classes, cx } = useStyles ( ) ;
7174
7275 const { t } = useTranslation ( ) ;
7376 const { lang } = useLang ( ) ;
7477
78+ const scoreToLabel = ( score : number ) => {
79+ if ( score < 0.1 ) return "error" ;
80+ if ( score < 0.34 ) return "warning" ;
81+ if ( score < 0.67 ) return "info" ;
82+ return "success" ;
83+ } ;
84+
7585 return (
7686 < >
7787 < section className = { classes . tabContainer } >
@@ -387,6 +397,64 @@ export const PreviewTab = (props: Props) => {
387397 ) }
388398 </ div >
389399 ) }
400+ { repoMetadata && (
401+ < div className = { classes . section } >
402+ < p className = { cx ( fr . cx ( "fr-text--bold" ) , classes . item ) } >
403+ { t ( "previewTab.repoMetadata" ) }
404+ { repoMetadata ?. healthCheck ?. score && (
405+ < Chip
406+ label = {
407+ (
408+ Math . round (
409+ repoMetadata . healthCheck . score * 10000
410+ ) / 100
411+ ) . toFixed ( 2 ) + " %"
412+ }
413+ color = { scoreToLabel ( repoMetadata . healthCheck . score ) }
414+ style = { { marginLeft : "10px" } }
415+ />
416+ ) }
417+ </ p >
418+ { repoMetadata ?. healthCheck ?. lastClosedIssue && (
419+ < p className = { cx ( fr . cx ( "fr-text--regular" ) , classes . item ) } >
420+ < span className = { classes . labelDetail } >
421+ { t ( "previewTab.repoLastClosedIssue" ) } :{ " " }
422+ </ span >
423+ < span >
424+ { useFormattedDate ( {
425+ time : repoMetadata . healthCheck . lastClosedIssue
426+ } ) }
427+ </ span >
428+ </ p >
429+ ) }
430+ { repoMetadata ?. healthCheck ?. lastClosedIssuePullRequest && (
431+ < p className = { cx ( fr . cx ( "fr-text--regular" ) , classes . item ) } >
432+ < span className = { classes . labelDetail } >
433+ { t ( "previewTab.repoLastClosedIssuePullRequest" ) } { " " }
434+ :{ " " }
435+ </ span >
436+ < span >
437+ { useFormattedDate ( {
438+ time : repoMetadata . healthCheck
439+ . lastClosedIssuePullRequest
440+ } ) }
441+ </ span >
442+ </ p >
443+ ) }
444+ { repoMetadata ?. healthCheck ?. lastCommit && (
445+ < p className = { cx ( fr . cx ( "fr-text--regular" ) , classes . item ) } >
446+ < span className = { classes . labelDetail } >
447+ { t ( "previewTab.repoLastCommit" ) } :{ " " }
448+ </ span >
449+ < span >
450+ { useFormattedDate ( {
451+ time : repoMetadata . healthCheck . lastCommit
452+ } ) }
453+ </ span >
454+ </ p >
455+ ) }
456+ </ div >
457+ ) }
390458 </ section >
391459 < CnllServiceProviderModal
392460 softwareName = { softwareName }
0 commit comments