-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Dashboard] optimization #1856
[Dashboard] optimization #1856
Changes from all commits
e573945
c297644
5807ffa
f37cda1
d763d8d
b15d47b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
module MenuHelper | ||
def main_menu_item(id, label, path, options = {}) | ||
fake_active = respond_to?(:active_upgrade_notice) && (id == active_upgrade_notice) | ||
|
@@ -27,9 +29,7 @@ def menu_item(label, path, options = {}) | |
|
||
def menu_link(level, title, path, options = {}, li_options = {}, &block) | ||
current_title = options.delete(:title) || title | ||
if active_menu?(level, current_title) || current_page?(path) | ||
li_options[:class] = :active | ||
end | ||
li_options[:class] = :active if active_menu?(level, current_title) || current_page?(path) | ||
|
||
# humanize only if it is NOT a string, otherwise it would destroy capitalization | ||
title = title.to_s.humanize.camelize unless title.is_a?(String) | ||
|
@@ -67,7 +67,7 @@ def link_to_switch_or_upgrade(name, options, path, switch) | |
if can?(:see, switch) | ||
link_to(name, path, options) | ||
elsif upgrade | ||
options[:class].gsub!(/(?: fancybox |^fancybox$)/, ' ') if options[:class] | ||
options[:class]&.gsub!(/(?: fancybox |^fancybox$)/, ' ') | ||
upgrade_notice_link(switch, name, options) | ||
end | ||
|
||
|
@@ -85,9 +85,12 @@ def forcibly_denied_switch?(switch) | |
end | ||
|
||
def api_selector_services | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't have a test and got too complicated/dangerous to don't have a test 😓 require 'test_helper'
class MenuHelperTest < ActionView::TestCase
def setup
@provider = FactoryBot.create(:provider_account)
end
attr_reader :provider
test 'switch_link with finance globally disabled' do
expects(:forcibly_denied_switch?).with(:finance).returns(true)
assert_nil switch_link('Billing', root_path, switch: :finance, upgrade_notice: true)
end
test 'switch_link with finance globally enabled' do
expects(:forcibly_denied_switch?).with(:finance).returns(false)
link = switch_link('Billing', root_path, switch: :finance, upgrade_notice: true)
assert_equal upgrade_notice_link(:finance, 'Billing'), link
end
test 'forcibly_denied_switch?' do
Settings.stubs(globally_denied_switches: [])
assert @provider.settings.finance.denied?
refute forcibly_denied_switch?(:finance)
Settings.stubs(globally_denied_switches: [:finance])
refute forcibly_denied_switch?(:finance)
end
test 'forcibly_denied_switch? for master' do
ThreeScale.config.stubs(onpremises: false)
@provider = master_account
assert @provider.settings.finance.denied?
refute forcibly_denied_switch?(:finance)
ThreeScale.config.stubs(onpremises: true)
assert @provider.settings.finance.denied?
assert forcibly_denied_switch?(:finance)
end
test 'api_selector_services for tenant logged in without api_as_product' do
FactoryBot.create(:simple_service, account: provider)
FactoryBot.create(:simple_service, account: provider, state: Service::DELETE_STATE)
rolling_updates_on
rolling_update(:api_as_product, enabled: false)
assert_equal provider.accessible_services.size, api_selector_services.size
api_selector_services.each do |api_decorated|
assert_equal ServiceDecorator, api_decorated.class
assert_includes provider.accessible_services.pluck(:id), api_decorated.id
end
end
test 'api_selector_services for tenant logged in with api_as_product' do
FactoryBot.create(:simple_service, account: provider)
FactoryBot.create(:simple_service, account: provider, state: Service::DELETE_STATE)
FactoryBot.create(:backend_api, account: provider)
FactoryBot.create(:backend_api, account: provider, state: BackendApi::DELETED_STATE)
rolling_updates_on
rolling_update(:api_as_product, enabled: true)
services_decorated, backend_apis_decorated = api_selector_services.partition { |api_decorated| api_decorated.class == ServiceDecorator }
assert_equal provider.accessible_services.size, services_decorated.size
assert_equal provider.backend_apis.accessible.size, backend_apis_decorated.size
assert_same_elements provider.accessible_services.pluck(:id), services_decorated.map(&:id)
assert_same_elements provider.backend_apis.accessible.pluck(:id), backend_apis_decorated.map(&:id)
assert backend_apis_decorated.all? { |api_decorated| api_decorated.class == BackendApiDecorator }
end
test 'api_selector_services if not logged in' do
@current_account = nil
assert_empty api_selector_services
end
test 'api_selector_services in developer portal' do
@current_account = FactoryBot.create(:simple_buyer, provider_account: provider)
assert_empty api_selector_services
end
protected
def current_user
@current_user ||= current_account.try!(:admin_user)
end
def current_account
return @current_account if defined? @current_account
@current_account = @provider
end
def ability
@ability ||= Ability.new(current_user)
end
def can?(*args)
ability.can?(*args)
end
end There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know that it is not your fault, but this name at this point is a bit misleading... it sounds like it is only |
||
@api_selector_services ||= (site_account.provider? && logged_in? ? current_user.accessible_services : Service.none).decorate | ||
@api_selector_services.concat(current_user.account.backend_apis.decorate) if current_account.provider_can_use?(:api_as_product) | ||
@api_selector_services | ||
@api_selector_services ||= if current_account && current_account.provider? | ||
accessible_backend_apis = current_account.provider_can_use?(:api_as_product) ? current_user.account.backend_apis.accessible : BackendApi.none | ||
current_user.accessible_services.decorate.concat(accessible_backend_apis.decorate) | ||
else | ||
Service.none.decorate | ||
end | ||
end | ||
|
||
def audience_link | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,11 +23,10 @@ nav.DashboardNavigation | |
admin_service_applications_path(service), | ||
icon_name: 'cubes' | ||
|
||
- unread_alerts = current_account.buyer_alerts.by_service(service).unread | ||
- if can?(:manage, :monitoring) && unread_alerts.any? | ||
- if can?(:manage, :monitoring) && service.unread_alerts_count > 0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as #1856 (comment) |
||
li.DashboardNavigation-list-item | ||
= dashboard_collection_link 'Alert', | ||
unread_alerts, | ||
service.unread_alerts_count, | ||
admin_service_alerts_path(service), | ||
icon_name: 'exclamation-triangle', | ||
notice: true | ||
|
@@ -44,14 +43,14 @@ nav.DashboardNavigation | |
// Active docs | ||
- if can?(:manage, :plans) | ||
li.DashboardNavigation-list-item | ||
= dashboard_collection_link 'ActiveDoc', | ||
service.api_docs_services, | ||
= dashboard_collection_size_link 'ActiveDoc', | ||
service.api_docs_services_count, | ||
admin_service_api_docs_path(service), | ||
icon_name: 'file-text' | ||
// Integration | ||
- if can?(:manage, :plans) | ||
li.DashboardNavigation-list-item | ||
- if service.has_traffic? || (apiap? && service.proxy.proxy_configs.sandbox.any?) | ||
- if service.cinstances_with_traffic_count > 0 || (apiap? && service.sandbox_proxy_configs_count > 0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you sure that this performs better than this?: - if service.cinstances_with_traffic.exists? || (apiap? && service.sandbox_proxy_configs.exists?) Because the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
- if has_out_of_date_configuration?(service) | ||
= dashboard_navigation_link 'Integration', | ||
path_to_service(service), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My 1st reaction was "what is that?" so I went to https://github.com/k0kubun/activerecord-precounter and saw:
Great, but we already use
counter_cache
for some things, and I know that they behave VERY differently, so I wondered if we really need both or what was the plan for the future.We spoke about it and
counter_cache
should eventually be completely replaced for this one because it is not as handy. Once this PR is merged, we will have a Jira issue for this goal 👍