diff --git a/api.go b/api.go index 6c333ab..00d3059 100644 --- a/api.go +++ b/api.go @@ -710,10 +710,12 @@ func (s *server) handleJob(w http.ResponseWriter, r *http.Request) { writeJSON(w, http.StatusOK, node) } -// handleGraph serves GET /api/graph -> Graph, the whole-history galaxy view. -// An optional ?repo= scopes the graph to a single repository. +// handleGraph serves GET /api/graph -> Graph, the galaxy view. An optional +// ?repo= scopes the graph to a single repository; ?range=30d|90d|all picks the +// time window, and anything else is the 30-day default. func (s *server) handleGraph(w http.ResponseWriter, r *http.Request) { - g, err := s.ds.Graph(r.Context(), r.URL.Query().Get("repo")) + q := r.URL.Query() + g, err := s.ds.Graph(r.Context(), q.Get("repo"), CanonicalGraphRange(q.Get("range"))) if err != nil { http.Error(w, err.Error(), statusForError(err)) return diff --git a/api_test.go b/api_test.go index a45d6a7..740cfaf 100644 --- a/api_test.go +++ b/api_test.go @@ -658,7 +658,7 @@ func TestHandleWorkflowClampsCursorsAndLimits(t *testing.T) { func TestFakeWorkflowContractAndPagination(t *testing.T) { t.Setenv("FAKEFEED_WORKFLOWS", "1") ds := NewFakeDataSource() - graph, err := ds.Graph(context.Background(), "") + graph, err := ds.Graph(context.Background(), "", GraphRange30d) if err != nil { t.Fatalf("Graph: %v", err) } @@ -739,7 +739,7 @@ func TestFakeGalaxyAgentRecordCoverage(t *testing.T) { byName[agent.Name] = agent } - graph, err := ds.Graph(context.Background(), "") + graph, err := ds.Graph(context.Background(), "", GraphRange30d) if err != nil { t.Fatalf("Graph: %v", err) } @@ -899,7 +899,7 @@ func TestWorkflowSummaryJSONContract(t *testing.T) { func TestFakeWorkflowDisabled(t *testing.T) { t.Setenv("FAKEFEED_WORKFLOWS", "0") ds := NewFakeDataSource() - graph, err := ds.Graph(context.Background(), "") + graph, err := ds.Graph(context.Background(), "", GraphRange30d) if err != nil { t.Fatalf("Graph: %v", err) } diff --git a/datasource.go b/datasource.go index 07aa180..31e85d4 100644 --- a/datasource.go +++ b/datasource.go @@ -127,12 +127,47 @@ type GraphLink struct { Kind string `json:"kind"` } -// Graph is the whole-history galaxy view: every job across every run, plus -// repo/agent hub nodes, unioned into one force-directed graph. +// Graph is the galaxy view: the runs created within a GraphRange across every +// root, plus repo/reviewer hub nodes, unioned into one force-directed graph. type Graph struct { Nodes []GraphNode `json:"nodes"` Links []GraphLink `json:"links"` Repos []string `json:"repos"` // distinct repos, for the filter + // Truncated is set when a wide range (90d/all) holds more runs than the UI + // can draw without freezing the tab: Nodes then carries the newest Shown of + // Total runs, while Repos still lists every repo in the range so a repo + // filter reaches its full history. Never set for the 30-day default. + Truncated *GraphTruncation `json:"truncated,omitempty"` +} + +// GraphTruncation reports a capped galaxy: Shown of Total runs are present. +type GraphTruncation struct { + Shown int `json:"shown"` + Total int `json:"total"` +} + +// GraphRange is the galaxy's time window: runs created within the last 30 or +// 90 days, or all of history. +type GraphRange string + +const ( + GraphRange30d GraphRange = "30d" + GraphRange90d GraphRange = "90d" + GraphRangeAll GraphRange = "all" +) + +// CanonicalGraphRange maps a ?range= value to a GraphRange. Anything missing or +// unknown is the 30-day default, so clients that never send ?range= keep +// today's view. +func CanonicalGraphRange(raw string) GraphRange { + switch GraphRange(raw) { + case GraphRange90d: + return GraphRange90d + case GraphRangeAll: + return GraphRangeAll + default: + return GraphRange30d + } } // WorkflowSummary is the aggregate header for one workflow label. State counts @@ -758,9 +793,10 @@ type DataSource interface { // summary plus config section. Unknown names return a not-found sentinel // (mapped to 404 by the API layer). Agent(ctx context.Context, name string) (AgentDetail, error) - // Graph returns the whole-history galaxy graph. Empty repo => all runs; a - // non-empty repo scopes to that repository's jobs (and their hubs). - Graph(ctx context.Context, repo string) (Graph, error) + // Graph returns the galaxy graph for the runs created within rng. Empty repo + // => all repos; a non-empty repo scopes to that repository's runs (and their + // hubs). rng is always canonical (see CanonicalGraphRange). + Graph(ctx context.Context, repo string, rng GraphRange) (Graph, error) // Charts returns the per-day time series plus top-agent/top-repo/totals // breakdowns for the Charts page. days selects the window: 7, 30 or 90; a // days of 0 means all history. Days is oldest->newest and zero-filled diff --git a/fakefeed.go b/fakefeed.go index b85b18f..29bf8e3 100644 --- a/fakefeed.go +++ b/fakefeed.go @@ -239,10 +239,10 @@ func (f *FakeDataSource) ChangeCursor(context.Context) (string, error) { return strconv.Itoa(f.step), nil } -// Graph implements DataSource. The fake feed has a single run, so the galaxy is -// that run's jobs plus a repo hub and per-agent hubs — enough to exercise the -// Galaxy view standalone. -func (f *FakeDataSource) Graph(ctx context.Context, repo string) (Graph, error) { +// Graph implements DataSource. The fake feed has a single current run, so every +// range returns the same graph: that run's runs plus a repo hub and per-reviewer +// hubs — enough to exercise the Galaxy view standalone. +func (f *FakeDataSource) Graph(ctx context.Context, repo string, rng GraphRange) (Graph, error) { f.mu.Lock() nodes := f.cloneNodesLocked() workflowsEnabled := f.workflowsEnabled diff --git a/graph_range_test.go b/graph_range_test.go new file mode 100644 index 0000000..3953820 --- /dev/null +++ b/graph_range_test.go @@ -0,0 +1,54 @@ +package dashboard + +import ( + "context" + "net/http" + "net/http/httptest" + "testing" +) + +// rangeRecordingDataSource records the range /api/graph hands to Graph. +type rangeRecordingDataSource struct { + DataSource + repo string + rng GraphRange +} + +func (r *rangeRecordingDataSource) Graph(ctx context.Context, repo string, rng GraphRange) (Graph, error) { + r.repo, r.rng = repo, rng + return r.DataSource.Graph(ctx, repo, rng) +} + +// /api/graph passes a canonical range to the DataSource: the three known values +// through, and anything else (missing, unknown, wrong case) as the 30-day +// default, so a client that never sends ?range= gets today's view. +func TestGraphRangeReachesDataSourceCanonical(t *testing.T) { + ds := &rangeRecordingDataSource{DataSource: NewFakeDataSource()} + handler := Serve(ds) + for target, want := range map[string]GraphRange{ + "/api/graph": GraphRange30d, + "/api/graph?range=30d": GraphRange30d, + "/api/graph?range=90d": GraphRange90d, + "/api/graph?range=all": GraphRangeAll, + "/api/graph?range=ALL": GraphRange30d, + "/api/graph?range=365d": GraphRange30d, + "/api/graph?range=": GraphRange30d, + "/api/graph?repo=a/b&range=all": GraphRangeAll, + "/api/graph?range=90d&range=all": GraphRange90d, + } { + ds.rng = "" + rec := httptest.NewRecorder() + handler.ServeHTTP(rec, httptest.NewRequest(http.MethodGet, target, nil)) + if rec.Code != http.StatusOK { + t.Fatalf("GET %s = %d: %s", target, rec.Code, rec.Body.String()) + } + if ds.rng != want { + t.Fatalf("GET %s passed range %q, want %q", target, ds.rng, want) + } + } + rec := httptest.NewRecorder() + handler.ServeHTTP(rec, httptest.NewRequest(http.MethodGet, "/api/graph?repo=a/b&range=all", nil)) + if ds.repo != "a/b" { + t.Fatalf("repo = %q, want a/b alongside the range", ds.repo) + } +} diff --git a/web/dist/index.html b/web/dist/index.html index 47a2ec1..92cf552 100644 --- a/web/dist/index.html +++ b/web/dist/index.html @@ -203,6 +203,7 @@ const r = this._parseRoute(location.pathname, location.search); this.state.view = r.view; if (r.view === 'jobs' && r.agent) this._jobsFacetAgent = r.agent; + if (r.view === 'galaxy') this._galaxyRange = r.range || '30d'; if (r.view === 'agents' && r.agent) this._pendingAgentDetail = r.agent; if (r.view === 'workflows') this._pendingWorkflowLabel = r.name || null; // Normalize unknown paths to '/' (Overview). Also tidy a non-canonical known @@ -210,7 +211,7 @@ if (r.unknown) { try { history.replaceState(null, '', '/'); } catch (e) {} } else { - const canon = this._routeUrl(r.view, { agent: r.agent, name: r.name }); + const canon = this._routeUrl(r.view, { agent: r.agent, name: r.name, range: r.range }); if ((location.pathname + location.search) !== canon) { try { history.replaceState(null, '', canon); } catch (e) {} } @@ -231,7 +232,7 @@ if (p.length > 1) p = p.replace(/\/+$/, '') || '/'; // drop trailing slash(es) if (p === '/' || p === '') return { view: 'overview' }; if (p === '/prs' || p === '/tasks') return { view: 'tasks' }; - if (p === '/galaxy') return { view: 'galaxy' }; + if (p === '/galaxy') { const rg = this._routeQueryRange(search); return rg === '30d' ? { view: 'galaxy' } : { view: 'galaxy', range: rg }; } if (p === '/charts') return { view: 'charts' }; if (p === '/health') return { view: 'health' }; if (p === '/config') return { view: 'config' }; @@ -277,7 +278,7 @@ switch (view) { case 'overview': return '/'; case 'tasks': return '/prs'; - case 'galaxy': return '/galaxy'; + case 'galaxy': return opts.range && opts.range !== '30d' ? '/galaxy?range=' + opts.range : '/galaxy'; case 'jobs': return opts.agent ? '/runs?reviewer=' + encodeURIComponent(opts.agent) : '/runs'; case 'workflows': return opts.name ? '/campaigns/' + encodeURIComponent(opts.name) : '/campaigns'; case 'agents': return opts.agent ? '/reviewers/' + encodeURIComponent(opts.agent) : '/reviewers'; @@ -353,6 +354,12 @@ } else if (r.view === 'jobs') { this._jobsFacetAgent = r.agent || ''; if (this._jobsRoot) this.renderJobs(false); + } else if (r.view === 'galaxy') { + const rg = r.range || '30d'; + if (rg !== (this._galaxyRange || '30d')) { + this._galaxyRange = rg; + if (this._galaxyRoot) { this._syncGalaxyRangeSelect(); this.fetchGalaxy(this._galaxyRepo || ''); } + } } if (this.state.view !== r.view) this.setState({ view: r.view }); } finally { @@ -767,7 +774,7 @@ // ============================================================ showOverview = () => { this.setState({ view: 'overview' }); this._navRoute('overview'); }; showTasks = () => { this.setState({ view: 'tasks' }); this._navRoute('tasks'); }; - showGalaxy = () => { this.setState({ view: 'galaxy' }); this._navRoute('galaxy'); }; + showGalaxy = () => { this.setState({ view: 'galaxy' }); this._navRoute('galaxy', { range: this._galaxyRange }); }; showWorkflows = () => { this._workflowLabel = ''; this._pendingWorkflowLabel = null; @@ -1334,8 +1341,14 @@ "#galaxy-root #g-count b{color:#7dcfff;font-weight:500}", "#galaxy-root #g-filterWrap{top:18px;right:18px;padding:10px 12px}", "#galaxy-root #g-filterWrap label{display:block;font-family:'JetBrains Mono',monospace;font-size:9.5px;text-transform:uppercase;letter-spacing:1.2px;color:#7f86ad;margin-bottom:6px}", - "#galaxy-root #g-repoFilter{appearance:none;-webkit-appearance:none;background:rgba(7,8,15,.85);color:#c8cce6;border:1px solid rgba(125,207,255,.18);border-radius:8px;font-family:'JetBrains Mono',monospace;font-size:12px;padding:7px 30px 7px 11px;min-width:210px;cursor:pointer;outline:none;background-image:url(\"data:image/svg+xml;utf8,\");background-repeat:no-repeat;background-position:right 11px center}", - "#galaxy-root #g-repoFilter:hover{border-color:rgba(125,207,255,.4)}", + "#galaxy-root #g-repoFilter,#galaxy-root #g-rangeFilter{appearance:none;-webkit-appearance:none;background:rgba(7,8,15,.85);color:#c8cce6;border:1px solid rgba(125,207,255,.18);border-radius:8px;font-family:'JetBrains Mono',monospace;font-size:12px;padding:7px 30px 7px 11px;min-width:210px;cursor:pointer;outline:none;background-image:url(\"data:image/svg+xml;utf8,\");background-repeat:no-repeat;background-position:right 11px center}", + "#galaxy-root #g-repoFilter:hover,#galaxy-root #g-rangeFilter:hover{border-color:rgba(125,207,255,.4)}", + "#galaxy-root #g-rangeFilter{min-width:0;width:100%}", + "#galaxy-root #g-repoFilter{width:100%;max-width:260px;text-overflow:ellipsis}", + "#galaxy-root #g-filterWrap{max-width:284px}", + "#galaxy-root #g-filterWrap .g-field+.g-field{margin-top:10px}", + "#galaxy-root #g-rangeNote{font-family:'JetBrains Mono',monospace;font-size:10px;color:#7f86ad;margin-top:6px;max-width:210px;line-height:1.5}", + "#galaxy-root #g-rangeNote:empty{display:none}", "#galaxy-root #g-legend{bottom:18px;left:18px;padding:13px 15px;max-width:230px}", "#galaxy-root #g-legend .grp{margin-bottom:11px}", "#galaxy-root #g-legend .grp:last-child{margin-bottom:0}", @@ -1423,8 +1436,15 @@ '