[v10.2.x] Templating: Json interpolation of single-value default selection does not create valid json (#79503)

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

(cherry picked from commit 31d79c0502)

Co-authored-by: kay delaney <45561153+kaydelaney@users.noreply.github.com>
(cherry picked from commit fe27d4835e)
This commit is contained in:
grafana-delivery-bot[bot]
2023-12-21 20:38:26 +00:00
committed by Andreas Christou
parent 51cc8f6c3f
commit 82ae879cf7
2 changed files with 8 additions and 4 deletions
@@ -305,7 +305,7 @@ describe('shared actions', () => {
key,
setCurrentVariableValue(
toVariablePayload(stats, {
option: { text: ALL_VARIABLE_TEXT, value: ALL_VARIABLE_VALUE, selected: false },
option: { text: [ALL_VARIABLE_TEXT], value: [ALL_VARIABLE_VALUE], selected: true },
})
)
),
@@ -473,8 +473,8 @@ describe('shared actions', () => {
${['A', 'B', 'C']} | ${['B']} | ${'C'} | ${['B']} | ${true}
${['A', 'B', 'C']} | ${['B', 'C']} | ${undefined} | ${['B', 'C']} | ${true}
${['A', 'B', 'C']} | ${['B', 'C']} | ${'C'} | ${['B', 'C']} | ${true}
${['A', 'B', 'C']} | ${['X']} | ${undefined} | ${'A'} | ${false}
${['A', 'B', 'C']} | ${['X']} | ${'C'} | ${'A'} | ${false}
${['A', 'B', 'C']} | ${['X']} | ${undefined} | ${['A']} | ${true}
${['A', 'B', 'C']} | ${['X']} | ${'C'} | ${['A']} | ${true}
`(
'then correct actions are dispatched',
async ({ withOptions, withCurrent, defaultValue, expectedText, expectedSelected }) => {
@@ -506,7 +506,11 @@ export const validateVariableSelectionState = (
// if none pick first
if (selected.length === 0) {
const option = variableInState.options[0];
return setValue(variableInState, option);
return setValue(variableInState, {
value: typeof option.value === 'string' ? [option.value] : option.value,
text: typeof option.text === 'string' ? [option.text] : option.text,
selected: true,
});
}
const option: VariableOption = {