mirror of
https://github.com/christianvidalwolf-prog/CrazeAnalytix.git
synced 2026-08-03 14:05:24 +02:00
Refine Top 50 badge visibility based on customer filters
This commit is contained in:
@@ -615,6 +615,7 @@ const App: React.FC = () => {
|
|||||||
stockMap={stockMap}
|
stockMap={stockMap}
|
||||||
stockFilter={filters.stock}
|
stockFilter={filters.stock}
|
||||||
onStockFilterChange={(s) => setFilters(prev => ({ ...prev, stock: s }))}
|
onStockFilterChange={(s) => setFilters(prev => ({ ...prev, stock: s }))}
|
||||||
|
customerFilters={filters.customer}
|
||||||
/>
|
/>
|
||||||
</Suspense>
|
</Suspense>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import React, { useMemo, useState, useEffect, useCallback, useRef } from 'react';
|
import React, { useMemo, useState, useEffect, useCallback, useRef } from 'react';
|
||||||
import * as XLSX from 'xlsx';
|
import * as XLSX from 'xlsx';
|
||||||
import { CombinedKPIs } from '../types';
|
import { CombinedKPIs } from '../types';
|
||||||
import { pivotWeeklySalesData, WeeklyPivotRow } from '../services/dataProcessor';
|
import { pivotWeeklySalesData, WeeklyPivotRow, PAN_EU_COUNTRIES } from '../services/dataProcessor';
|
||||||
import { StockBadge } from './StockBadge';
|
import { StockBadge } from './StockBadge';
|
||||||
import { InColumnStockFilter } from './InColumnStockFilter';
|
import { InColumnStockFilter } from './InColumnStockFilter';
|
||||||
|
|
||||||
@@ -15,6 +15,7 @@ interface WeeklyGridProps {
|
|||||||
stockMap?: Map<string, number>;
|
stockMap?: Map<string, number>;
|
||||||
stockFilter: string[];
|
stockFilter: string[];
|
||||||
onStockFilterChange: (newFilters: string[]) => void;
|
onStockFilterChange: (newFilters: string[]) => void;
|
||||||
|
customerFilters: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
type SortConfig = {
|
type SortConfig = {
|
||||||
@@ -65,17 +66,28 @@ const WeeklyRow: React.FC<{
|
|||||||
top50Mode: 'eu' | 'uk';
|
top50Mode: 'eu' | 'uk';
|
||||||
sortConfig: SortConfig;
|
sortConfig: SortConfig;
|
||||||
renderGrowth: (current: number, previous: number) => React.ReactNode;
|
renderGrowth: (current: number, previous: number) => React.ReactNode;
|
||||||
}> = React.memo(({ row, weeks, onDrillDown, stockMap, top50Ranking, top50Mode, sortConfig, renderGrowth }) => {
|
customerFilters: string[];
|
||||||
|
}> = React.memo(({ row, weeks, onDrillDown, stockMap, top50Ranking, top50Mode, sortConfig, renderGrowth, customerFilters }) => {
|
||||||
const ranks: { rank: number; label: string; theme: 'amber' | 'blue' | 'indigo' }[] = [];
|
const ranks: { rank: number; label: string; theme: 'amber' | 'blue' | 'indigo' }[] = [];
|
||||||
const asin = row.asin.trim().toUpperCase();
|
const asin = row.asin.trim().toUpperCase();
|
||||||
|
|
||||||
|
const isUKSelected = customerFilters.some(c => c.toLowerCase().includes('uk'));
|
||||||
|
const isEUPartialSelected = customerFilters.some(c => PAN_EU_COUNTRIES.includes(c));
|
||||||
|
const hasNoCustomerFilter = customerFilters.length === 0;
|
||||||
|
|
||||||
if (top50Ranking) {
|
if (top50Ranking) {
|
||||||
if (top50Mode === 'eu') {
|
// Only show UK rank if UK is explicitly selected
|
||||||
const rank = top50Ranking.eu.get(asin);
|
if (top50Mode === 'uk' && isUKSelected) {
|
||||||
if (rank) ranks.push({ rank, label: 'EU', theme: 'indigo' });
|
|
||||||
} else {
|
|
||||||
const rank = top50Ranking.uk.get(asin);
|
const rank = top50Ranking.uk.get(asin);
|
||||||
if (rank) ranks.push({ rank, label: 'UK', theme: 'blue' });
|
if (rank) ranks.push({ rank, label: 'UK', theme: 'blue' });
|
||||||
}
|
}
|
||||||
|
// Only show EU rank if at least one Pan-EU country is selected
|
||||||
|
// OR if no filters are selected (User might want to see them all then, but user said "only when... is selected")
|
||||||
|
// Actually the prompt says: "only appear when in the filters... is selected"
|
||||||
|
else if (top50Mode === 'eu' && isEUPartialSelected) {
|
||||||
|
const rank = top50Ranking.eu.get(asin);
|
||||||
|
if (rank) ranks.push({ rank, label: 'EU', theme: 'indigo' });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -145,7 +157,7 @@ const WeeklyRow: React.FC<{
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
const WeeklyGrid: React.FC<WeeklyGridProps> = ({ data, top50Ranking, onDrillDown, stockMap, stockFilter, onStockFilterChange }) => {
|
const WeeklyGrid: React.FC<WeeklyGridProps> = ({ data, top50Ranking, onDrillDown, stockMap, stockFilter, onStockFilterChange, customerFilters }) => {
|
||||||
// Pivot data - memoized
|
// Pivot data - memoized
|
||||||
const { rows, weeks: allWeeks } = useMemo(() => pivotWeeklySalesData(data), [data]);
|
const { rows, weeks: allWeeks } = useMemo(() => pivotWeeklySalesData(data), [data]);
|
||||||
|
|
||||||
@@ -599,6 +611,7 @@ const WeeklyGrid: React.FC<WeeklyGridProps> = ({ data, top50Ranking, onDrillDown
|
|||||||
top50Mode={top50Mode}
|
top50Mode={top50Mode}
|
||||||
sortConfig={sortConfig}
|
sortConfig={sortConfig}
|
||||||
renderGrowth={renderGrowth}
|
renderGrowth={renderGrowth}
|
||||||
|
customerFilters={customerFilters}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
{displayCount < sortedRows.length && (
|
{displayCount < sortedRows.length && (
|
||||||
|
|||||||
Reference in New Issue
Block a user