Skip to content

Commit

Permalink
[FIX] pivot: notify only with static formulas
Browse files Browse the repository at this point in the history
When we update a pivot from it's side panel with a static pivot present in the
viewport, we have the warning "Pivot updates only work with dynamic pivot
tables". But the warning is also present if you have no static pivot anywhere,
but that there is no dynamic pivot in the viewport (eg. you scolled a bit
after opening the pivot side panel).

The warning should only be displayed if you have a static pivot somewhere in
the viewport and no dynamic pivot.

Task: 4453844
  • Loading branch information
LucasLefevre committed Jan 8, 2025
1 parent bef5abc commit 171a0c7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { deepCopy, deepEquals } from "../../../../helpers";
import { getFirstPivotFunction } from "../../../../helpers/pivot/pivot_composer_helpers";
import { isDateOrDatetimeField } from "../../../../helpers/pivot/pivot_helpers";
import { pivotRegistry } from "../../../../helpers/pivot/pivot_registry";
import { Get } from "../../../../store_engine";
Expand Down Expand Up @@ -140,7 +141,11 @@ export class PivotSidePanelStore extends SpreadsheetStore {
pivot: this.draft,
});
this.draft = null;
if (!this.alreadyNotified && !this.isDynamicPivotInViewport()) {
if (
!this.alreadyNotified &&
!this.isDynamicPivotInViewport() &&
this.isStaticPivotInViewport()
) {
const formulaId = this.getters.getPivotFormulaId(this.pivotId);
const pivotExample = `=PIVOT(${formulaId})`;
this.alreadyNotified = true;
Expand Down Expand Up @@ -217,6 +222,19 @@ export class PivotSidePanelStore extends SpreadsheetStore {
return false;
}

private isStaticPivotInViewport() {
for (const position of this.getters.getVisibleCellPositions()) {
const cell = this.getters.getCell(position);
if (cell?.isFormula) {
const pivotFunction = getFirstPivotFunction(cell.compiledFormula.tokens);
if (pivotFunction && pivotFunction.functionName !== "PIVOT") {
return true;
}
}
}
return false;
}

private addDefaultDateTimeGranularity(fields: PivotFields, definition: PivotCoreDefinition) {
const { columns, rows } = definition;
const columnsWithGranularity = deepCopy(columns);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,12 @@ describe("Spreadsheet pivot side panel", () => {
setViewportOffset(model, 0, 1000);
await click(fixture.querySelector(".o-pivot-measure .add-dimension")!);
await click(fixture.querySelectorAll(".o-autocomplete-value")[1]);
expect(mockNotify).toHaveBeenCalledTimes(0);

// add a static pivot in the viewport
setCellContent(model, "A50", "=PIVOT.VALUE(1)");
await click(fixture.querySelector(".o-pivot-measure .add-dimension")!);
await click(fixture.querySelectorAll(".o-autocomplete-value")[1]);
expect(mockNotify).toHaveBeenCalledWith({
text: "Pivot updates only work with dynamic pivot tables. Use =PIVOT(1) or re-insert the static pivot from the Data menu.",
sticky: false,
Expand Down

0 comments on commit 171a0c7

Please sign in to comment.