-
Notifications
You must be signed in to change notification settings - Fork 3
fix non-lexicographical ordering in org dashboard programs / program collections #2523
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -131,13 +131,9 @@ const ProgramDescription = styled(Typography)({ | |
// Custom hook to handle multiple program queries and check if any have courses | ||
const useProgramCollectionCourses = (programIds: number[], orgId: number) => { | ||
const programQueries = useQueries({ | ||
queries: programIds.map((programId) => ({ | ||
...programsQueries.programsList({ id: programId, org_id: orgId }), | ||
queryKey: [ | ||
...programsQueries.programsList({ id: programId, org_id: orgId }) | ||
.queryKey, | ||
], | ||
})), | ||
queries: programIds.map((programId) => | ||
programsQueries.programsList({ id: programId, org_id: orgId }), | ||
), | ||
}) | ||
|
||
const isLoading = programQueries.some((query) => query.isLoading) | ||
|
@@ -175,6 +171,25 @@ const OrgProgramCollectionDisplay: React.FC<{ | |
const sanitizedDescription = DOMPurify.sanitize(collection.description ?? "") | ||
const { isLoading, programsWithCourses, hasAnyCourses } = | ||
useProgramCollectionCourses(collection.programIds, orgId) | ||
const firstCourseIds = programsWithCourses | ||
.map((p) => p?.program.courseIds[0]) | ||
.filter((id): id is number => id !== undefined) | ||
const courses = useQuery({ | ||
...coursesQueries.coursesList({ | ||
id: firstCourseIds, | ||
org_id: orgId, | ||
}), | ||
enabled: firstCourseIds.length > 0, | ||
}) | ||
const rawCourses = | ||
courses.data?.results.sort((a, b) => { | ||
return firstCourseIds.indexOf(a.id) - firstCourseIds.indexOf(b.id) | ||
}) ?? [] | ||
Comment on lines
+184
to
+187
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As far as I can tell, program collections have no ordering of the associated programs. So if the UAI vertical modules on prod look correct, great, but I don't think that's guaranteed by anything, is it? I.e., there's (currently) no way in wagtail / mitxonline admin to set the order of these programs, is there? ![]() There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a good point. I suppose it would preserve whatever ordering is passed back from the API though, nonetheless. |
||
const transformedCourses = transform.organizationCoursesWithContracts({ | ||
courses: rawCourses, | ||
contracts: contracts ?? [], | ||
enrollments: enrollments ?? [], | ||
}) | ||
|
||
const header = ( | ||
<ProgramHeader> | ||
|
@@ -214,17 +229,26 @@ const OrgProgramCollectionDisplay: React.FC<{ | |
<ProgramRoot data-testid="org-program-collection-root"> | ||
{header} | ||
<PlainList> | ||
{programsWithCourses.map((item) => | ||
item ? ( | ||
<ProgramCollectionItem | ||
key={item.programId} | ||
program={item.program} | ||
contracts={contracts} | ||
enrollments={enrollments} | ||
orgId={orgId} | ||
{courses.isLoading && | ||
programsWithCourses.map((item) => ( | ||
<Skeleton | ||
key={item?.programId} | ||
width="100%" | ||
height="65px" | ||
style={{ marginBottom: "16px" }} | ||
/> | ||
) : null, | ||
)} | ||
))} | ||
{transformedCourses.map((course) => ( | ||
<DashboardCardStyled | ||
Component="li" | ||
key={course.key} | ||
dashboardResource={course} | ||
courseNoun="Module" | ||
offerUpgrade={false} | ||
titleHref={course.run?.coursewareUrl} | ||
buttonHref={course.run?.coursewareUrl} | ||
/> | ||
))} | ||
</PlainList> | ||
</ProgramRoot> | ||
) | ||
|
@@ -260,8 +284,12 @@ const OrgProgramDisplay: React.FC<{ | |
<Skeleton width="100%" height="65px" style={{ marginBottom: "16px" }} /> | ||
) | ||
if (programLoading || courses.isLoading) return skeleton | ||
const rawCourses = | ||
courses.data?.results.sort((a, b) => { | ||
return program.courseIds.indexOf(a.id) - program.courseIds.indexOf(b.id) | ||
}) ?? [] | ||
const transformedCourses = transform.organizationCoursesWithContracts({ | ||
courses: courses.data?.results ?? [], | ||
courses: rawCourses, | ||
contracts: contracts ?? [], | ||
enrollments: courseRunEnrollments ?? [], | ||
}) | ||
|
@@ -307,59 +335,6 @@ const OrgProgramDisplay: React.FC<{ | |
) | ||
} | ||
|
||
const ProgramCollectionItem: React.FC<{ | ||
program: DashboardProgram | ||
contracts?: ContractPage[] | ||
enrollments?: CourseRunEnrollment[] | ||
orgId: number | ||
}> = ({ program, contracts, enrollments, orgId }) => { | ||
return ( | ||
<ProgramCard | ||
program={program} | ||
contracts={contracts} | ||
enrollments={enrollments} | ||
orgId={orgId} | ||
/> | ||
) | ||
} | ||
|
||
const ProgramCard: React.FC<{ | ||
program: DashboardProgram | ||
contracts?: ContractPage[] | ||
enrollments?: CourseRunEnrollment[] | ||
orgId: number | ||
}> = ({ program, contracts, enrollments, orgId }) => { | ||
const courses = useQuery( | ||
coursesQueries.coursesList({ | ||
id: program.courseIds, | ||
org_id: orgId, | ||
}), | ||
) | ||
const skeleton = ( | ||
<Skeleton width="100%" height="65px" style={{ marginBottom: "16px" }} /> | ||
) | ||
if (courses.isLoading) return skeleton | ||
const transformedCourses = transform.organizationCoursesWithContracts({ | ||
courses: courses.data?.results ?? [], | ||
contracts: contracts ?? [], | ||
enrollments: enrollments ?? [], | ||
}) | ||
if (courses.isLoading || !transformedCourses.length) return skeleton | ||
// For now we assume the first course is the main one for the program. | ||
const course = transformedCourses[0] | ||
return ( | ||
<DashboardCard | ||
Component="li" | ||
key={program.key} | ||
dashboardResource={course} | ||
courseNoun={"Module"} | ||
offerUpgrade={false} | ||
titleHref={course.run.coursewareUrl ?? ""} | ||
buttonHref={course.run.coursewareUrl ?? ""} | ||
/> | ||
) | ||
} | ||
|
||
const OrganizationRoot = styled.div({ | ||
display: "flex", | ||
flexDirection: "column", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is another example of something TS ^5.5 will catch automatically, no need for the
id is number
part.Inferred Type Predicates