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: onSave datasource raises React error #8049

Merged
merged 2 commits into from
Aug 15, 2019
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 @@ -368,5 +368,12 @@ describe('MetricsControl', () => {
wrapper.setProps({ ...props, columns: [] });
expect(onChange.calledOnce).toEqual(false);
});
it('Does not fail if no columns or savedMetrics are passed', () => {
const { wrapper } = setup({
savedMetrics: null,
columns: null,
});
expect(wrapper.exists('.metrics-select')).toEqual(true);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ const propTypes = {
const defaultProps = {
onChange: () => {},
clearable: true,
savedMetrics: [],
columns: [],
};

function isDictionaryForAdhocMetric(value) {
Expand All @@ -62,7 +64,7 @@ function isDictionaryForAdhocMetric(value) {

function columnsContainAllMetrics(value, nextProps) {
const columnNames = new Set(
[...nextProps.columns, ...nextProps.savedMetrics]
[...(nextProps.columns || []), ...(nextProps.savedMetrics || [])]
// eslint-disable-next-line camelcase
.map(({ column_name, metric_name }) => (column_name || metric_name)),
);
Expand Down Expand Up @@ -243,7 +245,7 @@ export default class MetricsControl extends React.PureComponent {
Object.keys(AGGREGATES).map(aggregate => ({ aggregate_name: aggregate })) :
[];
const options = [
...columns,
...(columns || []),
...aggregates,
...(savedMetrics || []),
];
Expand Down