Skip to content

Commit fdc5b48

Browse files
committed
[REV] pivot: chart field with mix of text and numbers
This reverts commit f28aac0. It raises a lot of tickets so we prefer to revert it for now and take the time to fix it properly. opw-4800411 closes #6508 Task: 4800411 X-original-commit: ab92eab Signed-off-by: Lucas Lefèvre (lul) <[email protected]> Signed-off-by: Pierre Rousseau (pro) <[email protected]>
1 parent 58da1fe commit fdc5b48

File tree

3 files changed

+46
-41
lines changed

3 files changed

+46
-41
lines changed

src/helpers/pivot/pivot_helpers.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,11 @@ const AGGREGATOR_NAMES = {
3737
sum: _t("Sum"),
3838
};
3939

40+
const NUMBER_CHAR_AGGREGATORS = ["max", "min", "avg", "sum", "count_distinct", "count"];
41+
4042
const AGGREGATORS_BY_FIELD_TYPE = {
41-
integer: ["max", "min", "avg", "sum", "count_distinct", "count"],
42-
char: ["count_distinct", "count"],
43+
integer: NUMBER_CHAR_AGGREGATORS,
44+
char: NUMBER_CHAR_AGGREGATORS,
4345
boolean: ["count_distinct", "count", "bool_and", "bool_or"],
4446
datetime: ["max", "min", "count_distinct", "count"],
4547
};

src/helpers/pivot/spreadsheet_pivot/spreadsheet_pivot.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -483,11 +483,7 @@ export class SpreadsheetPivot implements Pivot<SpreadsheetPivotRuntimeDefinition
483483
if (cell.value === "") {
484484
entry[field.name] = { value: null, type: CellValueType.empty, formattedValue: "" };
485485
} else {
486-
if (field.type === "char") {
487-
entry[field.name] = { ...cell, value: cell.formattedValue || null };
488-
} else {
489-
entry[field.name] = cell;
490-
}
486+
entry[field.name] = cell;
491487
}
492488
}
493489
entry["__count"] = { value: 1, type: CellValueType.number, formattedValue: "1" };

tests/pivots/spreadsheet_pivot/spreadsheet_pivot.test.ts

Lines changed: 41 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,21 @@ describe("Spreadsheet Pivot", () => {
631631
);
632632
});
633633

634+
test("Sum with a field that contains a string should work", () => {
635+
const model = createModelWithPivot("A1:I5");
636+
updatePivot(model, "1", {
637+
columns: [],
638+
rows: [],
639+
measures: [{ id: "Expected Revenue:sum", fieldName: "Expected Revenue", aggregator: "sum" }],
640+
});
641+
setCellContent(model, "A26", `=pivot(1)`);
642+
expect(getCellContent(model, "B28")).toBe("$17,500.00");
643+
644+
expect(getCellContent(model, "F2")).toBe("$2,000.00");
645+
setCellContent(model, "F2", "Hello");
646+
expect(getCellContent(model, "B28")).toBe("$15,500.00");
647+
});
648+
634649
test("quarter_number should be supported", () => {
635650
const model = createModelWithPivot("A1:I5");
636651
updatePivot(model, "1", {
@@ -878,15 +893,38 @@ describe("Spreadsheet Pivot", () => {
878893
expect(getEvaluatedCell(model, "A27").value).toBe(aggregatedValue);
879894
});
880895

896+
test.each([
897+
["sum", 15],
898+
["count", 3],
899+
["count_distinct", 3],
900+
["max", 10],
901+
["min", 5],
902+
["avg", 7.5],
903+
])("PIVOT.VALUE measure mixing text and number %s grand total", (aggregator, aggregatedValue) => {
904+
const grid = {
905+
A1: "Name",
906+
A2: "Alice",
907+
A3: "5",
908+
A4: "10",
909+
};
910+
const model = createModelFromGrid(grid);
911+
addPivot(model, "A1:A4", {
912+
columns: [],
913+
rows: [],
914+
measures: [{ id: `Name:${aggregator}`, fieldName: "Name", aggregator }],
915+
});
916+
setCellContent(model, "A27", `=PIVOT.VALUE(1, "Name:${aggregator}")`);
917+
expect(getEvaluatedCell(model, "A27").value).toBe(aggregatedValue);
918+
});
919+
881920
test("min and max aggregate format is inferred", () => {
882921
// prettier-ignore
883922
const grid = {
884923
A1: "Name", B1: "Revenue",
885-
A2: "Alice", B2: "22",
924+
A2: "Alice", B2: "Hi",
886925
A3: "Bob", B3: "5",
887926
};
888927
const model = createModelFromGrid(grid);
889-
setFormat(model, "B2", "[$€]#,##0");
890928
setFormat(model, "B3", "[$$]#,##0");
891929
addPivot(model, "A1:B3", {
892930
columns: [],
@@ -898,7 +936,7 @@ describe("Spreadsheet Pivot", () => {
898936
});
899937
setCellContent(model, "A27", '=PIVOT.VALUE(1, "Revenue:max")');
900938
setCellContent(model, "A28", '=PIVOT.VALUE(1, "Revenue:min")');
901-
expect(getEvaluatedCell(model, "A27").format).toBe("[$]#,##0");
939+
expect(getEvaluatedCell(model, "A27").format).toBe("[$$]#,##0");
902940
expect(getEvaluatedCell(model, "A28").format).toBe("[$$]#,##0");
903941
});
904942

@@ -1993,37 +2031,6 @@ describe("Spreadsheet Pivot", () => {
19932031
expect(model.getters.getPivotCoreDefinition("1")).toBeTruthy();
19942032
expect(model.getters.getPivot("1")).toBeTruthy();
19952033
});
1996-
1997-
test("char dimension supports mix of number and texts", () => {
1998-
// prettier-ignore
1999-
const grid = {
2000-
A1: "Customer", B1: "Price", C1: "=PIVOT(1)",
2001-
A2: "Alice", B2: "10",
2002-
A3: "", B3: "20",
2003-
A4: "1", B4: "30",
2004-
A5: "2", B5: "40",
2005-
A6: "2", B6: "50",
2006-
A7: '="1"', B7: "60",
2007-
};
2008-
const model = createModelFromGrid(grid);
2009-
setFormat(model, "A6", "m/d/yyyy");
2010-
addPivot(model, "A1:B7", {
2011-
rows: [{ fieldName: "Customer", order: "asc" }],
2012-
columns: [],
2013-
measures: [{ id: "Price:sum", fieldName: "Price", aggregator: "sum" }],
2014-
});
2015-
// prettier-ignore
2016-
expect(getEvaluatedGrid(model, "C1:D8")).toEqual([
2017-
["(#1) Pivot", "Total"],
2018-
["", "Price"],
2019-
["1", "90"],
2020-
["1/1/1900", "50"],
2021-
["2", "40"],
2022-
["Alice", "10"],
2023-
["(Undefined)", "20"],
2024-
["Total", "210"],
2025-
]);
2026-
});
20272034
});
20282035

20292036
describe("Spreadsheet arguments parsing", () => {

0 commit comments

Comments
 (0)