feat: Adds options to show subtotals in Pivot Table (#24960)

This commit is contained in:
Michael S. Molina 2023-08-14 09:20:32 -03:00 committed by GitHub
parent a44c99899a
commit be11556799
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 42 additions and 2 deletions

View File

@ -138,7 +138,9 @@ export default function PivotTableChart(props: PivotTableProps) {
rowSubtotalPosition, rowSubtotalPosition,
colSubtotalPosition, colSubtotalPosition,
colTotals, colTotals,
colSubTotals,
rowTotals, rowTotals,
rowSubTotals,
valueFormat, valueFormat,
currencyFormat, currencyFormat,
emitCrossFilters, emitCrossFilters,
@ -432,7 +434,9 @@ export default function PivotTableChart(props: PivotTableProps) {
clickRowHeaderCallback: toggleFilter, clickRowHeaderCallback: toggleFilter,
clickColumnHeaderCallback: toggleFilter, clickColumnHeaderCallback: toggleFilter,
colTotals, colTotals,
colSubTotals,
rowTotals, rowTotals,
rowSubTotals,
highlightHeaderCellsOnHover: highlightHeaderCellsOnHover:
emitCrossFilters || emitCrossFilters ||
isFeatureEnabled(FeatureFlag.DRILL_BY) || isFeatureEnabled(FeatureFlag.DRILL_BY) ||
@ -444,10 +448,12 @@ export default function PivotTableChart(props: PivotTableProps) {
}), }),
[ [
colTotals, colTotals,
colSubTotals,
dateFormatters, dateFormatters,
emitCrossFilters, emitCrossFilters,
metricColorFormatters, metricColorFormatters,
rowTotals, rowTotals,
rowSubTotals,
selectedFilters, selectedFilters,
toggleFilter, toggleFilter,
], ],

View File

@ -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', 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', name: 'transposePivot',

View File

@ -96,7 +96,9 @@ export default function transformProps(chartProps: ChartProps<QueryFormData>) {
rowSubtotalPosition, rowSubtotalPosition,
colSubtotalPosition, colSubtotalPosition,
colTotals, colTotals,
colSubTotals,
rowTotals, rowTotals,
rowSubTotals,
valueFormat, valueFormat,
dateFormat, dateFormat,
metricsLayout, metricsLayout,
@ -156,7 +158,9 @@ export default function transformProps(chartProps: ChartProps<QueryFormData>) {
rowSubtotalPosition, rowSubtotalPosition,
colSubtotalPosition, colSubtotalPosition,
colTotals, colTotals,
colSubTotals,
rowTotals, rowTotals,
rowSubTotals,
valueFormat, valueFormat,
currencyFormat, currencyFormat,
emitCrossFilters, emitCrossFilters,

View File

@ -92,14 +92,14 @@ export class TableRenderer extends React.Component {
const colSubtotalDisplay = { const colSubtotalDisplay = {
displayOnTop: false, displayOnTop: false,
enabled: rowTotals, enabled: tableOptions.colSubTotals,
hideOnExpand: false, hideOnExpand: false,
...subtotalOptions.colSubtotalDisplay, ...subtotalOptions.colSubtotalDisplay,
}; };
const rowSubtotalDisplay = { const rowSubtotalDisplay = {
displayOnTop: false, displayOnTop: false,
enabled: colTotals, enabled: tableOptions.rowSubTotals,
hideOnExpand: false, hideOnExpand: false,
...subtotalOptions.rowSubtotalDisplay, ...subtotalOptions.rowSubtotalDisplay,
}; };

View File

@ -63,7 +63,9 @@ interface PivotTableCustomizeProps {
rowSubtotalPosition: boolean; rowSubtotalPosition: boolean;
colSubtotalPosition: boolean; colSubtotalPosition: boolean;
colTotals: boolean; colTotals: boolean;
colSubTotals: boolean;
rowTotals: boolean; rowTotals: boolean;
rowSubTotals: boolean;
valueFormat: string; valueFormat: string;
currencyFormat: Currency; currencyFormat: Currency;
setDataMask: SetDataMaskHook; setDataMask: SetDataMaskHook;

View File

@ -34,7 +34,9 @@ const formData: PivotTableQueryFormData = {
rowSubtotalPosition: true, rowSubtotalPosition: true,
colSubtotalPosition: true, colSubtotalPosition: true,
colTotals: true, colTotals: true,
colSubTotals: true,
rowTotals: true, rowTotals: true,
rowSubTotals: true,
valueFormat: 'SMART_NUMBER', valueFormat: 'SMART_NUMBER',
datasource: '5__table', datasource: '5__table',
viz_type: 'my_chart', viz_type: 'my_chart',

View File

@ -95,6 +95,7 @@ class MigratePivotTable(MigrateViz):
def _pre_action(self) -> None: def _pre_action(self) -> None:
if pivot_margins := self.data.get("pivot_margins"): if pivot_margins := self.data.get("pivot_margins"):
self.data["colTotals"] = pivot_margins self.data["colTotals"] = pivot_margins
self.data["colSubTotals"] = pivot_margins
if pandas_aggfunc := self.data.get("pandas_aggfunc"): if pandas_aggfunc := self.data.get("pandas_aggfunc"):
self.data["pandas_aggfunc"] = self.aggregation_mapping[pandas_aggfunc] self.data["pandas_aggfunc"] = self.aggregation_mapping[pandas_aggfunc]

View File

@ -40,6 +40,7 @@ TARGET_FORM_DATA = {
"any_other_key": "untouched", "any_other_key": "untouched",
"aggregateFunction": "Sum", "aggregateFunction": "Sum",
"colTotals": True, "colTotals": True,
"colSubTotals": True,
"combineMetric": True, "combineMetric": True,
"form_data_bak": SOURCE_FORM_DATA, "form_data_bak": SOURCE_FORM_DATA,
"granularity_sqla": "ds", "granularity_sqla": "ds",