Skip to content

Commit

Permalink
add more reports
Browse files Browse the repository at this point in the history
  • Loading branch information
kaiomagalhaes committed Dec 10, 2024
1 parent 5764724 commit ccd1937
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 14 deletions.
40 changes: 26 additions & 14 deletions src/app/users/reports/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import SkillsSearch from "./presenters/components/SkillsSearch";
import UsersTable from "./presenters/components/UsersTable";
import useReportsController from "./presenters/controllers/useReportsController";
import VerticalBarChart from "@/components/Charts/VerticalBarChart";
import PieChart from "@/components/Charts/PieChart";

const UsersDashboard = () => {
const {
Expand All @@ -24,6 +25,7 @@ const UsersDashboard = () => {
skillsAnalytics,
professionAreas,
toggleProfessionArea,
topSkillsPieChart,
} = useReportsController();

if (isLoading) {
Expand Down Expand Up @@ -67,20 +69,30 @@ const UsersDashboard = () => {
/>
</Stack>
</Grid>
<Grid xs={12} md={12} style={{ marginTop: "32px" }}>
<VerticalBarChart
title="Skills Analytics"
verticalStacked={true}
horizontalStacked={true}
labelColor="white"
chart={skillsAnalytics}
valueType="number"
formatter={(value: number) => {
if (value == 0) return "";

return value.toFixed(0);
}}
/>
<Grid container spacing={3} mt={2}>
<Grid item xs={12} md={8}>
<VerticalBarChart
title="Skills Analytics"
verticalStacked={true}
horizontalStacked={true}
labelColor="white"
chart={skillsAnalytics}
valueType="number"
formatter={(value: number) => {
if (value == 0) return "";
return value.toFixed(0);
}}
/>
</Grid>
<Grid item xs={12} md={4}>
{topSkillsPieChart && (
<PieChart
title="Top 5 Skills Distribution"
chart={topSkillsPieChart}
valueType="number"
/>
)}
</Grid>
</Grid>
<Grid container justifyContent={"space-around"} display="flex" mt={5}>
<Grid item xs={12} md={12} pb={12}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,31 @@ const useReportsController = () => {
});
};

const buildPieChartData = () => {
if (!skillsAnalytics) return null;

// Sum up all levels for each skill
const skillTotals = skillsAnalytics
.filter((skill) =>
professionAreas.includes(skill.professional_area.toLowerCase())
)
.map((skill) => ({
name: skill.name,
total: skill.level.reduce((sum, level) => sum + level.count, 0),
}))
.sort((a, b) => b.total - a.total) // Sort by total descending
.slice(0, 5); // Get top 5

return {
labels: skillTotals.map((skill) => skill.name),
datasets: {
label: "Top Skills",
data: skillTotals.map((skill) => skill.total),
backgroundColors: ["info", "primary", "dark", "secondary", "warning"],
},
};
};

return {
users,
isLoading,
Expand All @@ -149,6 +174,7 @@ const useReportsController = () => {
skillsAnalytics: buildSkillsAnalytics(),
professionAreas,
toggleProfessionArea,
topSkillsPieChart: buildPieChartData(),
};
};

Expand Down

0 comments on commit ccd1937

Please sign in to comment.