Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .changeset/dashboard-link-globals.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ feat: more global vars for dashboard links

- Row-click link templates can use `{{__from}}`, `{{__to}}`, `{{__timezone}}`,
`{{__url_time_range}}`, `{{__all_variables}}`, and a
`{{date <value> "iso"|"seconds"|"ms"}}` helper. External links now carry
`{{formatDate <value> "iso"|"seconds"|"ms"}}` helper. External links now carry
the time range this way.
- Dashboard links can set a destination filter by variable name
(`kind: "variableTemplate"`), so static list filters can be prefilled.
Expand Down
2 changes: 1 addition & 1 deletion packages/api/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -3728,7 +3728,7 @@
"urlTemplate": {
"type": "string",
"minLength": 1,
"description": "Handlebars template rendered against the clicked row; supports `{{column}}` variables, plus the globals `{{__from}}` and `{{__to}}` (epoch ms), `{{__timezone}}`, `{{__url_time_range}}`, `{{__all_variables}}`, and the `{{date <value> \"iso\"}}` helper. The rendered value must be an absolute http(s) URL.\n",
"description": "Handlebars template rendered against the clicked row; supports `{{column}}` variables, plus the globals `{{__from}}` and `{{__to}}` (epoch ms), `{{__timezone}}`, `{{__url_time_range}}`, `{{__all_variables}}`, and the `{{formatDate <value> \"iso\"}}` helper. The rendered value must be an absolute http(s) URL.\n",
"example": "https://example.com/d/abc?var-service={{ServiceName}}"
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/mcp/prompts/dashboards/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1377,7 +1377,7 @@ Every template can also read these globals:
{{__timezone}} the IANA time zone times are shown in
{{__url_time_range}} "from=<ms>&to=<ms>", ready to drop into a ClickStack URL
{{__all_variables}} "filters=<…>" carrying the current dashboard's filter selections, or empty
{{date <value> "iso"}} formats a timestamp as ISO 8601; "seconds" and "ms" also work
{{formatDate <value> "iso"}} formats a timestamp as ISO 8601; "seconds" and "ms" also work
Search and dashboard links already carry the time range, so the globals matter most in external urlTemplates. Markdown tiles accept the same globals as $__from, $__to, $__timezone, $__url_time_range, and $__all_variables, and \${var:url} URL-encodes a variable's values, e.g. [Service detail](/dashboards/<id>?$__url_time_range&$__all_variables).

whereTemplate Handlebars-style template. The rendered string is placed in the destination's \`where\` query param. Uses Lucene or SQL syntax matching \`whereLanguage\`. Example: "ServiceName = '{{service.name}}'".
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/mcp/tools/dashboards/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ const LINK_GLOBALS_DESCRIPTION =
'Besides row columns, every template can use {{__from}} / {{__to}} (epoch ms), ' +
'{{__timezone}}, {{__url_time_range}} ("from=…&to=…"), {{__all_variables}} ' +
'("filters=…" with the current dashboard\'s filter selections, or empty), and ' +
'{{date <value> "iso"|"seconds"|"ms"}} to format a timestamp.';
'{{formatDate <value> "iso"|"seconds"|"ms"}} to format a timestamp.';

const mcpOnClickTargetSchema = z
.discriminatedUnion('mode', [
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/routers/external-api/v2/dashboards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2200,7 +2200,7 @@ const EXTERNAL_DASHBOARD_PROJECTION = {
* Handlebars template rendered against the clicked row; supports
* `{{column}}` variables, plus the globals `{{__from}}` and
* `{{__to}}` (epoch ms), `{{__timezone}}`, `{{__url_time_range}}`,
* `{{__all_variables}}`, and the `{{date <value> "iso"}}` helper.
* `{{__all_variables}}`, and the `{{formatDate <value> "iso"}}` helper.
* The rendered value must be an absolute http(s) URL.
* example: "https://example.com/d/abc?var-service={{ServiceName}}"
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const TEMPLATE_HELP_TEXT =
'Templates can reference column values from the clicked row using {{columnName}}, ' +
'and the page through {{__from}}, {{__to}} (epoch ms), {{__timezone}}, ' +
'{{__url_time_range}} and {{__all_variables}}. Format a timestamp with ' +
'{{date __from "iso"}} ("seconds" and "ms" also work).';
'{{formatDate __from "iso"}} ("seconds" and "ms" also work).';

function SearchOnClickFields({ control }: { control: DrawerControl }) {
const { data: sources } = useSources();
Expand Down
20 changes: 18 additions & 2 deletions packages/common-utils/src/core/__tests__/linkUrlBuilder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1257,7 +1257,7 @@ describe('link template globals', () => {
onClick: {
type: 'external',
urlTemplate:
'https://x.example.com/d/1?{{__url_time_range}}&{{__all_variables}}&f={{__from}}&t={{__to}}&tz={{__timezone}}&iso={{date __from "iso"}}&s={{date __to "seconds"}}',
'https://x.example.com/d/1?{{__url_time_range}}&{{__all_variables}}&f={{__from}}&t={{__to}}&tz={{__timezone}}&iso={{formatDate __from "iso"}}&s={{formatDate __to "seconds"}}',
},
row: {},
dateRange,
Expand Down Expand Up @@ -1405,8 +1405,24 @@ describe('link template globals', () => {
expect(() =>
validateOnClickTemplate({
type: 'external',
urlTemplate: 'https://x.example.com/?t={{date __from "nope"}}',
urlTemplate: 'https://x.example.com/?t={{formatDate __from "nope"}}',
}),
).toThrow('Unknown date format "nope"');
});

it('reads a row column named date as a variable, not a helper', () => {
const onClick: OnClickExternal = {
type: 'external',
urlTemplate: 'https://x.example.com/?d={{date}}',
};
expect(() => validateOnClickTemplate(onClick)).not.toThrow();
const result = renderOnClickExternal({
onClick,
row: { date: '2026-01-01' },
});
expect(result).toEqual({
ok: true,
url: 'https://x.example.com/?d=2026-01-01',
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ describe('renderPromqlSeriesNames', () => {
expect(nameOne({}, '{{missing}}')).toBe('sum(rate(up[5m]))');
});

it('resolves a label named date', () => {
expect(nameOne({ date: '2026-01-01' }, '{{date}}')).toBe('2026-01-01');
});

it('uses the default name on a syntax error', () => {
expect(nameOne({ pod: 'a' }, '{{unclosed')).toBe('sum(rate(up[5m]))');
});
Expand Down
2 changes: 1 addition & 1 deletion packages/common-utils/src/core/handlebarsEnv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const DATE_FORMATS = ['iso', 'seconds', 'ms'] as const;
* Formats a timestamp (epoch ms, or a date string) as `iso`, `seconds` or `ms`.
* Returns an empty string when the input can't be read as a date.
*/
hb.registerHelper('date', (value: unknown, format: unknown): string => {
hb.registerHelper('formatDate', (value: unknown, format: unknown): string => {
if (!DATE_FORMATS.some(f => f === format)) {
throw new Error(
`Unknown date format "${typeof format === 'string' ? format : ''}". Expected one of: ${DATE_FORMATS.join(', ')}.`,
Expand Down
Loading