Commit aaa98c73 authored by Phil Hughes's avatar Phil Hughes

Merge branch '38919/wiki-empty-states' into 'master'

Add helpful messages to empty wiki view

Closes #38919

See merge request gitlab-org/gitlab-ce!19007
parents 6e354cb6 67199aed
import bp from '../../../breakpoints';
import { slugify } from '../../../lib/utils/text_utility';
import { parseQueryStringIntoObject } from '../../../lib/utils/common_utils';
import { mergeUrlParams, redirectTo } from '../../../lib/utils/url_utility';
export default class Wikis {
constructor() {
......@@ -28,7 +30,12 @@ export default class Wikis {
if (slug.length > 0) {
const wikisPath = slugInput.getAttribute('data-wikis-path');
window.location.href = `${wikisPath}/${slug}`;
// If the wiki is empty, we need to merge the current URL params to keep the "create" view.
const params = parseQueryStringIntoObject(window.location.search.substr(1));
const url = mergeUrlParams(params, `${wikisPath}/${slug}`);
redirectTo(url);
e.preventDefault();
}
}
......
......@@ -14,6 +14,8 @@ class Projects::WikisController < Projects::ApplicationController
def show
@page = @project_wiki.find_page(params[:id], params[:version_id])
view_param = @project_wiki.empty? ? params[:view] : 'create'
if @page
render 'show'
elsif file = @project_wiki.find_file(params[:id], params[:version_id])
......@@ -26,12 +28,12 @@ class Projects::WikisController < Projects::ApplicationController
disposition: 'inline',
filename: file.name
)
else
return render('empty') unless can?(current_user, :create_wiki, @project)
elsif can?(current_user, :create_wiki, @project) && view_param == 'create'
@page = build_page(title: params[:id])
render 'edit'
else
render 'empty'
end
end
......
......@@ -11,6 +11,7 @@ module NavHelper
class_name = page_gutter_class
class_name << 'page-with-contextual-sidebar' if defined?(@left_sidebar) && @left_sidebar
class_name << 'page-with-icon-sidebar' if collapsed_sidebar? && @left_sidebar
class_name -= ['right-sidebar-expanded'] if defined?(@right_sidebar) && !@right_sidebar
class_name
end
......
- page_title _("Wiki")
- @right_sidebar = false
%h3.page-title= s_("Wiki|Empty page")
%hr
.error_message
= s_("WikiEmptyPageError|You are not allowed to create wiki pages")
= render 'shared/empty_states/wikis'
- layout_path = 'shared/empty_states/wikis_layout'
- if can?(current_user, :create_wiki, @project)
- create_path = project_wiki_path(@project, params[:id], { view: 'create' })
- create_link = link_to s_('WikiEmpty|Create your first page'), create_path, class: 'btn btn-new', title: s_('WikiEmpty|Create your first page')
= render layout: layout_path, locals: { image_path: 'illustrations/wiki_login_empty.svg' } do
%h4
= s_('WikiEmpty|The wiki lets you write documentation for your project')
%p.text-left
= s_("WikiEmpty|A wiki is where you can store all the details about your project. This can include why you've created it, it's principles, how to use it, and so on.")
= create_link
- elsif can?(current_user, :read_issue, @project)
- issues_link = link_to s_('WikiEmptyIssueMessage|issue tracker'), project_issues_path(@project)
- new_issue_link = link_to s_('WikiEmpty|Suggest wiki improvement'), new_project_issue_path(@project), class: 'btn btn-new', title: s_('WikiEmptyIssueMessage|Suggest wiki improvement')
= render layout: layout_path, locals: { image_path: 'illustrations/wiki_logout_empty.svg' } do
%h4
= s_('WikiEmpty|This project has no wiki pages')
%p.text-left
= s_('WikiEmptyIssueMessage|You must be a project member in order to add wiki pages. If you have suggestions for how to improve the wiki for this project, consider opening an issue in the %{issues_link}.').html_safe % { issues_link: issues_link }
= new_issue_link
- else
= render layout: layout_path, locals: { image_path: 'illustrations/wiki_logout_empty.svg' } do
%h4
= s_('WikiEmpty|This project has no wiki pages')
%p
= s_('WikiEmpty|You must be a project member in order to add wiki pages.')
.row.empty-state
.col-xs-12
.svg-content
= image_tag image_path
.col-xs-12
.text-content.text-center
= yield
---
title: Add helpful messages to empty wiki view
merge_request: 19007
author:
type: other
......@@ -8,8 +8,8 @@ msgid ""
msgstr ""
"Project-Id-Version: gitlab 1.0.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-05-21 12:38-0700\n"
"PO-Revision-Date: 2018-05-21 12:38-0700\n"
"POT-Creation-Date: 2018-05-23 07:40-0500\n"
"PO-Revision-Date: 2018-05-23 07:40-0500\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
......@@ -3998,6 +3998,12 @@ msgstr ""
msgid "There are problems accessing Git storage: "
msgstr ""
msgid "There was an error loading jobs"
msgstr ""
msgid "There was an error loading latest pipeline"
msgstr ""
msgid "There was an error loading users activity calendar."
msgstr ""
......@@ -4241,10 +4247,10 @@ msgstr ""
msgid "Timeago|in 1 year"
msgstr ""
msgid "Timeago|in a while"
msgid "Timeago|less than a minute ago"
msgstr ""
msgid "Timeago|less than a minute ago"
msgid "Timeago|right now"
msgstr ""
msgid "Time|hr"
......@@ -4479,7 +4485,31 @@ msgstr ""
msgid "WikiEdit|There is already a page with the same title in that path."
msgstr ""
msgid "WikiEmptyPageError|You are not allowed to create wiki pages"
msgid "WikiEmptyIssueMessage|Suggest wiki improvement"
msgstr ""
msgid "WikiEmptyIssueMessage|You must be a project member in order to add wiki pages. If you have suggestions for how to improve the wiki for this project, consider opening an issue in the %{issues_link}."
msgstr ""
msgid "WikiEmptyIssueMessage|issue tracker"
msgstr ""
msgid "WikiEmpty|A wiki is where you can store all the details about your project. This can include why you've created it, it's principles, how to use it, and so on."
msgstr ""
msgid "WikiEmpty|Create your first page"
msgstr ""
msgid "WikiEmpty|Suggest wiki improvement"
msgstr ""
msgid "WikiEmpty|The wiki lets you write documentation for your project"
msgstr ""
msgid "WikiEmpty|This project has no wiki pages"
msgstr ""
msgid "WikiEmpty|You must be a project member in order to add wiki pages."
msgstr ""
msgid "WikiHistoricalPage|This is an old version of this page."
......@@ -4548,9 +4578,6 @@ msgstr ""
msgid "Wiki|Edit Page"
msgstr ""
msgid "Wiki|Empty page"
msgstr ""
msgid "Wiki|More Pages"
msgstr ""
......
......@@ -19,6 +19,7 @@ feature 'Projects > Wiki > User previews markdown changes', :js do
visit project_path(project)
find('.shortcuts-wiki').click
click_link "Create your first page"
end
context "while creating a new wiki page" do
......
......@@ -8,6 +8,7 @@ describe "User creates wiki page" do
sign_in(user)
visit(project_wikis_path(project))
click_link "Create your first page"
end
context "when wiki is empty" do
......
......@@ -11,6 +11,7 @@ describe 'User updates wiki page' do
context 'when wiki is empty' do
before do
visit(project_wikis_path(project))
click_link "Create your first page"
end
context 'in a user namespace' do
......
require 'spec_helper'
describe 'User views empty wiki' do
let(:user) { create(:user) }
shared_examples 'empty wiki and accessible issues' do
it 'show "issue tracker" message' do
visit(project_wikis_path(project))
element = page.find('.row.empty-state')
expect(element).to have_content('This project has no wiki pages')
expect(element).to have_link("issue tracker", href: project_issues_path(project))
expect(element).to have_link("Suggest wiki improvement", href: new_project_issue_path(project))
end
end
shared_examples 'empty wiki and non-accessible issues' do
it 'does not show "issue tracker" message' do
visit(project_wikis_path(project))
element = page.find('.row.empty-state')
expect(element).to have_content('This project has no wiki pages')
expect(element).to have_no_link('Suggest wiki improvement')
end
end
context 'when user is logged out and issue tracker is public' do
let(:project) { create(:project, :public, :wiki_repo) }
it_behaves_like 'empty wiki and accessible issues'
end
context 'when user is logged in and not a member' do
let(:project) { create(:project, :public, :wiki_repo) }
before do
sign_in(user)
end
it_behaves_like 'empty wiki and accessible issues'
end
context 'when issue tracker is private' do
let(:project) { create(:project, :public, :wiki_repo, :issues_private) }
it_behaves_like 'empty wiki and non-accessible issues'
end
context 'when issue tracker is disabled' do
let(:project) { create(:project, :public, :wiki_repo, :issues_disabled) }
it_behaves_like 'empty wiki and non-accessible issues'
end
context 'when user is logged in and a memeber' do
let(:project) { create(:project, :public, :wiki_repo) }
before do
sign_in(user)
project.add_developer(user)
end
it 'show "create first page" message' do
visit(project_wikis_path(project))
element = page.find('.row.empty-state')
element.click_link 'Create your first page'
expect(page).to have_button('Create page')
end
end
end
......@@ -18,6 +18,7 @@ describe 'User views a wiki page' do
context 'when wiki is empty' do
before do
visit(project_wikis_path(project))
click_link "Create your first page"
click_on('New page')
......@@ -140,6 +141,7 @@ describe 'User views a wiki page' do
visit(project_path(project))
find('.shortcuts-wiki').click
click_link "Create your first page"
expect(page).to have_content('Home · Create Page')
end
......
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