Human-readable labels for Ad Hoc filters (keyLabel / DisplayNameFromDS)#106
Open
samjewell wants to merge 6 commits into
Open
Human-readable labels for Ad Hoc filters (keyLabel / DisplayNameFromDS)#106samjewell wants to merge 6 commits into
samjewell wants to merge 6 commits into
Conversation
…icker Use Cube dimension/measure Title as metadata label when present, so getTagKeys returns human-readable text for the Ad Hoc variable key dropdown. Fall back to Name when Title is empty. Ref: Grafana PR 117640 (ad hoc filter labels) Co-authored-by: Cursor <cursoragent@cursor.com>
Set field.Config.DisplayNameFromDS when building query result frames so panels can show human-readable keyLabel when adding Ad Hoc filters from Bar Chart tooltips or Table cell actions. Ref: Grafana PR 117640 (ad hoc filter labels) Co-authored-by: Cursor <cursoragent@cursor.com>
This comment has been minimized.
This comment has been minimized.
samjewell
commented
Feb 8, 2026
samjewell
commented
Feb 8, 2026
samjewell
commented
Feb 8, 2026
samjewell
commented
Feb 8, 2026
Use two separate checks so t.Fatalf never dereferences Config when nil. Co-authored-by: Cursor <cursoragent@cursor.com>
- displayLabel now prefers Title over ShortTitle for query builder, Ad Hoc key picker, and frame DisplayNameFromDS - Keeps labels unambiguous in flat lists; view nesting can follow later - Tests updated to expect Title-based labels Co-authored-by: Cursor <cursoragent@cursor.com>
- Use Title only for labels; remove ShortTitle from logic (struct fields kept for API unmarshalling) - Add NewTestDimension/NewTestMeasure(name, title, typ) so test mocks always set Title - Replace per-field three-map checks with annotationFieldMap + single lookup; use maps.Copy for merge - Inline former displayLabel (was identity); update setDisplayNamesFromAnnotation comment (Cube always provides Title) Co-authored-by: Cursor <cursoragent@cursor.com>
| if !processedDimensions[dimension.Name] { | ||
| dimensions = append(dimensions, SelectOption{ | ||
| Label: dimension.Name, | ||
| Label: dimension.Title, |
There was a problem hiding this comment.
No fallback to Name when Title is empty
Medium Severity
extractMetadataFromResponse uses dimension.Title and measure.Title directly as the Label without any fallback, while setDisplayNamesFromAnnotation defensively checks info.Title != "" before using it. If Title is ever empty (the schema marks it optional), the ad hoc filter dropdown would show empty labels instead of the previous behavior of showing the technical name. The old code used dimension.Name which is always populated.
Additional Locations (2)
|
Bugbot Autofix prepared fixes for 1 of the 1 bugs found in the latest run.
Or push these changes by commenting: Preview (3d5b2024ad)diff --git a/pkg/plugin/datasource.go b/pkg/plugin/datasource.go
--- a/pkg/plugin/datasource.go
+++ b/pkg/plugin/datasource.go
@@ -885,8 +885,12 @@
// Collect dimensions
for _, dimension := range item.Dimensions {
if !processedDimensions[dimension.Name] {
+ label := dimension.Title
+ if label == "" {
+ label = dimension.Name
+ }
dimensions = append(dimensions, SelectOption{
- Label: dimension.Title,
+ Label: label,
Value: dimension.Name,
Type: dimension.Type,
})
@@ -897,8 +901,12 @@
// Collect measures
for _, measure := range item.Measures {
if !processedMeasures[measure.Name] {
+ label := measure.Title
+ if label == "" {
+ label = measure.Name
+ }
measures = append(measures, SelectOption{
- Label: measure.Title,
+ Label: label,
Value: measure.Name,
Type: measure.Type,
}) |
6 tasks
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.



Human-readable labels for Ad Hoc filters (keyLabel / DisplayNameFromDS)
BLOCKED!⚠️
Do not merge until Grafana PR #117640 has been reviewed and merged, and shipped
Context
Grafana is adding support for human-readable labels when adding ad hoc filters from panels (e.g. Bar Chart tooltips, Table cell “Filter for value”). See Grafana PR #117640. To make that work end-to-end, datasources need to:
orders.status.DisplayNameFromDSon fields so that when a user clicks “Filter for value” from a panel, Grafana can use it askeyLabelon the filter chip.This PR adds both behaviours to the Cube datasource so the full flow is testable and so Cube users get friendly names in the UI.
What this PR does
Metadata (getTagKeys)
When the Cube
/metaAPI provides aTitle(orShortTitleisn’t used here; we useTitle) for a dimension or measure, we now use it as the metadatalabel. The frontend already mapsmetadata.dimensions[].label→ Ad Hoc key pickertext, so the key dropdown shows human-readable names. We keepvalueas the technical name (e.g.orders.status) for queries. IfTitleis empty, we fall back to the existing behaviour (label = name).Query frames (DisplayNameFromDS)
When building frames from the Cube
/loadresponse, we setfield.Config.DisplayNameFromDSfrom the annotation’sTitlefor each field (dimensions, measures, time dimensions). That lets Grafana show a human-readable key label when adding filters from Bar Chart tooltips or Table cell actions.Breaking change?
No. Dashboard JSON and query shape are unchanged: queries and filters still use technical names (e.g.
dimensions: ["orders.status"],member: "orders.status"). Only the UI (Ad Hoc key picker, filter chips, panel-originated filter labels) shows human-readable names. The metadata API still returns the same structure (label,value,type); when Cube provides aTitle, we use it forlabelinstead of the technical name. Thevaluefield is unchanged and remains the stable identifier.Testing
go test ./pkg/plugin/(includesTestExtractMetadataFromResponse,TestHandleMetadata,TestQueryDataWithCubeQuerywith DisplayNameFromDS assertion).npm test -- --watchAll=false.To manually test with Grafana PR 117640: run Grafana on the branch that includes the ad hoc filter label changes, build this plugin, load it, add a Cube datasource and an Ad Hoc filter variable, then use “Filter for value” from a Bar Chart or Table and confirm the filter chip shows the human-readable label (e.g. “Order Status”) instead of only the technical name.
Note
Low Risk
Label-only changes that affect UI display (
labelandDisplayNameFromDS) without altering query semantics or data handling; main risk is minor UI regressions if aTitleis missing/unexpected.Overview
Adds human-readable labels throughout the Cube datasource by using Cube-provided
Titlemetadata.Query result frames now set
field.Config.DisplayNameFromDSfrom/loadresponse annotations (dimensions/measures/timeDimensions) so panel-driven “Filter for value” and column headers show friendly names. The metadata extraction for Ad Hoc key selection now usesTitleas thelabel(instead of the technical field name), and tests were updated/expanded (helpers, new assertion) to lock in the new labeling behavior.Written by Cursor Bugbot for commit 0f641e9. This will update automatically on new commits. Configure here.