Skip to content

Commit

Permalink
feat(dashboard): Enables pivot table download option at dashboard lev…
Browse files Browse the repository at this point in the history
…el (#29123)

Co-authored-by: adimyth <[email protected]>
  • Loading branch information
adimyth and adimyth committed Jun 20, 2024
1 parent 03143bf commit 6378ec5
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ const SliceHeader: FC<SliceHeaderProps> = ({
supersetCanExplore = false,
supersetCanShare = false,
supersetCanCSV = false,
exportPivotCSV,
exportFullCSV,
exportFullXLSX,
slice,
Expand Down Expand Up @@ -266,6 +267,7 @@ const SliceHeader: FC<SliceHeaderProps> = ({
logExploreChart={logExploreChart}
logEvent={logEvent}
exportCSV={exportCSV}
exportPivotCSV={exportPivotCSV}
exportFullCSV={exportFullCSV}
exportXLSX={exportXLSX}
exportFullXLSX={exportFullXLSX}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ export interface SliceHeaderControlsProps {
logEvent?: (eventName: string, eventData?: object) => void;
toggleExpandSlice?: (sliceId: number) => void;
exportCSV?: (sliceId: number) => void;
exportPivotCSV?: (sliceId: number) => void;
exportFullCSV?: (sliceId: number) => void;
exportXLSX?: (sliceId: number) => void;
exportFullXLSX?: (sliceId: number) => void;
Expand Down Expand Up @@ -608,6 +609,10 @@ const SliceHeaderControls = (props: SliceHeaderControlsPropsWithRouter) => {
// eslint-disable-next-line no-unused-expressions
props.exportCSV?.(props.slice.slice_id);
break;
case MenuKeys.ExportPivotCsv:
// eslint-disable-next-line no-unused-expressions
props.exportPivotCSV?.(props.slice.slice_id);
break;
case MenuKeys.Fullscreen:
props.handleToggleFullSize();
break;
Expand Down Expand Up @@ -685,6 +690,7 @@ const SliceHeaderControls = (props: SliceHeaderControlsPropsWithRouter) => {
isCached = [],
} = props;
const isTable = slice.viz_type === 'table';
const isPivotTable = slice.viz_type === 'pivot_table_v2';
const cachedWhen = (cachedDttm || []).map(itemCachedDttm =>
moment.utc(itemCachedDttm).fromNow(),
);
Expand Down Expand Up @@ -866,6 +872,14 @@ const SliceHeaderControls = (props: SliceHeaderControlsPropsWithRouter) => {
>
{t('Export to .CSV')}
</Menu.Item>
{isPivotTable && (
<Menu.Item
key={MenuKeys.ExportPivotCsv}
icon={<Icons.FileOutlined css={dropdownIconsStyles} />}
>
{t('Export to Pivoted .CSV')}
</Menu.Item>
)}
<Menu.Item
key={MenuKeys.ExportXlsx}
icon={<Icons.FileOutlined css={dropdownIconsStyles} />}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ class Chart extends Component {
this.handleFilterMenuOpen = this.handleFilterMenuOpen.bind(this);
this.handleFilterMenuClose = this.handleFilterMenuClose.bind(this);
this.exportCSV = this.exportCSV.bind(this);
this.exportPivotCSV = this.exportPivotCSV.bind(this);
this.exportFullCSV = this.exportFullCSV.bind(this);
this.exportXLSX = this.exportXLSX.bind(this);
this.exportFullXLSX = this.exportFullXLSX.bind(this);
Expand Down Expand Up @@ -330,6 +331,10 @@ class Chart extends Component {
this.exportTable('csv', isFullCSV);
}

exportPivotCSV() {
this.exportTable('csv', false, true);
}

exportXLSX() {
this.exportTable('xlsx', false);
}
Expand All @@ -338,7 +343,7 @@ class Chart extends Component {
this.exportTable('xlsx', true);
}

exportTable(format, isFullCSV) {
exportTable(format, isFullCSV, isPivot = false) {
const logAction =
format === 'csv'
? LOG_ACTIONS_EXPORT_CSV_DASHBOARD_CHART
Expand All @@ -351,7 +356,7 @@ class Chart extends Component {
formData: isFullCSV
? { ...this.props.formData, row_limit: this.props.maxRows }
: this.props.formData,
resultType: 'full',
resultType: isPivot ? 'post_processed' : 'full',
resultFormat: format,
force: true,
ownState: this.props.ownState,
Expand Down Expand Up @@ -444,6 +449,7 @@ class Chart extends Component {
logEvent={logEvent}
onExploreChart={this.onExploreChart}
exportCSV={this.exportCSV}
exportPivotCSV={this.exportPivotCSV}
exportXLSX={this.exportXLSX}
exportFullCSV={this.exportFullCSV}
exportFullXLSX={this.exportFullXLSX}
Expand Down
1 change: 1 addition & 0 deletions superset-frontend/src/dashboard/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ export enum MenuKeys {
DownloadAsImage = 'download_as_image',
ExploreChart = 'explore_chart',
ExportCsv = 'export_csv',
ExportPivotCsv = 'export_pivot_csv',
ExportFullCsv = 'export_full_csv',
ExportXlsx = 'export_xlsx',
ExportFullXlsx = 'export_full_xlsx',
Expand Down

0 comments on commit 6378ec5

Please sign in to comment.