Skip to main content

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:

StatDescription
Total MOCsCount of all MOC documents
Active MOCsMOCs not yet completed or declined
Completed MOCsMOCs that passed all 6 steps
Declined MOCsMOCs declined at any step
Total PCRsCount of all PCR documents
Active PCRsPCRs in pending status

MocPcrCharts

File: src/features/analytics/MocPcrCharts.tsx

Renders interactive charts using Recharts. Chart types include:

ChartTypeData
MOCs by StatusBar chartCount per status (originator, implementer, hseq, etc.)
MOCs by DepartmentPie chartDistribution across departments
MOCs Over TimeLine chartMonthly creation trend
PCRs by StatusBar chartCount per status (draft, pending, approved, declined)
MOC Completion TimeBar chartAverage 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.

PurposePath
Analytics wrappersrc/features/analytics/AnalyticsWrapper.tsx
General statssrc/features/analytics/GeneralStats.tsx
MOC/PCR chartssrc/features/analytics/MocPcrCharts.tsx
Chart componentssrc/components/charts/
MOC data APIsrc/app/api/getAllMoc/route.ts
PCR data APIsrc/app/api/getAllPcr/route.ts