Skip to content
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

Search page cleanup #675

Merged
merged 11 commits into from
Mar 27, 2024
Merged

Search page cleanup #675

merged 11 commits into from
Mar 27, 2024

Conversation

ChristopherChudzicki
Copy link
Contributor

What are the relevant tickets?

For #640

Description (What does it do?)

This PR makes several changes to the search page:

  1. Removes the "Active Facets" display above facet list. (These chips have been removed.)
  2. Now, if a facet is active, its checkbox should always be shown.
  3. The results title count has been removed. (No more '524 results for "Physics".)
  4. "Clear all facets" no longer clears the resource tab selection.
  5. Adds "Offered by" facet.
  6. Facets now use API query names ("department" not "d")
  7. Facets now work even if they aren't explicitly included in UI.
    • e.g., http://localhost:8063/search?platform=mitx

Screenshots (if appropriate):

Screenshot 2024-03-25 at 3 01 27 PM Screenshot 2024-03-25 at 2 50 42 PM

How can this be tested?

  1. Visit http://localhost:8063/search

  2. Try:

    • click resource tabs
    • entering query text
    • toggling left sidebar filters on and off
    • using the "Clear all" filters button

    Things to look out for

    • URL bar should use "real" API parameter names ("department" not "d")
  3. Append a filter not included in the UI to the URL; for example ?platform=mitxonline or (&platform=mitxonline). The results should update.

Additional Context

Copy link

codecov bot commented Mar 25, 2024

Codecov Report

Attention: Patch coverage is 80.00000% with 13 lines in your changes are missing coverage. Please review.

Project coverage is 75.18%. Comparing base (398ad13) to head (59b4be8).
Report is 2 commits behind head on main.

❗ Current head 59b4be8 differs from pull request most recent head be24377. Consider uploading reports for the commit be24377 to get more accurate results

Files Patch % Lines
frontends/api/src/hooks/learningResources/index.ts 20.00% 4 Missing ⚠️
...ends/api/src/hooks/learningResources/keyFactory.ts 0.00% 2 Missing ⚠️
frontends/api/src/test-utils/urls.ts 33.33% 2 Missing ⚠️
...tends/mit-open/src/pages/SearchPage/SearchPage.tsx 95.83% 0 Missing and 2 partials ⚠️
frontends/api/src/clients.ts 50.00% 1 Missing ⚠️
.../api/src/test-utils/factories/learningResources.ts 50.00% 1 Missing ⚠️
...it-open/src/components/CardRowList/CardRowList.tsx 50.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #675      +/-   ##
==========================================
+ Coverage   72.58%   75.18%   +2.59%     
==========================================
  Files         281      260      -21     
  Lines       12581    11721     -860     
  Branches     2184     2030     -154     
==========================================
- Hits         9132     8812     -320     
+ Misses       3265     2727     -538     
+ Partials      184      182       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines 235 to 243
/**
* Augment the facet buckets for `groupKey` with active values that have no
* results.
*/
const includeActiveZerosInBuckets = (
groupKey: string,
aggregations: LearningResourceSearchResponse["metadata"]["aggregations"],
params: LRSearchRequest,
) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@abeglova Maybe the FacetDisplay component should handle this? OCW does seem to add-in active facets with zero count, but I don't think it's in course-search-utils currently?

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree, I think it makes sense for this to be moved to FacetDisplay in course-search-utils.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good. I'd like to do that separately from mitodl/course-search-utils#78, but I can do it before merging this PR.

mitodl/course-search-utils#78 is big enough already, and I'd like replace the Enzyme-based facet tests if I'm going to be adding more there.

@abeglova abeglova self-assigned this Mar 26, 2024
@ChristopherChudzicki ChristopherChudzicki added the Needs Review An open Pull Request that is ready for review label Mar 26, 2024
Copy link
Contributor

@abeglova abeglova left a comment

Choose a reason for hiding this comment

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

This works great!

I agree with you that includeActiveZerosInBuckets should be moved to course-search-utils.

Additionally it looks like you implemented useValidatedSearchParams in course-search-utils but are not using it in this pr - I can search for an invalid param such as http://localhost:8063/search/?topic=monkey and it adds monkey to the topics list

Comment on lines 235 to 243
/**
* Augment the facet buckets for `groupKey` with active values that have no
* results.
*/
const includeActiveZerosInBuckets = (
groupKey: string,
aggregations: LearningResourceSearchResponse["metadata"]["aggregations"],
params: LRSearchRequest,
) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I agree, I think it makes sense for this to be moved to FacetDisplay in course-search-utils.

@ChristopherChudzicki
Copy link
Contributor Author

Additionally it looks like you implemented useValidatedSearchParams in course-search-utils but are not using it in this pr - I can search for an invalid param such as http://localhost:8063/search/?topic=monkey and it adds monkey to the topics list

useValidatedSearchParams isn't actually exported from course-search-utils. But it is used in implementing useResourceSearchParams and useContentFileSearchParams. For example:

const useResourceSearchParams = ({
  searchParams,
  setSearchParams,
  facets = [],
  onFacetsChange
}: UseValidatedSearchParamsProps<ResourceSearchRequest>) => {
  return useValidatedSearchParams<ResourceSearchRequest>({
    searchParams,
    setSearchParams,
    facets,
    validators: resourceSearchValidators,
    onFacetsChange
  })
}

I can search for an invalid param such as http://localhost:8063/search/?topic=monkey and it adds monkey to the topics list

The validation is based on the OpenAPI spec, by which "monkey" is a valid topic. (For topic, the spec just says "string"; department and platform, we have an enum; similarly https://mitopen-rc.odl.mit.edu/api/v1/learning_resources_search/?topic=monkey is a 200 response with zero hits, whereas https://mitopen-rc.odl.mit.edu/api/v1/learning_resources_search/?department=monkey is a 400.) My preference would be to continue validating based only on the OpenAPI spec...It's not detrimental to the UI (since filter choices are populated off the API response) and keeps things simple.

@Ferdi
Copy link

Ferdi commented Mar 27, 2024

@ChristopherChudzicki if it's not too late can we change the order of tabs to all, courses, programs, podcasts ?

@ChristopherChudzicki
Copy link
Contributor Author

@ChristopherChudzicki if it's not too late can we change the order of tabs to all, courses, programs, podcasts ?
Screenshot 2024-03-27 at 11 25 45 AM

@ChristopherChudzicki ChristopherChudzicki merged commit 35e3113 into main Mar 27, 2024
9 checks passed
@odlbot odlbot mentioned this pull request Mar 27, 2024
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Review An open Pull Request that is ready for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants