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

This commit is contained in:
kay delaney 2023-12-14 10:42:36 +00:00 committed by GitHub
parent 5192150191
commit 31d79c0502
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 4 deletions

View File

@ -305,7 +305,7 @@ describe('shared actions', () => {
key, key,
setCurrentVariableValue( setCurrentVariableValue(
toVariablePayload(stats, { 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'} | ${['B']} | ${true}
${['A', 'B', 'C']} | ${['B', 'C']} | ${undefined} | ${['B', 'C']} | ${true} ${['A', 'B', 'C']} | ${['B', 'C']} | ${undefined} | ${['B', 'C']} | ${true}
${['A', 'B', 'C']} | ${['B', 'C']} | ${'C'} | ${['B', 'C']} | ${true} ${['A', 'B', 'C']} | ${['B', 'C']} | ${'C'} | ${['B', 'C']} | ${true}
${['A', 'B', 'C']} | ${['X']} | ${undefined} | ${'A'} | ${false} ${['A', 'B', 'C']} | ${['X']} | ${undefined} | ${['A']} | ${true}
${['A', 'B', 'C']} | ${['X']} | ${'C'} | ${'A'} | ${false} ${['A', 'B', 'C']} | ${['X']} | ${'C'} | ${['A']} | ${true}
`( `(
'then correct actions are dispatched', 'then correct actions are dispatched',
async ({ withOptions, withCurrent, defaultValue, expectedText, expectedSelected }) => { async ({ withOptions, withCurrent, defaultValue, expectedText, expectedSelected }) => {

View File

@ -506,7 +506,11 @@ export const validateVariableSelectionState = (
// if none pick first // if none pick first
if (selected.length === 0) { if (selected.length === 0) {
const option = variableInState.options[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 = { const option: VariableOption = {