Skip to content

Commit

Permalink
added dashboard page full xlsx export
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitali Logvin committed Jun 5, 2023
1 parent 18d2257 commit ecd37f1
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ const SliceHeader: FC<SliceHeaderProps> = ({
supersetCanCSV = false,
sliceCanEdit = false,
exportFullCSV,
exportFullXLSX,
slice,
componentId,
dashboardId,
Expand Down Expand Up @@ -266,6 +267,7 @@ const SliceHeader: FC<SliceHeaderProps> = ({
exportCSV={exportCSV}
exportFullCSV={exportFullCSV}
exportXLSX={exportXLSX}
exportFullXLSX={exportFullXLSX}
supersetCanExplore={supersetCanExplore}
supersetCanShare={supersetCanShare}
supersetCanCSV={supersetCanCSV}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const createProps = (viz_type = 'sunburst') =>
exportCSV: jest.fn(),
exportFullCSV: jest.fn(),
exportXLSX: jest.fn(),
exportFullXLSX: jest.fn(),
forceRefresh: jest.fn(),
handleToggleFullSize: jest.fn(),
toggleExpandSlice: jest.fn(),
Expand Down Expand Up @@ -226,6 +227,43 @@ test('Should not show export full CSV if report is not table', async () => {
expect(screen.queryByText('Export to full .CSV')).not.toBeInTheDocument();
});

test('Export full Excel is under featureflag', async () => {
// @ts-ignore
global.featureFlags = {
[FeatureFlag.ALLOW_FULL_CSV_EXPORT]: false,
};
const props = createProps('table');
renderWrapper(props);
userEvent.hover(screen.getByText('Download'));
expect(await screen.findByText('Export to Excel')).toBeInTheDocument();
expect(screen.queryByText('Export to full Excel')).not.toBeInTheDocument();
});

test('Should "export full Excel"', async () => {
// @ts-ignore
global.featureFlags = {
[FeatureFlag.ALLOW_FULL_CSV_EXPORT]: true,
};
const props = createProps('table');
renderWrapper(props);
expect(props.exportFullXLSX).toBeCalledTimes(0);
userEvent.hover(screen.getByText('Download'));
userEvent.click(await screen.findByText('Export to full Excel'));
expect(props.exportFullXLSX).toBeCalledTimes(1);
expect(props.exportFullXLSX).toBeCalledWith(371);
});

test('Should not show export full Excel if report is not table', async () => {
// @ts-ignore
global.featureFlags = {
[FeatureFlag.ALLOW_FULL_CSV_EXPORT]: true,
};
renderWrapper();
userEvent.hover(screen.getByText('Download'));
expect(await screen.findByText('Export to Excel')).toBeInTheDocument();
expect(screen.queryByText('Export to full Excel')).not.toBeInTheDocument();
});

test('Should "Show chart description"', () => {
const props = createProps();
renderWrapper(props);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const MENU_KEYS = {
EXPORT_CSV: 'export_csv',
EXPORT_FULL_CSV: 'export_full_csv',
EXPORT_XLSX: 'export_xlsx',
EXPORT_FULL_XLSX: 'export_full_xlsx',
FORCE_REFRESH: 'force_refresh',
FULLSCREEN: 'fullscreen',
TOGGLE_CHART_DESCRIPTION: 'toggle_chart_description',
Expand Down Expand Up @@ -146,6 +147,7 @@ export interface SliceHeaderControlsProps {
exportCSV?: (sliceId: number) => void;
exportFullCSV?: (sliceId: number) => void;
exportXLSX?: (sliceId: number) => void;
exportFullXLSX?: (sliceId: number) => void;
handleToggleFullSize: () => void;

addDangerToast: (message: string) => void;
Expand Down Expand Up @@ -296,6 +298,10 @@ const SliceHeaderControls = (props: SliceHeaderControlsPropsWithRouter) => {
// eslint-disable-next-line no-unused-expressions
props.exportFullCSV?.(props.slice.slice_id);
break;
case MENU_KEYS.EXPORT_FULL_XLSX:
// eslint-disable-next-line no-unused-expressions
props.exportFullXLSX?.(props.slice.slice_id);
break;
case MENU_KEYS.EXPORT_XLSX:
// eslint-disable-next-line no-unused-expressions
props.exportXLSX?.(props.slice.slice_id);
Expand Down Expand Up @@ -486,25 +492,33 @@ const SliceHeaderControls = (props: SliceHeaderControlsPropsWithRouter) => {
>
{t('Export to .CSV')}
</Menu.Item>
<Menu.Item
key={MENU_KEYS.EXPORT_XLSX}
icon={<Icons.FileOutlined css={dropdownIconsStyles} />}
>
{t('Export to Excel')}
</Menu.Item>

{props.slice.viz_type !== 'filter_box' &&
isFeatureEnabled(FeatureFlag.ALLOW_FULL_CSV_EXPORT) &&
props.supersetCanCSV &&
isTable && (
<Menu.Item
key={MENU_KEYS.EXPORT_FULL_CSV}
icon={<Icons.FileOutlined css={dropdownIconsStyles} />}
>
{t('Export to full .CSV')}
</Menu.Item>
<>
<Menu.Item
key={MENU_KEYS.EXPORT_FULL_CSV}
icon={<Icons.FileOutlined css={dropdownIconsStyles} />}
>
{t('Export to full .CSV')}
</Menu.Item>
<Menu.Item
key={MENU_KEYS.EXPORT_FULL_XLSX}
icon={<Icons.FileOutlined css={dropdownIconsStyles} />}
>
{t('Export to full Excel')}
</Menu.Item>
</>
)}

<Menu.Item
key={MENU_KEYS.EXPORT_XLSX}
icon={<Icons.FileOutlined css={dropdownIconsStyles} />}
>
{t('Export to Excel')}
</Menu.Item>
<Menu.Item
key={MENU_KEYS.DOWNLOAD_AS_IMAGE}
icon={<Icons.FileImageOutlined css={dropdownIconsStyles} />}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ class Chart extends React.Component {
this.exportCSV = this.exportCSV.bind(this);
this.exportFullCSV = this.exportFullCSV.bind(this);
this.exportXLSX = this.exportXLSX.bind(this);
this.exportFullXLSX = this.exportFullXLSX.bind(this);
this.forceRefresh = this.forceRefresh.bind(this);
this.resize = this.resize.bind(this);
this.setDescriptionRef = this.setDescriptionRef.bind(this);
Expand Down Expand Up @@ -338,6 +339,10 @@ class Chart extends React.Component {
this.exportTable('xlsx', false);
}

exportFullXLSX() {
this.exportTable('xlsx', true);
}

exportTable(format, isFullCSV) {
const logAction =
format === 'csv'
Expand Down Expand Up @@ -453,6 +458,7 @@ class Chart extends React.Component {
exportCSV={this.exportCSV}
exportXLSX={this.exportXLSX}
exportFullCSV={this.exportFullCSV}
exportFullXLSX={this.exportFullXLSX}
updateSliceName={updateSliceName}
sliceName={sliceName}
supersetCanExplore={supersetCanExplore}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ describe('Chart', () => {
exportCSV() {},
exportFullCSV() {},
exportXLSX() {},
exportFullXLSX() {},
componentId: 'test',
dashboardId: 111,
editMode: false,
Expand Down Expand Up @@ -162,4 +163,14 @@ describe('Chart', () => {
);
exploreUtils.exportChart.restore();
});
it('should call exportChart with row_limit props.maxRows when exportFullXLSX is clicked', () => {
const stubbedExportXLSX = sinon
.stub(exploreUtils, 'exportChart')
.returns(() => {});
const wrapper = setup();
wrapper.instance().exportFullXLSX(props.slice.sliceId);
expect(stubbedExportXLSX.calledOnce).toBe(true);
expect(stubbedExportXLSX.lastCall.args[0].formData.row_limit).toEqual(666);
exploreUtils.exportChart.restore();
});
});

0 comments on commit ecd37f1

Please sign in to comment.