Skip to content

Commit

Permalink
[FIX] formula assistant: localize argument separator
Browse files Browse the repository at this point in the history
The argument separator in the formula assistant was not localized, it
was always a comma no matter the locale. This commit fixes it.

Task: 3789860
X-original-commit: 050c6fb
  • Loading branch information
hokolomopo committed Mar 22, 2024
1 parent 0be37a0 commit 1335618
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component, onWillUnmount, useState } from "@odoo/owl";
import { COMPOSER_ASSISTANT_COLOR } from "../../../constants";
import { FunctionDescription } from "../../../types";
import { FunctionDescription, SpreadsheetChildEnv } from "../../../types";
import { css } from "../../helpers/css";

// -----------------------------------------------------------------------------
Expand Down Expand Up @@ -45,7 +45,7 @@ interface AssistantState {
allowCellSelectionBehind: boolean;
}

export class FunctionDescriptionProvider extends Component<Props> {
export class FunctionDescriptionProvider extends Component<Props, SpreadsheetChildEnv> {
static template = "o-spreadsheet-FunctionDescriptionProvider";
assistantState: AssistantState = useState({
allowCellSelectionBehind: false,
Expand Down Expand Up @@ -74,6 +74,10 @@ export class FunctionDescriptionProvider extends Component<Props> {
this.assistantState.allowCellSelectionBehind = false;
}, 2000) as unknown as number;
}

get formulaArgSeparator() {
return this.env.model.getters.getLocale().formulaArgSeparator + " ";
}
}

FunctionDescriptionProvider.props = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<span t-esc="context.functionName"/>
(
<t t-foreach="context.functionDescription.args" t-as="arg" t-key="arg.name">
<span t-if="arg_index > '0'">,&#xA0;</span>
<span t-if="arg_index > '0'" t-esc="formulaArgSeparator"/>
<span t-att-class="{ 'o-formula-assistant-focus': context.argToFocus === arg_index }">
<span>
<span t-if="arg.optional || arg.repeating || arg.default">[</span>
Expand Down
10 changes: 10 additions & 0 deletions tests/composer/formula_assistant_component.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { setTranslationMethod } from "../../src";
import { arg, functionRegistry } from "../../src/functions/index";
import { Model } from "../../src/model";
import { _t } from "../../src/translation";
import { DEFAULT_LOCALE } from "../../src/types";
import { registerCleanup } from "../setup/jest.setup";
import { updateLocale } from "../test_helpers/commands_helpers";
import { keyDown, keyUp } from "../test_helpers/dom_helper";
import {
ComposerWrapper,
Expand Down Expand Up @@ -253,6 +255,14 @@ describe("formula assistant", () => {
"FUNC3 ( f3Arg1, [f3Arg2, ...] ) "
);
});

test("arguments separator is localized", async () => {
updateLocale(model, { ...DEFAULT_LOCALE, formulaArgSeparator: ";" });
await typeInComposer("=FUNC1(");
expect(fixture.querySelectorAll(".o-formula-assistant-head")[0].textContent).toBe(
"FUNC1 ( f1Arg1; f1Arg2 ) "
);
});
});

describe("arguments description", () => {
Expand Down

0 comments on commit 1335618

Please sign in to comment.