Skip to content

fix(app): open the alert panel from a dashboard tile's alert button - #3680

Open
gedaliakliger wants to merge 2 commits into
ClickHouse:mainfrom
gedaliakliger:agent/1781-tile-alert-opens-panel
Open

gedaliakliger wants to merge 2 commits into
ClickHouse:mainfrom
gedaliakliger:agent/1781-tile-alert-opens-panel

Conversation

@gedaliakliger

Copy link
Copy Markdown

Summary

The bell on a dashboard tile (and the alert item in a narrow tile's menu) called onEditClick, so it opened the same editor as Edit. Since #3222 the alert form lives in a side panel that opens only on request, so after clicking the bell you had to click Add alert or Edit alert again inside the editor. Tile has declared an onAddAlertClick prop since the v2 dashboard, but nothing wired it.

  • The tile's alert actions now call onAlertClick, which opens the tile editor with the new defaultAlertPanelOpened.
  • EditTimeChartForm then opens the alert panel from the start, on the tile's alert. A tile without one gets a new alert, filled in as the Add alert button fills it (DEFAULT_TILE_ALERT plus the tile name as display name), and the panel opens it as a draft, so closing the panel discards it, as with the button.
  • The new alert is only added where the editor offers alerts: a saved dashboard, not local mode, and savedChartConfigSupportsAlerts. On a temporary dashboard the bell still opens a plain editor.
  • Until the chart has run once, a run ignores the new alert: it has no webhook yet, and since the form's resolver checks only the alert, the first run would otherwise stop there and leave the preview empty. That run, whether automatic or by hand (a raw SQL tile with no source doesn't run on open), previews the chart without the alert and shows no alert errors. Later runs check the alert as before.

eugeneo17's #3194 fixed this before the alert panel landed and was closed by the open-PR limit; its review is where the temporary-dashboard case came up.

Checks run here: the five related suites (DBEditTimeChartForm, AlertPanel, AlertPanelButton, TileAlertEditor, EditInlineAlertModal, 95 tests), ESLint and Prettier on the changed files (no new warnings), node scripts/ci/ratchet.mjs, and tsc --noEmit on packages/app. Left to CI: lint and unit tests across packages, and E2E. No unit test covers the DBDashboardPage wiring, since the page has no component test harness; the E2E dashboard specs already reach the button through getTileButton('alerts').

Screenshots or video

I couldn't capture these: local mode hides the tile alert editor (yarn app:dev:local and the Vercel preview), and the full stack needs Docker, which I don't have here.

Before After

How to reproduce

Starting point: yarn dev (alerts need the API), a saved dashboard with a Line or Number tile on the Logs source.

On main:

  1. Hover the tile and click its bell (Add alert).
  2. The tile editor opens without the alert panel. Add alert has to be clicked again inside the editor.

On this branch:

  1. Click the tile's bell: the editor opens with the alert panel showing a new alert. Add alert under its fields confirms it; closing the panel discards it.
  2. On a tile that has an alert, the bell opens the editor on that alert, with Update alert.
  3. On a temporary dashboard (New Dashboard → Temporary Dashboard), add a Line tile and click its bell: the editor opens without an alert, as before.

How to test on Vercel preview

N/A: the tile alert editor is hidden in local mode, so the preview can't show it.

References

The tile's bell opened the plain tile editor, so the alert panel needed a
second click. It now opens the editor on the tile's alert, or on a new draft
where the editor offers alerts.
@gedaliakliger
gedaliakliger requested a review from a team as a code owner November 16, 2026 17:41
@vercel

vercel Bot commented Nov 16, 2026

Copy link
Copy Markdown

@gedaliakliger is attempting to deploy a commit to the HyperDX Team on Vercel.

A member of the Team first needs to authorize it.

@changeset-bot

changeset-bot Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 5fffdb9

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

This PR includes changesets to release 3 packages
Name Type
@hyperdx/app Patch
@hyperdx/api 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

getFormReferenceVariables(savedFormValue).length === 0 &&
!IS_LOCAL_MODE &&
savedChartConfigSupportsAlerts(chartConfig);
const formValue: ChartEditorFormState = useMemo(() => {

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.

🟡 P2 — Putting the draft alert into the form's defaultValues makes discarding it look like an unsaved edit

formValue (with the draft alert) is passed as defaultValues/values, so RHF treats the draft as the saved state. When the user closes the panel, cancelAlertChanges(true) sets alert to undefined. From then on _getDirty() sees a difference from the defaults, so the next field edit, even one that is reverted, makes isDirty true. Closing the editor (EditTileModal.handleClose) then asks to discard changes on a tile the user never changed. Fix: keep savedFormValue as the form's defaults and add the draft after mount with setValue('alert', …) (the path the Add alert button already uses), so the defaults still match the saved tile.

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

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:

  • 🔴 P0/P1 in code this PR adds or changes: fix before asking for review.
  • 🟡 P2 in code this PR changes: your call. Fix if small, otherwise reply.
  • 🔵 P3 is collapsed at the bottom: nobody needs to act on it before merge.
  • 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
    priority. Reply with one sentence; if it is P0, 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.

4 finding(s): 🔴 0 P0/P1 · 🟡 1 P2 · 🔵 3 P3

1 posted as inline comment(s) on the changed lines. 3 P3 folded at the bottom.

🔵 3 P3 — no action needed before merge
  • 🔵 P3 packages/app/src/components/DBEditTimeChartForm/EditTimeChartForm.tsx:295 — opensOnNewAlert restates the editor's alert-availability rule by hand → The condition repeats alertsEnabled (EditTimeChartForm.tsx:432: enableAlerts ?? dashboardId != null and no reference variable) plus the !IS_LOCAL_MODE and display-type checks behind showAlertButton (ChartEditorControls.tsx:189, RawSqlChartEditor.tsx:191). That leaves three copies to keep in sync, and if one changes the bell can add a draft the editor has no button for, or the reverse. Fix: put the rule in one shared helper, e.g. canOfferTileAlert({enableAlerts, dashboardId, form}), and use it in all three places.
  • 🔵 P3 packages/app/src/components/DBEditTimeChartForm/EditTimeChartForm.tsx:306 — Third copy of how a new tile alert is built → {...DEFAULT_TILE_ALERT, ...(name && { displayName: name })} is already written inline in ChartEditorControls.tsx:517 and RawSqlChartEditor.tsx:252. This adds a third copy that has to keep matching what Add alert does, which is the behaviour the PR depends on. Fix: add makeNewTileAlert(chartName?: string) to @/utils/alerts next to DEFAULT_TILE_ALERT and call it from all three places.
  • 🔵 P3 packages/app/src/components/DBEditTimeChartForm/__tests__/DBEditTimeChartForm.test.tsx:398 — Only one of the new alert-gating conditions is tested → Only dashboardId: undefined is tested. Nothing covers a tile on a data source variable, a display type that doesn't support alerts, or savedChartConfigSupportsAlerts returning false, so if any of those checks is dropped from opensOnNewAlert, a draft alert would be added with no button to manage it and the tests would still pass. Fix: add a negative case for a $var source and one for an unsupported display type (e.g. Table), each asserting there is no alert-details.

Priority comes from a separate grading pass over the finished review. P3 is folded here instead of posted inline. No finding blocks merge automatically; a maintainer decides.

@github-actions

Copy link
Copy Markdown
Contributor

Deep Review

✅ No critical issues found.

This change is well-scoped frontend view-state plumbing: it wires the dashboard tile's alert bell to onAlertClick, which opens the existing tile editor with the alert panel pre-expanded on the tile's alert or a seeded draft. I traced the three highest-risk paths directly against the code and they hold up:

  • No error-swallowing in the ignoresNewAlert branch. When handleSubmit routes to the new onInvalid callback, it calls runChart({ ...getValues(), alert: undefined }), and runChart re-validates through validateAndNormalize; genuine chart-config errors still surface (or are suppressed only under autoRun, which is the intended quiet-open behavior).
  • No autoRun/first-run race. autoRunFiredRef guards re-fire, and on first fire queriedConfig == null, so ignoresNewAlert is correctly true for the seeded draft.
  • No stale isEditingTileAlert read. Every setEditedTile(chart) open path (onEditClick, onAlertClick, add-new-tile) sets isEditingTileAlert first; the only unset calls are closes (setEditedTile(undefined)). The modal remounts the form per open, so defaultAlertPanelOpened/defaultIsDraft re-apply cleanly.
  • onAlertClick wiring is complete. Tile is defined and used only in DBDashboardPage, and the removed optional onAddAlertClick had no other references, so making onAlertClick required is safe.

🟡 P2 -- recommended

  • packages/app/src/DBDashboardPage.tsx:2535 -- The core wiring of this PR (bell → onAlertClick → setIsEditingTileAlert(true) → defaultAlertPanelOpened, vs onEditClick → false) has no component-level test; only the downstream EditTimeChartForm behavior is covered, and the author confirms this branch relies on E2E alone.
    • Fix: Add a DBDashboardPage test (or extend the E2E dashboard spec assertion) that verifies the bell opens the editor with the alert panel expanded while Edit does not.
🔵 P3 nitpicks (2)
  • packages/app/src/components/DBEditTimeChartForm/EditTimeChartForm.tsx:836 -- The comment "The resolver only checks the alert" is imprecise: chartFormResolver validates the entire config via zodResolver(zSavedChartConfig), not just the alert, which could mislead a maintainer reasoning about what the onInvalid path is safe to drop.

    • Fix: Reword to note the resolver validates the whole config but that, in this draft-alert-on-open case, the alert is the only field expected to fail.
  • packages/app/src/components/DBEditTimeChartForm/EditTimeChartForm.tsx:295 -- opensOnNewAlert re-derives alert-eligibility conditions that overlap alertsEnabled (line 432) and savedChartConfigSupportsAlerts, but intentionally diverges (e.g. it adds !IS_LOCAL_MODE), creating a risk the two conditions drift out of sync as alert rules evolve.

    • Fix: Extract the shared eligibility predicate into one helper both sites call, keeping only the deliberate defaultAlertPanelOpened/draft-specific extras inline.

Reviewers (9 dispatched): correctness, adversarial, testing, maintainability, project-standards, kieran-typescript, julik-frontend-races, ce-agent-native-reviewer, ce-learnings-researcher. At synthesis time, agent-native (no parity gap — the bell is UI-only view state over the unchanged alert save path) and learnings (no relevant prior solutions in docs/solutions/) had returned; the correctness, adversarial, hook-safety, and race paths were verified directly by the orchestrator against the diff and surrounding code.

Testing gaps:

  • No DBDashboardPage component test for the onAlertClick vs onEditClick branch (see P2).
  • opensOnNewAlert guards for reference-variable tiles and unsupported display types are not directly exercised by the new tests (the dashboardId: undefined and missing-source cases are).

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

This branch has not been deployed

No deployments
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.

Clicking the Add Alert Icon on a Dashboard Tile does not open the modal with the alert editor

1 participant