-
Notifications
You must be signed in to change notification settings - Fork 216
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
Simplify Nuxt query parameter computation #3136
Conversation
Size Change: -609 B (0%) Total Size: 938 kB
ℹ️ View Unchanged
|
2f8d0ab
to
3db4968
Compare
351b8c8
to
eddeee5
Compare
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.
The changes look good to me.
eddeee5
to
57f6449
Compare
6094566
to
f3320ca
Compare
Based on the high urgency of this PR, the following reviewers are being gently reminded to review this PR: @AetherUnbound Excluding weekend1 days, this PR was ready for review 11 day(s) ago. PRs labelled with high urgency are expected to be reviewed within 2 weekday(s)2. @obulat, if this PR is not ready for a review, please draft it to prevent reviewers from getting further unnecessary pings. Footnotes
|
f3320ca
to
e6eb238
Compare
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.
Tests fine for me locally. A handful of non-blocking questions. One is an important request for an explanatory comment, but I don't want to further delay this PR as I was late to review it.
frontend/src/stores/search.ts
Outdated
if (!isSearchTypeSupported(searchType)) { | ||
return { q: searchTerm.trim() } | ||
} |
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 circumstances in which this would be the case? I'm not fully remembering how the supported/non-support search type thing works or why the code needs to handle both cases when only one is actually used (supported).
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.
If you turn on additional_search_types
feature flag and look into the content switcher in the search results page header, the links to the types that are "Coming soon" will have the q=cat
(or whatever) parameter set instead of just linking to /search/video
(which will probably just redirect to the homepage since we don't have a generic media type page without a search term).
frontend/src/stores/search.ts
Outdated
if (query[api_param_name]?.length) { | ||
search_query[api_param_name] = query[api_param_name] | ||
} | ||
const search_query: SearchQuery = { |
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.
Can we change this to use camel case, while we're modifying this function anyway?
const search_query: SearchQuery = { | |
const searchQuery: SearchQuery = { |
frontend/src/stores/media/index.ts
Outdated
const queryParams = useSearchStore() | ||
.searchQueryParams as PaginatedSearchQuery |
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.
Why is the case necessary here? Could we move it into the search store's searchQueryParams
getter? Is there some other way to refine this type that wouldn't require a cast?
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.
search
store can compute all of the parameters except for the page
, which is saved in the media
store.
I was trying not adding the page
parameter to the queryParams
when sending the first search request, that's why I wrote this code like this.
I refactored it now to remove the type cast.
frontend/src/stores/search.ts
Outdated
? this.frontendSearchUrlParams | ||
: computeQueryParams( | ||
searchType, | ||
this.filters, | ||
this.searchTerm, | ||
"frontend" | ||
) |
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's the difference between using frontendSearchUrlParams
and calling computeQueryParams
with the frontend strategy? frontendSearchUrlParams
's implementation looks the same as the else branch of this ternary. Is the difference in passing searchType
directly vs using this.searchType
as frontendSearchUrlParams
does? In what circumstances would type
be undefined? Can those circumstances safely fallback to ALL_MEDIA
, maybe?
If anything, a comment here would be helpful to explain why the branches are different and why an undefined search type dictates which we choose. Whatever the distinction is between these two branches seems to be very subtle and is completely lost on me.
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.
I simplified this code. The type
is passed here when creating a search page link (in the content switcher or in the content link on the All content search page) for a type that's different from the current search type.
@@ -508,7 +485,7 @@ export const useSearchStore = defineStore("search", { | |||
filterCategory: FilterCategory | |||
): boolean | undefined { | |||
if (!["licenseTypes", "licenses"].includes(filterCategory)) { | |||
return | |||
return false |
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.
Does this change allow us to remove undefined
from the return type of this function on line 486?
6da4e5f
to
033cc95
Compare
033cc95
to
e7a091e
Compare
Fixes
Related to #2858 by @obulat
Note: Most of the added lines are the saved API responses (tapes)
Description
This PR simplifies one of the most complicated parts of the Nuxt application: the building of API query string from the query parameters, and parsing of the query string into the filter parameters. This will make adding the store changes for Additional search views project much easier to do.
searchBy
filter kind was removed because it does not allow for the flexibility required by the Additional search views project. It will be replaced by a separate parameter on the search store state in the future PR.prepare-search-query-params
module was completely removed because it is no longer needed. Its functions are implemented more flexibly incomputeQueryParams
function.Some unused functions were removed. For example, we no longer parse the query string into filters, and use the
route.params
instead.This PR also adds more concise types for the search query.
Testing Instructions
The querying should work as expected, and CI should pass.
Checklist
Update index.md
).main
) or a parent feature branch.Developer Certificate of Origin
Developer Certificate of Origin