mirror of
https://github.com/christianvidalwolf-prog/CrazeAnalytix.git
synced 2026-08-03 13:45:23 +02:00
Refine YTD Logic: Allow full historical data when Month/Week filters are active
This commit is contained in:
@@ -514,26 +514,41 @@ const App: React.FC = () => {
|
|||||||
}, [rawData]);
|
}, [rawData]);
|
||||||
|
|
||||||
const ytdGridData = useMemo(() => {
|
const ytdGridData = useMemo(() => {
|
||||||
// Filter combinedAdsData to only include weeks <= maxWeek
|
// Smart YTD Logic:
|
||||||
// This ensures we compare "Like for Like" periods across years
|
// Only apply the "Max Week" cutoff if the user has NOT explicitly selected a specific time period.
|
||||||
// We do strictly LESS THAN OR EQUAL to maxWeek.
|
// If Month or Week filters are active, we show exactly what was asked (e.g., Full Year 2024).
|
||||||
|
// If no time filters are active, we default to YTD (Like-for-Like) comparison.
|
||||||
|
const isTimeFilterActive = filters.month.length > 0 || filters.week.length > 0;
|
||||||
|
|
||||||
if (!combinedAdsData) return [];
|
if (!combinedAdsData) return [];
|
||||||
|
|
||||||
|
if (isTimeFilterActive) {
|
||||||
|
return combinedAdsData;
|
||||||
|
}
|
||||||
|
|
||||||
return combinedAdsData.filter(item => {
|
return combinedAdsData.filter(item => {
|
||||||
// CombinedKPIs has 'week' property
|
if (!item.week) return true;
|
||||||
if (!item.week) return true; // Keep non-weekly items if any (shouldn't be)
|
|
||||||
return item.week <= gridContext.maxWeek;
|
return item.week <= gridContext.maxWeek;
|
||||||
});
|
});
|
||||||
}, [combinedAdsData, gridContext.maxWeek]);
|
}, [combinedAdsData, gridContext.maxWeek, filters.month, filters.week]);
|
||||||
|
|
||||||
// Derived Data for Dashboard (YTD Filtered - Isolated)
|
// Derived Data for Dashboard (YTD Filtered - Isolated)
|
||||||
// Dashboard needs aggregated data respecting the max week limit of current year.
|
// Dashboard needs aggregated data respecting the max week limit of current year.
|
||||||
|
// Dashboard needs aggregated data respecting the max week limit of current year...
|
||||||
|
// UNLESS the user explicitly filters for a period.
|
||||||
const ytdFilteredData = useMemo(() => {
|
const ytdFilteredData = useMemo(() => {
|
||||||
|
const isTimeFilterActive = filters.month.length > 0 || filters.week.length > 0;
|
||||||
|
if (isTimeFilterActive) return filteredData;
|
||||||
|
|
||||||
return filteredData.filter(r => r.week <= gridContext.maxWeek);
|
return filteredData.filter(r => r.week <= gridContext.maxWeek);
|
||||||
}, [filteredData, gridContext.maxWeek]);
|
}, [filteredData, gridContext.maxWeek, filters.month, filters.week]);
|
||||||
|
|
||||||
const ytdFilteredAdsData = useMemo(() => {
|
const ytdFilteredAdsData = useMemo(() => {
|
||||||
|
const isTimeFilterActive = filters.month.length > 0 || filters.week.length > 0;
|
||||||
|
if (isTimeFilterActive) return filteredAdsData;
|
||||||
|
|
||||||
return filteredAdsData.filter(r => r.week <= gridContext.maxWeek);
|
return filteredAdsData.filter(r => r.week <= gridContext.maxWeek);
|
||||||
}, [filteredAdsData, gridContext.maxWeek]);
|
}, [filteredAdsData, gridContext.maxWeek, filters.month, filters.week]);
|
||||||
|
|
||||||
const ytdAggregatedData = useMemo(() => {
|
const ytdAggregatedData = useMemo(() => {
|
||||||
return aggregateData(ytdFilteredData);
|
return aggregateData(ytdFilteredData);
|
||||||
|
|||||||
Reference in New Issue
Block a user