Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add progress bar #1168

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Suspense, useState } from 'react';
import { Suspense, useState, useCallback, useEffect } from 'react';

Check failure on line 1 in src/components/dashboard/main-content/course-enrollments/CourseSection.jsx

View workflow job for this annotation

GitHub Actions / tests (18)

Expected a line break after this opening brace

Check failure on line 1 in src/components/dashboard/main-content/course-enrollments/CourseSection.jsx

View workflow job for this annotation

GitHub Actions / tests (18)

Expected a line break before this closing brace

Check failure on line 1 in src/components/dashboard/main-content/course-enrollments/CourseSection.jsx

View workflow job for this annotation

GitHub Actions / tests (20)

Expected a line break after this opening brace

Check failure on line 1 in src/components/dashboard/main-content/course-enrollments/CourseSection.jsx

View workflow job for this annotation

GitHub Actions / tests (20)

Expected a line break before this closing brace
import PropTypes from 'prop-types';
import { sendEnterpriseTrackEvent } from '@edx/frontend-enterprise-utils';
import { Bubble, Collapsible, Skeleton } from '@openedx/paragon';
import { Bubble, Collapsible, Skeleton, ProgressBar } from '@openedx/paragon';

Check failure on line 4 in src/components/dashboard/main-content/course-enrollments/CourseSection.jsx

View workflow job for this annotation

GitHub Actions / tests (18)

Expected a line break after this opening brace

Check failure on line 4 in src/components/dashboard/main-content/course-enrollments/CourseSection.jsx

View workflow job for this annotation

GitHub Actions / tests (18)

Expected a line break before this closing brace

Check failure on line 4 in src/components/dashboard/main-content/course-enrollments/CourseSection.jsx

View workflow job for this annotation

GitHub Actions / tests (20)

Expected a line break after this opening brace

Check failure on line 4 in src/components/dashboard/main-content/course-enrollments/CourseSection.jsx

View workflow job for this annotation

GitHub Actions / tests (20)

Expected a line break before this closing brace
import { v4 as uuidv4 } from 'uuid';
import { getProgressTabData } from './course-cards/mark-complete-modal/data/service';

import {
AssignedCourseCard,
Expand Down Expand Up @@ -101,9 +102,27 @@
);
};

const [progress, setProgress] = useState({});
const fetchData = useCallback(
async (courseRun) => {
try {
const result = await getProgressTabData(courseRun);
setProgress(result);
} catch (error) {
console.log(error);

Check warning on line 112 in src/components/dashboard/main-content/course-enrollments/CourseSection.jsx

View workflow job for this annotation

GitHub Actions / tests (18)

Unexpected console statement

Check warning on line 112 in src/components/dashboard/main-content/course-enrollments/CourseSection.jsx

View workflow job for this annotation

GitHub Actions / tests (20)

Unexpected console statement
}
},
[],
);

const renderCourseCards = () => courseRuns.map(courseRun => {
const Component = CARD_COMPONENT_BY_COURSE_STATUS[courseRun.courseRunStatus];
const isAuditEnrollment = isEnrollmentUpgradeable(courseRun);
useEffect(() => {

Check failure on line 121 in src/components/dashboard/main-content/course-enrollments/CourseSection.jsx

View workflow job for this annotation

GitHub Actions / tests (18)

React Hook "useEffect" cannot be called inside a callback. React Hooks must be called in a React function component or a custom React Hook function

Check failure on line 121 in src/components/dashboard/main-content/course-enrollments/CourseSection.jsx

View workflow job for this annotation

GitHub Actions / tests (20)

React Hook "useEffect" cannot be called inside a callback. React Hooks must be called in a React function component or a custom React Hook function
fetchData(courseRun.courseRunId);
}, [fetchData]);

Check failure on line 123 in src/components/dashboard/main-content/course-enrollments/CourseSection.jsx

View workflow job for this annotation

GitHub Actions / tests (18)

React Hook useEffect has a missing dependency: 'courseRun.courseRunId'. Either include it or remove the dependency array. Outer scope values like 'fetchData' aren't valid dependencies because mutating them doesn't re-render the component

Check failure on line 123 in src/components/dashboard/main-content/course-enrollments/CourseSection.jsx

View workflow job for this annotation

GitHub Actions / tests (20)

React Hook useEffect has a missing dependency: 'courseRun.courseRunId'. Either include it or remove the dependency array. Outer scope values like 'fetchData' aren't valid dependencies because mutating them doesn't re-render the component
const numTotalUnits = progress?.completionSummary?.completeCount + progress?.completionSummary?.incompleteCount + progress?.completionSummary?.lockedCount;

Check failure on line 124 in src/components/dashboard/main-content/course-enrollments/CourseSection.jsx

View workflow job for this annotation

GitHub Actions / tests (18)

This line has a length of 159. Maximum allowed is 120

Check failure on line 124 in src/components/dashboard/main-content/course-enrollments/CourseSection.jsx

View workflow job for this annotation

GitHub Actions / tests (18)

Unsafe arithmetic operation on optional chaining. It can result in NaN

Check failure on line 124 in src/components/dashboard/main-content/course-enrollments/CourseSection.jsx

View workflow job for this annotation

GitHub Actions / tests (18)

Unsafe arithmetic operation on optional chaining. It can result in NaN

Check failure on line 124 in src/components/dashboard/main-content/course-enrollments/CourseSection.jsx

View workflow job for this annotation

GitHub Actions / tests (18)

Unsafe arithmetic operation on optional chaining. It can result in NaN

Check failure on line 124 in src/components/dashboard/main-content/course-enrollments/CourseSection.jsx

View workflow job for this annotation

GitHub Actions / tests (20)

This line has a length of 159. Maximum allowed is 120

Check failure on line 124 in src/components/dashboard/main-content/course-enrollments/CourseSection.jsx

View workflow job for this annotation

GitHub Actions / tests (20)

Unsafe arithmetic operation on optional chaining. It can result in NaN

Check failure on line 124 in src/components/dashboard/main-content/course-enrollments/CourseSection.jsx

View workflow job for this annotation

GitHub Actions / tests (20)

Unsafe arithmetic operation on optional chaining. It can result in NaN

Check failure on line 124 in src/components/dashboard/main-content/course-enrollments/CourseSection.jsx

View workflow job for this annotation

GitHub Actions / tests (20)

Unsafe arithmetic operation on optional chaining. It can result in NaN
const completePercentage = progress?.completionSummary?.completeCount ? Number(((progress?.completionSummary?.completeCount / numTotalUnits) * 100).toFixed(0)) : 0;
if (isAuditEnrollment && courseRun.courseRunStatus === COURSE_STATUSES.inProgress) {
return (
<Suspense
Expand All @@ -115,15 +134,27 @@
</DelayedFallbackContainer>
)}
>
<Component {...getCourseRunProps(courseRun)} />
<div>
<Component
{...getCourseRunProps(courseRun)}
key={courseRun.courseRunId}
/>
<ProgressBar now={`${completePercentage}%`} label={`${completePercentage}%`} variant="primary" />
<br />
</div>
</Suspense>
);
}
return (
<Component
{...getCourseRunProps(courseRun)}
key={courseRun.courseRunId}
/>
<div>
<Component
{...getCourseRunProps(courseRun)}
key={courseRun.courseRunId}
/>
<ProgressBar now={`${completePercentage}%`} label={`${completePercentage}%`} variant="primary" />
<br />
</div>

);
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';
import { getConfig } from '@edx/frontend-platform/config';
import { camelCaseObject } from '@edx/frontend-platform/utils';

export const ENROLL_ENDPOINT = '/enterprise_learner_portal/api/v1/enterprise_course_enrollments/';

Expand All @@ -24,3 +25,21 @@ export const updateCourseCompleteStatusRequest = (options) => {
}
return getAuthenticatedHttpClient().patch(url);
};


export async function getProgressTabData(courseId, targetUserId) {
let url = `${getConfig().LMS_BASE_URL}/api/course_home/progress/${courseId}`;

if (targetUserId) {
url += `/${targetUserId}/`;
}

try {
const { data } = await getAuthenticatedHttpClient().get(url);
const camelCasedData = camelCaseObject(data);

return camelCasedData;
} catch (error) {
throw error;
}
}
Loading