mirror of https://github.com/apache/superset.git
Allowing withVerification to remove all options if none are valid (#7652)
This commit is contained in:
parent
f278faa8be
commit
5864ddc079
|
@ -44,7 +44,7 @@ const defaultProps = {
|
|||
|
||||
const VALID_METRIC = { metric_name: 'sum__value', expression: 'SUM(energy_usage.value)' };
|
||||
|
||||
function setup(overrides) {
|
||||
function setup(overrides, validMetric) {
|
||||
const onChange = sinon.spy();
|
||||
const props = {
|
||||
onChange,
|
||||
|
@ -53,7 +53,7 @@ function setup(overrides) {
|
|||
};
|
||||
const VerifiedControl = withVerification(MetricsControl, 'metric_name', 'savedMetrics');
|
||||
const wrapper = shallow(<VerifiedControl {...props} />);
|
||||
fetchMock.mock('glob:*/valid_metrics*', `["${VALID_METRIC.metric_name}"]`);
|
||||
fetchMock.mock('glob:*/valid_metrics*', validMetric || `["${VALID_METRIC.metric_name}"]`);
|
||||
return { props, wrapper, onChange };
|
||||
}
|
||||
|
||||
|
@ -103,4 +103,14 @@ describe('VerifiedMetricsControl', () => {
|
|||
fetchMock.reset();
|
||||
}, 0);
|
||||
});
|
||||
|
||||
it('Returns no verified options if none are valid', () => {
|
||||
const { wrapper } = setup({}, []);
|
||||
setTimeout(() => {
|
||||
expect(fetchMock.calls(defaultProps.getEndpoint())).toHaveLength(1);
|
||||
const child = wrapper.find(MetricsControl);
|
||||
expect(child.props().savedMetrics).toEqual([]);
|
||||
fetchMock.reset();
|
||||
}, 0);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -31,7 +31,7 @@ export default function withVerification(WrappedComponent, optionLabel, optionsN
|
|||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
validOptions: new Set(),
|
||||
validOptions: null,
|
||||
hasRunVerification: false,
|
||||
};
|
||||
|
||||
|
@ -69,7 +69,7 @@ export default function withVerification(WrappedComponent, optionLabel, optionsN
|
|||
render() {
|
||||
const { validOptions } = this.state;
|
||||
const options = this.props[optionsName];
|
||||
const verifiedOptions = validOptions.size ?
|
||||
const verifiedOptions = validOptions ?
|
||||
options.filter(o => (validOptions.has(o[optionLabel]))) :
|
||||
options;
|
||||
|
||||
|
|
Loading…
Reference in New Issue