-
Notifications
You must be signed in to change notification settings - Fork 0
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
useResourceSearchParams
and export AvailableFacets component
#78
Conversation
9641412
to
512230e
Compare
512230e
to
baafa59
Compare
const useValidatedSearchParams = <ReqParams>({ | ||
searchParams, | ||
setSearchParams, | ||
facets = [], | ||
validators, | ||
onFacetsChange | ||
}: UseValidatedSearchParamsProps<ReqParams> & { | ||
validators: QueryParamValidators<ReqParams> | ||
}): UseValidatedSearchParamsResult<ReqParams> => { |
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.
There are some notable differences in these hooks vs the useSearchQueryParams
, which these two hooks replace.
-
"Facets" are less special: The old hook returned a
params
object with shape{ queryText, sort, activeFacets }
. Everything was a facet except queryText andsort
.This was problematic for some UIs, e.g., this one which has (A) resource tbas and (B) a sidebar for facets. Previously, the "Clear All" button would reset the resource tab, even though it's not part of the filtering sidebar.
In the new hooks, facets are determined by a parameter,
facets
, andclearAllFacets
only clears the parameters that are listed asfacets
. -
Two separate hooks for for
/api/v1/learning_resources_search
and/api/v1/content_files_search
. This makes the typescript much simpler, and seems reasonable since the APIs are separate. -
Uses API parameter names, not abbreviations. ("department" not "d").
@@ -47,8 +47,53 @@ const resultsWithLabels = ( | |||
return newResults | |||
} | |||
|
|||
const AvailableFacets: React.FC<Omit<FacetDisplayProps, "clearAllFilters">> = ({ |
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.
FacetDisplay
consisted over three portions:
- A title, "Facets" and "Clear All" button
- the "Active Facets", displayed in OCW as "chips" with rounded corners
- a list of the "Available Facets"
In MIT Open, we do not want (2). Since (1) is simple, it can be implemented easily in MIT Open.
But (3) is worth exporting on its own.
@@ -37,6 +37,7 @@ | |||
}, | |||
"homepage": "https://github.com/mitodl/course-search-utils#readme", | |||
"dependencies": { | |||
"@mitodl/open-api-axios": "^2024.3.22", |
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.
Originally, I was not going to introduce the @mitodl/open-api-axios
client in this PR. However, the client previously committed in this repo was missing the new resource_type: Video
which caused some type errors in MIT Open, so I went ahead and replaced the client in this PR.
useResourceSearchParams
and export AvailableFacets component
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.
👍
What are the relevant tickets?
-Issue Remove generated API client, use published client instead #76
Description (What does it do?)
This PR:
useSearchQueryParams
, which has not been used in any production codeuseResourceSearchParams
,useContentFileSearchParams
. These hooks:/api/v1/learning_resource_search
or/api/v1/content_file_search
based on a URLSearchParams object.AvailableFacets
, a portion of the existingFacetDisplay
component.How can this be tested?
Test by instructions in mitodl/mit-learn#675