Skip to content

refactor: Decompose heatmap query and view builders - #3276

Merged
pulpdrew merged 1 commit into
mainfrom
drew/heatmap-series-2
Oct 2, 2026
Merged

pulpdrew merged 1 commit into
mainfrom
drew/heatmap-series-2

Conversation

@pulpdrew

@pulpdrew pulpdrew commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR applies a few refactors to heatmap related components, hooks, and utilities. This is motivated by a new heatmap "mode" which will build, query, and plot a different data shape.

No behavior changes are expected in this PR.

Screenshots or video

Screenshot 2026-10-02 at 12 04 27 PM Screenshot 2026-10-02 at 12 04 16 PM Screenshot 2026-10-02 at 12 03 35 PM

How to test on Vercel preview

View the heatmap in search event deltas, in a dashboard, or in chart explorer.

References

  • Linear Issue:
  • Related PRs:

@vercel

vercel Bot commented Oct 2, 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 2, 2026 2:57pm UTC
hyperdx-storybook Ready Ready Preview Oct 2, 2026 2:57pm UTC

Request Review

@pulpdrew
pulpdrew marked this pull request as ready for review October 2, 2026 14:49
@changeset-bot

changeset-bot Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 2b3a0eb

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@github-actions github-actions Bot added the review/tier-3 Standard — full human review required label Oct 2, 2026
@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

🟡 Tier 3 — Standard

Introduces new logic, modifies core functionality, or touches areas with non-trivial risk.

Why this tier:

  • Diff size: 536 production lines changed (Tier 2 max: < 250)

Review process: Full human review — logic, architecture, edge cases.
SLA: First-pass feedback within 1 business day.

Stats
  • Production files changed: 14
  • Production lines changed: 536 (+ 36 in test files, excluded from tier calculation)
  • Branch: drew/heatmap-series-2
  • Author: pulpdrew

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

Comment on lines +32 to +33
export type HeatmapQuery = {
mode: 'distribution';

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This type will gain a second mode (series in subsequent PRs)

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.

Sounds good. Might be good to establish an ENUM at that time to avoid repeating plain text.

@github-actions

github-actions Bot commented Oct 2, 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.80%).
Run yarn dupes locally to reproduce, or yarn dupes:all for the full picture.

@@ -81,7 +78,7 @@ export function useHeatmapData({
queryKey: ['heatmap_bucket', bucketConfig],
// Wait for fresh bounds, so a refresh doesn't also query the new range
// bucketed with the previous range's min/max.
enabled: canQueryBuckets && !isMinMaxPlaceholderData,
enabled: enabled && canQueryBuckets && !isMinMaxPlaceholderData,

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 — The bucket query now waits on enabled, which changes behaviour and has no test

The PR says nothing should behave differently, but the bucket query now also checks enabled, so a disabled chart (e.g. DBSearchHeatmapChart with isReady=false) no longer fetches buckets from cached bounds. Mention this in the PR description and add a render test where enabled={false} with settled bounds expects lastOptionsFor('heatmap_bucket')?.enabled to be false. Every current test uses the default enabled=true, so removing the new check would still pass.

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

import { NumberFormat } from '@/types';
import { formatDurationMsCompact, formatNumber } from '@/utils';

import type { HeatmapScaleType } from './heatmapGrid';

/** Number format for a heatmap of trace durations in ms. */
export const HEATMAP_DURATION_NUMBER_FORMAT = {

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 — HEATMAP_DURATION_NUMBER_FORMAT duplicates the literal in EditTimeChartForm

applyHeatmapDefaults in packages/app/src/components/DBEditTimeChartForm/EditTimeChartForm.tsx:174 still hardcodes { output: 'duration', factor: 0.001 } for the same heatmap duration default. Import the new constant there (spread it if setValue needs a mutable object) so the two can't drift apart.

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

[fromMs, toMs, granularity],
);

return { granularity, generatedTsBuckets, fromMs, toMs };

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 — useHeatmapTimeBuckets returns fromMs/toMs, but nothing reads them

The only caller (useHeatmapData.ts:38) destructures just granularity and generatedTsBuckets. Return only those two values.

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

@github-actions

github-actions Bot commented Oct 2, 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.

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

1 posted as inline comment(s) on the changed lines. 1 listed below. 1 unchanged from an earlier push (already inline above).

Findings outside the changed lines

1 minor
  • 🔵 packages/app/src/components/DBHeatmapChart/HeatmapChartView.tsx:381 — onFilter, onClearFilter and selectionBounds are typed twice, inline, in two components → Move these three into the exported HeatmapChartViewProps (or a named type), and have DBHeatmapChartProps derive from it instead of redeclaring them in DBHeatmapChart.tsx:11-20. Right now the two inline signatures are kept in sync by hand, which goes against the convention to use reusable named types instead of repeating verbose ones.

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

@pulpdrew
pulpdrew force-pushed the drew/heatmap-series-2 branch from 6f9158c to 2b3a0eb Compare October 2, 2026 14:52
@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

E2E Test Results

✅ All tests passed • 393 passed • 1 skipped • 1618s

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

Tests ran across 4 shards in parallel.

View full report →

darkPalette: ['#000'],
lightPalette: ['#fff'],
toHeatmapChartConfig: jest.fn(() => ({ heatmapConfig: {} })),
toHeatmapQuery: jest.fn(() => ({

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 — No test checks that the scale chosen in Search reaches the heatmap

DBSearchHeatmapChart used to pass scaleType as a prop. Now the scale only arrives through select[0].heatmapScaleType inside toHeatmapQuery. The mock always returns scaleType: 'log' and nothing asserts on its arguments, so if heatmapScaleType were dropped and linear mode silently fell back to log, the test would still pass. Add an assertion that toHeatmapQuery receives select[0].heatmapScaleType === 'linear' when the setting is linear, or run the real toHeatmapQuery and assert on query.scaleType.

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

@greptile-apps

greptile-apps Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

[Medium risk] Refactors heatmap chart query and view builders.

The refactor has no identified blocking behavioral failure, but the required empty-state convention must be satisfied before merging.

Fix All in Claude CodeFindings

  1. P2 Inline heatmap empty state ▶
  2. P2 Enable transition lacks coverage ▶

Summary

The PR separates heatmap query construction, data hooks, and rendering while migrating dashboard, editor, search, and ClickHouse callers to a HeatmapQuery.

  • The new view should use the repository’s required empty-state component.
  • The changed bucket-query enablement needs a disable/re-enable test.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Dashboard, search, editor, ClickHouse] --> B[HeatmapQuery]
  B --> C[DBHeatmapChart]
  C --> D[useHeatmapData]
  D --> E[Bounds and bucket queries]
  D --> F[useSettledView]
  F --> G[HeatmapChartView]
  G --> H[HeatmapPlot]
Loading

Reviews (1) · Last reviewed commit: "refactor: Decompose heatmap query and vi..."

@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Deep Review

✅ No critical issues found. This is a clean, behavior-preserving decomposition: the config+scaleType prop pair collapses into a single query prop, toHeatmapChartConfig becomes toHeatmapQuery, and the view/refresh logic is extracted into HeatmapChartView + useHeatmapView. Direct verification confirmed every consumer of the old surface was migrated (no residual toHeatmapChartConfig, .heatmapConfig, or config=/scaleType= props remain), props flow intact through the ...viewProps spread into HeatmapChartView, scaleType is supplied at every callsite, and HeatmapView/HeatmapData have no stale external importers. No P0/P1/P2 findings.

🔵 P3 nitpicks (2)
  • packages/app/src/components/DBHeatmapChart/useHeatmapData.ts:76 -- the bucket query's enabled gate gained an enabled && term (enabled && canQueryBuckets && !isMinMaxPlaceholderData), the one semantic change in a PR that claims none, which suppresses the bucket query while the component is disabled even if the bounds query is serving placeholder data.
    • Fix: Confirm the added enabled && guard is intentional and leave an inline note that it is the deliberate behavior delta.
  • packages/app/src/components/DBHeatmapChart/heatmapQueries.ts:32 -- the exported HeatmapQuery type is currently unused outside the type-only test import, which the Knip check already flags.
    • Fix: Leave as-is for the follow-up series mode or re-export it where consumed; no change required if the next PR lands soon.

Reviewers (4): correctness (orchestrator-verified), api-contract (orchestrator-verified), previous-comments, agent-native.

Testing gaps: The extracted useHeatmapView hooks (useSettledView, useHeatmapTimeBuckets) and HeatmapChartView have no dedicated unit tests; they remain covered indirectly through the existing DBHeatmapChart.render.test.tsx refresh/scale suites, and the three updated jest mocks match the new toHeatmapQuery { mode, config, scaleType } contract.

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

@pulpdrew
pulpdrew merged commit 2ace22d into main Oct 2, 2026
36 checks passed

This branch was successfully deployed

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

Labels

review/tier-3 Standard — full human review required

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants