From 9f3227645442017e3518e2b0ba3e9270ebabfa06 Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Tue, 19 Sep 2017 13:43:04 +0100 Subject: Add context tabs to dashboard/projects This allows users to quickly switch between all projects they have access to & there own namespace projects. These tabs also keep the same filtering/search options selected so the user can quickly switch between the two different contexts. Closes #29045 --- app/views/dashboard/projects/_nav.html.haml | 8 ++++++++ app/views/dashboard/projects/index.html.haml | 1 + changelogs/unreleased/project-page-clearer.yml | 5 +++++ spec/features/dashboard/projects_spec.rb | 19 +++++++++++++++++++ spec/views/dashboard/projects/_nav.html.haml.rb | 17 +++++++++++++++++ 5 files changed, 50 insertions(+) create mode 100644 app/views/dashboard/projects/_nav.html.haml create mode 100644 changelogs/unreleased/project-page-clearer.yml create mode 100644 spec/views/dashboard/projects/_nav.html.haml.rb diff --git a/app/views/dashboard/projects/_nav.html.haml b/app/views/dashboard/projects/_nav.html.haml new file mode 100644 index 00000000000..697211d7ce8 --- /dev/null +++ b/app/views/dashboard/projects/_nav.html.haml @@ -0,0 +1,8 @@ +.top-area + %ul.nav-links + = nav_link(html_options: { class: ("active" unless params[:personal].present?) }) do + = link_to dashboard_projects_path do + #{ s_('DashboardProjects|All') } + = nav_link(html_options: { class: ("active" if params[:personal].present?) }) do + = link_to filter_projects_path(personal: true) do + #{ s_('DashboardProjects|Personal') } diff --git a/app/views/dashboard/projects/index.html.haml b/app/views/dashboard/projects/index.html.haml index a4dc49d2120..985871a888c 100644 --- a/app/views/dashboard/projects/index.html.haml +++ b/app/views/dashboard/projects/index.html.haml @@ -12,6 +12,7 @@ %div{ class: container_class } - if has_projects_or_name?(@projects, params) = render 'dashboard/projects_head' + = render 'nav' = render 'projects' - else = render "zero_authorized_projects" diff --git a/changelogs/unreleased/project-page-clearer.yml b/changelogs/unreleased/project-page-clearer.yml new file mode 100644 index 00000000000..7db01373360 --- /dev/null +++ b/changelogs/unreleased/project-page-clearer.yml @@ -0,0 +1,5 @@ +--- +title: Added tabs to dashboard/projects to easily switch to personal projects +merge_request: +author: +type: added diff --git a/spec/features/dashboard/projects_spec.rb b/spec/features/dashboard/projects_spec.rb index 9a7b8e3ba6b..4da95ccc169 100644 --- a/spec/features/dashboard/projects_spec.rb +++ b/spec/features/dashboard/projects_spec.rb @@ -50,6 +50,25 @@ feature 'Dashboard Projects' do end end + context 'when on Your projects tab' do + it 'shows all projects by default' do + visit dashboard_projects_path + + expect(page).to have_content(project.name) + end + + it 'shows personal projects on personal projects tab', :js do + project3 = create(:project, namespace: user.namespace) + + visit dashboard_projects_path + + click_link 'Personal' + + expect(page).not_to have_content(project.name) + expect(page).to have_content(project3.name) + end + end + context 'when on Starred projects tab' do it 'shows only starred projects' do user.toggle_star(project2) diff --git a/spec/views/dashboard/projects/_nav.html.haml.rb b/spec/views/dashboard/projects/_nav.html.haml.rb new file mode 100644 index 00000000000..f6a8ca13040 --- /dev/null +++ b/spec/views/dashboard/projects/_nav.html.haml.rb @@ -0,0 +1,17 @@ +require 'spec_helper' + +describe 'dashboard/projects/_nav.html.haml' do + it 'highlights All tab by default' do + render + + expect(rendered).to have_css('li.active a', text: 'All') + end + + it 'highlights Personal tab personal param is present' do + controller.params[:personal] = true + + render + + expect(rendered).to have_css('li.active a', text: 'Personal') + end +end -- cgit v1.2.1 From eab0ca8a0b2950dbbcf6662c34b2fc8313ba9bde Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Thu, 21 Sep 2017 11:03:14 +0100 Subject: Fixes dashboard/projects empty state showing when viewing personal projects This was caused by the `@projects` value being empty when the current user does not have any personal projects. --- app/helpers/projects_helper.rb | 4 ++-- app/views/dashboard/projects/index.html.haml | 2 +- spec/helpers/projects_helper_spec.rb | 12 ++++++++---- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index ddeff490d3a..21fb17e06d6 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -239,8 +239,8 @@ module ProjectsHelper end end - def has_projects_or_name?(projects, params) - !!(params[:name] || any_projects?(projects)) + def show_projects?(projects, params) + !!(params[:personal] || params[:name] || any_projects?(projects)) end private diff --git a/app/views/dashboard/projects/index.html.haml b/app/views/dashboard/projects/index.html.haml index 985871a888c..57a4da353fe 100644 --- a/app/views/dashboard/projects/index.html.haml +++ b/app/views/dashboard/projects/index.html.haml @@ -10,7 +10,7 @@ = render "projects/last_push" %div{ class: container_class } - - if has_projects_or_name?(@projects, params) + - if show_projects?(@projects, params) = render 'dashboard/projects_head' = render 'nav' = render 'projects' diff --git a/spec/helpers/projects_helper_spec.rb b/spec/helpers/projects_helper_spec.rb index a76c75e0c08..7ded95d01af 100644 --- a/spec/helpers/projects_helper_spec.rb +++ b/spec/helpers/projects_helper_spec.rb @@ -420,22 +420,26 @@ describe ProjectsHelper do end end - describe '#has_projects_or_name?' do + describe '#show_projects' do let(:projects) do create(:project) Project.all end it 'returns true when there are projects' do - expect(helper.has_projects_or_name?(projects, {})).to eq(true) + expect(helper.show_projects?(projects, {})).to eq(true) end it 'returns true when there are no projects but a name is given' do - expect(helper.has_projects_or_name?(Project.none, name: 'foo')).to eq(true) + expect(helper.show_projects?(Project.none, name: 'foo')).to eq(true) + end + + it 'returns true when there are no projects but personal is present' do + expect(helper.show_projects?(Project.none, personal: 'true')).to eq(true) end it 'returns false when there are no projects and there is no name' do - expect(helper.has_projects_or_name?(Project.none, {})).to eq(false) + expect(helper.show_projects?(Project.none, {})).to eq(false) end end -- cgit v1.2.1 From 8eb2d741ad038a80759b8db94ad475ad86f46543 Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Fri, 22 Sep 2017 12:26:23 +0100 Subject: simplify link_to call --- app/views/dashboard/projects/_nav.html.haml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/views/dashboard/projects/_nav.html.haml b/app/views/dashboard/projects/_nav.html.haml index 697211d7ce8..3701e1c0578 100644 --- a/app/views/dashboard/projects/_nav.html.haml +++ b/app/views/dashboard/projects/_nav.html.haml @@ -1,8 +1,6 @@ .top-area %ul.nav-links = nav_link(html_options: { class: ("active" unless params[:personal].present?) }) do - = link_to dashboard_projects_path do - #{ s_('DashboardProjects|All') } + = link_to s_('DashboardProjects|All'), dashboard_projects_path = nav_link(html_options: { class: ("active" if params[:personal].present?) }) do - = link_to filter_projects_path(personal: true) do - #{ s_('DashboardProjects|Personal') } + = link_to s_('DashboardProjects|Personal'), filter_projects_path(personal: true) -- cgit v1.2.1