Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMP] web, project: Add topbar actions #158441

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

luve-odoo
Copy link
Contributor

@luve-odoo luve-odoo commented Mar 20, 2024

This update introduces the implementation of topbar actions, enabling
the addition of a topbar in the control panel for seamless toggling
among various actions.

Functionnal specifications:

  • This task aims to centralize and access models related to the current
    parent model.

  • We introduce the concept of topbar action. If a model has topbar
    actions, then a button with an 'eye' icon is displayed in the control
    panel.

  • When the user clicks the button, the topbar appears.

  • The top bar consists of the various topbar actions chosen as visible
    by the user. By default, the topbar only displays the current action
    (or the first available).

  • There is a dropdown button to the right of the topbar that displays
    all the actions available to the user. These actions depend on the model
    , but it's also possible that there is a domain on these actions making
    them invisible. For example, a project without the 'allow timesheets'
    option will not display the 'Timesheets' action.

  • The default actions cannot be deleted by the user; they can only
    decide whether to display them or not. The visibility of actions is
    different for each model but also for each model ID, meaning, for
    example, that the actions visible in one project will not be the same
    for another.

  • Each user can also save the current view and thus create a new topbar
    action. They can decide to share this topbar action so that it is
    visible to everyone, or not. The view type and filters are saved when
    creating a new topbar action. Those saved filters are saved as favorites
    filters that cannot be deleted while the topbar action exists.

  • If the user has the rights, they can also drag and drop the actions to
    reorder them. This order will be the same for everyone, and if the
    concerned actions are default actions, the order will also be common to
    all records of the concerned model.

  • On Mobile, only a dropdown is displayed with the current action. When
    the dropdown is unfolded, all available actions are displayed. It is
    not possible to drag and drop. Deleting is always available, as well as
    the creation of new actions.

  • The breadcrumbs should never push new items. When navigating between
    topbar actions, the breadcrumbs should be replaced.


In order to create a new default topbar action for a model, the
developer has to create an xml record of that structure:

<record id="<id>" model="ir.actions.topbar">
    <field name="res_model"><parent_res_model></field>
    <field name="parent_action_id" ref="<xml_id_parent_action>"/>

    <!--
        for the triggered action, the developer can either choose
        between a xml action id or a python action
    -->
    <field name="action_id" ref=<triggered_action_id>/>
    <field name="python_action"><python_action></field>

    <!-- name is optionnal if the an action_id is declared -->
    <field name="name"><name_of_the_topbar_action></field>

    <!-- optionnal -->
    <field name="sequence"><sequence_order_integer></field>
    <field name="domain"><domain_to_filter_topbar_actions></field>
    <field name="context"><additional_context_keys></field>
    <field name="default_view_mode"><default_view></field>
</record>

taskid:3750721


I confirm I have signed the CLA and read the PR guidelines at www.odoo.com/submit-pr

@robodoo
Copy link
Contributor

robodoo commented Mar 20, 2024

@C3POdoo C3POdoo requested review from a team, xmo-odoo, HydrionBurst, Iucapad and fdardenne and removed request for a team March 20, 2024 16:38
@C3POdoo C3POdoo added the RD research & development, internal work label Mar 20, 2024
@luve-odoo luve-odoo force-pushed the master-top-bar-actions-luve branch 2 times, most recently from 7077a9a to 8fd69b7 Compare March 21, 2024 10:33
Copy link
Contributor

@auon-odoo auon-odoo left a comment

Choose a reason for hiding this comment

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

Very nice work, thanks a lot! 🔥 🔥

odoo/addons/base/models/ir_topbar_actions.py Outdated Show resolved Hide resolved
odoo/addons/base/models/ir_topbar_actions.py Outdated Show resolved Hide resolved
odoo/addons/base/models/ir_topbar_actions.py Outdated Show resolved Hide resolved
@luve-odoo luve-odoo force-pushed the master-top-bar-actions-luve branch 5 times, most recently from 092762e to e3ed922 Compare March 27, 2024 09:57
Copy link
Contributor

@auon-odoo auon-odoo left a comment

Choose a reason for hiding this comment

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

We're getting there 🔥

showTopBar: !!this.env.config.fromParentAction,
topBarActions: this.env.config.topBarActions,
newActionIsShared: false,
newActionName: `${this.currentTopBarAction?.name} Custom`,
Copy link
Contributor

Choose a reason for hiding this comment

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

this.currentTopBarAction can't be undefined, can it?
But looks like .name could be, in which case we would have undefined Custom.
I think we should do ${this.currentTopBarAction.name || <find the name of the model> || 'Action'} Custom,
or something like that. Am I missing something?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ignore my first line 🙈

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, this.currentTopBarAction can be undefined when the component is mounted, you can try, and I agree that we should put a fallback default name I case of no currentTopBarAction. I would go for directly putting "Action" and not try to find the name of the model, which could sometimes be undeterministic and pprovide strange results.

const topBarActions =
view.type === "form" ? [] : context.parentActionChildren || action.children_ids;
const fromParentAction = (view.type !== "form" && context.fromParentAction) || false;
const parentActionId = topBarActions?.[0]?.parent_action_id[0];
Copy link
Contributor

Choose a reason for hiding this comment

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

Can topBarActions be undefined?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, if there is no parentActionChildren or children_ids in the context, which is happening when no topbar_actions is defined

@@ -25,6 +25,7 @@ class IrFilters(models.Model):
"When left empty the filter applies to all menus "
"for this model.")
active = fields.Boolean(default=True)
topbar_action_id = fields.Many2one('ir.actions.topbar', string="The topbar action this filter is applied to", ondelete="cascade")
Copy link
Contributor

Choose a reason for hiding this comment

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

?

odoo/addons/base/models/ir_topbar_actions.py Outdated Show resolved Hide resolved
Comment on lines 43 to 46
if "action_id" in vals and isinstance(vals["action_id"], list):
vals["action_id"] = vals["action_id"][0]
if "parent_action_id" in vals and isinstance(vals["parent_action_id"], list):
vals["parent_action_id"] = vals["parent_action_id"][0]
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess the call is in your code. Can't we change it?
What is usually the value of a many2one in the vals of a create?

odoo/addons/base/models/ir_topbar_actions.py Show resolved Hide resolved
Comment on lines 393 to 397
const { action_id, parent_action_id } = currentTopBarAction;
const values = {
...currentTopBarAction,
parent_action_id: parent_action_id[0],
action_id: action_id[0],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@auon-odoo follow-up to my previous comment that is saying where I added lines to delete the crappy logic in the python model file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well now that I delete the lines, the response to the comment does not appear :/ the "crappy logic" reference to the logic in the override of the create method in the model ir.actions.topbar_actions

Comment on lines 416 to 473
const enrichedNewTopBarAction = {
...values,
parent_action_id,
action_id,
id: topBarActionId,
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@auon-odoo And here also

Copy link
Contributor

@auon-odoo auon-odoo left a comment

Choose a reason for hiding this comment

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

Thank you very much 🎖️

@luve-odoo luve-odoo force-pushed the master-top-bar-actions-luve branch 2 times, most recently from 4a0b525 to af4ffeb Compare April 5, 2024 14:22
@luve-odoo luve-odoo force-pushed the master-top-bar-actions-luve branch 2 times, most recently from a6d4689 to 007f245 Compare April 8, 2024 12:09
@luve-odoo luve-odoo force-pushed the master-top-bar-actions-luve branch 5 times, most recently from 9a61433 to 62a07ff Compare April 12, 2024 09:49
@luve-odoo luve-odoo force-pushed the master-top-bar-actions-luve branch 3 times, most recently from be29afb to 21bd35f Compare April 23, 2024 10:02
This update introduces the implementation of topbar actions, enabling
the addition of a topbar in the control panel for seamless toggling
among various actions.

Functionnal specifications:

* This task aims to centralize and access models related to the current
parent model.

* We introduce the concept of topbar action. If a model has topbar
actions, then a button with an 'eye' icon is displayed in the control
panel.

* When the user clicks the button, the topbar appears.

* The top bar consists of the various topbar actions chosen as visible
by the user. By default, the topbar only displays the current action
(or the first available).

* There is a dropdown button to the right of the topbar that displays
all the actions available to the user. These actions depend on the model
, but it's also possible that there is a domain on these actions making
them invisible. For example, a project without the 'allow timesheets'
option will not display the 'Timesheets' action.

* The default actions cannot be deleted by the user; they can only
decide whether to display them or not. The visibility of actions is
different for each model but also for each model ID, meaning, for
example, that the actions visible in one project will not be the same
for another.

* Each user can also save the current view and thus create a new topbar
action. They can decide to share this topbar action so that it is
visible to everyone, or not. The view type and filters are saved when
creating a new topbar action. Those saved filters are saved as favorites
filters that cannot be deleted while the topbar action exists.

* If the user has the rights, they can also drag and drop the actions to
reorder them. This order will be the same for everyone, and if the
concerned actions are default actions, the order will also be common to
all records of the concerned model.

* On Mobile, only a dropdown is displayed with the current action. When
the dropdown is unfolded, all available actions are displayed. It is
not possible to drag and drop. Deleting is always available, as well as
the creation of new actions.

* The breadcrumbs should never push new items. When navigating between
topbar actions, the breadcrumbs should be replaced.

------------------------------------------------------------------------

In order to create a new default topbar action for a model, the
developer has to create an xml record of that structure:

<record id="<id>" model="ir.actions.topbar">
    <field name="res_model"><parent_res_model></field>
    <field name="parent_action_id" ref="<xml_id_parent_action>"/>

    <!--
        for the triggered action, the developer can either choose
        between a xml action id or a python action
    -->
    <field name="action_id" ref=<triggered_action_id>/>
    <field name="python_action"><python_action></field>

    <!-- name is optionnal if the an action_id is declared -->
    <field name="name"><name_of_the_topbar_action></field>

    <!-- optionnal -->
    <field name="sequence"><sequence_order_integer></field>
    <field name="domain"><domain_to_filter_topbar_actions></field>
    <field name="context"><additional_context_keys></field>
    <field name="default_view_mode"><default_view></field>
</record>

taskid:3750721
def _get_readable_fields(self):
return super()._get_readable_fields() | {
"context", "mobile_view_mode", "domain", "filter", "groups_id", "limit",
"res_id", "res_model", "search_view_id", "target", "view_id", "view_mode", "views",
"res_id", "res_model", "search_view_id", "target", "view_id", "view_mode", "views", "children_ids",
Copy link
Contributor

Choose a reason for hiding this comment

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

create a one2many to have a real field. 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RD research & development, internal work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants