Skip to content

Commit

Permalink
Render edit URL in page usage view as a header button
Browse files Browse the repository at this point in the history
  • Loading branch information
laymonage authored and lb- committed Mar 13, 2024
1 parent c6bb19d commit dc93d28
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
8 changes: 8 additions & 0 deletions wagtail/admin/tests/pages/test_page_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ def test_simple(self):
]
self.assertBreadcrumbsItemsRendered(items, response.content)

# There should be exactly one edit link, rendered as a header button
edit_url = reverse("wagtailadmin_pages:edit", args=(self.page.id,))
soup = self.get_soup(response.content)
edit_links = soup.select(f"a[href='{edit_url}']")
self.assertEqual(len(edit_links), 1)
edit_link = edit_links[0]
self.assertIn("w-header-button", edit_link.attrs.get("class"))

def test_has_private_usage(self):
PageChooserModel.objects.create(page=self.page)
usage_url = reverse("wagtailadmin_pages:usage", args=(self.page.id,))
Expand Down
9 changes: 9 additions & 0 deletions wagtail/admin/views/pages/usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class UsageView(generic.UsageView):
pk_url_kwarg = "page_id"
header_icon = "doc-empty-inverse"
usage_url_name = "wagtailadmin_pages:usage"
edit_url_name = "wagtailadmin_pages:edit"
_show_breadcrumbs = True

def dispatch(self, request, *args, **kwargs):
Expand All @@ -88,3 +89,11 @@ def dispatch(self, request, *args, **kwargs):
@cached_property
def breadcrumbs_items(self):
return get_breadcrumbs_items_for_page(self.object, self.request.user)

def get_breadcrumbs_items(self):
# The generic UsageView will add an edit link for the current object as
# the second-to-last item, but we don't want that because we want to
# link to the explore view instead for consistency with how page
# breadcrumbs work elsewhere. So we only take the last item, which is
# the "self" (Usage) item.
return self.breadcrumbs_items + [super().get_breadcrumbs_items()[-1]]

0 comments on commit dc93d28

Please sign in to comment.