AdHocVariables: Allow setting valueLabels and customizing value when adding custom values #1038
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.
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
andvalue
prop of theMetricFindValue
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:
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. TheonAddCustomValue
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