Skip to content

Commit

Permalink
fix(altered-modal): displayed the metric value in altered modal corre…
Browse files Browse the repository at this point in the history
…ctly (#18813)

Co-authored-by: Evan Rusackas <evan@preset.io>
  • Loading branch information
prosdev0107 and rusackas authored Feb 21, 2022
1 parent 32409b7 commit 3c17c60
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"}';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,14 @@ export const fakePluginControls = {
default: null,
},
},
{
name: 'metrics',
config: {
type: 'MetricsControl',
label: 'Fake Metrics',
default: null,
},
},
],
],
},
Expand Down
4 changes: 4 additions & 0 deletions superset-frontend/src/components/AlteredSliceTag/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand Down

0 comments on commit 3c17c60

Please sign in to comment.