Compare commits

...

1 Commits

Author SHA1 Message Date
amaannawab923
cbcf75514f fix(plugin-chart-ag-grid-table): show correct percent-metric value in summary row (#104600)
The summary (totals) query was built with post_processing: [], which dropped
the 'contribution' operation that renames percent-metric columns from
`metric` to `%metric`. The totals query then returned `metric` while the grid
read `%metric`, so the summary row showed 0.000%.

Preserve the contribution (rename) operation in the totals query while still
dropping the time-comparison operator and orderby. Add a regression test.
2026-06-24 17:14:06 +05:30
2 changed files with 40 additions and 1 deletions

View File

@@ -652,13 +652,23 @@ const buildQuery: BuildQuery<TableChartFormData> = (
}
}
// Preserve the percent-metric "contribution" post-processing so the
// summary row renames `metric` -> `%metric` the same way the data rows
// do. Without it the totals query returns `metric` while the grid reads
// `%metric`, leaving the summary row at 0.000% (#104600). The
// time-comparison operator is intentionally dropped from the aggregate
// totals query (orderby/order_desc are cleared below for the same reason).
const totalsPostProcessing = postProcessing.filter(
rule => rule?.operation === 'contribution',
);
extraQueries.push({
...queryObject,
columns: [],
extras: totalsExtras, // Use extras with AG Grid WHERE removed
row_limit: 0,
row_offset: 0,
post_processing: [],
post_processing: totalsPostProcessing,
order_desc: undefined, // we don't need orderby stuff here,
orderby: undefined, // because this query will be used for get total aggregation.
});

View File

@@ -1363,4 +1363,33 @@ describe('plugin-chart-ag-grid-table', () => {
expect(query.extras?.where || undefined).toBeUndefined();
});
});
describe('buildQuery - percent metric summary totals (#104600)', () => {
test('totals query keeps the contribution rename for percent metrics', () => {
const { queries } = buildQuery(
{
...basicFormData,
metrics: ['revenue'],
percent_metrics: ['revenue'],
show_totals: true,
},
{ ownState: {} },
);
// queries[0] is the data query; the summary/totals query is the extra
// aggregate query with no row limit.
const totalsQuery = queries.slice(1).find(q => q.row_limit === 0);
expect(totalsQuery).toBeDefined();
const contributionOp = (totalsQuery?.post_processing || []).find(
(op: any) => op?.operation === 'contribution',
);
// Regression: the totals query previously used post_processing: [] which
// dropped the metric -> %metric rename, leaving the summary row at 0.000%.
expect(contributionOp).toBeDefined();
expect((contributionOp as any)?.options?.rename_columns).toContain(
'%revenue',
);
});
});
});