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

[IMP] pivot: persist defer update #4976

Open
wants to merge 2 commits into
base: master
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
1 change: 1 addition & 0 deletions src/components/grid/grid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ export class Grid extends Component<Props, SpreadsheetChildEnv> {
"Ctrl+Z": () => this.env.model.dispatch("REQUEST_UNDO"),
"Ctrl+Y": () => this.env.model.dispatch("REQUEST_REDO"),
F4: () => this.env.model.dispatch("REQUEST_REDO"),
F9: () => this.env.model.dispatch("EVALUATE_CELLS"),
"Ctrl+B": () =>
this.env.model.dispatch("SET_FORMATTING", {
sheetId: this.env.model.getters.getActiveSheetId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ import {
export class PivotSidePanelStore extends SpreadsheetStore {
mutators = ["reset", "deferUpdates", "applyUpdate", "discardPendingUpdate", "update"] as const;

private updatesAreDeferred: boolean = false;
private updatesAreDeferred: boolean;
private draft: PivotCoreDefinition | null = null;
constructor(get: Get, private pivotId: UID) {
super(get);
this.updatesAreDeferred =
this.getters.getPivotCoreDefinition(this.pivotId).deferUpdates ?? false;
}

handle(cmd: Command) {
Expand Down Expand Up @@ -121,10 +123,13 @@ export class PivotSidePanelStore extends SpreadsheetStore {
}

deferUpdates(shouldDefer: boolean) {
this.updatesAreDeferred = shouldDefer;
if (shouldDefer === false && this.draft) {
this.draft.deferUpdates = false;
this.applyUpdate();
} else {
this.update({ deferUpdates: shouldDefer });
}
this.updatesAreDeferred = shouldDefer;
}

applyUpdate() {
Expand Down
1 change: 1 addition & 0 deletions src/types/pivot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export interface CommonPivotCoreDefinition {
rows: PivotCoreDimension[];
measures: PivotCoreMeasure[];
name: string;
deferUpdates?: boolean;
}

export interface SpreadsheetPivotCoreDefinition extends CommonPivotCoreDefinition {
Expand Down
14 changes: 13 additions & 1 deletion tests/grid/grid_component.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,13 @@ import {
getSelectionAnchorCellXc,
getStyle,
} from "../test_helpers/getters_helpers";
import { mockChart, mountSpreadsheet, nextTick, typeInComposerGrid } from "../test_helpers/helpers";
import {
mockChart,
mountSpreadsheet,
nextTick,
spyModelDispatch,
typeInComposerGrid,
} from "../test_helpers/helpers";
import { mockGetBoundingClientRect } from "../test_helpers/mock_helpers";
jest.mock("../../src/components/composer/content_editable_helper", () =>
require("../__mocks__/content_editable_helper")
Expand Down Expand Up @@ -785,6 +791,12 @@ describe("Grid component", () => {
await simulateClick(".o-filter-icon");
expect(fixture.querySelectorAll(".o-filter-menu")).toHaveLength(1);
});

test("F9 triggers a re-evaluation of the grid", () => {
const spyDispatch = spyModelDispatch(model);
keyDown({ key: "F9" });
expect(spyDispatch).toHaveBeenCalledWith("EVALUATE_CELLS");
});
});

describe("Grid Scroll", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,21 @@ describe("Spreadsheet pivot side panel", () => {
expect(fixture.querySelectorAll(".pivot-dimension")).toHaveLength(0);
});

test("defer update option is persistent", async () => {
const pivotId = model.getters.getPivotIds()[0];
expect(".pivot-defer-update input").toHaveValue(false);
expect(model.getters.getPivotCoreDefinition(pivotId).deferUpdates).toBeFalsy();

await click(fixture, ".pivot-defer-update input");
expect(".pivot-defer-update input").toHaveValue(true);
expect(model.getters.getPivotCoreDefinition(pivotId).deferUpdates).toBeTruthy();

await click(fixture, ".o-sidePanelClose");
env.openSidePanel("PivotSidePanel", { pivotId });
await nextTick();
expect(".pivot-defer-update input").toHaveValue(true);
});

test("Measures have the correct default aggregator", async () => {
setCellContent(model, "A1", "amount");
setCellContent(model, "A2", "10");
Expand Down