mirror of
https://github.com/christianvidalwolf-prog/CrazeAnalytix.git
synced 2026-08-03 12:15:23 +02:00
feat: improve Week Coverage visibility, calculation robustness, and add aggregate WOC to grid totals and forecast view
This commit is contained in:
@@ -559,6 +559,26 @@ const WeeklyGrid: React.FC<WeeklyGridProps & { top50Mode: 'eu' | 'uk' }> = ({
|
||||
return totals;
|
||||
}, [rows, weeks]);
|
||||
|
||||
const aggregateWoc = useMemo(() => {
|
||||
if (!vendorStockMap || !velocityMap || filteredRows.length === 0) return null;
|
||||
|
||||
let totalStock = 0;
|
||||
let totalVelocity = 0;
|
||||
|
||||
filteredRows.forEach(row => {
|
||||
const asin = row.asin.trim().toUpperCase();
|
||||
const stockData = vendorStockMap.get(asin);
|
||||
if (stockData) {
|
||||
totalStock += (top50Mode === 'uk' ? stockData.uk : stockData.eu);
|
||||
}
|
||||
totalVelocity += (velocityMap.get(asin) || 0);
|
||||
});
|
||||
|
||||
if (totalVelocity > 0) return totalStock / totalVelocity;
|
||||
if (totalStock > 0) return 999;
|
||||
return 0;
|
||||
}, [filteredRows, vendorStockMap, velocityMap, top50Mode]);
|
||||
|
||||
// 1. Filter by search term, Top 50, and growth (using debounced value)
|
||||
const filteredRows = useMemo(() => {
|
||||
let result = rows.slice();
|
||||
@@ -1112,7 +1132,19 @@ const WeeklyGrid: React.FC<WeeklyGridProps & { top50Mode: 'eu' | 'uk' }> = ({
|
||||
))}
|
||||
</tr>
|
||||
<tr className="bg-indigo-950 border-b border-white/10 relative z-20">
|
||||
<th className="p-3 text-sm font-black text-white sticky left-0 z-40 bg-indigo-950 border-r border-white/10">TOTALS</th>
|
||||
<th className="p-3 text-sm font-black text-white sticky left-0 z-40 bg-indigo-950 border-r border-white/10">
|
||||
<div className="flex flex-col">
|
||||
<span>TOTALS</span>
|
||||
{aggregateWoc !== null && (
|
||||
<div className="mt-1 flex flex-col items-center">
|
||||
<span className="text-[9px] text-indigo-300 uppercase font-black leading-none">Week Coverage (Avg)</span>
|
||||
<span className={`text-xs font-black ${aggregateWoc < 4 ? 'text-rose-400' : 'text-emerald-400'}`}>
|
||||
{aggregateWoc === 999 ? '> 52 Weeks' : `${aggregateWoc.toFixed(1)} Weeks`}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</th>
|
||||
{weeks.map((week, idx) => (
|
||||
<th key={week} className="p-3 text-sm font-black text-white text-center border-r border-white/10">
|
||||
<div className="flex flex-col items-center">
|
||||
|
||||
Reference in New Issue
Block a user