fix: stabilize color mapping by using persistent global hash and add SSE heartbeat
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 1m18s

This commit is contained in:
Cauê Faleiros
2026-05-07 14:08:38 -03:00
parent d3167dbac1
commit 3bb46cff1a
2 changed files with 19 additions and 2 deletions

View File

@@ -15,6 +15,17 @@ const COLORS = [
'#67e8f9', '#f9a8d4', '#fde047', '#a5b4fc', '#5eead4'
];
const globalColorMap: Record<string, string> = {};
let globalColorIndex = 0;
const getProductColor = (name: string) => {
if (!globalColorMap[name]) {
globalColorMap[name] = COLORS[globalColorIndex % COLORS.length];
globalColorIndex++;
}
return globalColorMap[name];
};
const formatCurrency = (value: number) => {
return new Intl.NumberFormat('pt-BR', { style: 'currency', currency: 'BRL' }).format(value);
};
@@ -75,8 +86,8 @@ const Dashboard = () => {
const displayProducts = Array.from(new Set([...topSalesNames, ...topRevenueNames])).sort();
const productColors: Record<string, string> = {};
displayProducts.forEach((name, index) => {
productColors[name] = COLORS[index % COLORS.length];
displayProducts.forEach((name) => {
productColors[name] = getProductColor(name);
});
const productsData = topSalesNames.map(name => ({