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 #3661

X-original-commit: 7711581
Signed-off-by: Lucas Lefèvre (lul) <lul@odoo.com>
Signed-off-by: Dhrutik Patel (dhrp) <dhrp@odoo.com>
  • Loading branch information
dhrp-odoo committed Feb 12, 2024
1 parent 2e69e1b commit 192dc81
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/actions/menu_items_actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,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
3 changes: 2 additions & 1 deletion src/registries/menus/cell_menu_registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { MenuItemRegistry } from "../menu_items_registry";

import * as ACTION_EDIT from "../../actions/edit_actions";
import * as ACTION_INSERT from "../../actions/insert_actions";
import { INSERT_LINK_NAME } from "../../actions/menu_items_actions";

//------------------------------------------------------------------------------
// Context Menu Registry
Expand Down Expand Up @@ -89,7 +90,7 @@ cellMenuRegistry
})
.add("insert_link", {
...ACTION_INSERT.insertLink,
name: _lt("Insert link"),
name: INSERT_LINK_NAME,
sequence: 150,
separator: true,
});
14 changes: 14 additions & 0 deletions tests/components/link/link_display.test.ts
Original file line number Diff line number Diff line change
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 192dc81

Please sign in to comment.