Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
174 changes: 119 additions & 55 deletions src/components/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,23 @@ interface DashboardProps {
theme: Theme;
}

export const getTotalActiveDays = (issues: GitHubItem[], prs: GitHubItem[]) => {
const activeDays = new Set<string>();

[...issues, ...prs].forEach((item) => {
const activityDate = item?.created_at?.slice(0, 10);

if (activityDate) {
activeDays.add(activityDate);
}
});

return activeDays.size;
};

const Dashboard: React.FC<DashboardProps> = ({ totalIssues, totalPrs, data, theme }) => {

const totalContributions = totalIssues + totalPrs;

// Data for Pie Chart
const pieData = [
{ name: 'Issues', value: totalIssues },
Expand Down Expand Up @@ -64,75 +79,124 @@ const Dashboard: React.FC<DashboardProps> = ({ totalIssues, totalPrs, data, them

const hasData = totalIssues > 0 || totalPrs > 0;

if (!hasData) {
return (
<Paper elevation={1} sx={{ p: 4, mb: 4, textAlign: 'center', backgroundColor: theme.palette.background.paper }}>
<Typography variant="h6" color="textSecondary">
No data available. Enter a username to view analytics.
const renderChartCard = (
title: string,
subtitle: string,
content: React.ReactNode
) => (
<Paper
elevation={2}
sx={{
p: { xs: 2.5, sm: 3 },
height: '100%',
minHeight: 420,
display: 'flex',
flexDirection: 'column',
gap: 2,
backgroundColor: theme.palette.background.paper,
border: `1px solid ${theme.palette.divider}`,
}}
>
<Box sx={{ textAlign: 'center' }}>
<Typography variant="h6" color="textPrimary" sx={{ fontWeight: 700 }}>
{title}
</Typography>
</Paper>
);
}
<Typography variant="body2" color="textSecondary" sx={{ mt: 0.5 }}>
{subtitle}
</Typography>
</Box>

<Box sx={{ flex: 1, minHeight: 320, minWidth: 0 }}>
{content}
</Box>
</Paper>
);

return (
<Box sx={{ mb: 4 }}>
<Grid container spacing={3}>
{/* Pie Chart: Issues vs PRs */}
{!hasData && (
<Paper elevation={1} sx={{ p: 4, mb: 3, textAlign: 'center', backgroundColor: theme.palette.background.paper }}>
<Typography variant="h6" color="textSecondary">
No data available. Enter a username to view analytics.
</Typography>
</Paper>
)}

<Grid container spacing={3} alignItems="stretch">
<Grid item xs={12} md={6}>
<Paper elevation={2} sx={{ p: 2, height: 350, backgroundColor: theme.palette.background.paper }}>
<Typography variant="h6" gutterBottom align="center" color="textPrimary">
Contribution Mix (Total)
</Typography>
<ResponsiveContainer width="100%" height="90%">
<PieChart>
<Pie
data={pieData}
cx="50%"
cy="50%"
innerRadius={60}
outerRadius={80}
fill={theme.palette.primary.main}
paddingAngle={5}
dataKey="value"
label
>
{pieData.map((_entry, index) => (
<Cell key={`cell-${index}`} fill={COLORS[index % COLORS.length]} />
))}
</Pie>
<Tooltip
contentStyle={{ backgroundColor: theme.palette.background.paper, color: theme.palette.text.primary }}
/>
<Legend />
</PieChart>
</ResponsiveContainer>
</Paper>
{renderChartCard(
'Contribution Mix',
`Total activity across ${totalContributions} items`,
<Box sx={{ display: 'flex', flexDirection: 'column', height: '100%' }}>
<Box sx={{ flex: 1, minHeight: 260 }}>
<ResponsiveContainer width="100%" height="100%">
<PieChart>
<Pie
data={pieData}
cx="50%"
cy="50%"
innerRadius={70}
outerRadius={100}
fill={theme.palette.primary.main}
paddingAngle={6}
dataKey="value"
>
{pieData.map((_entry, index) => (
<Cell key={`cell-${index}`} fill={COLORS[index % COLORS.length]} />
))}
</Pie>
<Tooltip
contentStyle={{ backgroundColor: theme.palette.background.paper, color: theme.palette.text.primary }}
/>
<Legend verticalAlign="bottom" height={36} />
</PieChart>
</ResponsiveContainer>
</Box>

<Box sx={{ display: 'flex', justifyContent: 'space-between', gap: 2, mt: 1, px: 1 }}>
<Box>
<Typography variant="caption" color="textSecondary">
Issues
</Typography>
<Typography variant="h6" color="textPrimary" sx={{ fontWeight: 700, lineHeight: 1.2 }}>
{totalIssues}
</Typography>
</Box>
<Box sx={{ textAlign: 'right' }}>
<Typography variant="caption" color="textSecondary">
Pull Requests
</Typography>
<Typography variant="h6" color="textPrimary" sx={{ fontWeight: 700, lineHeight: 1.2 }}>
{totalPrs}
</Typography>
</Box>
</Box>
</Box>
)}
</Grid>

{/* Bar Chart: Activity by Repository */}
<Grid item xs={12} md={6}>
<Paper elevation={2} sx={{ p: 2, height: 350, backgroundColor: theme.palette.background.paper }}>
<Typography variant="h6" gutterBottom align="center" color="textPrimary">
Top Repositories (Current View)
</Typography>
{barData.length > 0 ? (
<ResponsiveContainer width="100%" height="90%">
<BarChart data={barData}>
<CartesianGrid strokeDasharray="3 3" stroke={theme.palette.divider} />
<XAxis dataKey="name" stroke={theme.palette.text.secondary} />
<YAxis stroke={theme.palette.text.secondary} />
<Tooltip
{renderChartCard(
'Top Repositories',
'Current view broken down by repository activity',
barData.length > 0 ? (
<ResponsiveContainer width="100%" height="100%">
<BarChart data={barData} layout="vertical" margin={{ top: 10, right: 20, left: 20, bottom: 10 }}>
<CartesianGrid strokeDasharray="3 3" stroke={theme.palette.divider} horizontal={false} />
<XAxis type="number" stroke={theme.palette.text.secondary} allowDecimals={false} />
<YAxis type="category" dataKey="name" stroke={theme.palette.text.secondary} width={120} />
<Tooltip
contentStyle={{ backgroundColor: theme.palette.background.paper, color: theme.palette.text.primary }}
/>
<Bar dataKey="count" fill={theme.palette.primary.light} radius={[4, 4, 0, 0]} />
<Bar dataKey="count" fill={theme.palette.primary.main} radius={[0, 8, 8, 0]} barSize={28} />
</BarChart>
</ResponsiveContainer>
) : (
<Box display="flex" justifyContent="center" alignItems="center" height="100%">
<Typography color="textSecondary">No repository data found in this view.</Typography>
<Typography color="textSecondary">No repository data found in this view.</Typography>
</Box>
)}
</Paper>
)
)}
</Grid>
</Grid>
</Box>
Expand Down
23 changes: 23 additions & 0 deletions src/components/__test__/Dashboard.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { describe, it, expect } from 'vitest';
import { getTotalActiveDays } from '../Dashboard';

describe('getTotalActiveDays', () => {
it('counts unique YYYY-MM-DD values across issues and pull requests', () => {
const issues = [
{ created_at: '2026-05-01T12:00:00Z' },
{ created_at: '2026-05-01T18:30:00Z' },
{ created_at: '2026-05-02T09:15:00Z' },
];

const prs = [
{ created_at: '2026-05-02T20:45:00Z' },
{ created_at: '2026-05-03T08:00:00Z' },
];

expect(getTotalActiveDays(issues as never[], prs as never[])).toBe(3);
});

it('returns 0 for empty datasets', () => {
expect(getTotalActiveDays([], [])).toBe(0);
});
});
Loading
Loading