Skip to content

Commit

Permalink
chore: PR feedback 2
Browse files Browse the repository at this point in the history
  • Loading branch information
brobro10000 committed Sep 16, 2024
1 parent 4c4f65f commit 8cfd7d8
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/components/app/data/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,5 @@ export const ASSIGNMENT_TYPES = {
EXPIRING: 'expiring',
};

// Start date threshold to default to today days, sets start date to today if course start date is beyond this value
// When the start date is before this number of days before today, display the alternate start date (fixed to today).
export const START_DATE_DEFAULT_TO_TODAY_THRESHOLD_DAYS = 14;
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const CourseImportantDates = () => {
// Match soonest expiring assignment to the corresponding course start date from course metadata
let soonestExpiringAllocatedAssignmentCourseStartDate = null;
if (soonestExpiringAssignment) {
const soonestExpiringAllocatedAssignment = courseMetadata.availableCourseRuns?.find(
const soonestExpiringAllocatedAssignment = courseMetadata.availableCourseRuns.find(
(courseRun) => courseRun.key === soonestExpiringAssignment?.contentKey,
);
soonestExpiringAllocatedAssignmentCourseStartDate = soonestExpiringAllocatedAssignment
Expand Down
2 changes: 2 additions & 0 deletions src/components/course/data/constants.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import GetSmarterLogo from '../../../assets/icons/getsmarter-header-icon.svg';

// The SELF and INSTRUCTOR values are keys/value pairs used specifically for pacing sourced from the
// enterprise_course_enrollments API.
export const COURSE_PACING_MAP = {
SELF_PACED: 'self_paced',
INSTRUCTOR_PACED: 'instructor_paced',
Expand Down
36 changes: 6 additions & 30 deletions src/components/course/data/utils.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ import {

/**
* Determines if the course has already started. Mostly used around text formatting for tense
* Introduces 'jitter' in the form of a 30 second offset to take into account any additional
* formatting that takes place down stream related to setting values to today's date through dayjs()
*
* This should also help with reducing 'flaky' tests.
*
* @param start
* @returns {boolean}
Expand Down Expand Up @@ -68,11 +64,11 @@ export function hasTimeToComplete(courseRun) {
}

export function isCourseSelfPaced(pacingType) {
return pacingType === COURSE_PACING_MAP.SELF_PACED || pacingType === COURSE_PACING_MAP.SELF;
return [COURSE_PACING_MAP.SELF_PACED, COURSE_PACING_MAP.SELF].includes(pacingType);
}

export function isCourseInstructorPaced(pacingType) {
return pacingType === COURSE_PACING_MAP.INSTRUCTOR_PACED || pacingType === COURSE_PACING_MAP.INSTRUCTOR;
return [COURSE_PACING_MAP.INSTRUCTOR_PACED, COURSE_PACING_MAP.INSTRUCTOR].includes(pacingType);
}

const isWithinMinimumStartDateThreshold = ({ start }) => dayjs(start).isBefore(dayjs().subtract(START_DATE_DEFAULT_TO_TODAY_THRESHOLD_DAYS, 'days'));
Expand All @@ -81,10 +77,10 @@ const isWithinMinimumStartDateThreshold = ({ start }) => dayjs(start).isBefore(d
* If the start date of the course is before today offset by the START_DATE_DEFAULT_TO_TODAY_THRESHOLD_DAYS
* then return today's formatted date. Otherwise, pass-through the start date in ISO format.
*
* @param start
* @param pacingType
* @param end
* @param weeksToComplete
* @param {String} start
* @param {String} pacingType
* @param {String} end
* @param {Number} weeksToComplete
* @returns {string}
*/
export const getNormalizedStartDate = ({
Expand Down Expand Up @@ -978,23 +974,3 @@ export function getSoonestEarliestPossibleExpirationData({
sortedExpirationAssignments: sortedByExpirationDate,
};
}

/**
* If the start date of the course is before today offset by the START_DATE_DEFAULT_TO_TODAY_THRESHOLD_DAYS
* then return today's formatted date. Otherwise, pass-through the start date in ISO format.
*
* For cases where a start date does not exist, just return today's date.
*
* @param start
* @param format
* @returns {string}
*/
export const setStaleCourseStartDates = ({ start }) => {
if (!start) {
return dayjs().toISOString();
}
if (dayjs(start).isBefore(dayjs().subtract(START_DATE_DEFAULT_TO_TODAY_THRESHOLD_DAYS, 'days'))) {
return dayjs().toISOString();
}
return dayjs(start).toISOString();
};

0 comments on commit 8cfd7d8

Please sign in to comment.