Repository navigation
Description
buildChart already takes a scope. analyticsScopeSchema in packages/core/src/analytics/schemas.ts accepts workspace, team, project and cycle, and scopeClause in distribution.ts implements all four correctly.
The analytics page uses exactly one of them:
const WORKSPACE: AnalyticsScope = { type: 'workspace' };That constant is at the top of apps/web/src/features/analytics/data.ts, and every loader in the file passes it. So a workspace with six teams gets one blended number per chart, which is the number least likely to be useful to anybody. A team lead cannot see their team. A project lead cannot see their project.
The work here is mostly wiring, because the hard part is already written and tested.
What to build
A scope picker in the page header.
Next to the measure toggle. It should offer:
- The workspace
- Each team the signed in person can see
- Each active project
- Each open sprint
loadCycleOptions in data.ts is a good model for how to build one of these lists with the right permission filter. Note how it handles a non admin: visibleCycleTeams returns sql\false`` when the person is on no teams rather than returning everything. Any new option loader has to do the same thing, and the server has to re-check rather than trusting what the client sent.
Thread the scope through the loaders.
loadScopeSeries, loadDistributions and loadBreakdown in data.ts all take principal and measure. They need to take a scope too. Keep the workspace default so nothing else that calls them changes.
Put it in the URL.
measure is already a search param, read in page.tsx and written by MeasureToggle. Do the same for scope, so a scoped dashboard is a link somebody can paste into Slack.
Make the section headings honest.
The page currently says "Scope, throughput, churn and distributions across the workspace." Once a scope is selectable, that sentence has to reflect the current one, and the card titles should say what they are counting. "By assignee" scoped to one project means something different from "By assignee" across the workspace, and the reader should not have to remember which one they picked.
Interaction with the cycle section
There is already a cycle selector further down the page, in cycle-panel.tsx, which drives the burndown and flow metrics. Once there is a page level scope, having a second independent sprint selector below it is confusing. Two reasonable answers:
- Selecting a sprint as the page scope also drives the cycle panel, and the panel's own selector goes away.
- The panel keeps its selector because sprint burndown is a different question from workspace distribution.
Pick one and say why in the pull request. Do not ship both controls with no relationship between them.
Permissions
assertCan(principal, 'project:read') is the current gate and it stays. What is new is that a scope id arrives from the client, so the server has to confirm the person may read that team, project or sprint before it queries. loadCycleBundle already does this correctly for cycles: it looks the row up scoped to the organisation and throws notFound if it is not there. Copy that shape rather than inventing a new one.
Tests
packages/core/tests/analytics/ already covers scoped charts at the engine level. What is missing is the route and page level test that a member of team A cannot request a scope of team B and get numbers back. Add that.
Files
apps/web/src/features/analytics/data.tsapps/web/src/app/(app)/analytics/page.tsxapps/web/src/features/analytics/measure-toggle.tsxis the pattern to copy for the new controlpackages/core/src/analytics/distribution.tsfor reference, probably unchanged
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsReady
Activity
imshashank commentedon Aug 8, 2026
The chart builder in #182 is designed to inherit the scope this issue introduces, and the drill-through in #181 has to carry it into the issue list it navigates to. Put the scope in the URL, the way
measurealready is, rather than in component state.Also note the open question in the body about the relationship between this page level scope and the sprint selector that already exists in
cycle-panel.tsx. Do not ship both controls with no relationship between them.imshashank commentedon Aug 15, 2026
Delivered, closing, but please read the permissions note at the bottom because the implementation deliberately does the opposite of what this issue asked for there.
The hardcoded
const WORKSPACE: AnalyticsScope = { type: 'workspace' }is gone from the shipping path. The planning cockpit in #309 replaced the scope picker idea with something broader:analyticsQuerySchemacarries afilterGroupQuerySchema, so the dashboard narrows by any filter property the issue list understands, not only by team, project or sprint.analytics-toolbar.tsxrenders it with the sameFilterMenuthe issue list uses, which avoids the second way of expressing the same thing.SprintFilterSelectinanalytics-toolbar.tsx, which writes a direct sprint condition into the filter.analyticsFocusSchema(focus.projectId,focus.personId), which is what the projects and people lenses drill into.query-state.tsserialises the whole query, so a scoped dashboard is a link somebody can paste into Slack.cycle-panel.tsxselector is no longer rendered at all.The permissions divergence. This issue asked for a test that "a member of team A cannot request a scope of team B and get numbers back". The implementation intentionally allows exactly that.
visibilityFiltersinpackages/core/src/work/issue-query.tshas aworkspace-analyticsmode which checksanalytics:readand then applies no team filter, where the legacy engine'svisibleTeamsClauseindistribution.tsrestricted a non-admin toprincipal.teamIdsand returned nothing for somebody on no teams.analytics:readis held by every role including guest, and the drilldown returns issue identifiers and titles, so a guest can now read the identifiers of issues on teams they are not a member of.This is a decision, not an oversight:
packages/core/tests/work/issue-query.test.tsasserts it explicitly, so it was chosen and pinned. I have raised it separately rather than reopening this issue, because it needs a yes or no from a maintainer rather than a fix in this scope.