Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 6 commits into from
Feb 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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