Commit b9f50513 authored by Kushal Pandya's avatar Kushal Pandya

Merge branch 'monitoring-dashboard-custom-type-vars-support-optional-text-attribute' into 'master'

Make text property optional for custom var types

See merge request gitlab-org/gitlab!32596
parents bdfd15ea 62adb5fb
...@@ -47,7 +47,7 @@ const textAdvancedVariableParser = advTextVar => ({ ...@@ -47,7 +47,7 @@ const textAdvancedVariableParser = advTextVar => ({
*/ */
const normalizeCustomVariableOptions = ({ default: defaultOpt = false, text, value }) => ({ const normalizeCustomVariableOptions = ({ default: defaultOpt = false, text, value }) => ({
default: defaultOpt, default: defaultOpt,
text, text: text || value,
value, value,
}); });
......
...@@ -621,6 +621,19 @@ const templatingVariableTypes = { ...@@ -621,6 +621,19 @@ const templatingVariableTypes = {
], ],
}, },
}, },
withoutOptText: {
label: 'Options without text',
type: 'custom',
options: {
values: [
{ value: 'value1' },
{
value: 'value2',
default: true,
},
],
},
},
}, },
}, },
}; };
...@@ -709,6 +722,26 @@ const responseForAdvancedCustomVariableWithoutLabel = { ...@@ -709,6 +722,26 @@ const responseForAdvancedCustomVariableWithoutLabel = {
}, },
}; };
const responseForAdvancedCustomVariableWithoutOptText = {
advCustomWithoutOptText: {
label: 'Options without text',
value: 'value2',
options: [
{
default: false,
text: 'value1',
value: 'value1',
},
{
default: true,
text: 'value2',
value: 'value2',
},
],
type: 'custom',
},
};
const responseForAdvancedCustomVariable = { const responseForAdvancedCustomVariable = {
...responseForSimpleCustomVariable, ...responseForSimpleCustomVariable,
advCustomNormal: { advCustomNormal: {
...@@ -752,6 +785,9 @@ export const mockTemplatingData = { ...@@ -752,6 +785,9 @@ export const mockTemplatingData = {
advCustomWithoutLabel: generateMockTemplatingData({ advCustomWithoutLabel: generateMockTemplatingData({
advCustomWithoutLabel: templatingVariableTypes.custom.advanced.withoutLabel, advCustomWithoutLabel: templatingVariableTypes.custom.advanced.withoutLabel,
}), }),
advCustomWithoutOptText: generateMockTemplatingData({
advCustomWithoutOptText: templatingVariableTypes.custom.advanced.withoutOptText,
}),
simpleAndAdv: generateMockTemplatingData({ simpleAndAdv: generateMockTemplatingData({
simpleCustom: templatingVariableTypes.custom.simple, simpleCustom: templatingVariableTypes.custom.simple,
advCustomNormal: templatingVariableTypes.custom.advanced.normal, advCustomNormal: templatingVariableTypes.custom.advanced.normal,
...@@ -773,6 +809,7 @@ export const mockTemplatingDataResponses = { ...@@ -773,6 +809,7 @@ export const mockTemplatingDataResponses = {
advCustomWithoutOpts: responseForAdvancedCustomVariableWithoutOptions, advCustomWithoutOpts: responseForAdvancedCustomVariableWithoutOptions,
advCustomWithoutType: {}, advCustomWithoutType: {},
advCustomWithoutLabel: responseForAdvancedCustomVariableWithoutLabel, advCustomWithoutLabel: responseForAdvancedCustomVariableWithoutLabel,
advCustomWithoutOptText: responseForAdvancedCustomVariableWithoutOptText,
simpleAndAdv: responseForAdvancedCustomVariable, simpleAndAdv: responseForAdvancedCustomVariable,
allVariableTypes: responsesForAllVariableTypes, allVariableTypes: responsesForAllVariableTypes,
}; };
...@@ -12,6 +12,7 @@ describe('parseTemplatingVariables', () => { ...@@ -12,6 +12,7 @@ describe('parseTemplatingVariables', () => {
${'Returns parsed object for advanced text variable'} | ${mockTemplatingData.advText} | ${mockTemplatingDataResponses.advText} ${'Returns parsed object for advanced text variable'} | ${mockTemplatingData.advText} | ${mockTemplatingDataResponses.advText}
${'Returns parsed object for simple custom variable'} | ${mockTemplatingData.simpleCustom} | ${mockTemplatingDataResponses.simpleCustom} ${'Returns parsed object for simple custom variable'} | ${mockTemplatingData.simpleCustom} | ${mockTemplatingDataResponses.simpleCustom}
${'Returns parsed object for advanced custom variable without options'} | ${mockTemplatingData.advCustomWithoutOpts} | ${mockTemplatingDataResponses.advCustomWithoutOpts} ${'Returns parsed object for advanced custom variable without options'} | ${mockTemplatingData.advCustomWithoutOpts} | ${mockTemplatingDataResponses.advCustomWithoutOpts}
${'Returns parsed object for advanced custom variable for option without text'} | ${mockTemplatingData.advCustomWithoutOptText} | ${mockTemplatingDataResponses.advCustomWithoutOptText}
${'Returns parsed object for advanced custom variable without type'} | ${mockTemplatingData.advCustomWithoutType} | ${{}} ${'Returns parsed object for advanced custom variable without type'} | ${mockTemplatingData.advCustomWithoutType} | ${{}}
${'Returns parsed object for advanced custom variable without label'} | ${mockTemplatingData.advCustomWithoutLabel} | ${mockTemplatingDataResponses.advCustomWithoutLabel} ${'Returns parsed object for advanced custom variable without label'} | ${mockTemplatingData.advCustomWithoutLabel} | ${mockTemplatingDataResponses.advCustomWithoutLabel}
${'Returns parsed object for simple and advanced custom variables'} | ${mockTemplatingData.simpleAndAdv} | ${mockTemplatingDataResponses.simpleAndAdv} ${'Returns parsed object for simple and advanced custom variables'} | ${mockTemplatingData.simpleAndAdv} | ${mockTemplatingDataResponses.simpleAndAdv}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment