Remove aggregates from metric options if datasource has no columns (#7586)

This commit is contained in:
michellethomas 2019-05-24 11:10:35 -07:00 committed by GitHub
parent 20143293eb
commit 47ba2ad394
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 3 deletions

View File

@ -85,6 +85,14 @@ describe('MetricsControl', () => {
]);
});
it('does not show aggregates in options if no columns', () => {
const { wrapper } = setup({ columns: [] });
expect(wrapper.state('options')).toEqual([
{ optionName: 'sum__value', metric_name: 'sum__value', expression: 'SUM(energy_usage.value)' },
{ optionName: 'avg__value', metric_name: 'avg__value', expression: 'AVG(energy_usage.value)' },
]);
});
it('coerces Adhoc Metrics from form data into instances of the AdhocMetric class and leaves saved metrics', () => {
const { wrapper } = setup({
value: [

View File

@ -238,10 +238,14 @@ export default class MetricsControl extends React.PureComponent {
}
optionsForSelect(props) {
const { columns, savedMetrics } = props;
const aggregates = columns && columns.length ?
Object.keys(AGGREGATES).map(aggregate => ({ aggregate_name: aggregate })) :
[];
const options = [
...props.columns,
...Object.keys(AGGREGATES).map(aggregate => ({ aggregate_name: aggregate })),
...props.savedMetrics,
...columns,
...aggregates,
...savedMetrics,
];
return options.reduce((results, option) => {