Skip to content

Commit a2e329c

Browse files
committed
[FIX] Actions: ensure the sequence is applied on action children
Currently, the helper 'createActions' pre-sorts a list of menuRegistry entries but this sort is not applied to the children (which can be generated dynamically). It never showed up as we rarely add children entries from different sources and their sequence often matches the order of insertion in the registry. closes #7827 Task: 5452669 X-original-commit: d29e94e Signed-off-by: Lucas Lefèvre (lul) <[email protected]> Signed-off-by: Rémi Rahir (rar) <[email protected]> Signed-off-by: Pierre Rousseau (pro) <[email protected]>
1 parent edc5f21 commit a2e329c

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

src/actions/action.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ export function createAction(item: ActionSpec): Action {
121121
return children
122122
.map((child) => (typeof child === "function" ? child(env) : child))
123123
.flat()
124-
.map(createAction);
124+
.map(createAction)
125+
.sort((a, b) => a.sequence - b.sequence);
125126
}
126127
: () => [],
127128
isReadonlyAllowed: item.isReadonlyAllowed || false,

tests/menus/menu_items_registry.test.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ import {
4545

4646
import { Currency, Model } from "../../src";
4747

48-
import { ActionSpec, createAction } from "../../src/actions/action";
48+
import { ActionSpec, createAction, createActions } from "../../src/actions/action";
4949
import { CellComposerStore } from "../../src/components/composer/composer/cell_composer_store";
5050
import { FONT_SIZES } from "../../src/constants";
5151
import { functionRegistry } from "../../src/functions";
@@ -118,6 +118,7 @@ describe("Top Bar MenuPopover Item Registry", () => {
118118
id: name,
119119
name: name,
120120
execute: () => {},
121+
sequence: 1,
121122
}));
122123
});
123124
const env = makeTestEnv();
@@ -2049,3 +2050,32 @@ describe("Menu Item actions", () => {
20492050
expect(executeMock).not.toHaveBeenCalled();
20502051
});
20512052
});
2053+
2054+
test("Menu children are sorted by sequence", async () => {
2055+
const env = makeTestEnv();
2056+
const menuItems = createActions([
2057+
{
2058+
id: "menu_1",
2059+
name: "Menu 1",
2060+
sequence: 20,
2061+
children: [
2062+
{
2063+
id: "secondItem",
2064+
name: "bigger sequence Item",
2065+
sequence: 30,
2066+
execute: () => {},
2067+
},
2068+
{
2069+
id: "firstItem",
2070+
name: "lower sequence Item",
2071+
sequence: 10,
2072+
execute: () => {},
2073+
},
2074+
],
2075+
},
2076+
]);
2077+
2078+
const children = menuItems[0].children(env);
2079+
expect(children[0].id).toBe("firstItem");
2080+
expect(children[1].id).toBe("secondItem");
2081+
});

0 commit comments

Comments
 (0)