Analytics Dashboard
The analytics dashboard provides visual statistics and charts for monitoring MOC and PCR activity across the platform.
Directory: src/features/analytics/
Components
AnalyticsWrapper
File: src/features/analytics/AnalyticsWrapper.tsx
The top-level component that orchestrates the analytics view. It fetches data and distributes it to child chart and stat components.
GeneralStats
File: src/features/analytics/GeneralStats.tsx
Displays summary statistics as cards at the top of the dashboard:
| Stat | Description |
|---|---|
| Total MOCs | Count of all MOC documents |
| Active MOCs | MOCs not yet completed or declined |
| Completed MOCs | MOCs that passed all 6 steps |
| Declined MOCs | MOCs declined at any step |
| Total PCRs | Count of all PCR documents |
| Active PCRs | PCRs in pending status |
MocPcrCharts
File: src/features/analytics/MocPcrCharts.tsx
Renders interactive charts using Recharts. Chart types include:
| Chart | Type | Data |
|---|---|---|
| MOCs by Status | Bar chart | Count per status (originator, implementer, hseq, etc.) |
| MOCs by Department | Pie chart | Distribution across departments |
| MOCs Over Time | Line chart | Monthly creation trend |
| PCRs by Status | Bar chart | Count per status (draft, pending, approved, declined) |
| MOC Completion Time | Bar chart | Average days from creation to completion |
Data Source
Analytics data is fetched from dedicated endpoints:
GET /api/getAllMoc → All MOC records with populated fields
GET /api/getAllPcr → All PCR records with populated fields
The analytics wrapper performs client-side aggregation on the returned data to compute statistics and prepare chart datasets.
Chart Library
Charts use Recharts (recharts package) with the following components:
import {
BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip, Legend,
PieChart, Pie, Cell,
LineChart, Line,
ResponsiveContainer
} from "recharts";
All charts are wrapped in ResponsiveContainer for proper sizing across screen widths.
Accessing Analytics
The analytics view is available at:
/dashboard/analytics
It is accessible to Admin and HSEQ roles via the sidebar navigation.
Related Files
| Purpose | Path |
|---|---|
| Analytics wrapper | src/features/analytics/AnalyticsWrapper.tsx |
| General stats | src/features/analytics/GeneralStats.tsx |
| MOC/PCR charts | src/features/analytics/MocPcrCharts.tsx |
| Chart components | src/components/charts/ |
| MOC data API | src/app/api/getAllMoc/route.ts |
| PCR data API | src/app/api/getAllPcr/route.ts |