Skip to content

Scope the analytics dashboard to a team, project or sprint #178

Closed

Description

@imshashank

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.ts
  • apps/web/src/app/(app)/analytics/page.tsx
  • apps/web/src/features/analytics/measure-toggle.tsx is the pattern to copy for the new control
  • packages/core/src/analytics/distribution.ts for reference, probably unchanged

Activity

  1. added
    enhancement
    help wanted
    ready
    p1 high
    area: analytics
    on Aug 8, 2026
  2. added
    size: medium
    points: 3
    on Aug 8, 2026
  3. imshashank commented on Aug 8, 2026

    @imshashank
    ContributorAuthor

    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 measure already 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.

  4. imshashank commented on Aug 15, 2026

    @imshashank
    ContributorAuthor

    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:

    • Scoping is now the filter engine. analyticsQuerySchema carries a filterGroupQuerySchema, so the dashboard narrows by any filter property the issue list understands, not only by team, project or sprint. analytics-toolbar.tsx renders it with the same FilterMenu the issue list uses, which avoids the second way of expressing the same thing.
    • Sprint selection has a dedicated control, SprintFilterSelect in analytics-toolbar.tsx, which writes a direct sprint condition into the filter.
    • Project and person focus are separate from filtering, through analyticsFocusSchema (focus.projectId, focus.personId), which is what the projects and people lenses drill into.
    • It is in the URL. query-state.ts serialises the whole query, so a scoped dashboard is a link somebody can paste into Slack.
    • The second sprint selector problem is resolved the first way this issue offered: the page-level sprint selection drives the sprint lens, and the old independent cycle-panel.tsx selector 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. visibilityFilters in packages/core/src/work/issue-query.ts has a workspace-analytics mode which checks analytics:read and then applies no team filter, where the legacy engine's visibleTeamsClause in distribution.ts restricted a non-admin to principal.teamIds and returned nothing for somebody on no teams. analytics:read is 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.ts asserts 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: analyticsenhancementhelp wantedp1 highpoints: 3readysize: medium

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions