Skip to content

Commit

Permalink
Fix tabs for clusterable snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
kaedroho committed Nov 4, 2020
1 parent c9f40ff commit f272215
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion wagtail_localize/tests/test_edit_translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'})
Expand Down
25 changes: 16 additions & 9 deletions wagtail_localize/views/edit_translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit f272215

Please sign in to comment.