In development, allow the toggling of the performance bar
The performance bar is still displayed by default in development. Signed-off-by: Rémy Coutable <remy@rymai.me>
This commit is contained in:
parent
612d226625
commit
28d39447c3
4 changed files with 34 additions and 10 deletions
|
@ -62,7 +62,7 @@ export default class Shortcuts {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const performanceBarCookieName = 'perf_bar_enabled';
|
const performanceBarCookieName = 'perf_bar_enabled';
|
||||||
if (Cookies.get(performanceBarCookieName) === 'true') {
|
if (Cookies.get(performanceBarCookieName) === 'true') {
|
||||||
Cookies.remove(performanceBarCookieName, { path: '/' });
|
Cookies.set(performanceBarCookieName, 'false', { path: '/' });
|
||||||
} else {
|
} else {
|
||||||
Cookies.set(performanceBarCookieName, 'true', { path: '/' });
|
Cookies.set(performanceBarCookieName, 'true', { path: '/' });
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,13 +6,22 @@ module WithPerformanceBar
|
||||||
end
|
end
|
||||||
|
|
||||||
def peek_enabled?
|
def peek_enabled?
|
||||||
return true if Rails.env.development?
|
|
||||||
return false unless Gitlab::PerformanceBar.enabled?(current_user)
|
return false unless Gitlab::PerformanceBar.enabled?(current_user)
|
||||||
|
|
||||||
if RequestStore.active?
|
if RequestStore.active?
|
||||||
RequestStore.fetch(:peek_enabled) { cookies[:perf_bar_enabled].present? }
|
RequestStore.fetch(:peek_enabled) { cookie_or_default_value }
|
||||||
else
|
else
|
||||||
cookies[:perf_bar_enabled].present?
|
cookie_or_default_value
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def cookie_or_default_value
|
||||||
|
if cookies[:perf_bar_enabled].present?
|
||||||
|
cookies[:perf_bar_enabled] == 'true'
|
||||||
|
else
|
||||||
|
cookies[:perf_bar_enabled] = 'true' if Rails.env.development?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,6 +6,7 @@ module Gitlab
|
||||||
EXPIRY_TIME = 5.minutes
|
EXPIRY_TIME = 5.minutes
|
||||||
|
|
||||||
def self.enabled?(user = nil)
|
def self.enabled?(user = nil)
|
||||||
|
return true if Rails.env.development?
|
||||||
return false unless user && allowed_group_id
|
return false unless user && allowed_group_id
|
||||||
|
|
||||||
allowed_user_ids.include?(user.id)
|
allowed_user_ids.include?(user.id)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe 'User can display performance bar', :js do
|
describe 'User can display performance bar', :js do
|
||||||
shared_examples 'performance bar is disabled' do
|
shared_examples 'performance bar cannot be displayed' do
|
||||||
it 'does not show the performance bar by default' do
|
it 'does not show the performance bar by default' do
|
||||||
expect(page).not_to have_css('#peek')
|
expect(page).not_to have_css('#peek')
|
||||||
end
|
end
|
||||||
|
@ -17,7 +17,7 @@ describe 'User can display performance bar', :js do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
shared_examples 'performance bar is enabled' do
|
shared_examples 'performance bar can be displayed' do
|
||||||
it 'does not show the performance bar by default' do
|
it 'does not show the performance bar by default' do
|
||||||
expect(page).not_to have_css('#peek')
|
expect(page).not_to have_css('#peek')
|
||||||
end
|
end
|
||||||
|
@ -33,6 +33,18 @@ describe 'User can display performance bar', :js do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
shared_examples 'performance bar is enabled by default in development' do
|
||||||
|
before do
|
||||||
|
allow(Rails.env).to receive(:development?).and_return(true)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'shows the performance bar by default' do
|
||||||
|
refresh # Because we're stubbing Rails.env after the 1st visit to root_path
|
||||||
|
|
||||||
|
expect(page).to have_css('#peek')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
let(:group) { create(:group) }
|
let(:group) { create(:group) }
|
||||||
|
|
||||||
context 'when user is logged-out' do
|
context 'when user is logged-out' do
|
||||||
|
@ -45,7 +57,7 @@ describe 'User can display performance bar', :js do
|
||||||
stub_application_setting(performance_bar_allowed_group_id: nil)
|
stub_application_setting(performance_bar_allowed_group_id: nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
it_behaves_like 'performance bar is disabled'
|
it_behaves_like 'performance bar cannot be displayed'
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when the performance_bar feature is enabled' do
|
context 'when the performance_bar feature is enabled' do
|
||||||
|
@ -53,7 +65,7 @@ describe 'User can display performance bar', :js do
|
||||||
stub_application_setting(performance_bar_allowed_group_id: group.id)
|
stub_application_setting(performance_bar_allowed_group_id: group.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
it_behaves_like 'performance bar is disabled'
|
it_behaves_like 'performance bar cannot be displayed'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -72,7 +84,8 @@ describe 'User can display performance bar', :js do
|
||||||
stub_application_setting(performance_bar_allowed_group_id: nil)
|
stub_application_setting(performance_bar_allowed_group_id: nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
it_behaves_like 'performance bar is disabled'
|
it_behaves_like 'performance bar cannot be displayed'
|
||||||
|
it_behaves_like 'performance bar is enabled by default in development'
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when the performance_bar feature is enabled' do
|
context 'when the performance_bar feature is enabled' do
|
||||||
|
@ -80,7 +93,8 @@ describe 'User can display performance bar', :js do
|
||||||
stub_application_setting(performance_bar_allowed_group_id: group.id)
|
stub_application_setting(performance_bar_allowed_group_id: group.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
it_behaves_like 'performance bar is enabled'
|
it_behaves_like 'performance bar is enabled by default in development'
|
||||||
|
it_behaves_like 'performance bar can be displayed'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue