Skip to content

Commit

Permalink
feat: Adds options to show subtotals in Pivot Table (#24960)
Browse files Browse the repository at this point in the history
(cherry picked from commit be11556)
  • Loading branch information
michael-s-molina committed Aug 14, 2023
1 parent dd53b33 commit 4b07b5d
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ export default function PivotTableChart(props: PivotTableProps) {
rowSubtotalPosition,
colSubtotalPosition,
colTotals,
colSubTotals,
rowTotals,
rowSubTotals,
valueFormat,
emitCrossFilters,
setDataMask,
Expand Down Expand Up @@ -425,7 +427,9 @@ export default function PivotTableChart(props: PivotTableProps) {
clickRowHeaderCallback: toggleFilter,
clickColumnHeaderCallback: toggleFilter,
colTotals,
colSubTotals,
rowTotals,
rowSubTotals,
highlightHeaderCellsOnHover:
emitCrossFilters ||
isFeatureEnabled(FeatureFlag.DRILL_BY) ||
Expand All @@ -437,10 +441,12 @@ export default function PivotTableChart(props: PivotTableProps) {
}),
[
colTotals,
colSubTotals,
dateFormatters,
emitCrossFilters,
metricColorFormatters,
rowTotals,
rowSubTotals,
selectedFilters,
toggleFilter,
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,18 @@ const config: ControlPanelConfig = {
},
},
],
[
{
name: 'rowSubTotals',
config: {
type: 'CheckboxControl',
label: t('Show rows subtotal'),
default: false,
renderTrigger: true,
description: t('Display row level subtotal'),
},
},
],
[
{
name: 'colTotals',
Expand All @@ -230,6 +242,18 @@ const config: ControlPanelConfig = {
},
},
],
[
{
name: 'colSubTotals',
config: {
type: 'CheckboxControl',
label: t('Show columns subtotal'),
default: false,
renderTrigger: true,
description: t('Display column level subtotal'),
},
},
],
[
{
name: 'transposePivot',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ export default function transformProps(chartProps: ChartProps<QueryFormData>) {
rowSubtotalPosition,
colSubtotalPosition,
colTotals,
colSubTotals,
rowTotals,
rowSubTotals,
valueFormat,
dateFormat,
metricsLayout,
Expand Down Expand Up @@ -155,7 +157,9 @@ export default function transformProps(chartProps: ChartProps<QueryFormData>) {
rowSubtotalPosition,
colSubtotalPosition,
colTotals,
colSubTotals,
rowTotals,
rowSubTotals,
valueFormat,
emitCrossFilters,
setDataMask,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ export class TableRenderer extends React.Component {

const colSubtotalDisplay = {
displayOnTop: false,
enabled: rowTotals,
enabled: tableOptions.colSubTotals,
hideOnExpand: false,
...subtotalOptions.colSubtotalDisplay,
};

const rowSubtotalDisplay = {
displayOnTop: false,
enabled: colTotals,
enabled: tableOptions.rowSubTotals,
hideOnExpand: false,
...subtotalOptions.rowSubtotalDisplay,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ interface PivotTableCustomizeProps {
rowSubtotalPosition: boolean;
colSubtotalPosition: boolean;
colTotals: boolean;
colSubTotals: boolean;
rowTotals: boolean;
rowSubTotals: boolean;
valueFormat: string;
setDataMask: SetDataMaskHook;
emitCrossFilters?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ const formData: PivotTableQueryFormData = {
rowSubtotalPosition: true,
colSubtotalPosition: true,
colTotals: true,
colSubTotals: true,
rowTotals: true,
rowSubTotals: true,
valueFormat: 'SMART_NUMBER',
datasource: '5__table',
viz_type: 'my_chart',
Expand Down
1 change: 1 addition & 0 deletions superset/migrations/shared/migrate_viz/processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class MigratePivotTable(MigrateViz):
def _pre_action(self) -> None:
if pivot_margins := self.data.get("pivot_margins"):
self.data["colTotals"] = pivot_margins
self.data["colSubTotals"] = pivot_margins

if pandas_aggfunc := self.data.get("pandas_aggfunc"):
self.data["pandas_aggfunc"] = self.aggregation_mapping[pandas_aggfunc]
Expand Down
1 change: 1 addition & 0 deletions tests/unit_tests/migrations/viz/pivot_table_v1_v2_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"any_other_key": "untouched",
"aggregateFunction": "Sum",
"colTotals": True,
"colSubTotals": True,
"combineMetric": True,
"form_data_bak": SOURCE_FORM_DATA,
"granularity_sqla": "ds",
Expand Down

0 comments on commit 4b07b5d

Please sign in to comment.