Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AdHocVariables: Allow setting valueLabels and customizing value when adding custom values #1038

Open
wants to merge 4 commits into
base: gtk-grafana/ad-hoc-tag-providers-meta
Choose a base branch
from

Conversation

gtk-grafana
Copy link
Contributor

@gtk-grafana gtk-grafana commented Jan 24, 2025

Problem:

When the user adds a custom value to an ad-hoc variable input, the valueLabels is automatically set to the value, so the scenes application is unable to customize the value or how that value is rendered in the ad-hoc variable.
With non-custom values, we can set the text and value prop of the MetricFindValue in the adHocVariable tagProviders, but user entered custom values are currently un-customizable.

Use case:

In Explore Logs we're encoding metadata into the filter value, so our filters look like:

{
    "key": "caller",
    "value": "{\"value\":\"valueLabel\",\"parser\":\"logfmt\"}",
    "operator": "=",
    "condition": "",
    "keyLabel": "caller",
    "valueLabels": ["valueLabel"]
}

But in order to support custom user input in the variable, we would either need to display the JSON encoded string to the user, instead of the input they entered in the variable, or we'd need to update the filters after the state has been changed, which would introduce broken/duplicate queries.

This PR:

Allows the plugin to provide a onAddCustomValue method to the AdHocFiltersVariable which will be called before the custom value is set to the filters state. The onAddCustomValue takes the selectedValue, and filter, and returns the desired value and valueLabels to be set in the filter state.

This change in addition to #1034 (and the fix in #1036), gives developers the flexibility to add metadata from API calls made in the getTagKeysProvider into the variable filters without exposing that metadata to the user in the UI.

Related PRs:

Parent branch: #1034
Combobox bug not displaying valueLabels: #1036

@gtk-grafana gtk-grafana changed the base branch from main to gtk-grafana/ad-hoc-tag-providers-meta January 24, 2025 18:43
@gtk-grafana gtk-grafana added usecase/app-plugins Needed for scene app plugins type/enhancement New feature or request labels Jan 24, 2025
@gtk-grafana gtk-grafana self-assigned this Jan 24, 2025
@gtk-grafana gtk-grafana changed the title AdHocVariables: Allow setting valueLabel and customizing value when adding custom values AdHocVariables: Allow setting valueLabels and customizing value when adding custom values Jan 24, 2025
@gtk-grafana gtk-grafana marked this pull request as ready for review January 24, 2025 19:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/enhancement New feature or request usecase/app-plugins Needed for scene app plugins
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant