diff --git a/components/VendorDataView.tsx b/components/VendorDataView.tsx index bde69b5..9190bc1 100644 --- a/components/VendorDataView.tsx +++ b/components/VendorDataView.tsx @@ -1,5 +1,5 @@ -import React, { useMemo, useState } from 'react'; -import { BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer, Cell } from 'recharts'; +import React, { useMemo } from 'react'; +import { AreaChart, Area, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer } from 'recharts'; import { BSRRecord } from '../types'; import { BuyBoxWarningBadge } from './BuyBoxWarningBadge'; @@ -8,7 +8,7 @@ const MARKET_COLORS: Record = { UK: '#ef4444', IT: '#22c55e', FR: '#a855f7', - ES: '#f59e0b', + ES: '#f97316', }; interface VendorDataViewProps { @@ -30,7 +30,7 @@ const VendorDataView: React.FC = ({ bsrData = [], asinMetad return Array.from(m).sort(); }, [bsrData]); - // Determine if daily resolution is available (>= half the records have a date) + // Determine if daily resolution is available const useDailyResolution = useMemo(() => { const withDate = bsrData.filter(r => r.date).length; return withDate > bsrData.length / 2; @@ -56,9 +56,8 @@ const VendorDataView: React.FC = ({ bsrData = [], asinMetad }; }, [uniqueAsins, asinMetadata]); - // Aggregate Data for Charts — daily if dates available, else weekly + // Aggregate Data for Charts const { topBsrChartData, detailBsrChartData, ratingChartData } = useMemo(() => { - // Group by date string (YYYY-MM-DD) or by week number const byBucket = new Map(); bsrData.forEach(r => { @@ -76,14 +75,12 @@ const VendorDataView: React.FC = ({ bsrData = [], asinMetad sortedKeys.forEach(key => { const rows = byBucket.get(key)!; - // Human-readable label let label: string; if (useDailyResolution && key.includes('-')) { - // YYYY-MM-DD → "DD MMM" const d = new Date(key + 'T12:00:00Z'); label = d.toLocaleDateString('en-GB', { day: '2-digit', month: 'short' }); } else { - label = key; // e.g. "W08" + label = key; } const topPoint: ChartPoint = { label, sortKey: key }; @@ -136,40 +133,43 @@ const VendorDataView: React.FC = ({ bsrData = [], asinMetad ); } - const resolutionLabel = useDailyResolution ? 'Daily Avg' : 'Weekly Avg'; - return ( -
-
- {bsrData.length.toLocaleString()} records filtered +
+ {/* Header Info */} +
+

Vendor Analytics

+ + {bsrData.length.toLocaleString()} records filtered +
- {/* Product Info Card - Only shown when single ASIN is selected */} + {/* Product Info Card */} {productInfo && ( -
-
-
-
- +
+
+
+
+
+ Product Details +

+ {productInfo.title} +

-
-
- SKU: - {productInfo.sku} + +
+
+ SKU: + {productInfo.sku}
-
- ASIN: - {productInfo.asin} -
-
- Title: - {productInfo.title} +
+ ASIN: + {productInfo.asin}
-
+
@@ -177,87 +177,199 @@ const VendorDataView: React.FC = ({ bsrData = [], asinMetad )} {/* Top Level BSR Trend Chart */} -
-

Top Level BSR Trend ({resolutionLabel})

-

Lower rank = better position. Averaged across filtered ASINs per market.

- - - - - - - - {activeMarkets.map(m => ( - +
+

Top Level BSR Trend

+

Weekly Average Rank • Lower is better

+
+
+ + + + + + + + {activeMarkets.map(m => ( + + + + + ))} + + + - ))} - - + + + {activeMarkets.map(m => ( + + ))} + + +
+
+ {activeMarkets.map(m => ( +
+
+ {m} BSR +
+ ))} +
{/* Detail Level BSR Trend Chart */} -
-

Detail Level BSR Trend ({resolutionLabel})

-

Lower rank = better position. Averaged across filtered ASINs per market.

- - - - - - - - {activeMarkets.map(m => ( - +
+

Detail Level BSR Trend

+

Sub-category Performance • Filtered ASINs

+
+
+ + + + {activeMarkets.map(m => ( + + + + + ))} + + + - ))} - - + + + {activeMarkets.map(m => ( + + ))} + + +
+
+ {activeMarkets.map(m => ( +
+
+ {m} Category Rank +
+ ))} +
{/* Average Rating Chart */} -
-

Average Rating ({resolutionLabel})

-

Averaged across filtered ASINs per market.

- - - - - - - - {activeMarkets.map(m => ( - +
+

Average Rating

+

Weekly Average • 1.0 - 5.0 Stars

+
+
+ + + + {activeMarkets.map(m => ( + + + + + ))} + + + - ))} - - + + + {activeMarkets.map(m => ( + + ))} + + +
+
+ {activeMarkets.map(m => ( +
+
+ {m} Star Rating +
+ ))} +
);