Route drawer CTAs for MITxOnline programs-as-courses to correct product pages#3063
Open
ChristopherChudzicki wants to merge 5 commits intomainfrom
Open
Route drawer CTAs for MITxOnline programs-as-courses to correct product pages#3063ChristopherChudzicki wants to merge 5 commits intomainfrom
ChristopherChudzicki wants to merge 5 commits intomainfrom
Conversation
…API enum generation Extract ResourceTypeGroupChoiceField and ComputedResourceTypeGroupField from the inline SerializerMethodField so that drf-spectacular generates a proper ResourceTypeGroupEnum instead of a plain string. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
resource_type_group is now typed as ResourceTypeGroupEnum instead of string. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…urses/p/
When the MITxOnline product pages feature flag is enabled, programs with
resource_type_group="course" now link to /courses/p/{readable_id} instead of
/programs/{readable_id}. Also adds resource_type_group to test factories and
test coverage for the program-as-course routing.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refines the resource_type_group concept across the backend API, OpenAPI specs, and frontend, so clients can reliably treat it as a first-class enum and correctly route “program displayed as course” content on MITxOnline product pages.
Changes:
- Introduces reusable DRF fields for
resource_type_group, including a computed, read-only serializer field for learning resources. - Updates OpenAPI specs (v0/v1) to document
resource_type_groupmore clearly and represent it as an enum (including addingResourceTypeGroupEnumto v0). - Updates frontend routing + tests + factories to handle MITxOnline “program-as-course” links using
resource_type_group.
Reviewed changes
Copilot reviewed 8 out of 10 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| openapi/specs/v1.yaml | Updates descriptions and schema typing for resource_type_group across query params and component schemas. |
| openapi/specs/v0.yaml | Adds ResourceTypeGroupEnum and updates resource_type_group fields to reference it. |
| learning_resources/serializers.py | Adds ResourceTypeGroupChoiceField and ComputedResourceTypeGroupField; replaces SerializerMethodField usage. |
| learning_resources/constants.py | Adds RESOURCE_TYPE_GROUP_CHOICES derived from RESOURCE_TYPE_GROUP_VALUES for DRF choice fields. |
| learning_resources_search/serializers.py | Reuses the shared ResourceTypeGroupChoiceField for the search request serializer. |
| frontends/main/src/page-components/LearningResourceExpanded/CallToActionSection.tsx | Routes MITxOnline programs to course-style pages when resource_type_group indicates “course”. |
| frontends/main/src/page-components/LearningResourceExpanded/CallToActionSection.test.tsx | Adds coverage for the MITxOnline “program-as-course” routing behavior under the feature flag. |
| frontends/api/src/test-utils/factories/learningResources.ts | Ensures factory resources include resource_type_group to match the new generated typings. |
| frontends/api/src/generated/v1/api.ts | Updates generated types so resource_type_group is ResourceTypeGroupEnum instead of string. |
| frontends/api/src/generated/v0/api.ts | Adds ResourceTypeGroupEnum and updates generated types accordingly. |
You can also share your feedback on Copilot code review. Take the survey.
Comment on lines
+49
to
+52
| """ | ||
| Choices+Descriptions for resource_type_group field, which is a higher level grouping | ||
| than resource_type. The _CHOICES version is for DRF field choices. | ||
| """ |
Comment on lines
4467
to
4476
| description: |- | ||
| The resource type group for UI grouping. | ||
|
|
||
| For courses/programs, this is derived from resource_category | ||
| (which may differ from resource_type). | ||
| For all other types, returns "learning_material". | ||
|
|
||
| * `course` - Course | ||
| * `program` - Program | ||
| * `learning_material` - Learning Material |
Comment on lines
4995
to
5004
| description: |- | ||
| The resource type group for UI grouping. | ||
|
|
||
| For courses/programs, this is derived from resource_category | ||
| (which may differ from resource_type). | ||
| For all other types, returns "learning_material". | ||
|
|
||
| * `course` - Course | ||
| * `program` - Program | ||
| * `learning_material` - Learning Material |
Comment on lines
5548
to
5557
| description: |- | ||
| The resource type group for UI grouping. | ||
|
|
||
| For courses/programs, this is derived from resource_category | ||
| (which may differ from resource_type). | ||
| For all other types, returns "learning_material". | ||
|
|
||
| * `course` - Course | ||
| * `program` - Program | ||
| * `learning_material` - Learning Material |
Comment on lines
6092
to
6101
| description: |- | ||
| The resource type group for UI grouping. | ||
|
|
||
| For courses/programs, this is derived from resource_category | ||
| (which may differ from resource_type). | ||
| For all other types, returns "learning_material". | ||
|
|
||
| * `course` - Course | ||
| * `program` - Program | ||
| * `learning_material` - Learning Material |
Comment on lines
13567
to
+13581
| resource_type_group: | ||
| type: array | ||
| items: | ||
| $ref: '#/components/schemas/ResourceTypeGroupEnum' | ||
| description: "The resource type grouping of learning resource \ | ||
| \ \n\n* `course` - Course\n* `program` - Program\n* `learning_material`\ | ||
| \ - Learning Material" | ||
| allOf: | ||
| - $ref: '#/components/schemas/ResourceTypeGroupEnum' | ||
| description: |- | ||
| The resource type group for UI grouping. | ||
|
|
||
| For courses/programs, this is derived from resource_category | ||
| (which may differ from resource_type). | ||
| For all other types, returns "learning_material". | ||
|
|
||
| * `course` - Course | ||
| * `program` - Program | ||
| * `learning_material` - Learning Material |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What are the relevant tickets?
Closes https://github.com/mitodl/hq/issues/10538
Description (What does it do?)
When the MITxOnline product pages feature flag is enabled, search drawer CTA links for MITxOnline resources now route to the correct product page based on
resource_type_group:/courses/{readable_id}/courses/p/{readable_id}/programs/{readable_id}Previously, all MITxOnline programs linked to
/programs/{readable_id}becausedisplay_modewas hardcoded tonull.Implementation overview
resource_type_groupfrom aSerializerMethodField(typed asstringin OpenAPI) to aComputedResourceTypeGroupFieldbacked byResourceTypeGroupChoiceField. This causes drf-spectacular to generate a properResourceTypeGroupEnuminstead of a plain string, giving the frontend typed values to branch on.getResourceUrlinCallToActionSection.tsxnow checksresource.resource_type_group === ResourceTypeGroupEnum.Courseto passDisplayModeEnum.CoursetoprogramPageView, routing program-as-course resources to/courses/p/.resource_type_groupto their appropriate enum value.How can this be tested?
mitxonline-product-pagesfeature flag in PostHog.display_mode="course"(i.e.,resource_type_group="course")./courses/p/{readable_id}, not/programs/{readable_id}./programs/{readable_id}./courses/{readable_id}.yarn test frontends/main/src/page-components/LearningResourceExpanded/CallToActionSection.test.tsx