-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Keep filter when showing unfiltered results on explore page #27192
Conversation
BTW, I think this type of query string handling is too prone to bugs as seen many times. We should have a template helper that merges specified params into current URL params: <a href="{{SetQueryParams ctx "param1" "value1" "param2" "value2"}}"></a> Would output |
We both had the same thought. I was actually planning to write a helper of for that next week while working on this. I did not include it in this PR, so it can be backportet. |
The only challenge with such a helper that I see is getting access to the HTTP request in the helper, but I assume if we pass I agree to landing this fix as-is. |
templates/explore/repo_search.tmpl
Outdated
@@ -36,7 +36,7 @@ | |||
</div> | |||
{{if and .PageIsExploreRepositories .OnlyShowRelevant}} | |||
<div class="ui message explore-relevancy-note"> | |||
<span data-tooltip-content="{{.locale.Tr "explore.relevant_repositories_tooltip"}}">{{.locale.Tr "explore.relevant_repositories" ((print $.Link "?only_show_relevant=0")|Escape) | Safe}}</span> | |||
<span data-tooltip-content="{{.locale.Tr "explore.relevant_repositories_tooltip"}}">{{.locale.Tr "explore.relevant_repositories" ((printf "%s?only_show_relevant=0&sort=%s&q=%s&language=%s" $.Link $.SortType $.Keyword $.Language)|Escape) | Safe}}</span> |
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.
It needs QueryEscape
. Otherwise, if you search "C++" or "C#", it breaks the URL.
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.
Its better to do this url formation in backend,
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.
It needs #27192 (comment)
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.
but there will be too much if we pass key:value in the template if we have many params. Template will not be human readable. So....
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.
No, the idea is that every link only specifies the param it controls, so only 1 key/value pair per link. The backend then fills the rest and renders a combined URL with all the existing params present on the request URL from ctx
.
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 have no objection if the new approach is well designed. Two points in my mind:
$.Link
is not necessary. The URL could be as simple as?k1=v1&k2=v2
SetQueryParams
doesn't seem a good name.SetXxx
seems to be a function which "sets a value to something, has no return value".
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.
Will make a proof of concept of this soon.
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 think I will name it ExtendQueryParams
. Or do you have a better idea?
SetQueryParams doesn't seem a good name. SetXxx seems to be a function which "sets a value to something, has no return value".
At least in JS it is somewhat common, for example a expression foo = 1
also evaluates to the 1
value.
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 think I will name it ExtendQueryParams. Or do you have a better idea?
I also had some thoughts about this problem, since Gitea has a lot of requirements of maintaining the URL components in the template, maybe something like:
// suppose current url is: "/path?k1=v1&k2=v2"
// the "search" matches JS window.location.search, which contains the leading `?`
{{ctx.LinkSearchWith "k1" 123}} -> "?k1=123&k2=v2"
{{WebUtils.BuildSearch "k1" 123}} -> "?k1=123"
{{WebUtils.BuildQuery "k1" 123}} -> "k1=123", it can be used for other "printf"
{{WebUtils.BuildLink "/other-path" (dict "k1" 123)}} -> "/other-path?k1=123"
At least in JS it is somewhat common, for example a expression foo = 1 also evaluates to the 1 value.
No, it is confusing in this case. In your case foo
is changed to 1
. But in the {{SetQueryParams ctx "only_show_relevant" "0"}}
case, has the ctx
been changed? That's a wrong design pattern.
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 think ExtendQuery
is a good name, based on URL.Query
name. Not sure if there is any benefit of making it ctx.ExtendQuery
I guess it only worsens performance having to "build" this function every time. I think I prefer ExtendQuery
with ctx
passed in as first argument.
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.
Need URL parameter encoding
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.
Sorry, still need more changes ....
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
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 haven't tested my suggestion. Let's try.
It can't be backported to 1.20, IIRC there is no proper |
…#27192) Fixes https://codeberg.org/Codeberg/Community/issues/1302 --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
…27589) Backport #27192 by @JakobDev Fixes https://codeberg.org/Codeberg/Community/issues/1302 Co-authored-by: JakobDev <jakobdev@gmx.de> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
* giteaofficial/main: [skip ci] Updated translations via Crowdin Keep filter when showing unfiltered results on explore page (go-gitea#27192) Don't show Link to TOTP if not set up (go-gitea#27585) Fix data-race bug when accessing task.LastRun (go-gitea#27584) Fix template bug (go-gitea#27581) Replace ajax with fetch, improve image diff (go-gitea#27267) Replace assert.Fail with assert.FailNow (go-gitea#27578) Fix the robots.txt path show manual cron run's last time (go-gitea#27544) fully replace drone with actions (go-gitea#27556) Revert "Simplify `contrib/backport` (go-gitea#27520)" (go-gitea#27566) Align ISSUE_TEMPLATE with the new label system (go-gitea#27573) Penultimate round of `db.DefaultContext` refactor (go-gitea#27414)
Fixes https://codeberg.org/Codeberg/Community/issues/1302