fix(alerts): pretty-print + highlight raw SQL, stop raw-query chart flash#155
Merged
Merged
Conversation
…lash On the alert overview, raw-SQL rules showed their query as an unstyled, right-aligned blob and flashed a "Raw SQL has no live preview" placeholder before the checks-driven chart loaded. - Add formatSql() (apps/web/src/lib/sql-format.ts): a conservative, dependency-free, ClickHouse-aware pretty-printer that breaks top-level clauses, SELECT columns, and WHERE AND/OR onto their own lines while keeping strings, comments, $__macros, Map['key'] access, and function-call commas atomic. Falls back to the original text on any failure. Unit-tested. - Render the Raw SQL in the Configuration card as a full-width, syntax- highlighted code block (reusing tokenizeSql) that matches the dashboard SQL editor. - Gate the hero chart's loading state on checks for raw_query rules (Result.isInitial(checksResult)) so the placeholder no longer flashes before the checks-driven chart appears; the genuine "no checks yet" empty state is unchanged. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Contributor
|
Your LLM provider API key was rejected. Rotate the key in your provider dashboard, then update the matching GitHub Actions secret. Update repo secret → · Model settings → · Setup docs → · Ask in Discord →
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

What
On the alert detail Overview (
/alerts/$ruleId), two fixes for raw SQL rules:listRuleChecksquery resolved — a confusing "says no chart, then shows one" moment.Why
useAlertRuleChartreturnschartLoading: falseimmediately for raw queries (they have no warehouse preview), and the route only passedloading={chartLoading}. So on first paintdata=[],checks=[],loading=false→ the raw placeholder showed, thenchecksloaded and the chart replaced it.How
apps/web/src/lib/sql-format.ts(new) —formatSql(): a conservative, dependency-free, ClickHouse-aware pretty-printer. Breaks top-level clauses / SELECT columns / WHEREAND/ORonto their own lines while keeping string literals, comments,$__macros,Map['key']access, and function-call commas (quantile(0.95)(Duration / 1e6)) atomic. Falls back to the original text on any error.apps/web/src/lib/sql-format.test.ts(new) — 9 unit tests, including an exact-output assertion for the canonical alert query plus footgun coverage (nested vs top-levelAND, map access, macros, string literals,GROUP BY, idempotency, no-throw on odd input).apps/web/src/routes/alerts/$ruleId.tsx— render the Raw SQL viatokenizeSql(formatSql(...))as a full-width highlighted block; gate the hero chart'sloadingonResult.isInitial(checksResult)forraw_queryrules so the placeholder no longer flashes. The genuine "no checks recorded yet" empty state is unchanged.Before:
After:
Verification
vitest run apps/web/src/lib/sql-format.test.ts→ 9/9 pass.bun --filter=@maple/web typecheck→ clean.🤖 Generated with Claude Code