You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by mi...@apache.org on 2023/08/14 12:20:41 UTC
[superset] branch master updated: feat: Adds options to show subtotals in Pivot Table (#24960)
This is an automated email from the ASF dual-hosted git repository.
michaelsmolina pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git
The following commit(s) were added to refs/heads/master by this push:
new be11556799 feat: Adds options to show subtotals in Pivot Table (#24960)
be11556799 is described below
commit be1155679963a90c7a0d699a2ebdceade40fb5a9
Author: Michael S. Molina <70...@users.noreply.github.com>
AuthorDate: Mon Aug 14 09:20:32 2023 -0300
feat: Adds options to show subtotals in Pivot Table (#24960)
---
.../src/PivotTableChart.tsx | 6 ++++++
.../src/plugin/controlPanel.tsx | 24 ++++++++++++++++++++++
.../src/plugin/transformProps.ts | 4 ++++
.../src/react-pivottable/TableRenderers.jsx | 4 ++--
.../plugins/plugin-chart-pivot-table/src/types.ts | 2 ++
.../test/plugin/buildQuery.test.ts | 2 ++
.../migrations/shared/migrate_viz/processors.py | 1 +
.../migrations/viz/pivot_table_v1_v2_test.py | 1 +
8 files changed, 42 insertions(+), 2 deletions(-)
diff --git a/superset-frontend/plugins/plugin-chart-pivot-table/src/PivotTableChart.tsx b/superset-frontend/plugins/plugin-chart-pivot-table/src/PivotTableChart.tsx
index 19211998a4..32f10b0771 100644
--- a/superset-frontend/plugins/plugin-chart-pivot-table/src/PivotTableChart.tsx
+++ b/superset-frontend/plugins/plugin-chart-pivot-table/src/PivotTableChart.tsx
@@ -138,7 +138,9 @@ export default function PivotTableChart(props: PivotTableProps) {
rowSubtotalPosition,
colSubtotalPosition,
colTotals,
+ colSubTotals,
rowTotals,
+ rowSubTotals,
valueFormat,
currencyFormat,
emitCrossFilters,
@@ -432,7 +434,9 @@ export default function PivotTableChart(props: PivotTableProps) {
clickRowHeaderCallback: toggleFilter,
clickColumnHeaderCallback: toggleFilter,
colTotals,
+ colSubTotals,
rowTotals,
+ rowSubTotals,
highlightHeaderCellsOnHover:
emitCrossFilters ||
isFeatureEnabled(FeatureFlag.DRILL_BY) ||
@@ -444,10 +448,12 @@ export default function PivotTableChart(props: PivotTableProps) {
}),
[
colTotals,
+ colSubTotals,
dateFormatters,
emitCrossFilters,
metricColorFormatters,
rowTotals,
+ rowSubTotals,
selectedFilters,
toggleFilter,
],
diff --git a/superset-frontend/plugins/plugin-chart-pivot-table/src/plugin/controlPanel.tsx b/superset-frontend/plugins/plugin-chart-pivot-table/src/plugin/controlPanel.tsx
index 3fbddffc98..64a2c00176 100644
--- a/superset-frontend/plugins/plugin-chart-pivot-table/src/plugin/controlPanel.tsx
+++ b/superset-frontend/plugins/plugin-chart-pivot-table/src/plugin/controlPanel.tsx
@@ -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',
@@ -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',
diff --git a/superset-frontend/plugins/plugin-chart-pivot-table/src/plugin/transformProps.ts b/superset-frontend/plugins/plugin-chart-pivot-table/src/plugin/transformProps.ts
index d4b972c249..76c58b895f 100644
--- a/superset-frontend/plugins/plugin-chart-pivot-table/src/plugin/transformProps.ts
+++ b/superset-frontend/plugins/plugin-chart-pivot-table/src/plugin/transformProps.ts
@@ -96,7 +96,9 @@ export default function transformProps(chartProps: ChartProps<QueryFormData>) {
rowSubtotalPosition,
colSubtotalPosition,
colTotals,
+ colSubTotals,
rowTotals,
+ rowSubTotals,
valueFormat,
dateFormat,
metricsLayout,
@@ -156,7 +158,9 @@ export default function transformProps(chartProps: ChartProps<QueryFormData>) {
rowSubtotalPosition,
colSubtotalPosition,
colTotals,
+ colSubTotals,
rowTotals,
+ rowSubTotals,
valueFormat,
currencyFormat,
emitCrossFilters,
diff --git a/superset-frontend/plugins/plugin-chart-pivot-table/src/react-pivottable/TableRenderers.jsx b/superset-frontend/plugins/plugin-chart-pivot-table/src/react-pivottable/TableRenderers.jsx
index 8915ed7e9c..760ff90c15 100644
--- a/superset-frontend/plugins/plugin-chart-pivot-table/src/react-pivottable/TableRenderers.jsx
+++ b/superset-frontend/plugins/plugin-chart-pivot-table/src/react-pivottable/TableRenderers.jsx
@@ -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,
};
diff --git a/superset-frontend/plugins/plugin-chart-pivot-table/src/types.ts b/superset-frontend/plugins/plugin-chart-pivot-table/src/types.ts
index ebe1eb090c..4e4dbbd058 100644
--- a/superset-frontend/plugins/plugin-chart-pivot-table/src/types.ts
+++ b/superset-frontend/plugins/plugin-chart-pivot-table/src/types.ts
@@ -63,7 +63,9 @@ interface PivotTableCustomizeProps {
rowSubtotalPosition: boolean;
colSubtotalPosition: boolean;
colTotals: boolean;
+ colSubTotals: boolean;
rowTotals: boolean;
+ rowSubTotals: boolean;
valueFormat: string;
currencyFormat: Currency;
setDataMask: SetDataMaskHook;
diff --git a/superset-frontend/plugins/plugin-chart-pivot-table/test/plugin/buildQuery.test.ts b/superset-frontend/plugins/plugin-chart-pivot-table/test/plugin/buildQuery.test.ts
index fa13f5fcce..0e29de9196 100644
--- a/superset-frontend/plugins/plugin-chart-pivot-table/test/plugin/buildQuery.test.ts
+++ b/superset-frontend/plugins/plugin-chart-pivot-table/test/plugin/buildQuery.test.ts
@@ -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',
diff --git a/superset/migrations/shared/migrate_viz/processors.py b/superset/migrations/shared/migrate_viz/processors.py
index 70c3c27055..d1978f33e1 100644
--- a/superset/migrations/shared/migrate_viz/processors.py
+++ b/superset/migrations/shared/migrate_viz/processors.py
@@ -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]
diff --git a/tests/unit_tests/migrations/viz/pivot_table_v1_v2_test.py b/tests/unit_tests/migrations/viz/pivot_table_v1_v2_test.py
index ab357b62c3..1e2229ca83 100644
--- a/tests/unit_tests/migrations/viz/pivot_table_v1_v2_test.py
+++ b/tests/unit_tests/migrations/viz/pivot_table_v1_v2_test.py
@@ -40,6 +40,7 @@ TARGET_FORM_DATA = {
"any_other_key": "untouched",
"aggregateFunction": "Sum",
"colTotals": True,
+ "colSubTotals": True,
"combineMetric": True,
"form_data_bak": SOURCE_FORM_DATA,
"granularity_sqla": "ds",