Skip to content

Commit

Permalink
Remove aggregates from metric options if datasource has no columns (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
michellethomas authored May 24, 2019
1 parent 2014329 commit 47ba2ad
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit 47ba2ad

Please sign in to comment.