diff --git a/swh/web/browse/views/utils/snapshot_context.py b/swh/web/browse/views/utils/snapshot_context.py --- a/swh/web/browse/views/utils/snapshot_context.py +++ b/swh/web/browse/views/utils/snapshot_context.py @@ -389,6 +389,14 @@ heading = ('Directory - %s - %s - %s' % (dir_path, snapshot_context['branch'], context_found)) + top_right_link = None + if not snapshot_context['is_empty']: + top_right_link = { + 'url': history_url, + 'icon': swh_object_icons['revisions history'], + 'text': 'History' + } + return render(request, 'browse/directory.html', {'heading': heading, 'swh_object_name': 'Directory', @@ -396,11 +404,7 @@ 'dirs': dirs, 'files': files, 'breadcrumbs': breadcrumbs if root_sha1_git else [], - 'top_right_link': { - 'url': history_url, - 'icon': swh_object_icons['revisions history'], - 'text': 'History' - }, + 'top_right_link': top_right_link, 'readme_name': readme_name, 'readme_url': readme_url, 'readme_html': readme_html, @@ -576,6 +580,14 @@ heading = ('Content - %s - %s - %s' % (content_path, snapshot_context['branch'], context_found)) + top_right_link = None + if not snapshot_context['is_empty']: + top_right_link = { + 'url': content_raw_url, + 'icon': swh_object_icons['content'], + 'text': 'Raw File' + } + return render(request, 'browse/content.html', {'heading': heading, 'swh_object_name': 'Content', @@ -587,11 +599,7 @@ 'language': language, 'available_languages': available_languages, 'breadcrumbs': breadcrumbs if root_sha1_git else [], - 'top_right_link': { - 'url': content_raw_url, - 'icon': swh_object_icons['content'], - 'text': 'Raw File' - }, + 'top_right_link': top_right_link, 'snapshot_context': snapshot_context, 'vault_cooking': None, 'show_actions_menu': True, diff --git a/swh/web/templates/includes/top-navigation.html b/swh/web/templates/includes/top-navigation.html --- a/swh/web/templates/includes/top-navigation.html +++ b/swh/web/templates/includes/top-navigation.html @@ -87,7 +87,7 @@
{% if top_right_link %} - + {% if top_right_link.icon %} {% endif %} diff --git a/swh/web/tests/browse/views/test_origin.py b/swh/web/tests/browse/views/test_origin.py --- a/swh/web/tests/browse/views/test_origin.py +++ b/swh/web/tests/browse/views/test_origin.py @@ -494,7 +494,9 @@ resp = client.get(url) assert resp.status_code == 200 assert_template_used(resp, 'browse/directory.html') - assert re.search('snapshot.*is empty', resp.content.decode('utf-8')) + resp_content = resp.content.decode('utf-8') + assert re.search('snapshot.*is empty', resp_content) + assert not re.search('swh-tr-link', resp_content) @given(origin_with_releases())