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

Keep filter when showing unfiltered results on explore page #27192

Merged
merged 7 commits into from Oct 11, 2023

Conversation

JakobDev
Copy link
Contributor

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Sep 22, 2023
@pull-request-size pull-request-size bot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Sep 22, 2023
@github-actions github-actions bot added the topic/ui Change the appearance of the Gitea UI label Sep 22, 2023
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Sep 22, 2023
@silverwind silverwind added backport/v1.20 This PR should be backported to Gitea 1.20 backport/v1.21 This PR should be backported to Gitea 1.21 labels Sep 22, 2023
@silverwind
Copy link
Member

silverwind commented Sep 22, 2023

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 ?param1=value1&param2=value2 when no params present and ?foo=bar&param1=value1&param2=value2 when foo is already present on current URL.

@JakobDev
Copy link
Contributor Author

BTW, I think this type of query string handling is too prone to bugs as seen many times.

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.

@silverwind
Copy link
Member

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 ctx into it, it should work.

I agree to landing this fix as-is.

@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Sep 23, 2023
@@ -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>
Copy link
Contributor

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.

Copy link
Member

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,

Copy link
Member

Choose a reason for hiding this comment

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

It needs #27192 (comment)

Copy link
Member

@puni9869 puni9869 Oct 6, 2023

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....

Copy link
Member

@silverwind silverwind Oct 6, 2023

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.

Copy link
Contributor

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:

  1. $.Link is not necessary. The URL could be as simple as ?k1=v1&k2=v2
  2. SetQueryParams doesn't seem a good name. SetXxx seems to be a function which "sets a value to something, has no return value".

Copy link
Member

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.

Copy link
Member

@silverwind silverwind Oct 6, 2023

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.

Copy link
Contributor

@wxiaoguang wxiaoguang Oct 7, 2023

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.

Copy link
Member

@silverwind silverwind Oct 7, 2023

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.

Copy link
Contributor

@wxiaoguang wxiaoguang left a 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

@GiteaBot GiteaBot added lgtm/blocked A maintainer has reservations with the PR and thus it cannot be merged and removed lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. labels Sep 23, 2023
@github-actions github-actions bot added the modifies/templates This PR modifies the template files label Oct 10, 2023
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/blocked A maintainer has reservations with the PR and thus it cannot be merged labels Oct 10, 2023
Copy link
Contributor

@wxiaoguang wxiaoguang left a 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 ....

@GiteaBot GiteaBot added lgtm/blocked A maintainer has reservations with the PR and thus it cannot be merged and removed lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. labels Oct 10, 2023
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Copy link
Contributor

@wxiaoguang wxiaoguang left a 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.

@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/blocked A maintainer has reservations with the PR and thus it cannot be merged labels Oct 11, 2023
@wxiaoguang wxiaoguang removed the backport/v1.20 This PR should be backported to Gitea 1.20 label Oct 11, 2023
@wxiaoguang
Copy link
Contributor

It can't be backported to 1.20, IIRC there is no proper ctx support. So the backport/1.20 label is removed.

@silverwind silverwind added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Oct 11, 2023
@silverwind silverwind enabled auto-merge (squash) October 11, 2023 21:34
@silverwind silverwind merged commit bf24852 into go-gitea:main Oct 11, 2023
25 checks passed
@GiteaBot GiteaBot added this to the 1.22.0 milestone Oct 11, 2023
GiteaBot pushed a commit to GiteaBot/gitea that referenced this pull request Oct 11, 2023
@GiteaBot GiteaBot added backport/done All backports for this PR have been created and removed reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. labels Oct 11, 2023
silverwind pushed a commit that referenced this pull request Oct 12, 2023
…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>
zjjhot added a commit to zjjhot/gitea that referenced this pull request Oct 12, 2023
* 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)
@go-gitea go-gitea locked as resolved and limited conversation to collaborators Jan 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
backport/done All backports for this PR have been created backport/v1.21 This PR should be backported to Gitea 1.21 lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. modifies/templates This PR modifies the template files size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. topic/ui Change the appearance of the Gitea UI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants