[FEAT] folding results for repo search (#4134)
closes #3855 unlike #3854, this implementation uses a generic details html tag and a bit of tailwind magic... --- ## Maintainers Note - previously tailwind classes of the form `[-a-zA-Z:0-9_.]` was disabled, however they were enabled since they were required for the `group-open:` classes --- ## Manual Testing 1. Visit the code search results after submitting a valid query for repo (if indexer disabled) or repo, user, explore (if indexer enabled) 2. Verify thst 1. the results are unfloded/open by default 2. the chevron points down when open and right when closed <video src="/attachments/5a55c56f-6159-4422-ab80-962e0121e7d2" title="fold2.mp4" controls></video> Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/4134 Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org> Reviewed-by: Beowulf <beowulf@noreply.codeberg.org> Co-authored-by: Shiny Nematoda <snematoda.751k2@aleeas.com> Co-committed-by: Shiny Nematoda <snematoda.751k2@aleeas.com>
This commit is contained in:
parent
291e145ac5
commit
53d4e90411
4 changed files with 38 additions and 18 deletions
1
release-notes/8.0.0/feat/4134.md
Normal file
1
release-notes/8.0.0/feat/4134.md
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Code Search results are now displayed in a foldable box
|
|
@ -44,8 +44,6 @@ export default {
|
||||||
'backdrop-filter',
|
'backdrop-filter',
|
||||||
// we use double-class tw-hidden defined in web_src/css/helpers.css for increased specificity
|
// we use double-class tw-hidden defined in web_src/css/helpers.css for increased specificity
|
||||||
'hidden',
|
'hidden',
|
||||||
// unneeded classes
|
|
||||||
'[-a-zA-Z:0-9_.]',
|
|
||||||
],
|
],
|
||||||
theme: {
|
theme: {
|
||||||
colors: {
|
colors: {
|
||||||
|
@ -100,6 +98,22 @@ export default {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
|
plugin(({addUtilities}) => {
|
||||||
|
// base veriables required for tranform utilities
|
||||||
|
// added as utilities since base is not imported
|
||||||
|
// note: required when using tailwind's transform classes
|
||||||
|
addUtilities({
|
||||||
|
'.transform-reset': {
|
||||||
|
'--tw-translate-x': 0,
|
||||||
|
'--tw-translate-y': 0,
|
||||||
|
'--tw-rotate': 0,
|
||||||
|
'--tw-skew-x': 0,
|
||||||
|
'--tw-skew-y': 0,
|
||||||
|
'--tw-scale-x': '1',
|
||||||
|
'--tw-scale-y': '1',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}),
|
||||||
plugin(({addUtilities}) => {
|
plugin(({addUtilities}) => {
|
||||||
addUtilities({
|
addUtilities({
|
||||||
// tw-hidden must win all other "display: xxx !important" classes to get the chance to "hide" an element.
|
// tw-hidden must win all other "display: xxx !important" classes to get the chance to "hide" an element.
|
||||||
|
|
|
@ -11,26 +11,31 @@
|
||||||
<div class="repository search">
|
<div class="repository search">
|
||||||
{{range $result := .SearchResults}}
|
{{range $result := .SearchResults}}
|
||||||
{{$repo := or $.Repo (index $.RepoMaps .RepoID)}}
|
{{$repo := or $.Repo (index $.RepoMaps .RepoID)}}
|
||||||
<div class="diff-file-box diff-box file-content non-diff-file-content repo-search-result">
|
<details class="tw-group diff-file-box diff-box file-content non-diff-file-content repo-search-result" open>
|
||||||
<h4 class="ui top attached header tw-font-normal tw-flex tw-flex-wrap">
|
<summary class="tw-list-none">
|
||||||
{{if not $.Repo}}
|
<h4 class="ui top attached header tw-font-normal tw-flex tw-flex-wrap tw-transform-reset">
|
||||||
<span class="file tw-flex-1">
|
<span class="tw-h-4 tw-transition -tw-rotate-90 group-open:tw-rotate-0">
|
||||||
<a rel="nofollow" href="{{$repo.Link}}">{{$repo.FullName}}</a>
|
{{svg "octicon-chevron-down"}}
|
||||||
{{if $repo.IsArchived}}
|
|
||||||
<span class="ui basic label">{{ctx.Locale.Tr "repo.desc.archived"}}</span>
|
|
||||||
{{end}}
|
|
||||||
- {{.Filename}}
|
|
||||||
</span>
|
</span>
|
||||||
{{else}}
|
{{if not $.Repo}}
|
||||||
<span class="file tw-flex-1">{{.Filename}}</span>
|
<span class="file tw-flex-1 tw-ml-2">
|
||||||
{{end}}
|
<a rel="nofollow" href="{{$repo.Link}}">{{$repo.FullName}}</a>
|
||||||
<a role="button" class="ui basic tiny button" rel="nofollow" href="{{$repo.Link}}/src/commit/{{$result.CommitID | PathEscape}}/{{.Filename | PathEscapeSegments}}">{{ctx.Locale.Tr "repo.diff.view_file"}}</a>
|
{{if $repo.IsArchived}}
|
||||||
</h4>
|
<span class="ui basic label">{{ctx.Locale.Tr "repo.desc.archived"}}</span>
|
||||||
|
{{end}}
|
||||||
|
- {{.Filename}}
|
||||||
|
</span>
|
||||||
|
{{else}}
|
||||||
|
<span class="file tw-flex-1 tw-ml-2">{{.Filename}}</span>
|
||||||
|
{{end}}
|
||||||
|
<a role="button" class="ui basic tiny button" rel="nofollow" href="{{$repo.Link}}/src/commit/{{$result.CommitID | PathEscape}}/{{.Filename | PathEscapeSegments}}">{{ctx.Locale.Tr "repo.diff.view_file"}}</a>
|
||||||
|
</h4>
|
||||||
|
</summary>
|
||||||
<div class="ui attached table segment">
|
<div class="ui attached table segment">
|
||||||
{{template "shared/searchfile" dict "RepoLink" $repo.Link "SearchResult" .}}
|
{{template "shared/searchfile" dict "RepoLink" $repo.Link "SearchResult" .}}
|
||||||
</div>
|
</div>
|
||||||
{{template "shared/searchbottom" dict "root" $ "result" .}}
|
{{template "shared/searchbottom" dict "root" $ "result" .}}
|
||||||
</div>
|
</details>
|
||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
{{template "base/paginate" .}}
|
{{template "base/paginate" .}}
|
||||||
|
|
|
@ -20,7 +20,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func resultFilenames(t testing.TB, doc *HTMLDoc) []string {
|
func resultFilenames(t testing.TB, doc *HTMLDoc) []string {
|
||||||
filenameSelections := doc.Find(".repository.search").Find(".repo-search-result").Find(".header").Find("span.file")
|
filenameSelections := doc.Find(".repository.search").Find("details.repo-search-result").Find(".header").Find("span.file")
|
||||||
result := make([]string, filenameSelections.Length())
|
result := make([]string, filenameSelections.Length())
|
||||||
filenameSelections.Each(func(i int, selection *goquery.Selection) {
|
filenameSelections.Each(func(i int, selection *goquery.Selection) {
|
||||||
result[i] = selection.Text()
|
result[i] = selection.Text()
|
||||||
|
|
Loading…
Reference in a new issue