Repository navigation
feat: support mixed course and pathway search responses [FC-0137] - #175
brian-smith-tcril merged 17 commits into
Conversation
|
Thanks for the pull request, @rpenido! This repository is currently maintained by Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review. 🔘 Get product approvalIf you haven't already, check this list to see if your contribution needs to go through the product review process.
🔘 Provide contextTo help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:
🔘 Get a green buildIf one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green. DetailsWhere can I find more information?If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources: When can I expect my changes to be merged?Our goal is to get community contributions seen and reviewed as efficiently as possible. However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:
💡 As a result it may take up to several weeks or months to complete a review and merge your PR. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #175 +/- ##
==========================================
+ Coverage 99.56% 99.57% +0.01%
==========================================
Files 101 101
Lines 682 708 +26
Branches 169 166 -3
==========================================
+ Hits 679 705 +26
Misses 2 2
Partials 1 1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
This looks solid to me 👍🏻 I'll Brian take a pass once the PR below this (#174) is ready |
kdmccormick
left a comment
There was a problem hiding this comment.
Pending #174 , this look good to me.
@brian-smith-tcril , could you also give this one a technical review? Just the last commit (refactor: support mixed course and pathway search responses); the others commits are in #174
4192786 to
e87d4fd
Compare
6076ab4 to
089a0cd
Compare
brian-smith-tcril
left a comment
There was a problem hiding this comment.
Thanks for splitting these PRs up! I looked through a bit of the diff against #174 and things are mostly looking good! I did notice a couple things, so I had Claude write up a few inline comments.
The inline comments were drafted with Claude Code and reviewed before posting.
| type CourseResult = Extract<CatalogSearchResult, { type: 'course' | '_doc' }>; | ||
|
|
||
| /** The home list renders course cards only until pathway cards land. */ | ||
| const isCourseResult = (result: CatalogSearchResult): result is CourseResult => result.type !== 'pathway'; |
There was a problem hiding this comment.
I think we could use switch/case to clarify the intention here, with pathway rendering nothing for now and course plus default rendering the course card:
{catalogData?.results?.map((result) => {
switch (result.type) {
case 'pathway':
return null;
case 'course':
default:
return <HomeCourseCardSlot key={result.id} original={result} />;
}
})}This makes the "anything we don't recognize is a course" behavior explicit. It also means the isCourseResult guard and the CourseResult type can go away since the switch narrows the type for us (and sets up a pathway case for #176 and #177 to use).
There was a problem hiding this comment.
Good call, updated to a switch/case in e405209. The isCourseResult guard and CourseResult type are gone; pathway returns null for now, and course/default render the course card.
| export type CatalogSearchResult = | ||
| | { | ||
| id: string; | ||
| index?: string; | ||
| type: 'course' | '_doc'; | ||
| title?: string; | ||
| data: CourseData; | ||
| } | ||
| | { | ||
| id: string; | ||
| index?: string; | ||
| type: 'pathway'; | ||
| title?: string; | ||
| data: PathwayData; | ||
| }; |
There was a problem hiding this comment.
Could this be Course | Pathway instead of two new object types? They already have the same fields (id, index?, type, data), and the card slots already take them as original?: Course (and original?: Pathway once #176 lands). The only thing missing is for type to be specific enough to tell them apart:
// src/generic/course-card/types.ts
export interface Course {
// ...
type: 'course' | '_doc';
}
// src/generic/pathway-card/types.ts
export interface Pathway {
// ...
type: 'pathway';
}
// src/data/catalog-search/types.ts
export type CatalogSearchResult = Course | Pathway;On the course side the only fallout I found is mockCourseResponse in src/__mocks__/course.ts, which doesn't set type today and would need type: '_doc'. This also drops title, which nothing reads and which the ADR's new response shape leaves out anyway.
There was a problem hiding this comment.
Agreed, done in 96d61f8. CatalogSearchResult is now Course | Pathway, Course.type is 'course' | '_doc', Pathway.type is 'pathway', and title is gone. mockCourseResponse now sets type: '_doc'.
| /** | ||
| * The search response can mix courses and pathways; narrow to the course arm | ||
| * before reading course-only fields off `data`. | ||
| */ | ||
| type CourseResult = Extract<CatalogSearchResult, { type: 'course' | '_doc' }>; | ||
| const isCourseResult = (result: CatalogSearchResult): result is CourseResult => result.type !== 'pathway'; | ||
| const courseResults = mockCatalogSearchResponse.results.filter(isCourseResult); |
There was a problem hiding this comment.
Could the mock export its course rows with the course type already on them?
export const mockCourseResults: Course[] = [ /* the three rows */ ];
export const mockCatalogSearchResponse: CatalogSearchResponse = {
// ...
results: mockCourseResults,
};Then this test can read mockCourseResults[index] and this block isn't needed. When #176 adds pathway rows, they can go in a mockPathwayResults next to it, and the tests that only care about courses don't have to change.
There was a problem hiding this comment.
Good idea, done in 30b97b0. The mock now exports mockCourseResults: Course[], the search response reuses it, and the HomePage and CatalogPage tests read it directly. The filter guard is gone from both.
| /** Future category badge fields. */ | ||
| category?: string; | ||
| categoryLabel?: string; | ||
| categoryBackgroundColor?: string; | ||
| categoryTextColor?: string; |
There was a problem hiding this comment.
"Future" confused me here (same on PathwayCardProps above). I tracked it back to db76b2d in #169, when the response shape was still to be decided; now that the ADR specifies it, I'd drop the comment.
Also, the ADR's Category registry section says
Pathway
dataincludes requiredcategoryandcategory_labeland optionalcategory_background_color/category_text_color.
but all four are optional here. I'm not sure which one is right, but we should make sure they're aligned.
There was a problem hiding this comment.
Good catch. I made both colors required as well in 083aa69, since the backend always provides them, and updated the ADR in #174 (5e5d27e). PathwayData now requires category, categoryLabel, categoryBackgroundColor, and categoryTextColor. Since the backend owns the colors, I am planning to drop the frontend default badge palette for pathways in #176 and render the backend colors directly.
| @@ -0,0 +1,40 @@ | |||
| export interface PathwayCardProps { | |||
There was a problem hiding this comment.
Nothing in this PR reads PathwayCardProps (its first reader is PathwayCard in #176). I think it makes more sense to wait until there's something using it to add it.
| ...camelCaseObject(facet), | ||
| // Preserve dynamic slug/label keys exactly. | ||
| terms: facet.terms, | ||
| ...(facet.labels ? { labels: facet.labels } : {}), | ||
| }, |
There was a problem hiding this comment.
Keeping terms verbatim fixes a bug on master: camelCaseObject was rewriting the facet term keys that transformAggregationsToFilterChoices sends back as filter values, so any org or slug lodash alters (open-edx → openEdx) never matched. Since that stands on its own, would you mind breaking it out (with the test for it) into a separate PR ahead of this one? labels is new with the ADR's response and belongs here.
297c6f2 to
19520c3
Compare
625e07f to
47a89ee
Compare
47a89ee to
8848af5
Compare
|
Hi @brian-smith-tcril! This is the next one in the stack. I already rebased it, and I think I addressed your previous review. |
|
This one is looking great! Had Claude write up a comment with something I noticed but I think we're really close here! Note This comment was written by Claude (Claude Code) and reviewed before posting. The change to I think those two slots need new ids, so the new slots can carry the new type while the old ones keep the shape they have today:
|
Thanks, @brian-smith-tcril! You are right that the old ids cannot keep a course-only contract while also rendering pathways, so here is the end state we would like to agree on before moving the ids:
To be explicit about the trade-off: this shape still has a breaking change ( 💥 ), and I think it is unavoidable. Once a response contains pathways, the old card view cannot keep both its course-only props and its place in the single grid; it either stops rendering, receives rows it was not written for, or silently hides the pathway rows. We picked "stops rendering", so the break is scoped to mixed responses, and the deprecated READMEs in #178 would say exactly that: the old ids keep working for course-only responses and stop applying once pathways are present. The shape in #177 would be: <Slot id="...catalogDataTableCardView.v1" displayData={displayData}>
{hasPathways ? (
<CardView CardComponent={ResultCard} />
) : (
<Slot id="...courseCatalogDataTableCardView.v1" displayData={courseDisplayData}>
<CardView CardComponent={CatalogDataTableCourseCardSlot} />
</Slot>
)}
</Slot>The current #177 dispatch lives under the old id (card view, pathway card), so that is the part we would move. Does this work for you? |
|
I don't think there's an unavoidable breaking change here. With my previous suggested shape <Slot id="...catalogDataTableCardView.v1" displayData={displayData}>
<Slot id="...courseCatalogDataTableCardView.v1" displayData={courseDisplayData}>
<CardView CardComponent={ResultCard} />
</Slot>
</Slot>the idea would be to filter that data going into It seems filtering/conditionally doing things based on if something is a course or pathway will need to happen in a few places, and I think having switch (result.type) {
case 'pathway':
return { ...result, type: 'pathway' };
case 'course':
default:
return { ...result, type: 'course' };
}then we could filter what we get here nicely (as in, not assuming const courseDisplayData = displayData && {
...displayData,
results: displayData.results.filter((result) => result.type === 'course'),
};This would make it so This would leave the conditional rendering of the It's possible I'm missing something here, so please push back if I am! Looking forward to hearing your thoughts! |
|
My bad @brian-smith-tcril! Your proposed shape works. |
|
Thanks for updating this! I asked Claude to give it another pass and this is what it came up with: Note This comment was written by Claude (Claude Code) and reviewed before posting. The new commits have the slot shape from the thread above:
A few things came up while reading the three commits:
|
|
Thanks @brian-smith-tcril! All five points are addressed:
One note: a site that replaces |
brian-smith-tcril
left a comment
There was a problem hiding this comment.
This looks great! Thanks for working through it with me!
Approving with a couple README suggestions.
As for
One note: a site that replaces courseCatalogDataTable.v1 or courseCatalogDataTableCardView.v1 receives only course rows, so no pathway cards render there, as they are filtered out. Is that the desired behavior, right? I'm not super happy with it, but I think it is the best we can do without adding a breaking change to the components that use the old id.
It also doesn't feel perfect to me, but it feels like the best way to avoid surprising behavior. I would expect someone using the courseCatalog* slots to have built it with only courses in mind, and there's no way to know how any given plugin would react to suddenly getting pathways data.
I'd also think it should be pretty easy for plugin authors to update their plugins to use the new catalog* slots and make sure everything works as they want it to when pathways data is included.
|
|
||
| ### Slot ID: `org.openedx.frontend.slot.catalog.catalogDataTable.v1` | ||
|
|
||
| > **Deprecated id:** `org.openedx.frontend.slot.catalog.catalogDataTable.v1` is still rendered for compatibility. It still receives a course-only `CourseListSearchResponse` with `totalCourses`. New code should use the id above. |
There was a problem hiding this comment.
| > **Deprecated id:** `org.openedx.frontend.slot.catalog.catalogDataTable.v1` is still rendered for compatibility. It still receives a course-only `CourseListSearchResponse` with `totalCourses`. New code should use the id above. | |
| > **Deprecated id:** `org.openedx.frontend.slot.catalog.courseCatalogDataTable.v1` is still rendered for compatibility. It still receives a course-only `CourseListSearchResponse` with `totalCourses`. New code should use the id above. |
|
|
||
| ### Slot ID: `org.openedx.frontend.slot.catalog.catalogDataTableCardView.v1` | ||
|
|
||
| > **Deprecated id:** `org.openedx.frontend.slot.catalog.catalogDataTableCardView.v1` is still rendered for compatibility. It still receives a course-only `CourseListSearchResponse`. New code should use the id above. |
There was a problem hiding this comment.
| > **Deprecated id:** `org.openedx.frontend.slot.catalog.catalogDataTableCardView.v1` is still rendered for compatibility. It still receives a course-only `CourseListSearchResponse`. New code should use the id above. | |
| > **Deprecated id:** `org.openedx.frontend.slot.catalog.courseCatalogDataTableCardView.v1` is still rendered for compatibility. It still receives a course-only `CourseListSearchResponse`. New code should use the id above. |
|
|
||
| > **Deprecated id:** `org.openedx.frontend.slot.catalog.catalogDataTableCardView.v1` is still rendered for compatibility. It still receives a course-only `CourseListSearchResponse`. New code should use the id above. | ||
|
|
||
| > **Previous documentation:** [README.catalogDataTableCardView.v1.md](./README.catalogDataTableCardView.v1.md). |
There was a problem hiding this comment.
| > **Previous documentation:** [README.catalogDataTableCardView.v1.md](./README.catalogDataTableCardView.v1.md). | |
| > **Previous documentation:** [README.courseCatalogDataTableCardView.v1.md](./README.courseCatalogDataTableCardView.v1.md). |
|
|
||
| > **Deprecated id:** `org.openedx.frontend.slot.catalog.catalogDataTable.v1` is still rendered for compatibility. It still receives a course-only `CourseListSearchResponse` with `totalCourses`. New code should use the id above. | ||
|
|
||
| > **Previous documentation:** [README.catalogDataTable.v1.md](./README.catalogDataTable.v1.md). |
There was a problem hiding this comment.
| > **Previous documentation:** [README.catalogDataTable.v1.md](./README.catalogDataTable.v1.md). | |
| > **Previous documentation:** [README.courseCatalogDataTable.v1.md](./README.courseCatalogDataTable.v1.md). |
|
|
||
| ### Slot Props | ||
|
|
||
| * `displayData?: CatalogSearchResponse` — the catalog search response (results, total count, aggregations, and other metadata). |
There was a problem hiding this comment.
| * `displayData?: CourseListSearchResponse` — the catalog search response (results, total count, aggregations, and other metadata) including only courses. |
|
|
||
| ### Slot Props | ||
|
|
||
| * `displayData?: CatalogSearchResponse` — the catalog search response containing results, total count, aggregations, and other metadata. |
There was a problem hiding this comment.
| * `displayData?: CourseListSearchResponse` — the catalog search response for courses only containing results, total count, aggregations, and other metadata. |
| + if (!displayData?.results) { return null; } | ||
| + return ( | ||
| + <div style={{ display: 'grid', gridTemplateColumns: 'repeat(2, 1fr)', gap: '2rem' }}> | ||
| + {displayData.results.map((course) => ( |
There was a problem hiding this comment.
This one is optional, if you'd rather leave it and wait until we have a slot that can handle pathways here that works for me.
| + {displayData.results.map((course) => ( | |
| + {displayData.results.filter((result) => result.type === 'course').map((course) => ( |
|
🎉 This PR is included in version 1.0.0-alpha.6 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Description
This PR teaches the catalog search data layer to return mixed course and pathway results. It does not render pathways yet; the cards land in the next PR. The request still goes to the legacy
course_list_searchendpoint, which returns courses only, so there is no visible change.Changes:
SearchResponseBase,CatalogSearchResultandCatalogSearchResponse, where a result is aCourseor aPathway.PathwayDatais the pathway payload type; the card component comes in the next PR.result.typeinnormalizeCatalogSearchResponse: pathway rows staypathwayand every other row becomescourse, so callers can testtype === 'course'instead of!== 'pathway'. The legacy_docarm is removed fromCourse.labelsto aggregation facets, and preserves the dynamic keys underaggs.*.labels, which are backend slugs and must be sent back verbatim as filter values. Theaggs.*.termsfix is in fix: preserve facet term keys in catalog search responses [FC-0137] #185.catalogDataTable.v1andcatalogDataTableCardView.v1slot ids. Both carry the mixed response and wrap the deprecatedcourseCatalogDataTable.v1andcourseCatalogDataTableCardView.v1, which keepCourseListSearchResponseandtotalCoursesand only receive course rows.totalItemsis the new data table prop.CourseListSearchResponseto its pre-pathway declaration and exports it next toCatalogSearchResponse.useCatalogDataand the page types to the mixed response.Supporting information
Part of the catalog split from #169. Branch
rpenido/fal-4374/mixed-catalog-search, based onmasteron top of the merged #174. The API contract this prepares for is indocs/decisions/0003-use-a-generic-catalog-search-endpoint.rst, added by the previous PR.Testing instructions
.nvmrcand install dependencies withnpm ci.npm run devagainst a running Open edX instance.catalogDataTableorcatalogDataTableCardViewfrom a site config and verify the custom component receives the mixedCatalogSearchResponse. Repeat with the deprecatedcourseCatalogDataTableandcourseCatalogDataTableCardViewids and verify they receive course rows only.AI disclosure: Use Claude to help with the split and drafting this pull request description.
Private ref: FAL-4374