feat(viz): add query mode switch to table chart (#10113)

1, Replace table chart rendering from jquery.DataTables to react-table: apache-superset/superset-ui#623
2. Rearrange the control panel, replace GROUP BY and NOT GROUP BY with a "Query Mode" switch: apache-superset/superset-ui#609
This commit is contained in:
Jesse Yang
2020-06-28 21:37:04 -07:00
committed by GitHub
parent 3414f35792
commit 9bdfa055ac
34 changed files with 5549 additions and 9234 deletions

View File

@@ -181,36 +181,40 @@ describe('MetricsControl', () => {
]);
});
it('handles aggregates being selected', done => {
const { wrapper, onChange } = setup();
const select = wrapper.find(OnPasteSelect);
it('handles aggregates being selected', () => {
return new Promise(done => {
const { wrapper, onChange } = setup();
const select = wrapper.find(OnPasteSelect);
// mock out the Select ref
const instance = wrapper.instance();
const handleInputChangeSpy = jest.fn();
const focusInputSpy = jest.fn();
// simulate react-select StateManager
instance.selectRef({
select: {
handleInputChange: handleInputChangeSpy,
inputRef: { value: '' },
focusInput: focusInputSpy,
},
});
// mock out the Select ref
const instance = wrapper.instance();
const handleInputChangeSpy = jest.fn();
const focusInputSpy = jest.fn();
// simulate react-select StateManager
instance.selectRef({
select: {
handleInputChange: handleInputChangeSpy,
inputRef: { value: '' },
focusInput: focusInputSpy,
},
});
select.simulate('change', [{ aggregate_name: 'SUM', optionName: 'SUM' }]);
select.simulate('change', [
{ aggregate_name: 'SUM', optionName: 'SUM' },
]);
expect(instance.select.inputRef.value).toBe('SUM()');
expect(handleInputChangeSpy).toHaveBeenCalledWith({
currentTarget: { value: 'SUM()' },
});
expect(onChange.calledOnceWith([])).toBe(true);
expect(focusInputSpy).toHaveBeenCalledTimes(0);
setTimeout(() => {
expect(focusInputSpy).toHaveBeenCalledTimes(1);
expect(instance.select.inputRef.selectionStart).toBe(4);
expect(instance.select.inputRef.selectionEnd).toBe(4);
done();
expect(instance.select.inputRef.value).toBe('SUM()');
expect(handleInputChangeSpy).toHaveBeenCalledWith({
currentTarget: { value: 'SUM()' },
});
expect(onChange.calledOnceWith([])).toBe(true);
expect(focusInputSpy).toHaveBeenCalledTimes(0);
setTimeout(() => {
expect(focusInputSpy).toHaveBeenCalledTimes(1);
expect(instance.select.inputRef.selectionStart).toBe(4);
expect(instance.select.inputRef.selectionEnd).toBe(4);
done();
});
});
});

View File

@@ -210,38 +210,47 @@ describe('SaveModal', () => {
Object.defineProperty(window, 'location', windowLocation);
});
it('Save & go to dashboard', done => {
wrapper.instance().saveOrOverwrite(true);
defaultProps.actions.saveSlice().then(() => {
expect(window.location.assign.callCount).toEqual(1);
expect(window.location.assign.getCall(0).args[0]).toEqual(
'http://localhost/mock_dashboard/',
);
done();
it('Save & go to dashboard', () => {
return new Promise(done => {
wrapper.instance().saveOrOverwrite(true);
defaultProps.actions.saveSlice().then(() => {
expect(window.location.assign.callCount).toEqual(1);
expect(window.location.assign.getCall(0).args[0]).toEqual(
'http://localhost/mock_dashboard/',
);
done();
});
});
});
it('saveas new slice', done => {
wrapper.setState({ action: 'saveas', newSliceName: 'new slice name' });
wrapper.instance().saveOrOverwrite(false);
defaultProps.actions.saveSlice().then(() => {
expect(window.location.assign.callCount).toEqual(1);
expect(window.location.assign.getCall(0).args[0]).toEqual(
'/mock_slice/',
);
done();
it('saveas new slice', () => {
return new Promise(done => {
wrapper.setState({
action: 'saveas',
newSliceName: 'new slice name',
});
wrapper.instance().saveOrOverwrite(false);
defaultProps.actions.saveSlice().then(() => {
expect(window.location.assign.callCount).toEqual(1);
expect(window.location.assign.getCall(0).args[0]).toEqual(
'/mock_slice/',
);
done();
});
});
});
it('overwrite original slice', done => {
wrapper.setState({ action: 'overwrite' });
wrapper.instance().saveOrOverwrite(false);
defaultProps.actions.saveSlice().then(() => {
expect(window.location.assign.callCount).toEqual(1);
expect(window.location.assign.getCall(0).args[0]).toEqual(
'/mock_slice/',
);
done();
it('overwrite original slice', () => {
return new Promise(done => {
wrapper.setState({ action: 'overwrite' });
wrapper.instance().saveOrOverwrite(false);
defaultProps.actions.saveSlice().then(() => {
expect(window.location.assign.callCount).toEqual(1);
expect(window.location.assign.getCall(0).args[0]).toEqual(
'/mock_slice/',
);
done();
});
});
});
});

View File

@@ -105,6 +105,8 @@ describe('controlUtils', () => {
expanded: true,
controlSetRows: [
[
'metric',
'metrics',
{
name: 'all_columns',
config: {
@@ -213,7 +215,12 @@ describe('controlUtils', () => {
expect(control.value).toBe('stack');
control = getControlState('stacked_style', 'test-chart', state, 'FOO');
expect(control.value).toBe(null);
expect(control.value).toBeNull();
});
it('returns null for non-existent field', () => {
const control = getControlState('NON_EXISTENT', 'table', state);
expect(control).toBeNull();
});
it('applies the default function for metrics', () => {
@@ -254,7 +261,11 @@ describe('controlUtils', () => {
it('in formData', () => {
const controlsState = getAllControlsState('table', 'table', {}, {});
const formData = getFormDataFromControls(controlsState);
expect(formData.queryFields).toEqual({ all_columns: 'columns' });
expect(formData.queryFields).toEqual({
all_columns: 'columns',
metric: 'metrics',
metrics: 'metrics',
});
});
});
});

View File

@@ -22,13 +22,13 @@ import exploreReducer from 'src/explore/reducers/exploreReducer';
import * as actions from 'src/explore/actions/exploreActions';
describe('reducers', () => {
it('sets correct control value given a key and value', () => {
it('sets correct control value given an arbitrary key and value', () => {
const newState = exploreReducer(
defaultState,
actions.setControlValue('x_axis_label', 'x', []),
actions.setControlValue('NEW_FIELD', 'x', []),
);
expect(newState.controls.x_axis_label.value).toBe('x');
expect(newState.form_data.x_axis_label).toBe('x');
expect(newState.controls.NEW_FIELD.value).toBe('x');
expect(newState.form_data.NEW_FIELD).toBe('x');
});
it('setControlValue works as expected with a checkbox', () => {
const newState = exploreReducer(