Commit 0152d6ff authored by Kushal Pandya's avatar Kushal Pandya

Merge branch 'improve-snippets-empty-state' into 'master'

Improve snippets empty state

Closes #44045 and #20847

See merge request gitlab-org/gitlab-ce!18348
parents cafc4943 220cb4c3
.page-title-holder .page-title-holder
%h1.page-title= _('Snippets') %h1.page-title= _('Snippets')
- if current_user - if current_user && current_user.snippets.any? || @snippets.any?
.page-title-controls .page-title-controls
= link_to "New snippet", new_snippet_path, class: "btn btn-success", title: "New snippet" = link_to _("New snippet"), new_snippet_path, class: "btn btn-success", title: _("New snippet")
.top-area .top-area
%ul.nav-links.nav.nav-tabs %ul.nav-links.nav.nav-tabs
......
...@@ -3,6 +3,14 @@ ...@@ -3,6 +3,14 @@
- header_title "Snippets", dashboard_snippets_path - header_title "Snippets", dashboard_snippets_path
= render 'dashboard/snippets_head' = render 'dashboard/snippets_head'
= render partial: 'snippets/snippets_scope_menu', locals: { include_private: true } - if current_user.snippets.exists?
= render partial: 'snippets/snippets_scope_menu', locals: { include_private: true }
= render partial: 'snippets/snippets', locals: { link_project: true } .d-block.d-sm-none
 
= link_to _("New snippet"), new_snippet_path, class: "btn btn-success btn-block", title: _("New snippet")
- if current_user.snippets.exists?
= render partial: 'shared/snippets/list', locals: { link_project: true }
- else
= render 'shared/empty_states/snippets', button_path: new_snippet_path
...@@ -7,4 +7,4 @@ ...@@ -7,4 +7,4 @@
- else - else
= render 'explore/head' = render 'explore/head'
= render partial: 'snippets/snippets', locals: { link_project: true } = render partial: 'shared/snippets/list', locals: { link_project: true }
- page_title _("Snippets") - page_title _("Snippets")
- if current_user - if @snippets.exists?
- if current_user
.top-area .top-area
- include_private = @project.team.member?(current_user) || current_user.admin? - include_private = @project.team.member?(current_user) || current_user.admin?
= render partial: 'snippets/snippets_scope_menu', locals: { subject: @project, include_private: include_private } = render partial: 'snippets/snippets_scope_menu', locals: { subject: @project, include_private: include_private }
- if can?(current_user, :create_project_snippet, @project)
.nav-controls .nav-controls
- if can?(current_user, :create_project_snippet, @project) - if can?(current_user, :create_project_snippet, @project)
= link_to _("New snippet"), new_project_snippet_path(@project), class: "btn btn-success", title: _("New snippet") = link_to _("New snippet"), new_project_snippet_path(@project), class: "btn btn-success", title: _("New snippet")
= render 'snippets/snippets' = render 'shared/snippets/list'
- else
= render 'shared/empty_states/snippets', button_path: new_namespace_project_snippet_path(@project.namespace, @project)
- add_to_breadcrumbs _("Snippets"), project_snippets_path(@project) - add_to_breadcrumbs _("Snippets"), project_snippets_path(@project)
- breadcrumb_title _("New") - breadcrumb_title _("New")
- page_title _("New Snippets") - page_title _("New Snippet")
%h3.page-title %h3.page-title
= _('New Snippet') = _("New Snippet")
%hr %hr
= render "shared/snippets/form", url: project_snippets_path(@project, @snippet) = render "shared/snippets/form", url: project_snippets_path(@project, @snippet)
- button_path = local_assigns.fetch(:button_path, false)
.row.empty-state
.col-12
.svg-content
= image_tag 'illustrations/snippets_empty.svg'
.text-content
- if current_user
%h4
= s_('SnippetsEmptyState|Snippets are small pieces of code or notes that you want to keep.')
%p
= s_('SnippetsEmptyState|They can be either public or private.')
.text-center
= link_to s_('SnippetsEmptyState|New snippet'), button_path, class: 'btn btn-success', title: s_('SnippetsEmptyState|New snippet'), id: 'new_snippet_link'
- unless current_page?(dashboard_snippets_path)
= link_to s_('SnippetsEmptyState|Explore public snippets'), explore_snippets_path, class: 'btn btn-default', title: s_('SnippetsEmptyState|Explore public snippets')
- else
%h4.text-center= s_('SnippetsEmptyState|There are no snippets to show.')
- remote = local_assigns.fetch(:remote, false)
- link_project = local_assigns.fetch(:link_project, false)
- if @snippets.exists?
.snippets-list-holder
%ul.content-list
= render partial: 'shared/snippets/snippet', collection: @snippets, locals: { link_project: link_project }
= paginate @snippets, theme: 'gitlab', remote: remote
- else
.nothing-here-block= s_("SnippetsEmptyState|No snippets found")
...@@ -10,4 +10,4 @@ ...@@ -10,4 +10,4 @@
= link_to user_path(@user) do = link_to user_path(@user) do
= _("%{user_name} profile page") % { user_name: @user.name } = _("%{user_name} profile page") % { user_name: @user.name }
= render 'snippets' = render 'shared/snippets/list'
---
title: Improve snippets empty state
merge_request: 18348
author: George Tsiolis
type: changed
...@@ -4862,9 +4862,6 @@ msgstr "" ...@@ -4862,9 +4862,6 @@ msgstr ""
msgid "New Snippet" msgid "New Snippet"
msgstr "" msgstr ""
msgid "New Snippets"
msgstr ""
msgid "New branch" msgid "New branch"
msgstr "" msgstr ""
...@@ -6790,6 +6787,24 @@ msgstr "" ...@@ -6790,6 +6787,24 @@ msgstr ""
msgid "Snippets" msgid "Snippets"
msgstr "" msgstr ""
msgid "SnippetsEmptyState|Explore public snippets"
msgstr ""
msgid "SnippetsEmptyState|New snippet"
msgstr ""
msgid "SnippetsEmptyState|No snippets found"
msgstr ""
msgid "SnippetsEmptyState|Snippets are small pieces of code or notes that you want to keep."
msgstr ""
msgid "SnippetsEmptyState|There are no snippets to show."
msgstr ""
msgid "SnippetsEmptyState|They can be either public or private."
msgstr ""
msgid "Someone edited this %{issueType} at the same time you did. The description has been updated and you will need to make your changes again." msgid "Someone edited this %{issueType} at the same time you did. The description has been updated and you will need to make your changes again."
msgstr "" msgstr ""
......
...@@ -44,7 +44,7 @@ describe 'Dashboard shortcuts', :js do ...@@ -44,7 +44,7 @@ describe 'Dashboard shortcuts', :js do
find('body').send_keys([:shift, 'S']) find('body').send_keys([:shift, 'S'])
find('.nothing-here-block') find('.nothing-here-block')
expect(page).to have_selector('.snippets-list-holder') expect(page).to have_content('No snippets found')
find('body').send_keys([:shift, 'P']) find('body').send_keys([:shift, 'P'])
......
...@@ -13,6 +13,21 @@ describe 'Dashboard snippets' do ...@@ -13,6 +13,21 @@ describe 'Dashboard snippets' do
it_behaves_like 'paginated snippets' it_behaves_like 'paginated snippets'
end end
context 'when there are no project snippets', :js do
let(:project) { create(:project, :public) }
before do
sign_in(project.owner)
visit dashboard_snippets_path
end
it 'shows the empty state when there are no snippets' do
element = page.find('.row.empty-state')
expect(element).to have_content("Snippets are small pieces of code or notes that you want to keep.")
expect(element.find('.svg-content img')['src']).to have_content('illustrations/snippets_empty')
end
end
context 'filtering by visibility' do context 'filtering by visibility' do
let(:user) { create(:user) } let(:user) { create(:user) }
let!(:snippets) do let!(:snippets) do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment