appview: pulls: group stacked pulls in all-pulls view #201

merged
opened by oppi.li targeting master from push-ykwytywspowp

the pull listing should be less noisy now.

Signed-off-by: oppiliappan me@oppi.li

Changed files
+61 -1
appview
pages
templates
repo
pulls
pulls
+1
appview/pages/pages.go
···
Active string
DidHandleMap map[string]string
FilteringBy db.PullState
+
Stacks map[string]db.Stack
}
func (p *Pages) RepoPulls(w io.Writer, params RepoPullsParams) error {
+37 -1
appview/pages/templates/repo/pulls/pulls.html
···
{{ define "repoAfter" }}
<div class="flex flex-col gap-2 mt-2">
{{ range .Pulls }}
-
<div class="rounded drop-shadow-sm bg-white dark:bg-gray-800 px-6 py-4">
+
<div class="rounded bg-white dark:bg-gray-800">
+
<div class="px-6 py-4 z-5">
<div class="pb-2">
<a href="/{{ $.RepoInfo.FullName }}/pulls/{{ .PullId }}" class="dark:text-white">
{{ .Title }}
···
{{ end }}
</span>
</p>
+
</div>
+
{{ if .StackId }}
+
{{ $otherPulls := index $.Stacks .StackId }}
+
<details class="bg-white dark:bg-gray-800 group">
+
<summary class="pb-4 px-6 text-xs list-none cursor-pointer hover:text-gray-500 hover:dark:text-gray-400">
+
{{ $s := "s" }}
+
{{ if eq (len $otherPulls) 1 }}
+
{{ $s = "" }}
+
{{ end }}
+
<div class="group-open:hidden flex items-center gap-2">
+
{{ i "chevrons-up-down" "w-4 h-4" }} expand {{ len $otherPulls }} pull{{$s}} in this stack
+
</div>
+
<div class="hidden group-open:flex items-center gap-2">
+
{{ i "chevrons-down-up" "w-4 h-4" }} hide {{ len $otherPulls }} pull{{$s}} in this stack
+
</div>
+
</summary>
+
{{ block "pullList" (list $otherPulls $) }} {{ end }}
+
</details>
+
{{ end }}
</div>
{{ end }}
</div>
{{ end }}
+
+
{{ define "pullList" }}
+
{{ $list := index . 0 }}
+
{{ $root := index . 1 }}
+
<div class="grid grid-cols-1 rounded-b border-b border-t border-gray-200 dark:border-gray-900 divide-y divide-gray-200 dark:divide-gray-900">
+
{{ range $pull := $list }}
+
<a href="/{{ $root.RepoInfo.FullName }}/pulls/{{ $pull.PullId }}" class="no-underline hover:no-underline hover:bg-gray-100/25 hover:dark:bg-gray-700/25">
+
<div class="flex gap-2 items-center px-6">
+
<div class="flex-grow min-w-0 w-full py-2">
+
{{ template "repo/pulls/fragments/summarizedHeader" $pull }}
+
</div>
+
</div>
+
</a>
+
{{ end }}
+
</div>
+
{{ end }}
+23
appview/pulls/pulls.go
···
}
}
+
// we want to group all stacked PRs into just one list
+
stacks := make(map[string]db.Stack)
+
n := 0
+
for _, p := range pulls {
+
// this PR is stacked
+
if p.StackId != "" {
+
// we have already seen this PR stack
+
if _, seen := stacks[p.StackId]; seen {
+
stacks[p.StackId] = append(stacks[p.StackId], p)
+
// skip this PR
+
} else {
+
stacks[p.StackId] = nil
+
pulls[n] = p
+
n++
+
}
+
} else {
+
pulls[n] = p
+
n++
+
}
+
}
+
pulls = pulls[:n]
+
identsToResolve := make([]string, len(pulls))
for i, pull := range pulls {
identsToResolve[i] = pull.OwnerDid
···
Pulls: pulls,
DidHandleMap: didHandleMap,
FilteringBy: state,
+
Stacks: stacks,
})
return
}