dmitri.shuralyov.com/app/changes/...

component: Rename {,Open,Closed}Issues{Nav,Tab} to {,Open,Closed}Changes{Nav,Tab}.

Improve naming consistency.
dmitshur committed 6 years ago commit 355a5c3f92690b2daa741388b73f381601a9598f
Collapse all
cmd/changesdev/main.go
@@ -12,10 +12,14 @@ https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#list-
https://gerrit-review.googlesource.com/Documentation/user-search.html#_search_operators
https://review.openstack.org/Documentation/config-hooks.html#_comment_added

Go CL <-> PR doc: https://docs.google.com/document/d/131IKF-SHY8cLwpXhkR46HVrKiIYJztZml3YyqECwrgk/edit

small Go CL:
-	http://localhost:8080/changes/92456
-	https://go-review.googlesource.com/c/go/+/92456

go-review / build / 80840 is a good simple CL with inline comments, replies, few revisions

another small one is go-review / debug / 92416:
-	https://go-review.googlesource.com/c/debug/+/92416/1
-	https://go-review.googlesource.com/c/debug/+/92416/1/gocore/dwarf.go#297
@@ -58,11 +62,11 @@ var httpFlag = flag.String("http", ":8080", "Listen for HTTP connections on this
func main() {
	flag.Parse()

	var usersService users.Service
	var service change.Service
	switch 1 {
	switch 2 {
	case 0:
		// Perform GitHub API authentication with provided token.
		token := os.Getenv("CHANGES_GITHUB_TOKEN")
		if token == "" {
			log.Fatalln("CHANGES_GITHUB_TOKEN env var is empty")
component/changes.go
@@ -12,28 +12,28 @@ import (
)

// Changes is a component that displays a page of changes,
// with a navigation bar on top.
type Changes struct {
	IssuesNav IssuesNav
	Filter    change.StateFilter
	Entries   []ChangeEntry
	ChangesNav ChangesNav
	Filter     change.StateFilter
	Entries    []ChangeEntry
}

func (i Changes) Render() []*html.Node {
	// TODO: Make this much nicer.
	// <div class="list-entry list-entry-border">
	// 	{{render .IssuesNav}}
	// 	{{render .ChangesNav}}
	// 	{{with .Entries}}{{range .}}
	// 		{{render .}}
	// 	{{end}}{{else}}
	// 		<div style="text-align: center; margin-top: 80px; margin-bottom: 80px;">There are no {{.Filter}} changes.</div>
	// 	{{end}}
	// </div>

	var ns []*html.Node
	ns = append(ns, i.IssuesNav.Render()...)
	ns = append(ns, i.ChangesNav.Render()...)
	for _, e := range i.Entries {
		ns = append(ns, e.Render()...)
	}
	if len(i.Entries) == 0 {
		// No changes with this filter. Let the user know via a blank slate.
component/tabs.go
@@ -8,21 +8,21 @@ import (
	"github.com/shurcooL/octiconssvg"
	"golang.org/x/net/html"
	"golang.org/x/net/html/atom"
)

// IssuesNav is a navigation component for displaying a header for a list of changes.
// ChangesNav is a navigation component for displaying a header for a list of changes.
// It contains tabs to switch between viewing open and closed changes.
type IssuesNav struct {
type ChangesNav struct {
	OpenCount     uint64     // Open changes count.
	ClosedCount   uint64     // Closed changes count.
	Path          string     // URL path of current page (needed to generate correct links).
	Query         url.Values // URL query of current page (needed to generate correct links).
	StateQueryKey string     // Name of query key for controlling change state filter. Constant, but provided externally.
}

func (n IssuesNav) Render() []*html.Node {
func (n ChangesNav) Render() []*html.Node {
	// TODO: Make this much nicer.
	// <header class="list-entry-header">
	// 	<nav>{{.Tabs}}</nav>
	// </header>
	nav := &html.Node{Type: html.ElementNode, Data: atom.Nav.String()}
@@ -34,21 +34,21 @@ func (n IssuesNav) Render() []*html.Node {
	}
	return []*html.Node{header}
}

// tabs renders the HTML nodes for <nav> element with tab header links.
func (n IssuesNav) tabs() []*html.Node {
func (n ChangesNav) tabs() []*html.Node {
	selectedTabName := n.Query.Get(n.StateQueryKey)
	var ns []*html.Node
	for i, tab := range []struct {
		Name      string // Tab name corresponds to its state filter query value.
		Component htmlg.Component
	}{
		// Note: The routing logic (i.e., exact tab Name values) is duplicated with tabStateFilter.
		//       Might want to try to factor it out into a common location (e.g., a route package or so).
		{Name: "", Component: OpenIssuesTab{Count: n.OpenCount}},
		{Name: "closed", Component: ClosedIssuesTab{Count: n.ClosedCount}},
		{Name: "", Component: OpenChangesTab{Count: n.OpenCount}},
		{Name: "closed", Component: ClosedChangesTab{Count: n.ClosedCount}},
	} {
		tabURL := (&url.URL{
			Path:     n.Path,
			RawQuery: n.rawQuery(tab.Name),
		}).String()
@@ -69,26 +69,26 @@ func (n IssuesNav) tabs() []*html.Node {
	}
	return ns
}

// rawQuery returns the raw query for a link pointing to tabName.
func (n IssuesNav) rawQuery(tabName string) string {
func (n ChangesNav) rawQuery(tabName string) string {
	q := n.Query
	if tabName == "" {
		q.Del(n.StateQueryKey)
		return q.Encode()
	}
	q.Set(n.StateQueryKey, tabName)
	return q.Encode()
}

// OpenIssuesTab is an "Open Issues Tab" component.
type OpenIssuesTab struct {
// OpenChangesTab is an "Open Changes Tab" component.
type OpenChangesTab struct {
	Count uint64 // Count of open changes.
}

func (t OpenIssuesTab) Render() []*html.Node {
func (t OpenChangesTab) Render() []*html.Node {
	// TODO: Make this much nicer.
	// <span style="margin-right: 4px;">{{octicon "git-pull-request"}}</span>
	// {{.Count}} Open
	icon := &html.Node{
		Type: html.ElementNode, Data: atom.Span.String(),
@@ -99,16 +99,16 @@ func (t OpenIssuesTab) Render() []*html.Node {
	}
	text := htmlg.Text(fmt.Sprintf("%d Open", t.Count))
	return []*html.Node{icon, text}
}

// ClosedIssuesTab is a "Closed Issues Tab" component.
type ClosedIssuesTab struct {
// ClosedChangesTab is a "Closed Changes Tab" component.
type ClosedChangesTab struct {
	Count uint64 // Count of closed changes.
}

func (t ClosedIssuesTab) Render() []*html.Node {
func (t ClosedChangesTab) Render() []*html.Node {
	// TODO: Make this much nicer.
	// <span style="margin-right: 4px;">{{octicon "check"}}</span>
	// {{.Count}} Closed
	icon := &html.Node{
		Type: html.ElementNode, Data: atom.Span.String(),
main.go
@@ -216,11 +216,11 @@ func (h *handler) ChangesHandler(w http.ResponseWriter, req *http.Request) error
	for _, i := range is {
		es = append(es, component.ChangeEntry{Change: i, BaseURI: state.BaseURI})
	}
	es = state.augmentUnread(req.Context(), es, h.cs, h.Notifications)
	state.Changes = component.Changes{
		IssuesNav: component.IssuesNav{
		ChangesNav: component.ChangesNav{
			OpenCount:     openCount,
			ClosedCount:   closedCount,
			Path:          state.BaseURI + state.ReqPath,
			Query:         req.URL.Query(),
			StateQueryKey: stateQueryKey,