header footer metrics update and credits by site fixes
This commit is contained in:
@@ -9,6 +9,7 @@ import TablePageTemplate from '../../templates/TablePageTemplate';
|
||||
import {
|
||||
fetchTasks,
|
||||
fetchImages,
|
||||
fetchContent,
|
||||
createTask,
|
||||
updateTask,
|
||||
deleteTask,
|
||||
@@ -47,11 +48,17 @@ export default function Tasks() {
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
// Total counts for footer widget and header metrics (not page-filtered)
|
||||
const [totalContent, setTotalContent] = useState(0);
|
||||
const [totalDraft, setTotalDraft] = useState(0);
|
||||
const [totalReview, setTotalReview] = useState(0);
|
||||
const [totalApproved, setTotalApproved] = useState(0);
|
||||
const [totalPublished, setTotalPublished] = useState(0);
|
||||
const [totalImagesCount, setTotalImagesCount] = useState(0);
|
||||
|
||||
// Footer widget specific counts (task-based)
|
||||
const [totalQueued, setTotalQueued] = useState(0);
|
||||
const [totalProcessing, setTotalProcessing] = useState(0);
|
||||
const [totalCompleted, setTotalCompleted] = useState(0);
|
||||
const [totalFailed, setTotalFailed] = useState(0);
|
||||
const [totalImagesCount, setTotalImagesCount] = useState(0);
|
||||
|
||||
// Filter state
|
||||
const [searchTerm, setSearchTerm] = useState('');
|
||||
@@ -111,45 +118,45 @@ export default function Tasks() {
|
||||
const loadTotalMetrics = useCallback(async () => {
|
||||
try {
|
||||
// Batch all API calls in parallel for better performance
|
||||
const [allRes, queuedRes, processingRes, completedRes, failedRes, imagesRes] = await Promise.all([
|
||||
// Get all tasks (site-wide)
|
||||
fetchTasks({
|
||||
const [allRes, draftRes, reviewRes, approvedRes, publishedRes, imagesRes] = await Promise.all([
|
||||
// Get all content (site-wide)
|
||||
fetchContent({
|
||||
page_size: 1,
|
||||
site_id: activeSite?.id,
|
||||
}),
|
||||
// Get tasks with status='queued'
|
||||
fetchTasks({
|
||||
// Get content with status='draft'
|
||||
fetchContent({
|
||||
page_size: 1,
|
||||
site_id: activeSite?.id,
|
||||
status: 'queued',
|
||||
status: 'draft',
|
||||
}),
|
||||
// Get tasks with status='in_progress'
|
||||
fetchTasks({
|
||||
// Get content with status='review'
|
||||
fetchContent({
|
||||
page_size: 1,
|
||||
site_id: activeSite?.id,
|
||||
status: 'in_progress',
|
||||
status: 'review',
|
||||
}),
|
||||
// Get tasks with status='completed'
|
||||
fetchTasks({
|
||||
// Get content with status='approved'
|
||||
fetchContent({
|
||||
page_size: 1,
|
||||
site_id: activeSite?.id,
|
||||
status: 'completed',
|
||||
status: 'approved',
|
||||
}),
|
||||
// Get tasks with status='failed'
|
||||
fetchTasks({
|
||||
// Get content with status='published'
|
||||
fetchContent({
|
||||
page_size: 1,
|
||||
site_id: activeSite?.id,
|
||||
status: 'failed',
|
||||
status: 'published',
|
||||
}),
|
||||
// Get actual total images count
|
||||
fetchImages({ page_size: 1 }),
|
||||
fetchImages({ page_size: 1, site_id: activeSite?.id }),
|
||||
]);
|
||||
|
||||
setTotalCount(allRes.count || 0);
|
||||
setTotalQueued(queuedRes.count || 0);
|
||||
setTotalProcessing(processingRes.count || 0);
|
||||
setTotalCompleted(completedRes.count || 0);
|
||||
setTotalFailed(failedRes.count || 0);
|
||||
setTotalContent(allRes.count || 0);
|
||||
setTotalDraft(draftRes.count || 0);
|
||||
setTotalReview(reviewRes.count || 0);
|
||||
setTotalApproved(approvedRes.count || 0);
|
||||
setTotalPublished(publishedRes.count || 0);
|
||||
setTotalImagesCount(imagesRes.count || 0);
|
||||
} catch (error) {
|
||||
console.error('Error loading total metrics:', error);
|
||||
@@ -384,24 +391,23 @@ export default function Tasks() {
|
||||
let value: number;
|
||||
|
||||
switch (metric.label) {
|
||||
case 'Tasks':
|
||||
value = totalCount || 0;
|
||||
case 'Content':
|
||||
value = totalContent || 0;
|
||||
break;
|
||||
case 'In Queue':
|
||||
// Use totalQueued from loadTotalMetrics()
|
||||
value = totalQueued;
|
||||
case 'Draft':
|
||||
value = totalDraft;
|
||||
break;
|
||||
case 'Processing':
|
||||
// Use totalProcessing from loadTotalMetrics()
|
||||
value = totalProcessing;
|
||||
case 'In Review':
|
||||
value = totalReview;
|
||||
break;
|
||||
case 'Completed':
|
||||
// Use totalCompleted from loadTotalMetrics()
|
||||
value = totalCompleted;
|
||||
case 'Approved':
|
||||
value = totalApproved;
|
||||
break;
|
||||
case 'Failed':
|
||||
// Use totalFailed from loadTotalMetrics()
|
||||
value = totalFailed;
|
||||
case 'Published':
|
||||
value = totalPublished;
|
||||
break;
|
||||
case 'Total Images':
|
||||
value = totalImagesCount;
|
||||
break;
|
||||
default:
|
||||
value = metric.calculate({ tasks, totalCount });
|
||||
@@ -414,7 +420,7 @@ export default function Tasks() {
|
||||
tooltip: (metric as any).tooltip,
|
||||
};
|
||||
});
|
||||
}, [pageConfig?.headerMetrics, tasks, totalCount, totalQueued, totalProcessing, totalCompleted, totalFailed]);
|
||||
}, [pageConfig?.headerMetrics, tasks, totalContent, totalDraft, totalReview, totalApproved, totalPublished, totalImagesCount]);
|
||||
|
||||
const resetForm = useCallback(() => {
|
||||
setFormData({
|
||||
|
||||
Reference in New Issue
Block a user