Skip to content

Commit

Permalink
[FIX] Composer: weird behavior of autocomplete dropdown
Browse files Browse the repository at this point in the history
Previously, when users typed "=S" in the composer, clicked outside, then
started editing another cell, the autocomplete dropdown remained visible.
Similarly, when they typed "=SUM(" and pressed enter, then edited another
cell, the function assistant persisted.

This commit addresses the problem by ensuring that state values are set
to false whenever the composer is not in edit mode.

closes #3923

Taskid: 3789473
X-original-commit: 8c7f35e
Signed-off-by: Rémi Rahir (rar) <rar@odoo.com>
Signed-off-by: Dhrutik Patel (dhrp) <dhrp@odoo.com>
  • Loading branch information
dhrp-odoo authored and rrahir committed Mar 26, 2024
1 parent 1561d0a commit efc14e7
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/components/composer/composer/composer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, onMounted, useEffect, useRef, useState } from "@odoo/owl";
import { Component, onMounted, onPatched, useEffect, useRef, useState } from "@odoo/owl";
import { DEFAULT_FONT, NEWLINE } from "../../../constants";
import { functionRegistry } from "../../../functions/index";
import { clip, getZoneArea, isEqual, splitReference } from "../../../helpers/index";
Expand Down Expand Up @@ -235,6 +235,13 @@ export class Composer extends Component<ComposerProps, SpreadsheetChildEnv> {
useEffect(() => {
this.processContent();
});

onPatched(() => {
// Required because typing '=SUM' and double-clicking another cell leaves ShowProvider/ShowDescription true
if (this.composerStore.editionMode === "inactive") {
this.processTokenAtCursor();
}
});
}

// ---------------------------------------------------------------------------
Expand Down
23 changes: 23 additions & 0 deletions tests/composer/autocomplete_dropdown_component.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,18 @@ describe("Functions autocomplete", () => {
await keyDown({ key: "ArrowDown" });
expect(composerStore.currentContent).toBe("=SUM(B2");
});

test("autocomplete should not appear when typing '=S', stop the edition, and editing back", async () => {
await typeInComposer("=S", true);
expect(fixture.querySelectorAll(".o-autocomplete-value")).toHaveLength(2);

await keyDown({ key: "Escape" });
await nextTick();
expect(fixture.querySelector(".o-autocomplete-dropdown")).toBeFalsy();

await typeInComposer("", true);
expect(fixture.querySelector(".o-autocomplete-dropdown")).toBeFalsy();
});
});

describe("autocomplete functions SUM IF", () => {
Expand Down Expand Up @@ -363,6 +375,17 @@ describe("Autocomplete parenthesis", () => {
expect(getCellText(model, "A1")).toBe("=sum(1,2)");
});

test("=sum( + enter + edit does not show the formula assistant", async () => {
await typeInComposer("=sum(");
expect(fixture.querySelector(".o-formula-assistant-container")).toBeTruthy();
await keyDown({ key: "Enter" });
await nextTick();
expect(fixture.querySelector(".o-formula-assistant-container")).toBeFalsy();

await typeInComposer("", true);
expect(fixture.querySelector(".o-formula-assistant-container")).toBeFalsy();
});

test("=sum(1,2) + enter + edit sum does not add parenthesis", async () => {
await typeInComposer("=sum(1,2)");
await keyDown({ key: "Enter" });
Expand Down
11 changes: 11 additions & 0 deletions tests/composer/composer_integration_component.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,17 @@ describe("Composer interactions", () => {
await clickCell(model, "B2");
expect(getCellText(model, "A1")).toBe("=sum(sum(1,2))");
});

test("Autocomplete should not appear when typing '=S', clicking outside, and editing back", async () => {
await typeInComposerGrid("=S");
expect(fixture.querySelectorAll(".o-autocomplete-value")).toHaveLength(10);

await clickCell(model, "B2");
expect(fixture.querySelector(".o-autocomplete-dropdown")).toBeFalsy();

await startGridComposition();
expect(fixture.querySelector(".o-autocomplete-dropdown")).toBeFalsy();
});
});

describe("Grid composer", () => {
Expand Down

0 comments on commit efc14e7

Please sign in to comment.