Skip to content

Commit

Permalink
Avoid removing custom sql adhoc metric when columns change (#7877)
Browse files Browse the repository at this point in the history
* Avoid removing custom sql adhoc metric when columns change

* Add tests to confirm sql metric does not get removed
  • Loading branch information
michellethomas authored Jul 16, 2019
1 parent a36c136 commit 86fdceb
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -333,5 +333,40 @@ describe('MetricsControl', () => {
'SUM(',
)).toBe(true);
});

it('Removes metrics if savedMetrics changes', () => {
const { props, wrapper, onChange } = setup({
value: [
{
expressionType: EXPRESSION_TYPES.SIMPLE,
column: { type: 'double', column_name: 'value' },
aggregate: AGGREGATES.SUM,
label: 'SUM(value)',
optionName: 'blahblahblah',
},
],
});
expect(wrapper.state('value')).toHaveLength(1);

wrapper.setProps({ ...props, columns: [] });
expect(onChange.lastCall.args).toEqual([[]]);
});

it('Does not remove custom sql metric if savedMetrics changes', () => {
const { props, wrapper, onChange } = setup({
value: [
{
expressionType: EXPRESSION_TYPES.SQL,
sqlExpression: 'COUNT(*)',
label: 'old label',
hasCustomLabel: true,
},
],
});
expect(wrapper.state('value')).toHaveLength(1);

wrapper.setProps({ ...props, columns: [] });
expect(onChange.calledOnce).toEqual(false);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function columnsContainAllMetrics(value, nextProps) {
.filter(metric => metric)
// find column names
.map(metric => metric.column ? metric.column.column_name : metric.column_name || metric)
.filter(name => name)
.filter(name => name && typeof name === 'string')
.every(name => columnNames.has(name));
}

Expand Down

0 comments on commit 86fdceb

Please sign in to comment.