< Summary - Frontend Coverage Report (WSL)

Information
Class: src/components/AnalyticsPanel.js
Assembly: Default
File(s): src/components/AnalyticsPanel.js
Line coverage
100%
Covered lines: 83
Uncovered lines: 0
Coverable lines: 83
Total lines: 83
Line coverage: 100%
Branch coverage
100%
Covered branches: 5
Total branches: 5
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

File(s)

src/components/AnalyticsPanel.js

#LineLine coverage
 11import React from 'react';
 12import {
 13    BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer,
 14    PieChart, Pie, Cell, Sector
 15} from 'recharts';
 16import { useMaintenance } from '../context/MaintenanceContext.js';
 17
 18const COLORS = ['#2ecc71', '#f1c40f', '#e74c3c', '#3498db'];
 19
 110export function AnalyticsPanel() {
 1711    const { machines, inventory } = useMaintenance();
 1712
 1713    // 1. Prepare Machine Status Data for Pie Chart
 1714    const statusCounts = machines.reduce((acc, m) => {
 215        const status = m.status.charAt(0).toUpperCase() + m.status.slice(1);
 216        acc[status] = (acc[status] || 0) + 1;
 217        return acc;
 1718    }, {});
 1719
 1720    const pieData = Object.keys(statusCounts).map(status => ({
 221        name: status,
 222        value: statusCounts[status]
 1723    }));
 1724
 1725    // 2. Prepare Inventory Data for Bar Chart
 1726    const barData = inventory.map(item => ({
 127        name: item.part_name,
 128        stock: item.quantity,
 129        min: item.min_stock_level
 1730    }));
 1731
 1732    return (
 1733        <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '20px', marginTop: '20px' }}>
 1734            {/* Machine Status Distribution */}
 1735            <div style={{ backgroundColor: 'white', padding: '20px', borderRadius: '12px', boxShadow: '0 4px 6px rgba(0,
 1736                <h4 style={{ margin: '0 0 20px 0', color: '#2c3e50' }}>Asset Status Distribution</h4>
 1737                <div style={{ width: '100%', height: 250 }}>
 1738                    <ResponsiveContainer>
 1739                        <PieChart>
 1740                            <Pie
 1741                                data={pieData}
 1742                                cx="50%"
 1743                                cy="50%"
 1744                                innerRadius={60}
 1745                                outerRadius={80}
 1746                                paddingAngle={5}
 1747                                dataKey="value"
 1748                            >
 1749                                {pieData.map((entry, index) => (
 250                                    <Cell key={`cell-${index}`} fill={COLORS[index % COLORS.length]} />
 1751                                ))}
 1752                            </Pie>
 1753                            <Tooltip />
 1754                            <Legend verticalAlign="bottom" height={36} />
 1755                        </PieChart>
 1756                    </ResponsiveContainer>
 1757                </div>
 1758            </div>
 1759
 1760            {/* Inventory Stock Levels */}
 1761            <div style={{ backgroundColor: 'white', padding: '20px', borderRadius: '12px', boxShadow: '0 4px 6px rgba(0,
 1762                <h4 style={{ margin: '0 0 20px 0', color: '#2c3e50' }}>Inventory Levels vs Min Stock</h4>
 1763                <div style={{ width: '100%', height: 250 }}>
 1764                    <ResponsiveContainer>
 1765                        <BarChart
 1766                            data={barData}
 1767                            layout="vertical"
 1768                            margin={{ top: 5, right: 30, left: 40, bottom: 5 }}
 1769                        >
 1770                            <CartesianGrid strokeDasharray="3 3" />
 1771                            <XAxis type="number" />
 1772                            <YAxis dataKey="name" type="category" width={100} style={{ fontSize: '0.7rem' }} />
 1773                            <Tooltip />
 1774                            <Legend />
 1775                            <Bar dataKey="stock" fill="#3498db" name="Current Stock" />
 1776                            <Bar dataKey="min" fill="#e74c3c" name="Minimum Level" />
 1777                        </BarChart>
 1778                    </ResponsiveContainer>
 1779                </div>
 1780            </div>
 1781        </div>
 1782    );
 1783}

Methods/Properties

AnalyticsPanel