Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dashboard): Enables pivot table download option at dashboard level #29123

Merged
merged 2 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -865,6 +871,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
Loading