[FIX] web: breadcrumbs of stacked, legacy client actions

Let's suppose a legacy client action that can be opened from
another action, s.t. it is stacked on it. Before this commit,
the breadcrumbs was incorrect in that client action, as it only
displayed the part of the client action itself, but not the
history. This commit fixes the issue.

Part-of: odoo/odoo#81031
This commit is contained in:
Aaron Bohy
2021-12-13 12:24:49 +00:00
parent 3fa70eed13
commit 2cdd30d61a
2 changed files with 39 additions and 7 deletions
@@ -31,12 +31,13 @@ function registerClientAction(name, action) {
for (const key in this.props) {
if (key === "action" || key === "actionId") {
continue;
} else if (key === "breadcrumbs") {
options[key] = breadcrumbsToLegacy(this.props[key]);
} else {
options[key] = this.props[key];
}
}
if (this.env.config.breadcrumbs) {
options.breadcrumbs = breadcrumbsToLegacy(this.env.config.breadcrumbs);
}
// always add user context to the action context
this.user = useService("user");
@@ -444,7 +444,7 @@ QUnit.module("ActionManager", (hooks) => {
QUnit.test("correctly transports legacy Props for doAction", async (assert) => {
assert.expect(4);
let ID=0;
let ID = 0;
const MyAction = AbstractAction.extend({
init() {
this._super(...arguments);
@@ -456,21 +456,52 @@ QUnit.module("ActionManager", (hooks) => {
const link = document.createElement("a");
link.setAttribute("id", `client_${this.ID}`);
link.addEventListener("click", () => {
this.do_action("testClientAction", { clear_breadcrumbs: true, props: { chain: "never break"}});
this.do_action("testClientAction", {
clear_breadcrumbs: true,
props: { chain: "never break" },
});
});
this.el.appendChild(link);
return res;
}
},
});
core.action_registry.add("testClientAction", MyAction);
registerCleanup(() => delete core.action_registry.map.testClientAction);
const webClient = await createWebClient({ serverData });
await doAction(webClient, "testClientAction");
assert.verifySteps(["id: 0 props: {\"breadcrumbs\":[]}"]);
assert.verifySteps(['id: 0 props: {"breadcrumbs":[]}']);
await click(document.getElementById("client_0"));
assert.verifySteps(["id: 1 props: {\"chain\":\"never break\",\"breadcrumbs\":[]}"]);
assert.verifySteps(['id: 1 props: {"chain":"never break","breadcrumbs":[]}']);
});
QUnit.test("breadcrumbs are correct in stacked legacy client actions", async function (assert) {
const ClientAction = AbstractAction.extend({
hasControlPanel: true,
async start() {
this.$el.addClass("client_action");
return this._super(...arguments);
},
getTitle() {
return "Blabla";
},
});
core.action_registry.add("clientAction", ClientAction);
registerCleanup(() => delete core.action_registry.map.clientAction);
const webClient = await createWebClient({ serverData });
await doAction(webClient, 3);
assert.containsOnce(webClient, ".o_list_view");
assert.strictEqual($(webClient.el).find(".breadcrumb-item").text(), "Partners");
await doAction(webClient, {
type: "ir.actions.client",
tag: "clientAction",
});
assert.containsOnce(webClient, ".client_action");
assert.strictEqual($(webClient.el).find(".breadcrumb-item").text(), "PartnersBlabla");
});
});