Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Fix pivot text overlapping when next header column is collapsed (#71104)

Kevin Kelleherc62b32e78f67
diff --git a/frontend/src/metabase/visualizations/visualizations/PivotTable/utils.ts b/frontend/src/metabase/visualizations/visualizations/PivotTable/utils.ts
index af6b77aafe4..c21ee797d7d 100644
--- a/frontend/src/metabase/visualizations/visualizations/PivotTable/utils.ts
+++ b/frontend/src/metabase/visualizations/visualizations/PivotTable/utils.ts
@@ -246,14 +246,14 @@ export const leftHeaderCellSizeAndPositionGetter = (
leftHeaderWidths: number[],
rowIndexes: number[],
) => {
- const { offset, span, depth, maxDepthBelow } = item;
+ const { offset, span, depth, maxDepthBelow, isSubtotal } = item;
const columnsToSpan = rowIndexes.length - depth - maxDepthBelow;
- // add up all the widths of the columns, other than itself, that this cell spans
- const spanWidth = sumArray(
- leftHeaderWidths.slice(depth + 1, depth + columnsToSpan),
- );
+ // for subtotals, add up all the widths of the columns, other than itself, that this cell spans
+ const spanWidth = isSubtotal
+ ? sumArray(leftHeaderWidths.slice(depth + 1, depth + columnsToSpan))
+ : 0;
const columnPadding = depth === 0 ? LEFT_HEADER_LEFT_SPACING : 0;
const columnWidth = leftHeaderWidths[depth];
diff --git a/frontend/src/metabase/visualizations/visualizations/PivotTable/utils.unit.spec.ts b/frontend/src/metabase/visualizations/visualizations/PivotTable/utils.unit.spec.ts
index be50d0a25fe..e14e29c4006 100644
--- a/frontend/src/metabase/visualizations/visualizations/PivotTable/utils.unit.spec.ts
+++ b/frontend/src/metabase/visualizations/visualizations/PivotTable/utils.unit.spec.ts
@@ -14,6 +14,7 @@ import {
getLeftHeaderWidths,
isColumnValid,
isFormattablePivotColumn,
+ leftHeaderCellSizeAndPositionGetter,
updateValueWithCurrentColumns,
} from "./utils";
@@ -355,4 +356,33 @@ describe("Visualizations > Visualizations > PivotTable > utils", () => {
]);
});
});
+
+ describe("leftHeaderCellSizeAndPositionGetter", () => {
+ it("should return the correct width for a subtotal", () => {
+ const result = leftHeaderCellSizeAndPositionGetter(
+ { depth: 1, maxDepthBelow: 0, isSubtotal: true } as HeaderItem,
+ [100, 100, 100],
+ [0, 1, 2],
+ );
+ expect(result.width).toBe(200);
+ });
+
+ it("should return the correct width for a non-subtotal", () => {
+ const result = leftHeaderCellSizeAndPositionGetter(
+ { depth: 1, maxDepthBelow: 1, isSubtotal: false } as HeaderItem,
+ [100, 100, 100],
+ [0, 1, 2],
+ );
+ expect(result.width).toBe(100);
+ });
+
+ it("non-subtotal widths should not increase when columns are collapsed", () => {
+ const result = leftHeaderCellSizeAndPositionGetter(
+ { depth: 1, maxDepthBelow: 0, isSubtotal: false } as HeaderItem,
+ [100, 100, 100],
+ [0, 1, 2],
+ );
+ expect(result.width).toBe(100);
+ });
+ });
});