Skip to content
Closed
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { rangeTokenize } from "../../../formulas";
import { localizeContent } from "../../../helpers/locale";
import { AutoCompleteProviderDefinition } from "../../../registries";
import { Get } from "../../../store_engine";
import { UID } from "../../../types";
Expand Down Expand Up @@ -31,12 +32,13 @@ export class StandaloneComposerStore extends AbstractComposerStore {
}

protected getComposerContent(): string {
let content = this._currentContent;
if (this.editionMode === "inactive") {
// References in the content might not be linked to the current active sheet
// We here force the sheet name prefix for all references that are not in
// the current active sheet
const defaultRangeSheetId = this.args().defaultRangeSheetId;
return rangeTokenize(this.args().content)
content = rangeTokenize(this.args().content)
.map((token) => {
if (token.type === "REFERENCE") {
const range = this.getters.getRangeFromSheetXC(defaultRangeSheetId, token.value);
Expand All @@ -46,7 +48,8 @@ export class StandaloneComposerStore extends AbstractComposerStore {
})
.join("");
}
return this._currentContent;

return localizeContent(content, this.getters.getLocale());
}

stopEdition() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,8 @@ export class PivotMeasureEditor extends Component<Props> {
measure: this.props.measure,
});
}

get isCalculatedMeasureInvalid(): boolean {
return this.env.model.getters.getMeasureCompiledFormula(this.props.measure).isBadExpression;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
composerContent="measure.computedBy.formula"
defaultRangeSheetId="measure.computedBy.sheetId"
contextualAutocomplete="getMeasureAutocomplete()"
invalid="isCalculatedMeasureInvalid"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll let francois decide but it feels like the simple "o-invalid" doesn't draw enough attention

/>
</div>
</div>
Expand Down
17 changes: 16 additions & 1 deletion tests/composer/standalone_composer_component.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { StandaloneComposer } from "../../src/components/composer/standalone_com
import { zoneToXc } from "../../src/helpers";
import { sidePanelRegistry } from "../../src/registries/side_panel_registry";
import { Store } from "../../src/store_engine";
import { createSheet } from "../test_helpers/commands_helpers";
import { createSheet, updateLocale } from "../test_helpers/commands_helpers";
import { FR_LOCALE } from "../test_helpers/constants";
import { click, keyDown, simulateClick } from "../test_helpers/dom_helper";
import { editStandaloneComposer, mountSpreadsheet, nextTick } from "../test_helpers/helpers";

Expand Down Expand Up @@ -134,4 +135,18 @@ describe("Spreadsheet integrations tests", () => {
// to the new confirmed content
expect(composerEl.textContent).toBe("content from props");
});

test("Standalone composer works with non-default locale", async () => {
updateLocale(model, FR_LOCALE);
await openSidePanelWithComposer("=SUM(1,2.5)");
expect(composerEl.textContent).toBe("=SUM(1;2,5)");

await editStandaloneComposer(composerSelector, " + SUM(1,5;4)", {
fromScratch: false,
confirm: false,
});
expect(composerEl.textContent).toBe("=SUM(1;2,5) + SUM(1,5;4)");
await keyDown({ key: "Enter" });
expect(onConfirm).toHaveBeenCalledWith("=SUM(1,2.5) + SUM(1.5,4)");
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,14 @@ describe("Spreadsheet pivot side panel", () => {
]);
});

test("Invalid calculated measure formula have an invalid class on the composer", async () => {
await click(fixture.querySelectorAll(".add-dimension")[2]);
expect(fixture.querySelector(".o-popover")).toBeDefined();
await click(fixture, ".add-calculated-measure");
await editStandaloneComposer(".pivot-dimension .o-composer", "=abcdefg()");
expect(fixture.querySelector(".o-standalone-composer")).toHaveClass("o-invalid");
});

test("can select a cell in the grid in several sheets", async () => {
setCellContent(model, "A1", "amount");
setCellContent(model, "A2", "10");
Expand Down
40 changes: 40 additions & 0 deletions tests/setup/jest_extend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ declare global {
toHaveValue(value: string | boolean): R;
toHaveText(text: string): R;
toHaveCount(count: number): R;
toHaveClass(className: string): R;
toHaveAttribute(attribute: string, value: string): R;
}
}
}
Expand Down Expand Up @@ -258,6 +260,44 @@ CancelledReasons: ${this.utils.printReceived(dispatchResult.reasons)}
}
return { pass: true, message: () => "" };
},
toHaveClass(target: DOMTarget, expectedClass: string) {
const element = getTarget(target);
if (!(element instanceof HTMLElement)) {
const message = element ? "Target is not an HTML element" : "Target not found";
return { pass: false, message: () => message };
}
const pass = element.classList.contains(expectedClass);
const message = () =>
pass
? ""
: `expect(target).toHaveClass(expected);\n\n${this.utils.printDiffOrStringify(
expectedClass,
element.className,
"Expected class",
"Received class",
false
)}`;
return { pass, message };
},
toHaveAttribute(target: DOMTarget, attribute: string, expectedValue: string) {
const element = getTarget(target);
if (!(element instanceof HTMLElement)) {
const message = element ? "Target is not an HTML element" : "Target not found";
return { pass: false, message: () => message };
}
const pass = element.getAttribute(attribute) === expectedValue;
const message = () =>
pass
? ""
: `expect(target).toHaveAttribute(attribute, expected);\n\n${this.utils.printDiffOrStringify(
expectedValue,
element.getAttribute(attribute),
"Expected value",
"Received value",
false
)}`;
return { pass, message };
},
});

function getTarget(target: DOMTarget): Element | Document | Window {
Expand Down