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:27:08 UTC
[superset] 06/06: 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 3.0
in repository https://gitbox.apache.org/repos/asf/superset.git
commit 4b07b5d62874567c26ee31028b356f68e46dc26d
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)
(cherry picked from commit be1155679963a90c7a0d699a2ebdceade40fb5a9)
---
.../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 f463990b1d..0912deea1d 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,
emitCrossFilters,
setDataMask,
@@ -425,7 +427,9 @@ export default function PivotTableChart(props: PivotTableProps) {
clickRowHeaderCallback: toggleFilter,
clickColumnHeaderCallback: toggleFilter,
colTotals,
+ colSubTotals,
rowTotals,
+ rowSubTotals,
highlightHeaderCellsOnHover:
emitCrossFilters ||
isFeatureEnabled(FeatureFlag.DRILL_BY) ||
@@ -437,10 +441,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 d099406c55..2ba473358b 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 f335c6978e..829f0178be 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,
@@ -155,7 +157,9 @@ export default function transformProps(chartProps: ChartProps<QueryFormData>) {
rowSubtotalPosition,
colSubtotalPosition,
colTotals,
+ colSubTotals,
rowTotals,
+ rowSubTotals,
valueFormat,
emitCrossFilters,
setDataMask,
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 dea5236666..8eeef30efa 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;
setDataMask: SetDataMaskHook;
emitCrossFilters?: boolean;
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 7bb47d785c..468a1d62ba 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",