From a0faa59264385a2d5dfe7ed562220c7fe4e36d24 Mon Sep 17 00:00:00 2001 From: Aaron Knudtson <87577305+knudtty@users.noreply.github.com> Date: Tue, 1 Dec 2026 08:06:45 -0600 Subject: [PATCH] fix: rename handlebar helper "date" to "formatDate" --- .changeset/dashboard-link-globals.md | 2 +- packages/api/openapi.json | 2 +- .../api/src/mcp/prompts/dashboards/content.ts | 2 +- .../api/src/mcp/tools/dashboards/schemas.ts | 2 +- .../src/routers/external-api/v2/dashboards.ts | 2 +- .../OnClickForm/OnClickDrawer.tsx | 2 +- .../src/core/__tests__/linkUrlBuilder.test.ts | 20 +++++++++++++++++-- .../core/__tests__/seriesNameTemplate.test.ts | 4 ++++ .../common-utils/src/core/handlebarsEnv.ts | 2 +- 9 files changed, 29 insertions(+), 9 deletions(-) diff --git a/.changeset/dashboard-link-globals.md b/.changeset/dashboard-link-globals.md index 62792c1471..f4228747ee 100644 --- a/.changeset/dashboard-link-globals.md +++ b/.changeset/dashboard-link-globals.md @@ -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 "iso"|"seconds"|"ms"}}` helper. External links now carry + `{{formatDate "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. diff --git a/packages/api/openapi.json b/packages/api/openapi.json index 69cd2b340d..4db86fa2b9 100644 --- a/packages/api/openapi.json +++ b/packages/api/openapi.json @@ -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 \"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 \"iso\"}}` helper. The rendered value must be an absolute http(s) URL.\n", "example": "https://example.com/d/abc?var-service={{ServiceName}}" } } diff --git a/packages/api/src/mcp/prompts/dashboards/content.ts b/packages/api/src/mcp/prompts/dashboards/content.ts index d8a6c4ee30..273fb97e7f 100644 --- a/packages/api/src/mcp/prompts/dashboards/content.ts +++ b/packages/api/src/mcp/prompts/dashboards/content.ts @@ -1377,7 +1377,7 @@ Every template can also read these globals: {{__timezone}} the IANA time zone times are shown in {{__url_time_range}} "from=&to=", ready to drop into a ClickStack URL {{__all_variables}} "filters=<…>" carrying the current dashboard's filter selections, or empty - {{date "iso"}} formats a timestamp as ISO 8601; "seconds" and "ms" also work + {{formatDate "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/?$__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}}'". diff --git a/packages/api/src/mcp/tools/dashboards/schemas.ts b/packages/api/src/mcp/tools/dashboards/schemas.ts index 2e6f0a174f..916db33d71 100644 --- a/packages/api/src/mcp/tools/dashboards/schemas.ts +++ b/packages/api/src/mcp/tools/dashboards/schemas.ts @@ -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 "iso"|"seconds"|"ms"}} to format a timestamp.'; + '{{formatDate "iso"|"seconds"|"ms"}} to format a timestamp.'; const mcpOnClickTargetSchema = z .discriminatedUnion('mode', [ diff --git a/packages/api/src/routers/external-api/v2/dashboards.ts b/packages/api/src/routers/external-api/v2/dashboards.ts index 69978c7053..c70f14f291 100644 --- a/packages/api/src/routers/external-api/v2/dashboards.ts +++ b/packages/api/src/routers/external-api/v2/dashboards.ts @@ -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 "iso"}}` helper. + * `{{__all_variables}}`, and the `{{formatDate "iso"}}` helper. * The rendered value must be an absolute http(s) URL. * example: "https://example.com/d/abc?var-service={{ServiceName}}" * diff --git a/packages/app/src/components/DBEditTimeChartForm/OnClickForm/OnClickDrawer.tsx b/packages/app/src/components/DBEditTimeChartForm/OnClickForm/OnClickDrawer.tsx index 23c515716c..cbd0a984ab 100644 --- a/packages/app/src/components/DBEditTimeChartForm/OnClickForm/OnClickDrawer.tsx +++ b/packages/app/src/components/DBEditTimeChartForm/OnClickForm/OnClickDrawer.tsx @@ -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(); diff --git a/packages/common-utils/src/core/__tests__/linkUrlBuilder.test.ts b/packages/common-utils/src/core/__tests__/linkUrlBuilder.test.ts index c39a9df15c..ec7c8a40f4 100644 --- a/packages/common-utils/src/core/__tests__/linkUrlBuilder.test.ts +++ b/packages/common-utils/src/core/__tests__/linkUrlBuilder.test.ts @@ -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, @@ -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', + }); + }); }); diff --git a/packages/common-utils/src/core/__tests__/seriesNameTemplate.test.ts b/packages/common-utils/src/core/__tests__/seriesNameTemplate.test.ts index 74548cfe8c..8e817a08c1 100644 --- a/packages/common-utils/src/core/__tests__/seriesNameTemplate.test.ts +++ b/packages/common-utils/src/core/__tests__/seriesNameTemplate.test.ts @@ -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]))'); }); diff --git a/packages/common-utils/src/core/handlebarsEnv.ts b/packages/common-utils/src/core/handlebarsEnv.ts index 1f0f4a469b..9b51c8b905 100644 --- a/packages/common-utils/src/core/handlebarsEnv.ts +++ b/packages/common-utils/src/core/handlebarsEnv.ts @@ -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(', ')}.`,