feat(tracker): add Active Days analytics and contribution insights#671
feat(tracker): add Active Days analytics and contribution insights#671arpit2006 wants to merge 1 commit into
Conversation
✅ Deploy Preview for github-spy ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
📝 WalkthroughWalkthroughThis PR implements the "Total Active Days" analytics feature for the GitHub Tracker. It adds a ChangesTotal Active Days Analytics Feature
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
src/components/__test__/Dashboard.test.tsx (1)
6-17: 💤 Low valuePrefer type-safe mocks over
as never[]casts.The test data is missing required
GitHubItemproperties. Instead of usingas never[]which suppresses all type checking, create complete mock objects or use a factory helper.♻️ Suggested improvement
+const createMockItem = (created_at: string): Parameters<typeof getTotalActiveDays>[0][number] => ({ + id: 1, + title: 'test', + state: 'open', + created_at, + repository_url: 'https://api.github.com/repos/test/repo', + html_url: 'https://github.com/test/repo/issues/1', +}); + 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' }, + createMockItem('2026-05-01T12:00:00Z'), + createMockItem('2026-05-01T18:30:00Z'), + createMockItem('2026-05-02T09:15:00Z'), ]; const prs = [ - { created_at: '2026-05-02T20:45:00Z' }, - { created_at: '2026-05-03T08:00:00Z' }, + createMockItem('2026-05-02T20:45:00Z'), + createMockItem('2026-05-03T08:00:00Z'), ]; - expect(getTotalActiveDays(issues as never[], prs as never[])).toBe(3); + expect(getTotalActiveDays(issues, prs)).toBe(3); });🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/components/__test__/Dashboard.test.tsx` around lines 6 - 17, The test is casting incomplete test data to never[] which bypasses type safety; replace those casts by creating properly typed mock GitHubItem objects (or a small factory helper) that include the required properties used by getTotalActiveDays (e.g., created_at plus any other fields present on the GitHubItem type), and use those mocks instead of issues as never[] and prs as never[] when calling getTotalActiveDays so the compiler enforces correctness.src/pages/Tracker/Tracker.tsx (1)
173-191: ⚡ Quick winOptimize
activeDaysDatacomputation to single-pass O(N).The current implementation iterates the combined array multiple times: once to build the Set, then once per unique date to count activities. With many items this becomes O(N*D). A single-pass approach using a Map is more efficient.
Additionally, this duplicates the date extraction logic from the exported
getTotalActiveDaysutility in Dashboard.tsx.♻️ Single-pass implementation
- const activeDaysData = Array.from( - new Set( - [...filteredIssues, ...filteredPrs] - .map((item) => item.created_at?.slice(0, 10)) - .filter((date): date is string => Boolean(date)) - ) - ) - .map((date) => ({ - date, - count: [...filteredIssues, ...filteredPrs].filter( - (item) => item.created_at?.slice(0, 10) === date - ).length, - })) - .sort((a, b) => b.date.localeCompare(a.date)); + const activeDaysData = (() => { + const countsByDate = new Map<string, number>(); + [...filteredIssues, ...filteredPrs].forEach((item) => { + const date = item.created_at?.slice(0, 10); + if (date) { + countsByDate.set(date, (countsByDate.get(date) ?? 0) + 1); + } + }); + return Array.from(countsByDate, ([date, count]) => ({ date, count })) + .sort((a, b) => b.date.localeCompare(a.date)); + })();🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/pages/Tracker/Tracker.tsx` around lines 173 - 191, activeDaysData is built with multiple passes over [...filteredIssues, ...filteredPrs], causing O(N*D) behavior and duplicating logic from Dashboard.tsx; replace it with a single-pass date counting using a Map (iterate once over the combined array, extract created_at?.slice(0,10) and increment counts in the Map), then convert the Map entries to the [{date, count}] array, sort by date descending, set totalActiveDays = map.size, and compute activeDaysPageData via the same slice logic using activeDaysPage and ACTIVE_DAYS_ROWS_PER_PAGE; alternatively import and call the exported getTotalActiveDays utility from Dashboard.tsx (if it returns the needed structure) to avoid duplicating date-extraction logic.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/components/__test__/Dashboard.test.tsx`:
- Around line 6-17: The test is casting incomplete test data to never[] which
bypasses type safety; replace those casts by creating properly typed mock
GitHubItem objects (or a small factory helper) that include the required
properties used by getTotalActiveDays (e.g., created_at plus any other fields
present on the GitHubItem type), and use those mocks instead of issues as
never[] and prs as never[] when calling getTotalActiveDays so the compiler
enforces correctness.
In `@src/pages/Tracker/Tracker.tsx`:
- Around line 173-191: activeDaysData is built with multiple passes over
[...filteredIssues, ...filteredPrs], causing O(N*D) behavior and duplicating
logic from Dashboard.tsx; replace it with a single-pass date counting using a
Map (iterate once over the combined array, extract created_at?.slice(0,10) and
increment counts in the Map), then convert the Map entries to the [{date,
count}] array, sort by date descending, set totalActiveDays = map.size, and
compute activeDaysPageData via the same slice logic using activeDaysPage and
ACTIVE_DAYS_ROWS_PER_PAGE; alternatively import and call the exported
getTotalActiveDays utility from Dashboard.tsx (if it returns the needed
structure) to avoid duplicating date-extraction logic.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 26eb192f-6fa1-40d4-a71a-ed2b5cb81190
📒 Files selected for processing (3)
src/components/Dashboard.tsxsrc/components/__test__/Dashboard.test.tsxsrc/pages/Tracker/Tracker.tsx
|
@mehul-m-prajapati , Requesting Review! |
Related Issue
Description
Implemented Total Active Days Analytics in the GitHub Tracker dashboard.
Changes Made
This enhancement provides contributors with a better understanding of their contribution consistency and engagement over time.
How Has This Been Tested?
Screenshots (if applicable)
Type of Change
Summary by CodeRabbit
Release Notes
New Features
Improvements
Tests