diff --git a/wagtail_localize/tests/test_edit_translation.py b/wagtail_localize/tests/test_edit_translation.py index 17d42475..57f83f00 100644 --- a/wagtail_localize/tests/test_edit_translation.py +++ b/wagtail_localize/tests/test_edit_translation.py @@ -283,7 +283,7 @@ def test_edit_snippet_translation(self): self.assertIsNone(props['object']['lastPublishedDate']) self.assertIsNone(props['object']['liveUrl']) self.assertEqual(props['breadcrumb'], []) - self.assertEqual(props['tabs'], [{'label': '', 'slug': ''}]) + self.assertEqual(props['tabs'], [{'label': 'Content', 'slug': 'content'}]) self.assertEqual(props['sourceLocale'], {'code': 'en', 'displayName': 'English'}) self.assertEqual(props['locale'], {'code': 'fr', 'displayName': 'French'}) diff --git a/wagtail_localize/views/edit_translation.py b/wagtail_localize/views/edit_translation.py index 34bf7233..8086230e 100644 --- a/wagtail_localize/views/edit_translation.py +++ b/wagtail_localize/views/edit_translation.py @@ -20,7 +20,7 @@ from rest_framework.decorators import api_view from rest_framework.response import Response from wagtail.admin import messages -from wagtail.admin.edit_handlers import TabbedInterface +from wagtail.admin.edit_handlers import TabbedInterface, ObjectList from wagtail.admin.navigation import get_explorable_root_page from wagtail.admin.templatetags.wagtailadmin_tags import avatar_url from wagtail.admin.views.pages.utils import get_valid_next_url_from_request @@ -105,16 +105,23 @@ def edit_handler(self): @cached_property def tabs(self): - if isinstance(self.edit_handler, TabbedInterface): - tabs = [] + tabs = [] + if isinstance(self.edit_handler, TabbedInterface): for tab in self.edit_handler.children: - tabs.append(tab.heading) - - return tabs - - else: - return [_("Content")] + # On Pages, the TabbedInterface children are instances of ObjectList + # which contain the fields + # On Snippets, the fields can be added directly into the TabbedInterface + # In this case, we do not want to add any tabs and instead just fall back + # to the default "Content" tab added below. + if isinstance(tab, ObjectList): + tabs.append(tab.heading) + + # Add a default "Content" tab if this object doesn't have any tabs + if not tabs: + tabs = [_("Content")] + + return tabs @property def tabs_with_slugs(self):