Repository navigation
Conversation
Raw SQL charts and row-click link templates now expand ${__from}/${__to}
(with :date, 📅iso, 📅seconds), $__range/_s/_ms, ${__timezone},
${__url_time_range} and ${__all_variables}, so SQL and links migrated from
Grafana work unchanged.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🟡 Tier 3 — StandardIntroduces new logic, modifies core functionality, or touches areas with non-trivial risk. Why this tier:
Review process: Full human review — logic, architecture, edge cases. Stats
|
🦋 Changeset detectedLatest commit: 1ecb71d The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
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 |
Duplicate code analysis1 new clone introduced by this PR.
If one of these duplicates a helper that already exists, import it instead jscpd compared this branch against |
| variables: ChartVariable[], | ||
| ): ChartVariable[] { | ||
| // `${__all_variables}` reads every variable, from the SQL or a link template. | ||
| if (/\$\{?__all_variables\b/.test(JSON.stringify(config))) return variables; |
There was a problem hiding this comment.
🔵 minor — A link that uses ${__all_variables} makes the tile's query re-run whenever any variable changes
filterReferencedVariables decides which variables go into the tile config, and that config is the query key in useQueriedChartConfig and useOffsetPaginatedQuery (DBDashboardPage.tsx:619-630). So when only an onClick template reads ${__all_variables}, the tile still gets every variable and re-queries ClickHouse on each unrelated selection change, even though its SQL is unchanged. The JSON.stringify(config) regex also matches the token inside SQL comments, builder where strings, aliases and markdown. Fix: only short-circuit here when the SQL itself uses the token, found with the scanner rather than a regex over the whole config. Pass the full dashboard variable list to useOnClickLinkBuilder separately (from DBDashboardPage through DBTableChart), not via config.variables.
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
| if (input.charAt(i + 1) === '{') { | ||
| const closeIndex = input.indexOf('}', i + 2); // no escaping because variable names can't contain `}` or `\` | ||
|
|
||
| // Grafana's braced macro form, `${__from}` / `${__from:date:iso}`, whose format is the macro's argument |
There was a problem hiding this comment.
🔵 minor — The new braced form for every macro has no tests outside the global variables
This branch now turns ${__<any macro>} / ${__<macro>:fmt} into a macro token for every caller: SQL, PromQL and the variable-macro scan. It also changes ${__filter} from a pass-through into an error, which the PR lists as a behaviour change. The added tests only cover the new global names. Add scanTemplateTokens/replaceMacros cases for ${__fromTime}, ${__interval_s}, ${__filter} (now an argument error), and a PromQL ${__range}. Also add a case where the text up to } merely starts with a macro name, e.g. ${__from_x}, and should stay verbatim.
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
PR Review
3 finding(s): 🔴 0 critical · 🟠 0 major · 🔵 3 minor 2 posted as inline comment(s) on the changed lines. 1 listed below. Findings outside the changed lines1 minor
Severity is the reviewer's own estimate and is used for ordering, not filtering. No finding blocks merge automatically; a maintainer decides. |
Deep ReviewScope: 16 files vs base ✅ No critical issues found. The injection surfaces are handled well: 🟡 P2 — recommended
🔵 P3 nitpicks (5)
Reviewers (9): correctness, security, maintainability, testing, kieran-typescript, performance, api-contract, adversarial, project-standards. Testing gaps: 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 |
E2E Test Results✅ All tests passed • 466 passed • 1 skipped • 1199s
Tests ran across 4 shards in parallel. |
Summary
Raw SQL charts and row-click link templates now expand:
${__from}/${__to}:date/:date:isogive ISO 8601,:date:secondsgives epoch seconds$__range/$__range_s/$__range_ms3600s/3600/3600000${__timezone}tzoverride, or browser zone);UTCfor alerts and MCP${__url_time_range}from=<ms>&to=<ms>${__all_variables}filters=<encoded variable selections>, the param ClickStack dashboards readEach works as
$__nameor${__name}.How:
packages/common-utils/src/globalVariables.ts, used byreplaceMacrosand by the link builder. Link templates are expanded before Handlebars, so Grafana URLs paste in unchanged, and a#fragmentis not treated as a SQL comment.${__name:format}for any macro, so${__fromTime}also works.'${__from:date:iso}'works inside quotes. Without a date range (saved-config validation) they fall back to the query params, so the time-filter checks still pass.${__timezone}in the three query hooks. Other charts don't refetch when the zone changes.${__all_variables}(in SQL or anonClicktemplate) receives every dashboard variable, not just the ones it references.${__timezone}must look like an IANA name, and${__all_variables}percent-encodes', so neither can break out of a SQL string.TIME_RANGE_MACROS, and the MCP prompts/SQL tool description are updated.Behaviour changes:
$__from,$__to,$__rangeor$__timezonenow gets expanded.${__filter}is now read as the$__filtermacro and errors for missing arguments, instead of passing through.Not supported: custom moment formats (
${__from:date:YYYY-MM}) raise a clear error. PromQL and markdown tiles don't get the new variables.How to reproduce
Starting point:
yarn app:dev:localconnected to the demo server.On
main:SELECT ${__from} AS f, $__range AS r, '${__timezone}' AS tz.On this branch:
900s), and your time zone.https://example.com/?${__url_time_range}&${__all_variables}. Hover a row: the link showsfrom=…&to=…&filters=….How to test on Vercel preview
Preview routes: /chart
Steps:
SELECT ${__from} AS f, $__range AS r, '${__timezone}' AS tzand run the query.f, anrending ins, and an IANA zone intz.References