diff --git a/addons/web/static/src/core/debug/debug_providers.js b/addons/web/static/src/core/debug/debug_providers.js
index 24e839fbf50..2bcba19e131 100644
--- a/addons/web/static/src/core/debug/debug_providers.js
+++ b/addons/web/static/src/core/debug/debug_providers.js
@@ -13,18 +13,16 @@ commandProviderRegistry.add("debug", {
if (env.services.user.isAdmin) {
if (env.debug) {
result.push({
- name: "Deactivate debug mode",
- category: "debug",
- action: () => {
+ action() {
const route = env.services.router.current;
route.search.debug = "";
browser.location.href = browser.location.origin + routeToUrl(route);
},
+ category: "debug",
+ name: "Deactivate debug mode",
});
result.push({
- name: "Debug menu",
- category: "debug",
- action: () => {
+ action() {
return {
placeHolder: "Choose a debug action...",
provide: async (env) => {
@@ -33,20 +31,22 @@ commandProviderRegistry.add("debug", {
return items
.filter((item) => item.type === "item")
.map((item) => ({
- name: item.description,
action: item.callback,
+ name: item.description,
}));
},
};
},
+ category: "debug",
+ name: "Debug menu",
});
} else {
result.push({
- name: "Activate debug mode",
- category: "debug",
- action: () => {
+ action() {
browser.location.search = "?debug=assets";
},
+ category: "debug",
+ name: "Activate debug mode",
});
}
}
diff --git a/addons/web/static/src/webclient/commands/command_palette.js b/addons/web/static/src/webclient/commands/command_palette.js
index 906395c775e..c58a16588e9 100644
--- a/addons/web/static/src/webclient/commands/command_palette.js
+++ b/addons/web/static/src/webclient/commands/command_palette.js
@@ -18,7 +18,20 @@ const commandCategoryRegistry = registry.category("command_categories");
const commandProviderRegistry = registry.category("command_provider");
/**
- * @typedef {import("./command_service").Command} Command
+ * @typedef {{
+ * Component?: Component,
+ * action: ()=>(void | NextProvider),
+ * category?: string,
+ * name: string,
+ * props?: Object,
+ * }} CommandItem
+ */
+
+/**
+ * @typedef {{
+ * placeHolder?: string,
+ * provide: ()=>CommandItem[],
+ * }} NextProvider
*/
/**
@@ -38,7 +51,7 @@ function commandsWithinCategory(categoryName) {
}
export class DefaultCommandItem extends Component {}
-DefaultCommandItem.template = "web.defaultCommandItem";
+DefaultCommandItem.template = "web.DefaultCommandItem";
export class CommandPalette extends Component {
setup() {
@@ -57,7 +70,7 @@ export class CommandPalette extends Component {
useHotkey("ArrowDown", () => this.selectCommandAndScrollTo("NEXT"), { allowRepeat: true });
/**
- * @type {{commands: Command[], selectedCommand: Command, placeHolder: String}}
+ * @type {{commands: CommandItem[], selectedCommand: CommandItem, placeHolder: String}}
*/
this.state = useState({
commands: [],
@@ -174,20 +187,24 @@ export class CommandPalette extends Component {
this.executeSelectedCommand();
}
- async executeSelectedCommand() {
+ async executeCommand(command) {
+ const result = await command.action();
+ if (result) {
+ const { placeHolder, provide } = result;
+ this.providerStack.push({ __default__: [{ provide }] });
+ this.setCommands("__default__", {
+ activeElement: this.activeElement,
+ });
+ this.state.placeHolder = placeHolder || DEFAULT_PLACEHOLDER;
+ this.searchBar.el.value = "";
+ } else {
+ this.props.closeMe();
+ }
+ }
+
+ executeSelectedCommand() {
if (this.state.selectedCommand) {
- const result = await this.state.selectedCommand.action();
- if (result) {
- const { placeHolder, provide } = result;
- this.providerStack.push({ __default__: [{ provide }] });
- this.setCommands("__default__", {
- activeElement: this.activeElement,
- });
- this.state.placeHolder = placeHolder || DEFAULT_PLACEHOLDER;
- this.searchBar.el.value = "";
- } else {
- this.props.closeMe();
- }
+ this.executeCommand(this.state.selectedCommand);
}
}
diff --git a/addons/web/static/src/webclient/commands/command_palette.xml b/addons/web/static/src/webclient/commands/command_palette.xml
index 6a0a0218530..d7b6c6c4f75 100644
--- a/addons/web/static/src/webclient/commands/command_palette.xml
+++ b/addons/web/static/src/webclient/commands/command_palette.xml
@@ -19,7 +19,7 @@