Skip to content

Commit

Permalink
[IMP] pivot: highlight pivot cells on panel open
Browse files Browse the repository at this point in the history
The pivot cells should be highlighted when the pivot side panel for
this pivot is open.

closes #5224

Task: 4341467
Signed-off-by: Lucas Lefèvre (lul) <[email protected]>
  • Loading branch information
hokolomopo committed Nov 20, 2024
1 parent fac71e9 commit 022f3b3
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Component } from "@odoo/owl";
import { getPivotHighlights } from "../../../../helpers/pivot/pivot_highlight";
import { pivotSidePanelRegistry } from "../../../../helpers/pivot/pivot_side_panel_registry";
import { SpreadsheetChildEnv, UID } from "../../../../types";
import { useHighlights } from "../../../helpers/highlight_hook";
import { Section } from "../../components/section/section";
import { PivotLayoutConfigurator } from "../pivot_layout_configurator/pivot_layout_configurator";

Expand All @@ -20,11 +22,19 @@ export class PivotSidePanel extends Component<Props, SpreadsheetChildEnv> {
Section,
};

setup() {
useHighlights(this);
}

get sidePanelEditor() {
const pivot = this.env.model.getters.getPivotCoreDefinition(this.props.pivotId);
if (!pivot) {
throw new Error("pivotId does not correspond to a pivot.");
}
return pivotSidePanelRegistry.get(pivot.type).editor;
}

get highlights() {
return getPivotHighlights(this.env.model.getters, this.props.pivotId);
}
}
29 changes: 25 additions & 4 deletions tests/pivots/pivot_side_panel.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { Model, SpreadsheetChildEnv, SpreadsheetPivotCoreDefinition } from "../../src";
import { toZone } from "../../src/helpers";
import { toZone, zoneToXc } from "../../src/helpers";
import { HighlightStore } from "../../src/stores/highlight_store";
import { createSheet, deleteSheet } from "../test_helpers/commands_helpers";
import { click, setInputValueAndTrigger, simulateClick } from "../test_helpers/dom_helper";
import { mountSpreadsheet, nextTick } from "../test_helpers/helpers";
import {
getHighlightsFromStore,
mountSpreadsheet,
nextTick,
setGrid,
} from "../test_helpers/helpers";
import { SELECTORS, addPivot, removePivot } from "../test_helpers/pivot_helpers";

describe("Pivot side panel", () => {
Expand All @@ -15,8 +21,8 @@ describe("Pivot side panel", () => {
{ model: new Model() },
{ askConfirmation: jest.fn((title, callback) => callback()) }
));
addPivot(model, "A1:D5", {}, "1");
addPivot(model, "A1:D5", {}, "2");
addPivot(model, "A1:B2", {}, "1");
addPivot(model, "A1:B2", {}, "2");
});

test("It should open the pivot editor when pivotId is provided", async () => {
Expand Down Expand Up @@ -60,4 +66,19 @@ describe("Pivot side panel", () => {
zone: toZone("A1:A100"),
});
});

test("Pivot cells are highlighted when the panel is open", async () => {
// prettier-ignore
setGrid(model, {
A1: "Partner", B1: "Amount",
A2: "Alice", B2: "10",
A5: "=PIVOT(1)"
});
const highlightStore = env.getStore(HighlightStore);
expect(highlightStore.highlights.map((h) => zoneToXc(h.zone))).toEqual([]);

env.openSidePanel("PivotSidePanel", { pivotId: "1" });
await nextTick();
expect(getHighlightsFromStore(env).map((h) => zoneToXc(h.zone))).toEqual(["A5:A7"]);
});
});

0 comments on commit 022f3b3

Please sign in to comment.