From e78e9e7998a36dc513253340e0d5e406f3211969 Mon Sep 17 00:00:00 2001 From: Arif Date: Mon, 23 Sep 2024 13:54:49 +0530 Subject: [PATCH 1/2] Issue #PS-1623: Status update for topic-subtopic and progress update for subject API integration --- src/pages/course-planner-detail.tsx | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/pages/course-planner-detail.tsx b/src/pages/course-planner-detail.tsx index 03dde731..e5ba12b3 100644 --- a/src/pages/course-planner-detail.tsx +++ b/src/pages/course-planner-detail.tsx @@ -102,16 +102,25 @@ const CoursePlannerDetail = () => { const calculateProgress = (tasks: any[]) => { let totalSubtasks = 0; let completedSubtasks = 0; - + tasks.forEach((task: any) => { - totalSubtasks += task.children.length ?? 0; - completedSubtasks += task?.children?.filter( - (subtask: any) => subtask.status === 'completed' - ).length; + if (task.status === 'completed') { + completedSubtasks += 1; + } + + const subtasks = task.children || []; + totalSubtasks += subtasks.length; + completedSubtasks += subtasks.filter((subtask: any) => subtask.status === 'completed').length; }); - setCompletionPercentage(totalSubtasks ? Number(((completedSubtasks / totalSubtasks) * 100).toFixed()) : 0); + + const totalTasks = tasks.length; + const totalItems = totalTasks + totalSubtasks; + const completedItems = completedSubtasks; + + const completionPercentage = totalItems ? Number(((completedItems / totalItems) * 100).toFixed()) : 0; + setCompletionPercentage(completionPercentage); }; - + if (userProjectDetails?.tasks?.length) { calculateProgress(userProjectDetails.tasks); } From 62b5955335528d863368c00b0cc4113b8d029f2a Mon Sep 17 00:00:00 2001 From: Arif Date: Mon, 23 Sep 2024 13:58:38 +0530 Subject: [PATCH 2/2] fix --- src/pages/course-planner-detail.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/course-planner-detail.tsx b/src/pages/course-planner-detail.tsx index e5ba12b3..8d8e1255 100644 --- a/src/pages/course-planner-detail.tsx +++ b/src/pages/course-planner-detail.tsx @@ -104,13 +104,13 @@ const CoursePlannerDetail = () => { let completedSubtasks = 0; tasks.forEach((task: any) => { - if (task.status === 'completed') { + if (task.status === AssessmentStatus.COMPLETED) { completedSubtasks += 1; } const subtasks = task.children || []; totalSubtasks += subtasks.length; - completedSubtasks += subtasks.filter((subtask: any) => subtask.status === 'completed').length; + completedSubtasks += subtasks.filter((subtask: any) => subtask.status === AssessmentStatus.COMPLETED).length; }); const totalTasks = tasks.length;