Skip to content

Commit

Permalink
Rename main_actions and more_actions to header_buttons and header_mor…
Browse files Browse the repository at this point in the history
…e_buttons

To follow the pattern for get_list_buttons and get_list_more_buttons

This will be made clearer in the next commit
  • Loading branch information
laymonage authored and thibaudcolas committed Jan 2, 2024
1 parent c900ba6 commit 4554dbd
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 30 deletions.
22 changes: 11 additions & 11 deletions wagtail/admin/templates/wagtailadmin/generic/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@
{% block slim_header %}
{% if breadcrumbs_items %}
{% fragment stripped as actions %}
{% block main_actions %}
{% for action in main_actions %}
<a href="{{ action.url }}" class="header-main-action-button w-h-slim-header w-ml-3" data-controller="w-tooltip" data-w-tooltip-content-value="{{ action.label }}">
{% icon name=action.icon_name %}
{% block header_buttons %}
{% for button in header_buttons %}
<a href="{{ button.url }}" class="header-main-action-button w-h-slim-header w-ml-3" data-controller="w-tooltip" data-w-tooltip-content-value="{{ button.label }}">
{% icon name=button.icon_name %}
</a>
{% endfor %}
{% endblock %}
{% block more_actions %}
{% if more_actions %}
{% block header_more_buttons %}
{% if header_more_buttons %}
{% trans "Actions" as actions_toggle_title %}
{% dropdown toggle_icon="dots-horizontal" toggle_aria_label=actions_toggle_title toggle_classname="w-p-0 w-w-10 w-h-slim-header hover:w-scale-110 w-transition w-outline-offset-inside w-relative w-z-30" toggle_tooltip_offset="[0, -2]" %}
{% for action in more_actions %}
<a href="{{ action.url }}" {{ action.base_attrs_string }}>
{% if action.icon_name %}
{% icon name=action.icon_name %}
{% for button in header_more_buttons %}
<a href="{{ button.url }}" {{ button.base_attrs_string }}>
{% if button.icon_name %}
{% icon name=button.icon_name %}
{% endif %}
{{ action.label }}
{{ button.label }}
</a>
{% endfor %}
{% enddropdown %}
Expand Down
16 changes: 8 additions & 8 deletions wagtail/admin/views/generic/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class WagtailAdminTemplateMixin(TemplateResponseMixin, ContextMixin):
_show_breadcrumbs = False
breadcrumbs_items = [{"url": reverse_lazy("wagtailadmin_home"), "label": _("Home")}]
template_name = "wagtailadmin/generic/base.html"
main_actions = []
more_actions = []
header_buttons = []
header_more_buttons = []

def get_page_title(self):
return self.page_title
Expand All @@ -48,11 +48,11 @@ def get_header_icon(self):
def get_breadcrumbs_items(self):
return self.breadcrumbs_items

def get_main_actions(self):
return self.main_actions
def get_header_buttons(self):
return self.header_buttons

def get_more_actions(self):
return self.more_actions
def get_header_more_buttons(self):
return self.header_more_buttons

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
Expand All @@ -68,8 +68,8 @@ def get_context_data(self, **kwargs):
context["breadcrumbs_items"] = None
if self._show_breadcrumbs:
context["breadcrumbs_items"] = self.get_breadcrumbs_items()
context["main_actions"] = self.get_main_actions()
context["more_actions"] = self.get_more_actions()
context["header_buttons"] = self.get_header_buttons()
context["header_more_buttons"] = self.get_header_more_buttons()
return context

def get_template_names(self):
Expand Down
3 changes: 2 additions & 1 deletion wagtail/admin/views/generic/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ def get_breadcrumbs_items(self):
},
]

def get_main_actions(self):
@cached_property
def header_buttons(self):
return [
Button(
label=gettext("Edit"),
Expand Down
20 changes: 11 additions & 9 deletions wagtail/admin/views/generic/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,39 +384,41 @@ def get_breadcrumbs_items(self):
{"url": "", "label": capfirst(self.model._meta.verbose_name_plural)},
]

def get_main_actions(self):
actions = []
@cached_property
def header_buttons(self):
buttons = []
if not self.permission_policy or self.permission_policy.user_has_permission(
self.request.user, "add"
):
actions.append(
buttons.append(
Button(
self.add_item_label,
url=self.get_add_url(),
icon_name="plus",
)
)
return actions
return buttons

def get_more_actions(self):
actions = []
@cached_property
def header_more_buttons(self):
buttons = []
if self.list_export:
actions.append(
buttons.append(
Button(
_("Download XLSX"),
url=self.xlsx_export_url,
icon_name="download",
)
)
actions.append(
buttons.append(
Button(
_("Download CSV"),
url=self.csv_export_url,
icon_name="download",
)
)

return actions
return buttons

def get_translations(self):
index_url = self.get_index_url()
Expand Down
3 changes: 2 additions & 1 deletion wagtail/admin/views/generic/usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ def get_breadcrumbs_items(self):
)
return self.breadcrumbs_items + items

def get_main_actions(self):
@cached_property
def header_buttons(self):
return [
Button(
label=_("Edit"),
Expand Down

0 comments on commit 4554dbd

Please sign in to comment.