Monorepo for Tangled tangled.org

appview/pages: make issue labels clickable #1179

open opened by tachyonism.tngl.sh targeting master from tachyonism.tngl.sh/tangled-core: master

Make the issue labels clickable, similar to how GitHub does it.

Labels

None yet.

assignee

None yet.

Participants 2
AT URI
at://did:plc:w6qiwij62bmdugsd3gemhpy2/sh.tangled.repo.pull/3mhco2k45tx22
+44 -3
Diff #0
+23
appview/pages/funcmap.go
··· 31 31 "tangled.org/core/appview/models" 32 32 "tangled.org/core/appview/oauth" 33 33 "tangled.org/core/appview/pages/markup" 34 + "tangled.org/core/appview/searchquery" 34 35 "tangled.org/core/crypto" 35 36 ) 36 37 37 38 type tab map[string]string 38 39 40 + func appendQuery(query, token string) string { 41 + token = strings.TrimSpace(token) 42 + if token == "" { 43 + return query 44 + } 45 + 46 + parsed := searchquery.Parse(query) 47 + for _, item := range parsed.Items() { 48 + if item.Raw == token { 49 + return query 50 + } 51 + } 52 + 53 + query = strings.TrimSpace(query) 54 + if query == "" { 55 + return token 56 + } 57 + 58 + return query + " " + token 59 + } 60 + 39 61 func (p *Pages) funcMap() template.FuncMap { 40 62 return template.FuncMap{ 41 63 "split": func(s string) []string { ··· 370 392 } 371 393 return vals, nil 372 394 }, 395 + "appendQuery": appendQuery, 373 396 "deref": func(v any) any { 374 397 val := reflect.ValueOf(v) 375 398 if val.Kind() == reflect.Pointer && !val.IsNil() {
+7 -1
appview/pages/templates/labels/fragments/label.html
··· 2 2 {{ $d := .def }} 3 3 {{ $v := .val }} 4 4 {{ $withPrefix := .withPrefix }} 5 + {{ $href := .href }} 5 6 6 7 {{ $lhs := printf "%s" $d.Name }} 7 8 {{ $rhs := "" }} ··· 26 27 27 28 {{ $chipClasses := "w-fit flex items-center gap-2 font-normal normal-case rounded py-1 px-2 border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 text-sm text-inherit" }} 28 29 29 - {{ if $isDid }} 30 + {{ if $href }} 31 + <a href="{{ safeUrl $href }}" class="{{ $chipClasses }} no-underline hover:underline"> 32 + {{ template "repo/fragments/colorBall" (dict "color" $d.GetColor) }} 33 + {{ printf "%s%s" $lhs $rhs }} 34 + </a> 35 + {{ else if $isDid }} 30 36 <a href="/{{ $resolvedVal }}" class="{{ $chipClasses }} no-underline hover:underline"> 31 37 {{ template "repo/fragments/colorBall" (dict "color" $d.GetColor) }} 32 38 {{ printf "%s%s" $lhs $rhs }}
+13 -1
appview/pages/templates/repo/issues/fragments/issueListing.html
··· 45 45 {{ $state := .Labels }} 46 46 {{ range $k, $d := $.LabelDefs }} 47 47 {{ range $v, $s := $state.GetValSet $d.AtUri.String }} 48 - {{ template "labels/fragments/label" (dict "def" $d "val" $v "withPrefix" true) }} 48 + {{ $token := "" }} 49 + {{ if $d.ValueType.IsNull }} 50 + {{ $token = printf "label:%s" $d.Name }} 51 + {{ else }} 52 + {{ $tokenVal := $v }} 53 + {{ if $d.ValueType.IsDidFormat }} 54 + {{ $tokenVal = resolve $v }} 55 + {{ end }} 56 + {{ $token = printf "%s:%s" $d.Name $tokenVal }} 57 + {{ end }} 58 + {{ $searchQuery := appendQuery $.FilterQuery $token }} 59 + {{ $searchHref := printf "?%s" ((queryParams "q" $searchQuery).Encode) }} 60 + {{ template "labels/fragments/label" (dict "def" $d "val" $v "withPrefix" true "href" $searchHref) }} 49 61 {{ end }} 50 62 {{ end }} 51 63 </div>
+1 -1
appview/pages/templates/repo/issues/issues.html
··· 65 65 66 66 {{ define "repoAfter" }} 67 67 <div class="mt-2"> 68 - {{ template "repo/issues/fragments/issueListing" (dict "Issues" .Issues "RepoPrefix" .RepoInfo.FullName "LabelDefs" .LabelDefs) }} 68 + {{ template "repo/issues/fragments/issueListing" (dict "Issues" .Issues "RepoPrefix" .RepoInfo.FullName "LabelDefs" .LabelDefs "FilterQuery" .FilterQuery) }} 69 69 </div> 70 70 {{if gt .IssueCount .Page.Limit }} 71 71 {{ template "fragments/pagination" (dict

History

1 round 3 comments
sign up or login to add to the discussion
1 commit
expand
appview/pages: make issue labels clickable
no conflicts, ready to merge
expand 3 comments

thanks for working on this! few nits:

appview/pages/funcmap.go:395: this is kind of an antipattern, to introduce highly specific functions into funcmap.#

appview/pages/templates/repo/issues/fragments/issueListing.html:60: is there a reason this is available only on issues?

at a higher level, i think we may need to rethink the approach here: each label can have a func to expose the "search query token", which could be strongly typed. we can then have the issueListing/pullListing templates accept a strongly typed Query that can have a method such as Query.AddFilter or similar!

whoops! apologies for the poor formatting on that! didn't mean to shout.

this is kind of an antipattern, to introduce highly specific functions into funcmap.

So where would you recommend to put this function instead?

is there a reason this is available only on issues?

No specific reason. Just that I thought I may start out small, then add the same functionality later in the PR page. If you want, I can add clickable labels for all pages with labels.

Other than that, I'll try to explore your proposed implementation.