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: ensure correct format status in menu #5339

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
16 changes: 12 additions & 4 deletions src/actions/format_actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,13 +396,21 @@ function fontSizeMenuBuilder(): ActionSpec[] {
}

function isAutomaticFormatSelected(env: SpreadsheetChildEnv): boolean {
const activeCell = env.model.getters.getCell(env.model.getters.getActivePosition());
return !activeCell || !activeCell.format;
const activePosition = env.model.getters.getActivePosition();
const pivotCell = env.model.getters.getPivotCellFromPosition(activePosition);
if (pivotCell.type === "VALUE") {
return !env.model.getters.getEvaluatedCell(activePosition).format;
}
return !env.model.getters.getCell(activePosition)?.format;
}

function isFormatSelected(env: SpreadsheetChildEnv, format: string): boolean {
const activeCell = env.model.getters.getCell(env.model.getters.getActivePosition());
return activeCell?.format === format;
const activePosition = env.model.getters.getActivePosition();
const pivotCell = env.model.getters.getPivotCellFromPosition(activePosition);
if (pivotCell.type === "VALUE") {
return env.model.getters.getEvaluatedCell(activePosition).format === format;
}
return env.model.getters.getCell(activePosition)?.format === format;
}

function isFontSizeSelected(env: SpreadsheetChildEnv, fontSize: number): boolean {
Expand Down
20 changes: 19 additions & 1 deletion tests/formats/formatting_plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
getEvaluatedCell,
getEvaluatedGrid,
} from "../test_helpers/getters_helpers";
import { createModelFromGrid, target } from "../test_helpers/helpers";
import { createModelFromGrid, getNode, makeTestEnv, target } from "../test_helpers/helpers";
import { addPivot } from "../test_helpers/pivot_helpers";

function setDecimal(model: Model, targetXc: string, step: SetDecimalStep) {
Expand Down Expand Up @@ -387,6 +387,24 @@ describe("pivot contextual formatting", () => {
expect(model.getters.getPivotCoreDefinition("1")?.measures[0].format).toBeUndefined();
expect(getCell(model, "C1")?.format).toBe("[$$]#,##0.00");
});

test("topbar menu correctly indicates the format of the selected pivot cell", () => {
const env = makeTestEnv();
const { model } = env;

setCellContent(model, "A1", "Price");
setCellContent(model, "A2", "10");
setCellContent(model, "B1", "=PIVOT(1)");

addPivot(model, "A1:A2", {
measures: [{ id: "Price", fieldName: "Price", aggregator: "sum" }],
});
setContextualFormat(model, "C3", "[$$]#,##0.00");
selectCell(model, "C3");

const action = getNode(["format", "format_number", "format_number_currency"], env);
expect(action.isActive?.(env)).toBe(true);
});
});

describe("formatting values (when change decimal)", () => {
Expand Down