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
3 changes: 2 additions & 1 deletion src/components/dashboard/clickable_cell_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,13 @@ export class ClickableCellsStore extends SpreadsheetStore {
if (!item) {
continue;
}
const title = typeof item.title === "function" ? item.title(position, getters) : item.title;
const zone = getters.expandZone(sheetId, positionToZone(position));
cells.push({
coordinates: getters.getVisibleRect(zone),
position,
action: item.execute,
title: item.title || "",
title: title || "",
});
}
return cells;
Expand Down
12 changes: 11 additions & 1 deletion src/registries/cell_clickable_registry.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { openLink } from "../helpers/links";
import { _t } from "../translation";
import { CellPosition, Getters, SpreadsheetChildEnv } from "../types";
import { Registry } from "./registry";

export interface CellClickableItem {
condition: (position: CellPosition, getters: Getters) => boolean;
execute: (position: CellPosition, env: SpreadsheetChildEnv, isMiddleClick?: boolean) => void;
title?: string;
title?: string | ((position: CellPosition, getters: Getters) => string);
sequence: number;
}

Expand All @@ -17,5 +18,14 @@ clickableCellRegistry.add("link", {
},
execute: (position: CellPosition, env: SpreadsheetChildEnv, isMiddleClick?: boolean) =>
openLink(env.model.getters.getEvaluatedCell(position).link!, env, isMiddleClick),
title: (position, getters) => {
const link = getters.getEvaluatedCell(position).link;
if (!link) return "";
if (link.isExternal) {
return _t("Go to url: %(url)s", { url: link.url });
} else {
return _t("Go to %(label)s", { label: link.label });
}
},
sequence: 5,
});
17 changes: 16 additions & 1 deletion tests/grid/dashboard_grid_component.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ describe("Grid component in dashboard mode", () => {
expect(fn).toHaveBeenCalledWith(true);
});

test("Clickable cells actions can have a tooltip", async () => {
test("Clickable cells actions can have a generic tooltip", async () => {
addToRegistry(clickableCellRegistry, "fake", {
condition: () => true,
execute: () => {},
Expand All @@ -185,4 +185,19 @@ describe("Grid component in dashboard mode", () => {
"hello there"
);
});

test("Clickable cells actions can have a tooltip based on their position", async () => {
addToRegistry(clickableCellRegistry, "fake", {
condition: () => true,
execute: () => {},
title: (position, getters) => `hello ${getters.getCell(position)?.content}`,
sequence: 5,
});
setCellContent(model, "A1", "Magical Françoise");
model.updateMode("dashboard");
await nextTick();
expect(fixture.querySelector("div.o-dashboard-clickable-cell")?.getAttribute("title")).toBe(
"hello Magical Françoise"
);
});
});