Skip to content

feat: add pie charts for Content Agent usage#25

Open
recoup-coding-agent wants to merge 2 commits intomainfrom
feature/content-agent-pie-charts
Open

feat: add pie charts for Content Agent usage#25
recoup-coding-agent wants to merge 2 commits intomainfrom
feature/content-agent-pie-charts

Conversation

@recoup-coding-agent
Copy link
Copy Markdown
Collaborator

@recoup-coding-agent recoup-coding-agent commented Apr 2, 2026

Summary

  • Added reusable AdminPieChart component (components/Admin/AdminPieChart.tsx) using Recharts PieChart with donut style, legend, and tooltips
  • Added data helpers getTagsByUser and getTagsByTemplate to aggregate content slack tags for pie chart display
  • Updated Content Agent page to show two pie charts: Tags by User (who triggered the content agent) and Tags by Template (which template was used)
  • No new dependencies — uses existing Recharts PieChart, Pie, and Cell components

Test plan

  • Verify pie charts render on /content page when tags data is available
  • Verify pie charts show correct user breakdown and template breakdown
  • Verify charts are responsive (side-by-side on desktop, stacked on mobile)
  • Verify tooltips display correct values on hover
  • Verify empty state still works when no tags exist
  • Verify legend labels match the data

Closes REC-44

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added a "Tags by User" pie chart visualization to the ContentSlack section. This chart displays how tags are distributed across team members, providing insights into engagement patterns and activity levels.
    • Includes an animated skeleton loading state that appears while data is being retrieved, ensuring a polished and responsive user experience.

Add reusable AdminPieChart component using Recharts PieChart with donut
style. Add two pie charts to the Content Agent page showing who triggered
the content agent most and which templates are used most.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 2, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
admin Ready Ready Preview Apr 2, 2026 8:12pm

Request Review

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 2, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 27064654-f58a-43df-9e73-5732657828bc

📥 Commits

Reviewing files that changed from the base of the PR and between 53ed685 and e099611.

📒 Files selected for processing (2)
  • components/ContentSlack/ContentSlackPage.tsx
  • components/ContentSlack/PieChartSkeleton.tsx
✅ Files skipped from review due to trivial changes (2)
  • components/ContentSlack/PieChartSkeleton.tsx
  • components/ContentSlack/ContentSlackPage.tsx

📝 Walkthrough

Walkthrough

A new pie chart visualization feature is introduced to display tag distributions by user in the Content Slack page. This includes a reusable AdminPieChart component, a PieChartSkeleton loading placeholder, and a getTagsByUser utility function that aggregates and sorts tag data by user.

Changes

Cohort / File(s) Summary
New Pie Chart Component
components/Admin/AdminPieChart.tsx
Introduces AdminPieChart component that renders an interactive pie chart with cyclic color assignment from a fixed palette. Accepts title and data (array of PieChartSlice objects) as props; returns null if data is empty.
New Skeleton Loader
components/ContentSlack/PieChartSkeleton.tsx
Adds PieChartSkeleton component for loading state, featuring animated placeholder elements (horizontal bar and circular placeholder).
Data Transformation Utility
lib/contentSlack/getTagsByUser.ts
Exports getTagsByUser function that aggregates tags by user display name, counts occurrences, and returns sorted array of PieChartSlice objects in descending order by value.
Integration with Content Slack Page
components/ContentSlack/ContentSlackPage.tsx
Integrates new pie chart feature by computing tagsByUser dataset, rendering PieChartSkeleton during load, and displaying AdminPieChart titled "Tags by User" when data is available.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~35 minutes

Poem

🥧 A pie chart springs to life with vibrant hues,
Each slice a user's tale of tags they use.
From data rows to circles bright and round,
The rabbit hops through colors newly found! 🐰
Loading states and skeletal frames in place,
Visualization graces the workspace. ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately describes the main change: adding pie charts for Content Agent usage. The changes introduce AdminPieChart component and integrate it into ContentSlackPage for displaying tags by user.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/content-agent-pie-charts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
lib/contentSlack/getTagsByUser.ts (1)

8-19: Consider extracting shared aggregation logic.

This function and getTagsByTemplate share identical aggregation mechanics—only the key extraction differs. You could DRY this up with a generic helper:

function aggregateBy<T>(
  items: T[],
  keyFn: (item: T) => string,
): PieChartSlice[] {
  const counts = new Map<string, number>();
  for (const item of items) {
    const key = keyFn(item);
    counts.set(key, (counts.get(key) ?? 0) + 1);
  }
  return Array.from(counts.entries())
    .map(([name, value]) => ({ name, value }))
    .sort((a, b) => b.value - a.value);
}

Then both helpers become one-liners. This is optional—the current duplication is minimal and both functions are clear.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/contentSlack/getTagsByUser.ts` around lines 8 - 19, Extract the shared
aggregation logic used in getTagsByUser and getTagsByTemplate into a generic
helper (e.g., aggregateBy) that accepts items and a keyFn to produce
PieChartSlice[]; replace the loop/counting/sorting in getTagsByUser and
getTagsByTemplate by calling aggregateBy(tags, t => t.user_name ?? "Unknown")
and aggregateBy(tags, t => t.template_name ?? "Unknown") respectively so both
become one-line wrappers around the new aggregateBy function which returns the
sorted {name, value} slices.
components/Admin/AdminPieChart.tsx (1)

62-67: Key relies on slice.name uniqueness.

Using slice.name as the React key assumes all slice names are unique. This holds for the current callers (getTagsByUser/getTagsByTemplate) since they aggregate via Map, but the component API doesn't enforce this. If a future caller passes duplicate names, React will warn and rendering may be incorrect.

Consider adding an index fallback or documenting the uniqueness requirement:

♻️ Optional: safer key
 {data.map((slice, i) => (
   <Cell
-    key={slice.name}
+    key={`${slice.name}-${i}`}
     fill={COLORS[i % COLORS.length]}
   />
 ))}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@components/Admin/AdminPieChart.tsx` around lines 62 - 67, The React key for
each Cell in AdminPieChart currently uses slice.name which assumes uniqueness;
update the key generation in the data.map callback used to render <Cell> (in
AdminPieChart) to include an index fallback (e.g., combine slice.name with the
loop index or use index when name is falsy) so keys are stable and unique even
if callers supply duplicate or missing names, and optionally add a short prop
comment in AdminPieChart’s API noting that slice.name should be unique when
possible.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@components/Admin/AdminPieChart.tsx`:
- Around line 62-67: The React key for each Cell in AdminPieChart currently uses
slice.name which assumes uniqueness; update the key generation in the data.map
callback used to render <Cell> (in AdminPieChart) to include an index fallback
(e.g., combine slice.name with the loop index or use index when name is falsy)
so keys are stable and unique even if callers supply duplicate or missing names,
and optionally add a short prop comment in AdminPieChart’s API noting that
slice.name should be unique when possible.

In `@lib/contentSlack/getTagsByUser.ts`:
- Around line 8-19: Extract the shared aggregation logic used in getTagsByUser
and getTagsByTemplate into a generic helper (e.g., aggregateBy) that accepts
items and a keyFn to produce PieChartSlice[]; replace the loop/counting/sorting
in getTagsByUser and getTagsByTemplate by calling aggregateBy(tags, t =>
t.user_name ?? "Unknown") and aggregateBy(tags, t => t.template_name ??
"Unknown") respectively so both become one-line wrappers around the new
aggregateBy function which returns the sorted {name, value} slices.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7a6b116e-7b9e-4ee8-8c15-17f535c2a7f5

📥 Commits

Reviewing files that changed from the base of the PR and between b425199 and 53ed685.

📒 Files selected for processing (4)
  • components/Admin/AdminPieChart.tsx
  • components/ContentSlack/ContentSlackPage.tsx
  • lib/contentSlack/getTagsByTemplate.ts
  • lib/contentSlack/getTagsByUser.ts

- Remove Tags by Template pie chart and getTagsByTemplate util
- Add PieChartSkeleton with circular placeholder for loading state
- Single pie chart no longer needs 2-column grid

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants