Skip to content

Commit

Permalink
feat: Ajout d'un démo d'exploitation de données extraites d'un fichie…
Browse files Browse the repository at this point in the history
…r Excel avec photos: répertoire du personnel
  • Loading branch information
remillc committed Apr 9, 2024
1 parent 2389ae9 commit 3e3b8e4
Show file tree
Hide file tree
Showing 42 changed files with 373 additions and 1 deletion.
12 changes: 12 additions & 0 deletions content/fiche-personnel.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
title: Fiche d'employé
slug: fiche-personnel
---

// import FichePersonnel from '@/components/personnel/FichePersonnel.jsx'

# Fiche d'employé

Voici un composant où on peut rechercher un employé et afficher sa fiche à partir d'un fichier `.csv`.

{/* <FichePersonnel /> */}
12 changes: 12 additions & 0 deletions content/personnel.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
title: Répertoire du personnel
slug: personnel
---

// import RepertoirePersonnel from '@/components/personnel/RepertoirePersonnel.jsx'

# Liste du personnel

Voici un composant qui affiche une liste du personnel à partir d'un fichier `.csv`.

{/* <RepertoirePersonnel /> */}
Binary file added data/personnel/liste-personnel.xlsx
Binary file not shown.
Binary file added data/personnel/photos/_profile.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/personnel/photos/alexandre-amar-zifkin.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/personnel/photos/aminata-keita.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/personnel/photos/amy-bergeron.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/personnel/photos/anne-hakier.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/personnel/photos/assia-mourid.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/personnel/photos/caroline-patenaude.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/personnel/photos/christiane-melancon.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/personnel/photos/cynthia-gagne.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/personnel/photos/david-patenaude.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/personnel/photos/denis-arvisais.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/personnel/photos/dominic-desaulniers.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/personnel/photos/emilie-dalpe.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/personnel/photos/graham-lavender.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/personnel/photos/indiana-delsart.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/personnel/photos/jeanfrancois-durnin.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/personnel/photos/julia-genereux-randall.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/personnel/photos/marc-olivier-croteau.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/personnel/photos/marie-claude-poirier.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/personnel/photos/melanie-masse.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/personnel/photos/nadege-arsa.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/personnel/photos/nino-gabrielli.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/personnel/photos/pascal-martinolli.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/personnel/photos/sara-bouhlal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/personnel/photos/simon-blais-longtin.jpg
Binary file added data/personnel/photos/simon-pierre-crevier.jpg
Binary file added data/personnel/photos/stephanie-pham-dang.png
Binary file added data/personnel/photos/tatiana-bobeica-talpa.jpg
Binary file added data/personnel/photos/thien-sa-hoang.png
Binary file added data/personnel/photos/valerie-bastien.jpg
Binary file added data/personnel/photos/valerie-rioux.jpg
Binary file added data/personnel/photos/viviane-angers.jpg
59 changes: 59 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"@mdx-js/react": "^3.0.1",
"@mui/icons-material": "^5.15.14",
"@mui/material": "^5.15.14",
"@mui/x-data-grid": "^7.1.0",
"@sindresorhus/slugify": "^2.2.1",
"gatsby": "^5.13.3",
"gatsby-plugin-alias-imports": "^1.0.5",
Expand All @@ -30,8 +31,12 @@
"gatsby-plugin-sitemap": "^6.13.1",
"gatsby-plugin-webfonts": "^2.3.2",
"gatsby-source-filesystem": "^5.13.1",
"gatsby-transformer-excel": "^5.13.1",
"gatsby-transformer-sharp": "^5.13.1",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"overrides": {
"xlsx": "https://cdn.sheetjs.com/xlsx-latest/xlsx-latest.tgz"
}
}
2 changes: 1 addition & 1 deletion plugins/gatsby-plugin-bib-theme/BibTheme.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import CssBaseline from '@mui/material/CssBaseline'
import { responsiveFontSizes, experimental_extendTheme as extendTheme, Experimental_CssVarsProvider as CssVarsProvider } from '@mui/material/styles'
import tokens from './tokens'

const theme = responsiveFontSizes(extendTheme(tokens))
export const theme = responsiveFontSizes(extendTheme(tokens))

// const GlobalStyles = withStyles(theme => {
// const isLight = theme.palette.mode === 'light'
Expand Down
166 changes: 166 additions & 0 deletions src/components/personnel/FichePersonnel.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
import { useStaticQuery, graphql } from 'gatsby'
import { Box, Chip, Grid, Typography, IconButton, Stack, Autocomplete, TextField } from '@mui/material'
import { EmailRounded } from '@mui/icons-material'
import { createTheme, ThemeProvider } from '@mui/material/styles'
import { frFR } from '@mui/x-data-grid/locales'
import tokens from '../../../plugins/gatsby-plugin-bib-theme/tokens'
import { GatsbyImage, getImage, StaticImage } from 'gatsby-plugin-image'

const theme = createTheme(tokens, frFR)

const columns = [
{
field: 'nomComplet',
headerName: 'Nom',
valueGetter: (_, row) => `${row.prenom} ${row.nom}`,
renderCell: ({ row, value }) => {
console.log('row: %o', row)
return (
<Box>
<GatsbyImage image={row.photo} alt={value} />
<IconButton href={`mailto:${row.courriel}`} aria-label="courriel">
<EmailRounded />
</IconButton>
</Box>
)
},
},
// {
// field: 'prenom',
// headerName: 'Prénom',
// },
// {
// field: 'nom',
// headerName: 'Nom',
// },
// {
// field: 'courriel',
// headerName: 'Courriel'
// },
// {
// field: 'fonction',
// headerName: 'Fonction',
// },
{
field: 'disciplines',
headerName: 'Disciplines',
flex: 1,
renderCell: ({ value }) => (
<Box>
{value.split('|').map((discipline) => (
<Chip label={discipline} size="small" sx={{ mr: 0.5 }} />
))}
</Box>
),
},
// {
// field: 'photo',
// headerName: 'Photo',
// },
]

function disciplinesSort(a, b) {
const nameA = a.discipline.toUpperCase() // ignore upper and lowercase
const nameB = b.discipline.toUpperCase() // ignore upper and lowercase
if (nameA < nameB) {
return -1
}
if (nameA > nameB) {
return 1
}

// names must be equal
return 0
}

export default function ListePersonnel() {
const data = useStaticQuery(graphql`
query MyQuery {
allFile(filter: { sourceInstanceName: { eq: "personnel" }, relativeDirectory: { eq: "photos" } }) {
nodes {
name
extension
ext
childImageSharp {
gatsbyImageData(width: 50, formats: WEBP)
}
sourceInstanceName
id
relativePath
relativeDirectory
root
absolutePath
base
dir
}
}
allListePersonnelXlsxSheet1 {
nodes {
id
nom
photo
prenom
fonction
disciplines
courriel
}
}
}
`)
console.log('allFile: %o', data.allFile.nodes)
const disciplinesMap = new Map()
const fallbackPicture = data.allFile.nodes.find((node) => node.name === '_profile').childImageSharp.gatsbyImageData

data.allListePersonnelXlsxSheet1.nodes.forEach(({ courriel, disciplines, fonction, id, nom, photo, prenom }) => {
const _disciplines = disciplines.split(/\s*\|\s*/)

const photoId = photo.replace(/\.\w+$/, '')
const photoData = data.allFile.nodes.find((node) => node.name === photoId)?.childImageSharp.gatsbyImageData ?? fallbackPicture

_disciplines.forEach((discipline) => {
if (!disciplinesMap.has(discipline)) {
disciplinesMap.set(discipline, [])
}

disciplinesMap.get(discipline).push({ courriel, discipline, fonction, nom, photo: photoData, prenom })
})
})

const personnelByDiscipline = [...disciplinesMap.values()].flat().sort(disciplinesSort)

return (
<Autocomplete
options={personnelByDiscipline}
getOptionLabel={(option) => option.discipline}
renderInput={(params) => <TextField {...params} label="Add a location" fullWidth />}
renderOption={(props, option) => {
const matches = option.structured_formatting.main_text_matched_substrings || []

const parts = parse(
option.structured_formatting.main_text,
matches.map((match) => [match.offset, match.offset + match.length])
)

return (
<li {...props}>
<Grid container alignItems="center">
<Grid item sx={{ display: 'flex', width: 44 }}>
{/* <LocationOnIcon sx={{ color: 'text.secondary' }} /> */}awef
</Grid>
<Grid item sx={{ width: 'calc(100% - 44px)', wordWrap: 'break-word' }}>
{parts.map((part, index) => (
<Box key={index} component="span" sx={{ fontWeight: part.highlight ? 'bold' : 'regular' }}>
{part.text}
</Box>
))}
<Typography variant="body2" color="text.secondary">
{option.structured_formatting.secondary_text}
</Typography>
</Grid>
</Grid>
</li>
)
}}
/>
)
}
Loading

0 comments on commit 3e3b8e4

Please sign in to comment.