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

Templating: Json interpolation of single-value default selection does not create valid json #79137

Merged
merged 2 commits into from
Dec 14, 2023

Conversation

kaydelaney
Copy link
Contributor

Fixes an issue where, if a template variable with options doesn't have a value selected, the default value picked wasn't wrapped in an array as it would be if a user were to select it themselves.

Effectively the old value was

{
    value: option.value,
    text: option.text,
    selected: true,
}

where the new value is

{
    value: typeof option.value === 'string' ? [option.value] : option.value,
    text: typeof option.text === 'string' ? [option.text] : option.text,
    selected: true,
}

So value and text are wrapped in an array if they are plain strings.

@kaydelaney kaydelaney added this to the 10.3.x milestone Dec 6, 2023
@kaydelaney kaydelaney self-assigned this Dec 6, 2023
@kaydelaney kaydelaney requested a review from a team as a code owner December 6, 2023 13:14
@kaydelaney kaydelaney requested review from axelavargas and ivanortegaalba and removed request for a team December 6, 2023 13:14
@kaydelaney kaydelaney added the no-changelog Skip including change in changelog/release notes label Dec 6, 2023
Copy link
Member

@axelavargas axelavargas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏅 Nice, this one was a bit tricky to reproduce, I also noticed the problem when the default variable is not in the options (maybe an old option configured).

Great job figuring this one, @kaydelaney 🙌🏾

@ivanortegaalba ivanortegaalba changed the title Templating: Ensure default variable option is wrapped in array Templating: Json interpolation of single-value default selection does not create valid json Dec 14, 2023
@ivanortegaalba ivanortegaalba added add to changelog and removed no-changelog Skip including change in changelog/release notes labels Dec 14, 2023
@ivanortegaalba ivanortegaalba merged commit 31d79c0 into main Dec 14, 2023
28 checks passed
@ivanortegaalba ivanortegaalba deleted the default-var-array branch December 14, 2023 10:42
grafana-delivery-bot bot pushed a commit that referenced this pull request Dec 14, 2023
… not create valid json (#79137)

(cherry picked from commit 31d79c0)
ivanortegaalba pushed a commit that referenced this pull request Dec 14, 2023
…ction does not create valid json (#79503)

Templating: Json interpolation of single-value default selection does not create valid json (#79137)

(cherry picked from commit 31d79c0)

Co-authored-by: kay delaney <45561153+kaydelaney@users.noreply.github.com>
aangelisc pushed a commit that referenced this pull request Dec 21, 2023
…ction does not create valid json (#79503)

Templating: Json interpolation of single-value default selection does not create valid json (#79137)

(cherry picked from commit 31d79c0)

Co-authored-by: kay delaney <45561153+kaydelaney@users.noreply.github.com>
(cherry picked from commit fe27d48)
@summerwollin summerwollin modified the milestones: 10.3.x, 10.3.0 Jan 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

4 participants