mirror of
https://github.com/christianvidalwolf-prog/CrazeAnalytix.git
synced 2026-08-03 13:05:24 +02:00
feat: auto-sort by ranking (1-50) when Top 50 filter is active in Ads tab
This commit is contained in:
@@ -184,11 +184,26 @@ const AdsPerformance: React.FC<AdsPerformanceProps> = ({ data, filters, top50Ran
|
||||
item.title.toLowerCase().includes(searchTerm.toLowerCase())
|
||||
);
|
||||
|
||||
// Sort: by ranking when Top 50 is active, otherwise by sortConfig
|
||||
if (showOnlyTop50 && top50Ranking) {
|
||||
result.sort((a, b) => {
|
||||
const asinA = a.asin.trim().toUpperCase();
|
||||
const asinB = b.asin.trim().toUpperCase();
|
||||
const rankA = top50Mode === 'eu'
|
||||
? (top50Ranking.eu.get(asinA) || 999)
|
||||
: (top50Ranking.uk.get(asinA) || 999);
|
||||
const rankB = top50Mode === 'eu'
|
||||
? (top50Ranking.eu.get(asinB) || 999)
|
||||
: (top50Ranking.uk.get(asinB) || 999);
|
||||
return rankA - rankB;
|
||||
});
|
||||
} else {
|
||||
result.sort((a, b) => {
|
||||
const valA = a[sortConfig.key] as number;
|
||||
const valB = b[sortConfig.key] as number;
|
||||
return sortConfig.direction === 'asc' ? valA - valB : valB - valA;
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
}, [aggregatedByAsin, searchTerm, sortConfig, showOnlyTop50, top50Ranking, top50Mode]);
|
||||
|
||||
Reference in New Issue
Block a user