Skip to content

Conversation

@ashharrison90
Copy link
Contributor

@ashharrison90 ashharrison90 commented Oct 19, 2021

What this PR does / why we need it:

there are some scenarios where having variables with different labels but the same underlying value could make sense. e.g. if the variables are key=location, value=hostname. you may have a server that is responsible for asia + australia for example. in which case you might have 2 different variables, asia=<hostname> and australia=<hostname> where hostname are the same value.

i don't think we can ever fully support this use case without a significant amount of refactoring. for example, the current variable value is stored in the query parameter, but if there are 2 variables with the same value we have no way of knowing which variable was actually selected.

the confusion happens when you select one of these options from the variable picker. because they share the same value, when you select one of these variables it displays the first option matching the value as selected. this may or may not be the actual option you selected. by introducing a check on the label as well, we at least ensure that the option you selected is then displayed in the variable picker.

Which issue(s) this PR fixes:

Fixes #40414

Special notes for your reviewer:

@ashharrison90 ashharrison90 added this to the 8.2.2 milestone Oct 19, 2021
@ashharrison90 ashharrison90 requested a review from a team October 19, 2021 09:33
@ashharrison90 ashharrison90 self-assigned this Oct 19, 2021
@ashharrison90 ashharrison90 requested review from axelavargas and kaydelaney and removed request for a team October 19, 2021 09:33
@ashharrison90 ashharrison90 merged commit e48d77b into main Oct 19, 2021
@ashharrison90 ashharrison90 deleted the ash/40414 branch October 19, 2021 13:13
grafanabot pushed a commit that referenced this pull request Oct 19, 2021
…ue (#40607)

* Variables: Allow selection of different variables with the same value

* Variables: Don't modify this key

(cherry picked from commit e48d77b)
ashharrison90 added a commit that referenced this pull request Oct 19, 2021
…ue (#40607) (#40630)

* Variables: Allow selection of different variables with the same value

* Variables: Don't modify this key

(cherry picked from commit e48d77b)

Co-authored-by: Ashley Harrison <ashley.harrison@grafana.com>

if (option) {
const selected = !selectedValues.find((o) => o.value === option.value);
const selected = !selectedValues.find((o) => o.value === option.value && o.text === option.text);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should have added tests for this change but never mind now.

lean257 pushed a commit that referenced this pull request Oct 20, 2021
…ue (#40607)

* Variables: Allow selection of different variables with the same value

* Variables: Don't modify this key
ArturWierzbicki pushed a commit that referenced this pull request Oct 24, 2021
…ue (#40607)

* Variables: Allow selection of different variables with the same value

* Variables: Don't modify this key
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ templating ] [ custom type ] key : value pairs break with duplicate value

3 participants