Skip to content

feat: Support single-select dashboard filters - #3295

Merged
kodiakhq[bot] merged 2 commits into
mainfrom
drew/single-select-vars
Oct 7, 2026
Merged

kodiakhq[bot] merged 2 commits into
mainfrom
drew/single-select-vars

Conversation

@pulpdrew

@pulpdrew pulpdrew commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Support configuring dashboard variables / filters as single-select, so that no more than one value can be selected.

If the URL contains multiple values for the filter, then the first is used.

Screenshots or video

Screenshot 2026-10-05 at 11 59 45 AM Screenshot 2026-10-05 at 11 59 49 AM

How to test on Vercel preview

  • Create a dashboard
  • Add some single select variables
  • Observe the selection behavior

References

@changeset-bot

changeset-bot Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: bd596e2

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@hyperdx/common-utils Patch
@hyperdx/api Patch
@hyperdx/app Patch
@hyperdx/otel-collector Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel

vercel Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
hyperdx-oss Ready Ready Preview Oct 7, 2026 4:26pm UTC
hyperdx-storybook Ready Ready Preview Oct 7, 2026 4:26pm UTC

Request Review

@github-actions github-actions Bot added the review/tier-4 Critical — deep review + domain expert sign-off label Oct 5, 2026
@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

🔴 Tier 4 — Critical

Touches authentication, tenancy data models, the public API or shipped database config — or substantially changes the query rendering engine, background tasks, the OTel pipeline, image build, or release CI.

Why this tier:

  • Critical-path files (1) — tenancy, public API, or shipped database config:
    • packages/api/src/routers/external-api/v2/dashboards.ts
  • Cross-layer change: touches frontend (packages/app) + backend (packages/api) + shared utils (packages/common-utils)

Review process: Deep review from a domain expert. Synchronous walkthrough may be required.
SLA: Schedule synchronous review within 2 business days.

Stats
  • Production files changed: 13
  • Production lines changed: 184 (+ 425 in test files, excluded from tier calculation)
  • Critical-path lines changed: 24
  • Branch: drew/single-select-vars
  • Author: pulpdrew

To override this classification, remove the review/tier-4 label and apply a different review/tier-* label. Manual overrides are preserved on subsequent pushes.

@github-actions

github-actions Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Duplicate code analysis

No new duplicate code introduced by this PR.


jscpd compared this branch against origin/main
across app, api and common-utils. Only new clones are listed; the codebase
currently holds 127 in total (1.78%).
Run yarn dupes locally to reproduce, or yarn dupes:all for the full picture.

Comment thread packages/common-utils/src/types.ts Resolved
@github-actions

github-actions Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

PR Review

If you are a coding agent acting for the author, read this first.
Nothing below blocks merge automatically; a maintainer decides. What they will expect:

  • 🔴 critical or 🟠 major in code this PR adds or changes: fix before asking for review.
  • 🔵 minor in code this PR changes: your call. Fix if small, otherwise reply.
  • Anything about surrounding code, or asking you to widen the change (hoist a helper,
    dedupe with another file, fix other call sites): never fix here, whatever the
    severity. Reply with one sentence; if it is critical, say so plainly so a human sees it.

One commit per review round. After two rounds, stop and ask a maintainer to review
scope rather than addressing more automated findings. Full rule: AGENTS.md.

5 finding(s): 🔴 0 critical · 🟠 2 major · 🔵 3 minor

4 posted as inline comment(s) on the changed lines. 1 listed below.

Findings outside the changed lines

  • 🟠 packages/app/tests/e2e/features/dashboard-single-select-filters.spec.ts:817 — E2E test expects focus on an input that the component renders as type="hidden" → getFilterSearchInput uses getByRole('textbox') (DashboardPage.ts:1162). With a value selected, VirtualMultiSelect renders the field as type="hidden", which has no textbox role and can't take focus. So toBeFocused() here should time out. Either keep the field a focusable text input (see the VirtualMultiSelect finding) or change the test to assert what actually happens.

Severity is the reviewer's own estimate and is used for ordering, not filtering. No finding blocks merge automatically; a maintainer decides.

@greptile-apps

greptile-apps Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium risk] Adds single-select mode to dashboard filters.

The PR appears safe to merge based on the reviewed changes.

Summary

Adds single-select dashboard filters across the editor, URL-backed selection state, variable resolution, and API contracts.

  • A single-select filter accepts one value; existing URLs with multiple values use the first.
  • Tests cover persistence, validation, selection behavior, and URL handling.

Reviews (2) · Last reviewed commit: "Merge branch 'main' into drew/single-sel..." · Reviewed by Greptile

@github-actions

github-actions Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Deep Review

Scope: PR #3295 — single-select dashboard filters (maxSelections: 1) across common-utils, api (external v2 + MCP), and app. Diff base 6ea5f52c. Mode: report-only (read-only).

The change is small, symmetric with the existing minSelections/required-filter pattern, and carries broad coverage: unit tests in common-utils, integration tests on the REST and MCP surfaces, form round-trip tests, and a new e2e spec. CI reports the full e2e suite green (397 passed / 0 failed). Verified independently: maxSelections round-trips through the external API (projection is whole-array filters: 1), and the "keep only the first value" truncation in resolveFilterSelection is deterministic (Set insertion order follows URL/SQL write order).

✅ No critical issues found.

No P0/P1 or P2 findings survived re-grading. The one substantive prior review comment (Greptile P1, "hidden input breaks typing test") is not confirmed: the e2e spec dashboard-single-select-filters.spec.ts passes in CI, which means the locked field still resolves and focuses as a textbox at runtime — readOnly is what actually blocks typing, so the test exercises real behavior rather than timing out. The remaining observations are cosmetic.

🔵 P3 nitpicks (2)
  • packages/app/src/components/VirtualMultiSelect/VirtualMultiSelect.tsx:178 — type={isInputFieldLocked ? 'hidden' : 'visible'} uses 'visible', which is not a valid HTML input type (browsers coerce the unknown value to text), and the 'hidden' branch appears ineffective since the passing e2e test still locates and focuses the field as a textbox while locked.
    • Fix: Use 'text' for the unlocked case, and confirm the locked field visibly hides the cursor; if it does not, rely on readOnly alone and drop the type toggle.
  • packages/common-utils/src/types.ts:1719 — ChartVariableSchema.maxSelections is typed z.number().optional(), looser than the filter-definition schema's z.number().int().min(1).max(1); harmless because the value is derived internally, but the two schemas disagree on the field's constraints.
    • Fix: Mirror .int().min(1).max(1) on the variable schema so both definitions agree.

Reviewers (6): correctness, api-contract, frontend-races, testing, maintainability, previous-comments.

Testing gaps: Coverage is strong; two behaviors have no explicit assertion — clearing/removing a single-select pill back to empty, and toggling single-select off (confirming maxSelections is dropped from the saved filter). Both are low risk given the existing round-trip tests.

No finding blocks merge automatically. A maintainer will expect P0/P1 findings in code this PR changes to be fixed; P2/P3 are your call -- fix or reply. Never fix findings about surrounding code here; reply instead. Do not widen the PR. How to respond

@github-actions

github-actions Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

E2E Test Results

✅ All tests passed • 401 passed • 1 skipped • 1544s

Status Count
✅ Passed 401
❌ Failed 0
⚠️ Flaky 2
⏭️ Skipped 1

Tests ran across 4 shards in parallel.

View full report →

@pulpdrew
pulpdrew requested review from a team and teeohhem and removed request for a team October 5, 2026 16:18
<PillsInput.Field
onFocus={() => combobox.openDropdown()}
onBlur={() => combobox.closeDropdown()}
type={isInputFieldLocked ? 'hidden' : 'visible'}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 major — type="hidden" makes the combobox's only keyboard target unfocusable once a single-select filter has a value

A hidden input can't take focus and gets no key events. So once a value is picked, Tab skips the filter, arrow keys and Enter can't choose another option, the Backspace removal in handleKeyDown stops working, and you can't search a long list (e.g. the host picker from the MCP prompt) without clearing first. Keep the input type text and stop typing a second way instead: use readOnly plus caretColor: 'transparent', or ignore onChange while locked. Also drop 'visible': it isn't a valid input type and browsers just fall back to text.

Nothing blocks merge automatically, but a maintainer will expect this fixed if it is a real defect in code this PR changes. If it is about surrounding code, reply and say so instead of patching. Do not widen the PR. How to respond

values: selection
? Array.from(selection.included).map(String).sort()
: [],
maxSelections: filter.maxSelections,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 minor — maxSelections is added to every tile's chart-config variables, and the app never reads it

The comment just above says variables are built explicitly 'so no extra key leaks into' react-query keys. This line adds such a key anyway: checking or unchecking single-select now refetches every tile that uses variables, and no query code reads it. Remove it here and from ChartVariableSchema (types.ts:1721). The only consumer is the MCP check in api/src/mcp/tools/dashboards/variables.ts, which can look up single-select names from the filters via getDashboardVariableFilters, the same way buildStaticOptionsByName already does.

Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond

/** Empty means nothing is selected. */
values: z.array(z.string()),
/** The filter's selection cap; 1 means the variable is single-select. */
maxSelections: z.number().optional(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 minor — Selection cap is defined twice with different constraints

dashboardFilterBaseSchema.maxSelections is int().min(1).max(1), while the ChartVariableSchema copy accepts any number. If the variable-side field is kept, derive it from the filter schema (e.g. dashboardFilterBaseSchema.shape.maxSelections). Better, drop it, since only the declaration type needs it (see the useDashboardFilters finding).

Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond

{showRequiredFilterOptions && (
<Stack gap="xs">
<Divider my="xs" />
<CheckBoxControlled

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 minor — Single-select checkbox sits behind showRequiredFilterOptions, but that prop is documented as covering required-filter options only

The prop doc at line 69-70 (and in DashboardFiltersModal/index.tsx:19) says it controls 'the options for marking a filter as required', yet it now also hides the single-select option. Rename it (e.g. showSelectionLimitOptions) or give single-select its own flag, so a caller like ServicesDashboardPage can control the two separately.

Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond

@kodiakhq
kodiakhq Bot merged commit 0d2425d into main Oct 7, 2026
29 checks passed
kodiakhq Bot pushed a commit that referenced this pull request Oct 8, 2026
## Summary

This PR adds a new format for variable references - `promql`. This is intended to be used in promql expressions and is the new default when another format is not specified. This replaces the previous default (`regex`).

The new format is identical in behavior to the previous format, except that single-select variables are not regex-escaped. 

Motivation: Single select variables are typically referenced in PromQL with `field="$var"`. If $var is regex escaped, that doesn't work. Multi-select should always be regex escaped and referenced via the regex match operator `field=~"$var"`.

This is backwards compatible except for references to single-select variables (#3295), which have not yet been released.

### Screenshots or video

<img width="795" height="201" alt="Screenshot 2026-10-05 at 1 04 19 PM" src="https://github.com/user-attachments/assets/67399be7-cb93-4ba7-9372-caff473533e5" />

### How to test locally

1. Create a timeseries / promql source off of metrics_ts timeseries table
2. Create a dashboard with a promql labels variable
3. Reference the variable in a promql tile

### References



- Linear Issue: Closes HDX-5563
- Related PRs:

This branch was successfully deployed

2 active deployments
Preview – hyperdx-oss — bd596e29 Deployed Oct 7, 2026 by vercel[bot]
Preview – hyperdx-storybook — bd596e29 Deployed Oct 7, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automerge review/tier-4 Critical — deep review + domain expert sign-off

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants