Skip to content

Commit

Permalink
chore: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
brobro10000 committed Aug 9, 2024
1 parent a518fb7 commit 3211653
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 165 deletions.
3 changes: 1 addition & 2 deletions src/components/app/data/hooks/useCourseMetadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,11 @@ export default function useCourseMetadata(queryOptions = {}) {
...data,
availableCourseRuns,
};
const keys = ['course-v1:edx+H200+2018', 'course-v1:edx+H200+2T2020'];
// This logic should appropriately handle multiple course runs being assigned, and return the appropriate metadata
transformedData = transformCourseMetadataByAllocationCourseRun({
hasMultipleAssignedCourseRuns,
courseMetadata: transformedData,
allocatedCourseRunAssignmentKeys: keys,
allocatedCourseRunAssignmentKeys,
});
if (select) {
return select({
Expand Down
222 changes: 66 additions & 156 deletions src/components/app/data/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -733,158 +733,7 @@ export const getSubsidyToApplyForCourse = ({

return undefined;
};
const test = {
uuid: 'df4f42e2-ed44-47bb-a73f-607f926c69af',
assignmentConfiguration: 'c40950ce-15d6-46d9-bf1f-62a0988239db',
learnerEmail: 'hullah@2u.com',
lmsUserId: 5266560,
contentKey: 'course-v1:edx+H200+2025',
contentTitle: 'Intermediate Happiness',
contentQuantity: -100,
state: 'allocated',
transactionUuid: null,
actions: [
{
created: '2024-08-06T12:11:55.618790Z',
modified: '2024-08-06T12:11:55.618821Z',
uuid: 'cdd6eb1e-6834-4199-be3d-2ff41e43f9e7',
actionType: 'learner_linked',
completedAt: '2024-08-06T12:11:55.618262Z',
errorReason: null,
learnerAcknowledged: null,
},
{
created: '2024-08-06T12:11:55.798956Z',
modified: '2024-08-06T12:11:55.798993Z',
uuid: '5d5b2650-693d-4eed-a79e-c8805108cbf9',
actionType: 'notified',
completedAt: '2024-08-06T12:11:55.798321Z',
errorReason: null,
learnerAcknowledged: null,
},
],
earliestPossibleExpiration: {
date: '2024-11-04T12:11:55.366834Z',
reason: 'NINETY_DAYS_PASSED',
},
contentMetadata: {
startDate: '2020-10-01T16:00:00Z',
endDate: '2112-10-21T16:00:00Z',
enrollByDate: '2112-10-11T23:59:59Z',
contentPrice: 1,
courseType: 'verified-audit',
partners: [
{
name: 'edX',
logoImageUrl: 'https://stage-discovery.edx-cdn.org/organization/logos/4f8cb2c9-589b-4d1e-88c1-b01a02db3a9c-086cef28bdf5.png',
},
],
},
learnerAcknowledged: null,
subsidyExpirationDate: '2025-07-17T00:00:00Z',
};

const test2 = {
uuid: 'df4f42e2-ed44-47bb-a73f-607f926c69af',
assignmentConfiguration: 'c40950ce-15d6-46d9-bf1f-62a0988239db',
learnerEmail: 'hullah@2u.com',
lmsUserId: 5266560,
contentKey: 'course-v1:edx+H200+2018',
contentTitle: 'Intermediate Happiness',
contentQuantity: -100,
state: 'allocated',
transactionUuid: null,
actions: [
{
created: '2024-08-06T12:11:55.618790Z',
modified: '2024-08-06T12:11:55.618821Z',
uuid: 'cdd6eb1e-6834-4199-be3d-2ff41e43f9e7',
actionType: 'learner_linked',
completedAt: '2024-08-06T12:11:55.618262Z',
errorReason: null,
learnerAcknowledged: null,
},
{
created: '2024-08-06T12:11:55.798956Z',
modified: '2024-08-06T12:11:55.798993Z',
uuid: '5d5b2650-693d-4eed-a79e-c8805108cbf9',
actionType: 'notified',
completedAt: '2024-08-06T12:11:55.798321Z',
errorReason: null,
learnerAcknowledged: null,
},
],
earliestPossibleExpiration: {
date: '2023-12-03T12:11:55.366834Z',
reason: 'NINETY_DAYS_PASSED',
},
contentMetadata: {
startDate: '2020-10-01T16:00:00Z',
endDate: '2112-10-21T16:00:00Z',
enrollByDate: '2112-10-11T23:59:59Z',
contentPrice: 1,
courseType: 'verified-audit',
partners: [
{
name: 'edX',
logoImageUrl: 'https://stage-discovery.edx-cdn.org/organization/logos/4f8cb2c9-589b-4d1e-88c1-b01a02db3a9c-086cef28bdf5.png',
},
],
},
learnerAcknowledged: null,
subsidyExpirationDate: '2025-07-17T00:00:00Z',
};

const test3 = {
uuid: 'df4f42e2-ed44-47bb-a73f-607f926c69af',
assignmentConfiguration: 'c40950ce-15d6-46d9-bf1f-62a0988239db',
learnerEmail: 'hullah@2u.com',
lmsUserId: 5266560,
contentKey: 'course-v1:edx+H200+2T2020',
contentTitle: 'Intermediate Happiness',
contentQuantity: -100,
state: 'allocated',
transactionUuid: null,
actions: [
{
created: '2024-08-06T12:11:55.618790Z',
modified: '2024-08-06T12:11:55.618821Z',
uuid: 'cdd6eb1e-6834-4199-be3d-2ff41e43f9e7',
actionType: 'learner_linked',
completedAt: '2024-08-06T12:11:55.618262Z',
errorReason: null,
learnerAcknowledged: null,
},
{
created: '2024-08-06T12:11:55.798956Z',
modified: '2024-08-06T12:11:55.798993Z',
uuid: '5d5b2650-693d-4eed-a79e-c8805108cbf9',
actionType: 'notified',
completedAt: '2024-08-06T12:11:55.798321Z',
errorReason: null,
learnerAcknowledged: null,
},
],
earliestPossibleExpiration: {
date: '2025-01-05T12:11:55.366834Z',
reason: 'NINETY_DAYS_PASSED',
},
contentMetadata: {
startDate: '2020-10-01T16:00:00Z',
endDate: '2112-10-21T16:00:00Z',
enrollByDate: '2112-10-11T23:59:59Z',
contentPrice: 1,
courseType: 'verified-audit',
partners: [
{
name: 'edX',
logoImageUrl: 'https://stage-discovery.edx-cdn.org/organization/logos/4f8cb2c9-589b-4d1e-88c1-b01a02db3a9c-086cef28bdf5.png',
},
],
},
learnerAcknowledged: null,
subsidyExpirationDate: '2025-07-17T00:00:00Z',
};
/**
* Determines whether the course enrollment can be upgraded to verified enrollment.
*
Expand All @@ -899,6 +748,26 @@ export function isEnrollmentUpgradeable(enrollment) {
return canUpgradeToVerifiedEnrollment;
}

/**
* Determines if allocatedAssignments are courseRun based
*
* @param redeemableLearnerCreditPolicies
* @param courseKey
* @returns {
* {
* hasAssignedCourseRuns: boolean,
* allocatedCourseRunAssignmentKeys: *,
* allocatedCourseRunAssignments: *,
* hasMultipleAssignedCourseRuns: boolean
* } |
* {
* hasAssignedCourseRuns: boolean,
* allocatedCourseRunAssignmentKeys: *[],
* allocatedCourseRunAssignments: *[],
* hasMultipleAssignedCourseRuns: boolean
* }
* }
*/
export function determineAllocatedCourseRuns({
redeemableLearnerCreditPolicies,
courseKey,
Expand All @@ -917,10 +786,10 @@ export function determineAllocatedCourseRuns({
const hasAssignedCourseRuns = allocatedCourseRunAssignmentKeys.length > 0;
const hasMultipleAssignedCourseRuns = allocatedCourseRunAssignmentKeys.length > 1;
return {
allocatedCourseRunAssignmentKeys: ['course-v1:edx+H200+2018', 'course-v1:edx+H200+2T2020'],
allocatedCourseRunAssignments: [test2, test3],
hasAssignedCourseRuns: true,
hasMultipleAssignedCourseRuns: true,
allocatedCourseRunAssignmentKeys,
allocatedCourseRunAssignments,
hasAssignedCourseRuns,
hasMultipleAssignedCourseRuns,
};
}
return {
Expand All @@ -931,12 +800,28 @@ export function determineAllocatedCourseRuns({
};
}

/**
* Transform course metadata to display available runs with multiple allocated course runs
*
* @param hasMultipleAssignedCourseRuns
* @param courseMetadata
* @param allocatedCourseRunAssignmentKeys
* @returns {
* * |
* (* &
* {
* courseRuns: *,
* availableCourseRuns: *
* }
* )
* }
*/
export function transformCourseMetadataByAllocationCourseRun({
hasMultipleAssignedCourseRuns,
courseMetadata,
allocatedCourseRunAssignmentKeys,
}) {
if (true || hasMultipleAssignedCourseRuns && allocatedCourseRunAssignmentKeys.length > 1) {
if (hasMultipleAssignedCourseRuns && allocatedCourseRunAssignmentKeys.length > 1) {
return {
...courseMetadata,
courseRuns: courseMetadata.courseRuns.filter(
Expand All @@ -950,6 +835,31 @@ export function transformCourseMetadataByAllocationCourseRun({
return courseMetadata;
}

/**
* Takes assignments with the earliestPossibleExpirationDate field and sorts by the
* soonest expiring expiration date, along with returns relevant metadata
*
* @param assignmentObjectArray
* @param dateFormat
* @returns {
* {
* date: (*|string),
* reason: string,
* sortedExpirationDateData: *,
* soonestExpirationDateData: *
* } |
* {
* date: null,
* reason: null,
* sortedExpirationDateData: null
* } |
* {
* date: null,
* reason: null,
* sortedByExpirationDate: null
* }
* }
*/
export function getSoonestEarliestPossibleExpirationData({
assignmentObjectArray,
dateFormat = null,
Expand Down
13 changes: 8 additions & 5 deletions src/components/course/course-header/CourseImportantDates.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
} from '@openedx/paragon';
import { Calendar } from '@openedx/paragon/icons';
import dayjs from 'dayjs';
import { useParams } from 'react-router-dom';
import { useParams, useSearchParams } from 'react-router-dom';
import { defineMessages, useIntl } from '@edx/frontend-platform/i18n';
import { DATE_FORMAT } from '../data';
import {
Expand Down Expand Up @@ -43,24 +43,27 @@ const CourseImportantDates = () => {
const intl = useIntl();
const {
allocatedCourseRunAssignments,
allocatedCourseRunAssignmentKeys,
hasAssignedCourseRuns,
} = determineAllocatedCourseRuns({
redeemableLearnerCreditPolicies,
courseKey,
});

if (!hasAssignedCourseRuns) {
const [searchParams] = useSearchParams();
const courseRunKey = searchParams.get('course_run_key')?.replaceAll(' ', '+');

if (!hasAssignedCourseRuns || !allocatedCourseRunAssignmentKeys.includes(courseRunKey)) {
return null;
}

const { date, soonestExpirationDateData } = getSoonestEarliestPossibleExpirationData({
assignmentObjectArray: allocatedCourseRunAssignments,
dateFormat: `${DATE_FORMAT} h:mm A`,
});

const soonestExpiringAllocatedAssignmentCourseStartDate = courseMetadata.availableCourseRuns.find(
(courseRun) => courseRun.key === soonestExpirationDateData.contentKey,
).start;
(courseRun) => courseRun.key === soonestExpirationDateData?.contentKey,
)?.start;

const enrollByDate = date;
const courseStartDate = dayjs(soonestExpiringAllocatedAssignmentCourseStartDate).format(DATE_FORMAT);
Expand Down
3 changes: 1 addition & 2 deletions src/components/course/data/courseLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,10 @@ export default function makeCourseLoader(queryClient) {
const lateEnrollmentBufferDays = getLateEnrollmentBufferDays(
redeemableLearnerCreditPoliciesLoader.redeemablePolicies,
);
const keys = ['course-v1:edX+H200+2018', 'course-v1:edX+H200+2T2020'];
const transformedCourseMetadata = transformCourseMetadataByAllocationCourseRun({
hasMultipleAssignedCourseRuns,
courseMetadata,
allocatedCourseRunAssignmentKeys: keys,
allocatedCourseRunAssignmentKeys,
});
return queryClient.ensureQueryData(
queryCanRedeem(enterpriseCustomer.uuid, transformedCourseMetadata, lateEnrollmentBufferDays),
Expand Down

0 comments on commit 3211653

Please sign in to comment.