diff --git a/App.tsx b/App.tsx index 4695390..cf6b54a 100644 --- a/App.tsx +++ b/App.tsx @@ -596,9 +596,10 @@ const App: React.FC = () => { const gridContext = useMemo(() => { if (rawData.length === 0) return { minWeek: 1, maxWeek: 53, currentYear: new Date().getFullYear() }; - const currentYear = Math.max(...rawData.map(r => r.year)); + const currentYear = rawData.reduce((max, r) => Math.max(max, r.year), 0); const currentYearData = rawData.filter(r => r.year === currentYear); - const maxWeek = Math.max(...currentYearData.map(r => r.week).filter(Boolean)); + const maxWeek = currentYearData.map(r => r.week).filter((w): w is number => w !== undefined) + .reduce((max, w) => Math.max(max, w), 0); return { minWeek: 1, maxWeek: maxWeek || 53, currentYear }; }, [rawData]); diff --git a/components/mkt/MasterTable.tsx b/components/mkt/MasterTable.tsx index 13bb6dd..dc62551 100644 --- a/components/mkt/MasterTable.tsx +++ b/components/mkt/MasterTable.tsx @@ -158,19 +158,20 @@ export const MasterTable: React.FC = ({ products, includeCOGS, {/* Product Rows */} - {sortedProducts.map((product) => { - const metrics = calculateProductMetrics(product, includeCOGS); - - // Data bar width calculation (relative to max sales) - const maxSales = Math.max(...products.map(p => p.grossSales)); - const salesBarWidth = `${(product.grossSales / maxSales) * 100}%`; + {(() => { + const maxSales = products.reduce((max, p) => Math.max(max, p.grossSales), 0); + return sortedProducts.map((product) => { + const metrics = calculateProductMetrics(product, includeCOGS); + + // Data bar width calculation (relative to max sales) + const salesBarWidth = maxSales > 0 ? `${(product.grossSales / maxSales) * 100}%` : '0%'; - return ( - onProductClick(product)} - > + return ( + onProductClick(product)} + >
{product.name}
{product.sku} | {product.asin}
@@ -230,7 +231,7 @@ export const MasterTable: React.FC = ({ products, includeCOGS, ); - })} + })})()} diff --git a/services/dataProcessor.ts b/services/dataProcessor.ts index 561b0a0..55c8992 100644 --- a/services/dataProcessor.ts +++ b/services/dataProcessor.ts @@ -2461,9 +2461,12 @@ export const calculateVelocityMap = (data: SalesRecord[]): Map = const validYears = data.map(r => r.year).filter(y => y > 0); if (validYears.length === 0) return new Map(); - const latestYear = Math.max(...validYears); + const latestYear = validYears.reduce((a, b) => Math.max(a, b), 0); const yearData = data.filter(r => r.year === latestYear); - const latestWeek = yearData.length > 0 ? Math.max(...yearData.map(r => r.week).filter(w => w !== undefined) as number[]) : 0; + const latestWeek = yearData.length > 0 + ? (yearData.map(r => r.week).filter(w => w !== undefined) as number[]) + .reduce((a, b) => Math.max(a, b), 0) + : 0; const last4WeeksKeys = new Set(); for (let i = 0; i < 4; i++) {