feat(dashboard): Let users download full CSV of a table (#15046)

* - Convert SliceHeader to TSX in progress
- Add menu option to download full CSV. Probably will change it

* Add Download Full CSV feature, and tests

* Added more tests, more TS fixes

* Added feature flag

* Update @superset-ui package versions

* Update @superset-ui packages versions

* use backend config instead of hardcoding number of rows

* Update tests

* front end test fix

* Lint fixes and test fixes
This commit is contained in:
Ajay M
2021-06-14 17:26:18 -04:00
committed by GitHub
parent 6ed0a3a9e0
commit 045fa1bc7a
17 changed files with 578 additions and 433 deletions

View File

@@ -23,7 +23,7 @@ import sinon from 'sinon';
import Chart from 'src/dashboard/components/gridComponents/Chart';
import SliceHeader from 'src/dashboard/components/SliceHeader';
import ChartContainer from 'src/chart/ChartContainer';
import * as exploreUtils from 'src/explore/exploreUtils';
import { sliceEntitiesForChart as sliceEntities } from 'spec/fixtures/mockSliceEntities';
import mockDatasource from 'spec/fixtures/mockDatasource';
import chartQueries, {
@@ -38,6 +38,7 @@ describe('Chart', () => {
updateSliceName() {},
// from redux
maxRows: 666,
chart: chartQueries[queryId],
formData: chartQueries[queryId].formData,
datasource: mockDatasource[sliceEntities.slices[queryId].datasource],
@@ -59,6 +60,8 @@ describe('Chart', () => {
unsetFocusedFilterField() {},
addSuccessToast() {},
addDangerToast() {},
exportCSV() {},
exportFullCSV() {},
componentId: 'test',
dashboardId: 111,
editMode: false,
@@ -86,7 +89,6 @@ describe('Chart', () => {
it('should render a description if it has one and isExpanded=true', () => {
const wrapper = setup();
expect(wrapper.find('.slice_description')).not.toExist();
wrapper.setProps({ ...props, isExpanded: true });
expect(wrapper.find('.slice_description')).toExist();
});
@@ -104,4 +106,30 @@ describe('Chart', () => {
wrapper.instance().changeFilter();
expect(changeFilter.callCount).toBe(1);
});
it('should call exportChart when exportCSV is clicked', () => {
const stubbedExportCSV = sinon
.stub(exploreUtils, 'exportChart')
.returns(() => {});
const wrapper = setup();
wrapper.instance().exportCSV(props.slice.sliceId);
expect(stubbedExportCSV.calledOnce).toBe(true);
expect(stubbedExportCSV.lastCall.args[0]).toEqual(
expect.objectContaining({
formData: expect.anything(),
resultType: 'results',
resultFormat: 'csv',
}),
);
exploreUtils.exportChart.restore();
});
it('should call exportChart with row_limit props.maxRows when exportFullCSV is clicked', () => {
const stubbedExportCSV = sinon
.stub(exploreUtils, 'exportChart')
.returns(() => {});
const wrapper = setup();
wrapper.instance().exportFullCSV(props.slice.sliceId);
expect(stubbedExportCSV.calledOnce).toBe(true);
expect(stubbedExportCSV.lastCall.args[0].formData.row_limit).toEqual(666);
exploreUtils.exportChart.restore();
});
});