From 6b1283d2ce0e5c36029f8e2fb8eeb3c6b7c29209 Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Thu, 26 Jan 2023 11:36:00 +0100 Subject: dashboard: display subsystems in bug lists To generate filtering URLs, use the ability of context.Context to carry on variable values. --- dashboard/app/handler.go | 11 +++++++++++ dashboard/app/main.go | 12 ++++++++++++ dashboard/app/templates.html | 7 ++++++- pkg/html/html.go | 15 +++++++++++++++ pkg/html/pages/style.css | 15 +++++++++++++++ 5 files changed, 59 insertions(+), 1 deletion(-) diff --git a/dashboard/app/handler.go b/dashboard/app/handler.go index 2cb0d2739..7c6e9a23e 100644 --- a/dashboard/app/handler.go +++ b/dashboard/app/handler.go @@ -32,6 +32,7 @@ func handlerWrapper(fn contextHandler) http.Handler { func handleContext(fn contextHandler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { c := appengine.NewContext(r) + c = context.WithValue(c, currentURLKey, r.URL.RequestURI()) if err := fn(c, w, r); err != nil { hdr := commonHeaderRaw(c, r) data := &struct { @@ -73,6 +74,16 @@ func handleContext(fn contextHandler) http.Handler { }) } +const currentURLKey = "current_url" + +func getCurrentURL(c context.Context) string { + val, ok := c.Value(currentURLKey).(string) + if ok { + return val + } + return "" +} + type ( ErrClient struct{ error } ErrRedirect struct{ error } diff --git a/dashboard/app/main.go b/dashboard/app/main.go index 9d1340425..05eee1687 100644 --- a/dashboard/app/main.go +++ b/dashboard/app/main.go @@ -234,6 +234,12 @@ type uiBug struct { MissingOn []string NumManagers int LastActivity time.Time + Subsystems []*uiBugSubsystem +} + +type uiBugSubsystem struct { + Name string + Link string } type uiCrash struct { @@ -1120,6 +1126,12 @@ func createUIBug(c context.Context, bug *Bug, state *ReportingState, managers [] NumManagers: len(managers), LastActivity: bug.LastActivity, } + for _, entry := range bug.Tags.Subsystems { + uiBug.Subsystems = append(uiBug.Subsystems, &uiBugSubsystem{ + Name: entry.Name, + Link: html.AmendURL(getCurrentURL(c), "subsystem", entry.Name), + }) + } updateBugBadness(c, uiBug) if len(bug.Commits) != 0 { for i, com := range bug.Commits { diff --git a/dashboard/app/templates.html b/dashboard/app/templates.html index 12b51072a..01055dd5c 100644 --- a/dashboard/app/templates.html +++ b/dashboard/app/templates.html @@ -125,7 +125,12 @@ Use of this source code is governed by Apache 2 LICENSE that can be found in the {{range $b := .Bugs}} {{if $.ShowNamespace}}{{$b.Namespace}}{{end}} - {{$b.Title}} + + {{$b.Title}} + {{- range $b.Subsystems}} + {{link .Link .Name}} + {{- end}} + {{formatReproLevel $b.ReproLevel}} {{print $b.BisectCause}} {{print $b.BisectFix}} diff --git a/pkg/html/html.go b/pkg/html/html.go index 8dc075bb6..c89c42fbb 100644 --- a/pkg/html/html.go +++ b/pkg/html/html.go @@ -6,6 +6,7 @@ package html import ( "fmt" "html/template" + "net/url" "reflect" "strings" texttemplate "text/template" @@ -191,3 +192,17 @@ func dereferencePointer(v interface{}) interface{} { func commitLink(repo, commit string) string { return vcs.CommitLink(repo, commit) } + +func AmendURL(baseURL, key, value string) string { + if baseURL == "" { + return "" + } + parsed, err := url.Parse(baseURL) + if err != nil { + return "" + } + values := parsed.Query() + values.Set(key, value) + parsed.RawQuery = values.Encode() + return parsed.String() +} diff --git a/pkg/html/pages/style.css b/pkg/html/pages/style.css index d5ceef253..71a3efe71 100644 --- a/pkg/html/pages/style.css +++ b/pkg/html/pages/style.css @@ -194,6 +194,21 @@ table td, table th { display: inline-block; } +.list_table .subsystem { + background: white; + border: 1pt solid black; + display: inline-block; + padding-left: 2pt; + padding-right: 2pt; + margin-left: 4pt; + font-size: small; +} + +.list_table .subsystem a { + text-decoration: none; + color: black; +} + .bad { color: #f00; font-weight: bold; -- cgit mrf-deployment