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
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion templates/explore/repo_search.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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>
delvh marked this conversation as resolved.
Show resolved Hide resolved
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.

</div>
{{end}}
<div class="divider"></div>