Skip to content

Commit

Permalink
[FIX] cell_menu_registry: link cell displays 'Edit Link' in context menu
Browse files Browse the repository at this point in the history
Previously, if a link was inserted into a cell and right-clicked, the
context menu incorrectly displayed 'Insert Link' instead of 'Edit Link'.

This commit addresses the problem by verifying whether the cell is a
link cell and adjusts the menu item name accordingly.

Task ID: 3698437

closes #3586

X-original-commit: 573ae1f
Signed-off-by: Lucas Lefèvre (lul) <lul@odoo.com>
Signed-off-by: Adrien Minne (adrm) <adrm@odoo.com>
  • Loading branch information
dhrp-odoo committed Feb 9, 2024
1 parent 753173b commit 206487f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/registries/menus/cell_menu_registry.ts
Expand Up @@ -100,7 +100,7 @@ cellMenuRegistry
action: ACTIONS.DELETE_CELL_SHIFT_LEFT,
})
.add("insert_link", {
name: _lt("Insert link"),
name: ACTIONS.INSERT_LINK_NAME,
separator: true,
sequence: 150,
action: ACTIONS.INSERT_LINK,
Expand Down
8 changes: 8 additions & 0 deletions src/registries/menus/menu_items_actions.ts
Expand Up @@ -696,6 +696,14 @@ export const INSERT_LINK = (env: SpreadsheetChildEnv) => {
env.model.dispatch("OPEN_CELL_POPOVER", { col, row, popoverType: "LinkEditor" });
};

export const INSERT_LINK_NAME = (env: SpreadsheetChildEnv) => {
const sheetId = env.model.getters.getActiveSheetId();
const { col, row } = env.model.getters.getActivePosition();
const cell = env.model.getters.getEvaluatedCell({ sheetId, col, row });

return cell && cell.link ? _lt("Edit link") : _lt("Insert link");
};

//------------------------------------------------------------------------------
// Filters action
//------------------------------------------------------------------------------
Expand Down
14 changes: 14 additions & 0 deletions tests/components/link/link_display.test.ts
Expand Up @@ -85,6 +85,20 @@ describe("link display component", () => {
expect(fixture.querySelector(".o-link-tool")).toBeFalsy();
});

test("right-click on a linked cell should show 'Edit Link' instead of 'Insert Link' in the context menu", async () => {
setCellContent(model, "A1", "HELLO");
await rightClickCell(model, "A1");
expect(
fixture.querySelector(".o-menu .o-menu-item[data-name='insert_link']")?.textContent
).toBe("Insert link");

setCellContent(model, "A1", "[label](url.com)");
await rightClickCell(model, "A1");
expect(
fixture.querySelector(".o-menu .o-menu-item[data-name='insert_link']")?.textContent
).toBe("Edit link");
});

test("component is closed when cell is deleted", async () => {
setCellContent(model, "A1", "[label](url.com)");
await hoverCell(model, "A1", 400);
Expand Down

0 comments on commit 206487f

Please sign in to comment.