[FIX] web: order items by sequence globally instead of by category
Before this commit, all items from the same category were grouped together because we were sorting items within categories rather than sorting all items after getting them from the various categories. closes odoo/odoo#74598 Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
@@ -44,18 +44,19 @@ class DebugContext {
|
||||
|
||||
async getItems(env) {
|
||||
const accessRights = await getAccessRights(this.orm);
|
||||
return [...this.categories.entries()].flatMap(([category, contexts]) => {
|
||||
return debugRegistry
|
||||
.category(category)
|
||||
.getAll()
|
||||
.map((factory) => factory(Object.assign({ env, accessRights }, ...contexts)))
|
||||
.filter(Boolean)
|
||||
.sort((x, y) => {
|
||||
const xSeq = x.sequence || 1000;
|
||||
const ySeq = y.sequence || 1000;
|
||||
return xSeq - ySeq;
|
||||
});
|
||||
});
|
||||
return [...this.categories.entries()]
|
||||
.flatMap(([category, contexts]) => {
|
||||
return debugRegistry
|
||||
.category(category)
|
||||
.getAll()
|
||||
.map((factory) => factory(Object.assign({ env, accessRights }, ...contexts)));
|
||||
})
|
||||
.filter(Boolean)
|
||||
.sort((x, y) => {
|
||||
const xSeq = x.sequence || 1000;
|
||||
const ySeq = y.sequence || 1000;
|
||||
return xSeq - ySeq;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ const { xml } = tags;
|
||||
|
||||
export class DebugMenuParent extends Component {
|
||||
setup() {
|
||||
useOwnDebugContext({ categories: ["default"] });
|
||||
useOwnDebugContext({ categories: ["default", "custom"] });
|
||||
}
|
||||
}
|
||||
DebugMenuParent.template = xml`<DebugMenu/>`;
|
||||
@@ -118,6 +118,52 @@ QUnit.module("DebugMenu", (hooks) => {
|
||||
assert.verifySteps(["callback item_2", "callback item_1", "callback item_3"]);
|
||||
});
|
||||
|
||||
QUnit.test("items are sorted by sequence regardless of category", async (assert) => {
|
||||
debugRegistry
|
||||
.category("default")
|
||||
.add("item_1", () => {
|
||||
return {
|
||||
type: "item",
|
||||
description: "Item 4",
|
||||
sequence: 4,
|
||||
};
|
||||
})
|
||||
.add("item_2", () => {
|
||||
return {
|
||||
type: "item",
|
||||
description: "Item 1",
|
||||
sequence: 1,
|
||||
};
|
||||
});
|
||||
debugRegistry
|
||||
.category("custom")
|
||||
.add("item_1", () => {
|
||||
return {
|
||||
type: "item",
|
||||
description: "Item 3",
|
||||
sequence: 3,
|
||||
};
|
||||
})
|
||||
.add("item_2", () => {
|
||||
return {
|
||||
type: "item",
|
||||
description: "Item 2",
|
||||
sequence: 2,
|
||||
};
|
||||
});
|
||||
const env = await makeTestEnv(testConfig);
|
||||
const debugManager = await mount(DebugMenuParent, { env, target });
|
||||
registerCleanup(() => debugManager.destroy());
|
||||
await click(debugManager.el.querySelector("button.o_dropdown_toggler"));
|
||||
const items = [
|
||||
...debugManager.el.querySelectorAll("ul.o_dropdown_menu li.o_dropdown_item span"),
|
||||
];
|
||||
assert.deepEqual(
|
||||
items.map((el) => el.textContent),
|
||||
["Item 1", "Item 2", "Item 3", "Item 4"]
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test("Don't display the DebugMenu if debug mode is disabled", async (assert) => {
|
||||
const env = await makeTestEnv(testConfig);
|
||||
const actionDialog = await mount(ActionDialog, {
|
||||
|
||||
Reference in New Issue
Block a user