mirror of
https://github.com/forcedotcom/afv-library.git
synced 2026-07-31 04:01:24 +08:00
* feat: removing old webapp skills * feat: adding sync of skills from webapps to afv * feat: adding the first iteration of skills * feat: pin template deps to latest npm versions and flatten skill folders - Add pin-template-deps.js to resolve "*" deps to exact npm versions - Integrate pinning into sync-template-skills npm script - Remove check-template-skills-versions.js (no longer needed) - Simplify workflow to single sync step - Flatten skill output: one folder per skill with cleaned names Made-with: Cursor * fix: resolve skill validation errors - Move .template-versions.json from skills/ to root - Shorten skill names to meet 64-char limit: - salesforce-webapp-feature-micro-frontend-generating-micro-frontend-lwc → salesforce-webapp-micro-frontend-lwc - salesforce-webapp-feature-react-agentforce-conversation-client-integrating-agentforce-conversation-client → salesforce-webapp-agentforce-conversation-client - salesforce-webapp-feature-react-file-upload-implementing-file-upload → salesforce-webapp-react-file-upload - Expand descriptions to meet 20-word minimum with trigger context * Add webapp skills from template, sync script updates - Rename skill folders from salesforce-webapp-* to *-webapp-* convention - Update sync-template-skills.js: set SKILL.md front matter name to dest folder - Remove sync-template-skills workflow and pin-template-deps script - Add .synced-template-skills.json manifest, deploying-webapp-to-salesforce skill - Replace salesforce-webapp-designing-webapp-ui-ux with designing-webapp-ui-ux Made-with: Cursor * Align SKILL.md front matter name with folder for all webapp skills Made-with: Cursor * Fix skill validation: description length and trigger context for configuring-webapp-metadata, creating-webapp Made-with: Cursor * Rename sync script to sync-webapp-skills, drop manifest file - Rename sync-template-skills.js to sync-webapp-skills.js - Update package.json script to sync-webapp-skills - Remove .synced-template-skills.json creation and add to .gitignore Made-with: Cursor * Revert sync-react-b2e-sample and sync-react-b2x-sample to upstream version Made-with: Cursor * Sync script: pin b2e and b2x to latest, sync skills from template - Pin both template packages to latest in sync-webapp-skills.js - Update package.json / package-lock.json (b2x 1.109.0) - Sync skills: managing-webapp-agentforce-conversation-client, bar-line-chart, remove building-webapp-analytics-charts and integrating-webapp-agentforce-conversation-client - Minor skill content updates Made-with: Cursor * Remove interactive map, weather widget, and Unsplash skills (no longer in template) Made-with: Cursor --------- Co-authored-by: Hemant Singh Bisht <hsinghbisht@salesforce.com>
4.9 KiB
4.9 KiB
Donut / Pie Chart — Implementation Guide
Requires recharts (install from the web app directory; see SKILL.md Step 2).
Data structure
Charts expect an array of objects with name, value, and color:
interface ChartData {
name: string;
value: number;
color: string;
}
Donut chart component
Create at components/DonutChart.tsx:
import React from "react";
import { PieChart, Pie, Cell, ResponsiveContainer } from "recharts";
import { Card } from "@/components/ui/card";
interface ChartData {
name: string;
value: number;
color: string;
}
interface DonutChartProps {
title: string;
data: ChartData[];
}
export const DonutChart: React.FC<DonutChartProps> = ({ title, data }) => {
const total = data.reduce((sum, item) => sum + item.value, 0);
const mainPercentage = total > 0 ? Math.round((data[0]?.value / total) * 100) : 0;
return (
<Card className="p-4 border-gray-200 shadow-sm flex flex-col">
<h3 className="text-sm font-medium text-primary mb-2 uppercase tracking-wide">
{title}
</h3>
<div className="relative flex items-center justify-center">
<ResponsiveContainer width="100%" height={300}>
<PieChart>
<Pie
data={data}
cx="50%"
cy="50%"
innerRadius={70}
outerRadius={110}
paddingAngle={2}
dataKey="value"
>
{data.map((entry, index) => (
<Cell key={`cell-${index}`} fill={entry.color} />
))}
</Pie>
</PieChart>
</ResponsiveContainer>
{/* Center label */}
<div className="absolute inset-0 flex items-center justify-center">
<div className="text-center">
<div className="text-5xl font-bold text-primary">{mainPercentage}%</div>
</div>
</div>
</div>
{/* Legend */}
<div className="mt-6 grid grid-cols-2 gap-3">
{data.map((item, index) => (
<div key={index} className="flex items-center gap-2">
<div className="w-3 h-3 rounded-full" style={{ backgroundColor: item.color }} />
<span className="text-sm text-gray-700">{item.name}</span>
</div>
))}
</div>
</Card>
);
};
Key Recharts concepts
| Component | Purpose |
|---|---|
ResponsiveContainer |
Wraps chart to make it fill its parent's width |
PieChart |
Chart container for pie/donut |
Pie |
The data ring; innerRadius > 0 makes it a donut |
Cell |
Individual segment; accepts fill color |
paddingAngle |
Gap between segments (degrees) |
Donut vs Pie
| Property | Donut | Pie |
|---|---|---|
innerRadius |
> 0 (e.g. 70) |
0 |
| Center label | Yes, positioned absolutely | Not typical |
Preparing chart data from raw records
Transform API data into the ChartData[] format before passing to the chart:
const CATEGORIES = ["Plumbing", "HVAC", "Electrical"] as const;
const OTHER_LABEL = "Other";
const COLORS = ["#7C3AED", "#EC4899", "#14B8A6", "#06B6D4"];
const chartData = useMemo(() => {
const counts: Record<string, number> = {};
CATEGORIES.forEach((c) => (counts[c] = 0));
counts[OTHER_LABEL] = 0;
records.forEach((record) => {
const type = record.category;
if (CATEGORIES.includes(type as (typeof CATEGORIES)[number])) {
counts[type]++;
} else {
counts[OTHER_LABEL]++;
}
});
return [
...CATEGORIES.map((name, i) => ({ name, value: counts[name], color: COLORS[i] })),
{ name: OTHER_LABEL, value: counts[OTHER_LABEL], color: COLORS[CATEGORIES.length] },
];
}, [records]);
Color palette recommendations
| Use case | Colors |
|---|---|
| Categorical (4 items) | #7C3AED #EC4899 #14B8A6 #06B6D4 |
| Status (3 items) | #22C55E #F59E0B #EF4444 (green/amber/red) |
| Sequential | Use opacity variants of one hue: #7C3AED at 100%, 75%, 50%, 25% |
Keep chart colors consistent with the app's design system. Define them as constants, not inline values.
Other chart types
For bar charts and line / area charts, see bar-line-chart.md in this directory.
Accessibility
- Always include a text legend (not just colors).
- Chart should be wrapped in a section with a visible heading.
- For critical data, provide a text summary or table alternative.
- Use sufficient color contrast between segments.
- Consider
prefers-reduced-motionfor chart animations.
Common mistakes
| Mistake | Fix |
|---|---|
Missing ResponsiveContainer |
Chart won't resize; always wrap in ResponsiveContainer |
Fixed width/height on PieChart |
Let ResponsiveContainer control sizing |
| No legend | Add a grid legend below the chart |
| Inline colors | Extract to constants for consistency |
| No fallback for empty data | Show "No data" message when data is empty |