Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] pivot: notify only with static formulas #5431

Open
wants to merge 1 commit into
base: 18.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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