fix(altered-modal): displayed the metric value in altered modal correctly (#18813)

Co-authored-by: Evan Rusackas <evan@preset.io>
This commit is contained in:
smileydev 2022-02-20 19:27:46 -05:00 committed by GitHub
parent 32409b71be
commit 3c17c609c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 0 deletions

View File

@ -218,6 +218,18 @@ describe('AlteredSliceTag', () => {
).toBe(expected);
});
it('returns Metrics if the field type is metrics', () => {
const value = [
{
label: 'SUM(Sales)',
},
];
const expected = 'SUM(Sales)';
expect(
wrapper.instance().formatValue(value, 'metrics', controlsMap),
).toBe(expected);
});
it('stringifies objects', () => {
const value = { 1: 2, alpha: 'bravo' };
const expected = '{"1":2,"alpha":"bravo"}';

View File

@ -159,6 +159,14 @@ export const fakePluginControls = {
default: null,
},
},
{
name: 'metrics',
config: {
type: 'MetricsControl',
label: 'Fake Metrics',
default: null,
},
},
],
],
},

View File

@ -134,6 +134,10 @@ export default class AlteredSliceTag extends React.Component {
if (controlsMap[key]?.type === 'CollectionControl') {
return value.map(v => safeStringify(v)).join(', ');
}
if (controlsMap[key]?.type === 'MetricsControl' && Array.isArray(value)) {
const formattedValue = value.map(v => (v.label ? v.label : v));
return formattedValue.length ? formattedValue.join(', ') : '[]';
}
if (typeof value === 'boolean') {
return value ? 'true' : 'false';
}