diff --git a/src/components/side_panel/pivot/pivot_side_panel/pivot_side_panel_store.ts b/src/components/side_panel/pivot/pivot_side_panel/pivot_side_panel_store.ts index 5c6e7db547..883a942058 100644 --- a/src/components/side_panel/pivot/pivot_side_panel/pivot_side_panel_store.ts +++ b/src/components/side_panel/pivot/pivot_side_panel/pivot_side_panel_store.ts @@ -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"; @@ -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; @@ -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); diff --git a/tests/pivots/spreadsheet_pivot/spreadsheet_pivot_side_panel.test.ts b/tests/pivots/spreadsheet_pivot/spreadsheet_pivot_side_panel.test.ts index 5e827be40b..a4aab66696 100644 --- a/tests/pivots/spreadsheet_pivot/spreadsheet_pivot_side_panel.test.ts +++ b/tests/pivots/spreadsheet_pivot/spreadsheet_pivot_side_panel.test.ts @@ -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,