Skip to content

Route drawer CTAs for MITxOnline programs-as-courses to correct product pages#3063

Open
ChristopherChudzicki wants to merge 5 commits intomainfrom
cc/drawer-links
Open

Route drawer CTAs for MITxOnline programs-as-courses to correct product pages#3063
ChristopherChudzicki wants to merge 5 commits intomainfrom
cc/drawer-links

Conversation

@ChristopherChudzicki
Copy link
Contributor

@ChristopherChudzicki ChristopherChudzicki commented Mar 17, 2026

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/courses/{readable_id}
  • Programs displayed as courses/courses/p/{readable_id}
  • Programs/programs/{readable_id}

Previously, all MITxOnline programs linked to /programs/{readable_id} because display_mode was hardcoded to null.

Implementation overview

  • Backend serializers: Refactored resource_type_group from a SerializerMethodField (typed as string in OpenAPI) to a ComputedResourceTypeGroupField backed by ResourceTypeGroupChoiceField. This causes drf-spectacular to generate a proper ResourceTypeGroupEnum instead of a plain string, giving the frontend typed values to branch on.
  • Drawer CTA: getResourceUrl in CallToActionSection.tsx now checks resource.resource_type_group === ResourceTypeGroupEnum.Course to pass DisplayModeEnum.Course to programPageView, routing program-as-course resources to /courses/p/.
  • Test factories: All resource type factories now set resource_type_group to their appropriate enum value.
  • Test coverage: Added a test case for the program-as-course drawer CTA routing.

How can this be tested?

  1. Enable the mitxonline-product-pages feature flag in PostHog.
  2. Search for a MITxOnline program that has display_mode="course" (i.e., resource_type_group="course").
  3. Open the search drawer for that resource.
  4. Verify the CTA links to /courses/p/{readable_id}, not /programs/{readable_id}.
  5. Verify regular MITxOnline programs still link to /programs/{readable_id}.
  6. Verify MITxOnline courses still link to /courses/{readable_id}.
  7. yarn test frontends/main/src/page-components/LearningResourceExpanded/CallToActionSection.test.tsx

ChristopherChudzicki and others added 3 commits March 17, 2026 14:55
…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>
Copilot AI review requested due to automatic review settings March 17, 2026 19:03
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_group more clearly and represent it as an enum (including adding ResourceTypeGroupEnum to 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
ChristopherChudzicki and others added 2 commits March 17, 2026 15:12
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants