Skip to content

Commit

Permalink
[FIX] pivot: pivot UI not removed on pivot deletion
Browse files Browse the repository at this point in the history
The command `REMOVE_PIVOT` was not handled inside the `PivotUIPlugin`.

closes #4845

Task: 4115738
Signed-off-by: Lucas Lefèvre (lul) <[email protected]>
  • Loading branch information
hokolomopo committed Aug 16, 2024
1 parent a516421 commit 22625e8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/plugins/ui_core_views/pivot_ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ export class PivotUIPlugin extends UIPlugin {
this.setupPivot(cmd.pivotId, { recreate: true });
break;
}
case "REMOVE_PIVOT": {
delete this.pivots[cmd.pivotId];
break;
}
case "DELETE_SHEET":
case "UPDATE_CELL": {
this.unusedPivots = undefined;
Expand Down
19 changes: 18 additions & 1 deletion tests/pivots/spreadsheet_pivot/spreadsheet_pivot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ import {
getEvaluatedGrid,
} from "../../test_helpers/getters_helpers";
import { createModelFromGrid } from "../../test_helpers/helpers";
import { addPivot, createModelWithPivot, updatePivot } from "../../test_helpers/pivot_helpers";
import {
addPivot,
createModelWithPivot,
removePivot,
updatePivot,
} from "../../test_helpers/pivot_helpers";
import { CellValue, CellValueType } from "./../../../src/types/cells";

describe("Spreadsheet Pivot", () => {
Expand Down Expand Up @@ -1272,6 +1277,18 @@ describe("Spreadsheet Pivot", () => {
expect(model.getters.getPivot("1").isValid()).toBeTruthy();
});
});

test("Pivot is removed on command REMOVE_PIVOT", () => {
const model = createModelWithPivot("A1:I5");
expect(model.getters.getPivotIds()).toEqual(["1"]);
expect(model.getters.getPivotCoreDefinition("1")).toBeTruthy();
expect(model.getters.getPivot("1")).toBeTruthy();

removePivot(model, "1");
expect(model.getters.getPivotIds()).toEqual([]);
expect(() => model.getters.getPivotCoreDefinition("1")).toThrow();
expect(model.getters.getPivot("1")).toBeUndefined();
});
});

describe("Spreadsheet arguments parsing", () => {
Expand Down

0 comments on commit 22625e8

Please sign in to comment.