-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Speakers company/geolocation/job title stats & fix dev log error for …
…rerender (#90) * Add speakers stats * Remove unused imports * Fix error in dev with rerender on Sessions and Speakers * Improve stats sort and calc * Remove unused improt
- Loading branch information
1 parent
3d26437
commit 9327c98
Showing
3 changed files
with
117 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
src/events/page/speakers/components/SpeakersStatsDialog.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { Speaker } from '../../../../types' | ||
import { Button, Dialog, DialogContent, Grid, Typography } from '@mui/material' | ||
import * as React from 'react' | ||
import { useMemo } from 'react' | ||
|
||
const aggregateFields = <K extends keyof Speaker>(speakers: Speaker[], field: K) => { | ||
const aggregate = speakers.reduce((acc: Record<string, number>, speaker) => { | ||
const key = speaker[field] ? String(speaker[field]) : 'N/A' | ||
if (key) { | ||
acc[key] = acc[key] ? acc[key] + 1 : 1 | ||
} | ||
return acc | ||
}, {}) | ||
|
||
return Object.entries(aggregate) | ||
.map(([key, value]) => ({ | ||
key, | ||
value, | ||
})) | ||
.sort((a, b) => b.value - a.value) | ||
} | ||
export const SpeakersStatsDialog = ({ | ||
isOpen, | ||
onClose, | ||
speakers, | ||
}: { | ||
isOpen: boolean | ||
onClose: () => void | ||
speakers: Speaker[] | ||
}) => { | ||
const stats = useMemo(() => { | ||
return { | ||
companies: aggregateFields(speakers, 'company'), | ||
jobTitles: aggregateFields(speakers, 'jobTitle'), | ||
geolocations: aggregateFields(speakers, 'geolocation'), | ||
} | ||
}, [speakers]) | ||
|
||
return ( | ||
<Dialog open={isOpen} onClose={onClose} maxWidth="lg" fullWidth={true} scroll="body"> | ||
<DialogContent> | ||
<Typography variant="h5">Speakers stats</Typography> | ||
|
||
<Grid container spacing={2}> | ||
<Grid item xs={12} md={6}> | ||
<Typography variant="h6">Companies ({Object.keys(stats.companies).length})</Typography> | ||
|
||
<ul> | ||
{stats.companies.map((company) => ( | ||
<li key={company.key}> | ||
{company.key} ({company.value}) | ||
</li> | ||
))} | ||
</ul> | ||
</Grid> | ||
<Grid item xs={12} md={6}> | ||
<Typography variant="h6">Job titles ({Object.keys(stats.jobTitles).length})</Typography> | ||
|
||
<ul> | ||
{stats.jobTitles.map((jobTitle) => ( | ||
<li key={jobTitle.key}> | ||
{jobTitle.key} ({jobTitle.value}) | ||
</li> | ||
))} | ||
</ul> | ||
</Grid> | ||
<Grid item xs={12} md={6}> | ||
<Typography variant="h6">Geolocations ({Object.keys(stats.geolocations).length})</Typography> | ||
|
||
<ul> | ||
{stats.geolocations.map((geolocation) => ( | ||
<li key={geolocation.key}> | ||
{geolocation.key} ({geolocation.value}) | ||
</li> | ||
))} | ||
</ul> | ||
</Grid> | ||
</Grid> | ||
|
||
<Button variant="outlined" onClick={onClose}> | ||
Close | ||
</Button> | ||
</DialogContent> | ||
</Dialog> | ||
) | ||
} |