metrics to always show total fixed

This commit is contained in:
IGNY8 VPS (Salman)
2026-01-15 06:28:29 +00:00
parent a8309078c6
commit ee4749c6c6
3 changed files with 24 additions and 12 deletions

View File

@@ -50,6 +50,8 @@ export default function Ideas() {
const [totalInTasks, setTotalInTasks] = useState(0);
const [totalPending, setTotalPending] = useState(0);
const [totalImagesCount, setTotalImagesCount] = useState(0);
// Actual total count (unfiltered) for header metrics - not affected by filters
const [actualTotalIdeas, setActualTotalIdeas] = useState(0);
// Dynamic filter options
// Initialize as undefined to distinguish "not loaded yet" from "loaded but empty array"
@@ -178,7 +180,7 @@ export default function Ideas() {
fetchImages({ page_size: 1 }),
]);
setTotalCount(allRes.count || 0);
setActualTotalIdeas(allRes.count || 0); // Store actual total (unfiltered) for header metrics
setTotalInTasks((queuedRes.count || 0) + (completedRes.count || 0));
setTotalPending(newRes.count || 0);
setTotalImagesCount(imagesRes.count || 0);
@@ -359,8 +361,9 @@ export default function Ideas() {
});
}, [clusters, activeSector, formData, searchTerm, statusFilter, clusterFilter, structureFilter, typeFilter, statusOptions, contentTypeOptions, contentStructureOptions, clusterOptions]);
// Calculate header metrics - use totalInTasks/totalPending from API calls (not page data)
// Calculate header metrics - use actualTotalIdeas/totalInTasks/totalPending from API calls (not page data)
// This ensures metrics show correct totals across all pages, not just current page
// Note: actualTotalIdeas is NOT affected by filters - it always shows the true total
const headerMetrics = useMemo(() => {
if (!pageConfig?.headerMetrics) return [];
@@ -370,7 +373,8 @@ export default function Ideas() {
switch (metric.label) {
case 'Ideas':
value = totalCount || 0;
// Use actualTotalIdeas (unfiltered) for header metrics - not affected by filters
value = actualTotalIdeas || 0;
break;
case 'New':
// Use totalPending from loadTotalMetrics() (ideas with status='new')
@@ -395,7 +399,7 @@ export default function Ideas() {
tooltip: (metric as any).tooltip,
};
});
}, [pageConfig?.headerMetrics, ideas, totalCount, totalPending, totalInTasks]);
}, [pageConfig?.headerMetrics, ideas, totalCount, totalPending, totalInTasks, actualTotalIdeas]);
const resetForm = useCallback(() => {
setFormData({