Skip to content

fix(dashboard): auto-default --limit for grouped widgets (CLI-WW)#799

Merged
BYK merged 1 commit intomainfrom
byk/dashboard-widget-auto-limit
Apr 21, 2026
Merged

fix(dashboard): auto-default --limit for grouped widgets (CLI-WW)#799
BYK merged 1 commit intomainfrom
byk/dashboard-widget-auto-limit

Conversation

@BYK
Copy link
Copy Markdown
Member

@BYK BYK commented Apr 21, 2026

Summary

The Sentry API rejects grouped dashboard widgets without a limit. Previously the CLI threw ValidationError when users passed --group-by without --limit:

$ sentry dashboard widget add 'My Dashboard' "By Browser" --display line --query count --group-by browser.name
Error: Widgets with --group-by require --limit. Add --limit <n> …

The Sentry UI defaults to 5 for grouped widgets, so the CLI now applies the same default transparently and emits an [info] nudge so users understand what happened.

$ sentry dashboard widget add 'My Dashboard' "By Browser" --display line --query count --group-by browser.name
[info] [dashboard] Auto-defaulting --limit to 5 for grouped widget. Pass --limit <n> to override.
Widget added.

Design

  • DEFAULT_GROUP_BY_LIMIT = 5 + autoDefaultGroupLimit() + applyGroupLimitAutoDefault() live in src/commands/dashboard/resolve.ts and are shared between widget add and widget edit (no duplication, no drift).
  • The helper only fires when the user explicitly passes --group-by. Auto-defaulted columns like ["issue"] on dataset=issue display=table still produce a widget without a limit (regression-tested).
  • Explicit --limit always wins over the default. If the user literally passes --limit 5 the log is silenced (no spurious info line).
  • For edit: adding --group-by to a widget that already has a limit preserves the existing value; only unset limits get filled.
  • Removed the now-dead validateGroupByRequiresLimit helper.

Tests

  • Unit tests for autoDefaultGroupLimit and applyGroupLimitAutoDefault covering all combinations of grouped/ungrouped × explicit/empty limit.
  • New add tests: auto-default fires on group-by; explicit --limit wins; ungrouped widgets don't get a limit; issue/table default columns do NOT trigger auto-default.
  • New edit tests: auto-default fires when adding --group-by; explicit --limit wins; existing widget limit preserved when adding --group-by; no auto-default for ungrouped --query-only edits.

All unit tests pass (5543 tests).

References

Based on work in #784 by @cursor; split out per review.

Fixes CLI-WW.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 21, 2026

Semver Impact of This PR

🟢 Patch (bug fixes)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features ✨

Bug Fixes 🐛

Dashboard

  • Auto-default --limit for grouped widgets (CLI-WW) by BYK in #799
  • Accept dataset aliases (errors, transactions, metrics) (CLI-JG) by BYK in #800

Init

  • Send dirListing/fileCache/existingSentry via initialState by betegon in #796
  • Force process exit after wizard completes by betegon in #782

Other

Documentation 📚

  • Fix auth token precedence, update stale architecture tree, and documentation audit report by cursor in #783

Internal Changes 🔧

  • (init) Trim deprecated --features help entries by MathurAditya724 in #781
  • (issue) Skip redundant API lookups via project+issue-org caches by BYK in #794
  • Regenerate docs by github-actions[bot] in 58a84035

🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 21, 2026

PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://cli.sentry.dev/_preview/pr-799/

Built to branch gh-pages at 2026-04-21 13:23 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 21, 2026

Codecov Results 📊

138 passed | Total: 138 | Pass Rate: 100% | Execution Time: 0ms

📊 Comparison with Base Branch

Metric Change
Total Tests
Passed Tests
Failed Tests
Skipped Tests

✨ No test changes detected

All tests are passing successfully.

✅ Patch coverage is 100.00%. Project has 1761 uncovered lines.
✅ Project coverage is 95.63%. Comparing base (base) to head (head).

Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
+ Coverage    95.62%    95.63%    +0.01%
==========================================
  Files          280       280         —
  Lines        40208     40273       +65
  Branches         0         0         —
==========================================
+ Hits         38444     38512       +68
- Misses        1764      1761        -3
- Partials         0         0         —

Generated by Codecov Action

The Sentry API rejects grouped widgets without a limit. Previously the
CLI threw `ValidationError` when users passed `--group-by` without
`--limit`, forcing them to read the error and retry. The Sentry UI
defaults to 5 in this case, so the CLI now applies the same default
transparently and emits an `[info]` nudge so users understand what
happened.

Both `dashboard widget add` and `dashboard widget edit` share the same
`applyGroupLimitAutoDefault()` helper and `DEFAULT_GROUP_BY_LIMIT`
constant (`src/commands/dashboard/resolve.ts`). The predicate only
fires when the user *explicitly* passes `--group-by` — auto-defaulted
columns like `["issue"]` on `dataset=issue display=table` are left
alone, since those widgets legitimately work without a limit.

Removed the now-dead `validateGroupByRequiresLimit` helper and its
imports. Added unit tests for both helpers plus integration tests in
`add.test.ts` and `edit.test.ts` covering: auto-default fires; explicit
`--limit` wins; ungrouped widgets don't get a limit; existing widget
limit is preserved when adding `--group-by`.

Based on work in #784 by @cursor; split out per review.
@BYK BYK force-pushed the byk/dashboard-widget-auto-limit branch from 842a4e5 to 57326a9 Compare April 21, 2026 13:22
@BYK BYK merged commit e45ff5f into main Apr 21, 2026
27 checks passed
@BYK BYK deleted the byk/dashboard-widget-auto-limit branch April 21, 2026 13:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant