Thanks to visit codestin.com
Credit goes to Github.com

Skip to content

Conversation

@anusriNPS
Copy link

Module web_sort_menu is introduced to sort apps in alphabetical order while displayed on NavBar

@anusriNPS anusriNPS force-pushed the 16.0-web_sort_menu branch 2 times, most recently from a4867e9 to aad2db6 Compare June 17, 2025 10:31
@anusriNPS
Copy link
Author

image

Copy link

@SirPyTech SirPyTech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!
It is a very clean approach, please see the comments below.

t-inherit-mode="extension"
owl="1"
>
<xpath expr="//header[@class='o_navbar']//t/t" position="replace">

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Please use a more focused xpath: if you want to find the element that has t-set="apps", then you can use t[@t-set='apps'] in the xpath.
Searching for //t/t is difficult to maintain because it is not clear which node you are looking for.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the input. Updated as suggested.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

t-inherit-mode="extension"
owl="1"
>
<xpath expr="//header[@class='o_navbar']//t/t" position="replace">

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: replace is risky because other modules might expect that node to be present, so it should be avoided as much as possible.
In this case I suggest to go after the node that sets the apps variable and substitute its value with the sorted list.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated using "attributes"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

"author": "Anusri Veerappan Prakasam, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/web",
"license": "AGPL-3",
"depends": ["web", "web_responsive"],

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion

Suggested change
"depends": ["web", "web_responsive"],
"depends": ["web",],

I can't find where the dependency from web_responsive is needed, could you please check if that's actually necessary?
Without web_responsive, I expect that the dropdown menu is sorted.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed to think about dropdown menu getting sorted, I thought only NavBar would be sorted hence added web_responsive in the dependency.

I see dropdown menu getting sorted, hence removed web_responsive module as dependency.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


onWillStart(() => {
const apps = this.menuService.getApps();
this.sortedApps = apps.sort((a, b) => a.name.localeCompare(b.name));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: It is worth noting that apps are sorted based on the translated name, so users with different languages will see them in a different order

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, based on different languages sorting happens according to it.

Updated Description of module with this information.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: Thanks for updating the documentation, this is something that developers rarely do in response to this kind of comments.
👍

this.sortedApps = [];

onWillStart(() => {
const apps = this.menuService.getApps();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought: I don't think this search is that expensive, but we could avoid it by sorting directly in the template, or exposing a method and calling it in the template.
This would also preserve any edit that other modules have done to the apps variable in the template.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with you that we preseve any other module editing the value of apps,.

I tried to implement this search explicitly in the sort menu. However, I see we would need to use menuService in order to get information about available apps to sort them. If so, we could directly use the function exposed in menuService to know apps information.

Please let me know your views on it.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant that you could create a new method in this patched class like

sortApps((apps) => {
    return apps.sort((a, b) => a.name.localeCompare(b.name));
}),

and then in the template just add a call to this method:

<xpath expr="<select the t-set="apps" node>" position="after">
    <t t-set="apps" t-value="sortApps(apps)"/>
</xpath>

since the method is really simple, everything could be in the template too, but I think it's better to keep the code where code should be (JS in this case) and let the templates handle only the rendering as much as possible.

t-inherit-mode="extension"
owl="1"
>
<xpath expr="//header[@class='o_navbar']//t/t" position="replace">

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: The usage of @class is discouraged (see odoo/odoo@cbffd99), please use hasclass instead.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated using hasclass

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@anusriNPS anusriNPS force-pushed the 16.0-web_sort_menu branch from aad2db6 to 17e20fa Compare June 18, 2025 09:02
Copy link

@SirPyTech SirPyTech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code and functional review, looks good to me.

I have just added an example for the improvement I suggested in #3199 (comment), but it's already good for merge in my opinion.


onWillStart(() => {
const apps = this.menuService.getApps();
this.sortedApps = apps.sort((a, b) => a.name.localeCompare(b.name));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: Thanks for updating the documentation, this is something that developers rarely do in response to this kind of comments.
👍

this.sortedApps = [];

onWillStart(() => {
const apps = this.menuService.getApps();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant that you could create a new method in this patched class like

sortApps((apps) => {
    return apps.sort((a, b) => a.name.localeCompare(b.name));
}),

and then in the template just add a call to this method:

<xpath expr="<select the t-set="apps" node>" position="after">
    <t t-set="apps" t-value="sortApps(apps)"/>
</xpath>

since the method is really simple, everything could be in the template too, but I think it's better to keep the code where code should be (JS in this case) and let the templates handle only the rendering as much as possible.

t-inherit-mode="extension"
owl="1"
>
<xpath expr="//header[@class='o_navbar']//t/t" position="replace">

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

t-inherit-mode="extension"
owl="1"
>
<xpath expr="//header[@class='o_navbar']//t/t" position="replace">

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

"author": "Anusri Veerappan Prakasam, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/web",
"license": "AGPL-3",
"depends": ["web", "web_responsive"],

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

t-inherit-mode="extension"
owl="1"
>
<xpath expr="//header[@class='o_navbar']//t/t" position="replace">

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@anusriNPS anusriNPS force-pushed the 16.0-web_sort_menu branch from 17e20fa to bfcd7ce Compare June 20, 2025 13:39
@anusriNPS
Copy link
Author

Suggestion was super good and precise, so implemented the same.

@OCA-git-bot
Copy link
Contributor

This PR has the approved label and has been created more than 5 days ago. It should therefore be ready to merge by a maintainer (or a PSC member if the concerned addon has no declared maintainer). 🤖

Copy link

@andreampiovesana andreampiovesana left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, merge?

Copy link
Member

@ivs-cetmix ivs-cetmix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @anusriNPS thank you for your contribution! Some small change and LGTM 😉

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this icon, it will be added automatically on merge. Or use the actually one from

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the icon as suggested.

@ivs-cetmix
Copy link
Member

@anusriNPS thank you for prompt action 😉
/ocabot merge nobump

@OCA-git-bot
Copy link
Contributor

On my way to merge this fine PR!
Prepared branch 16.0-ocabot-merge-pr-3199-by-ivs-cetmix-bump-nobump, awaiting test results.

@OCA-git-bot
Copy link
Contributor

Congratulations, your PR was merged at 7640f2a. Thanks a lot for contributing to OCA. ❤️

@OCA-git-bot OCA-git-bot merged commit 43fde86 into OCA:16.0 Dec 22, 2025
7 checks passed
@aleuffre aleuffre deleted the 16.0-web_sort_menu branch December 22, 2025 16:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants