Skip to content

Commit

Permalink
[IMP] pivot: persist defer update
Browse files Browse the repository at this point in the history
Add the defer update option to the pivot core definition so it
is persisted when re-opening the side panel.

Task: 4080797
  • Loading branch information
hokolomopo committed Sep 13, 2024
1 parent e85b11b commit 0baa4b5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
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 @@ -123,10 +125,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 @@ -56,6 +56,7 @@ export interface CommonPivotCoreDefinition {
rows: PivotCoreDimension[];
measures: PivotCoreMeasure[];
name: string;
deferUpdates?: boolean;
}

export interface SpreadsheetPivotCoreDefinition extends CommonPivotCoreDefinition {
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

0 comments on commit 0baa4b5

Please sign in to comment.