Hides Triggers if integration only has one event
Removes confusing/unnecessary checkboxes when trying to configure an integration. If there is only one supported event we don't need to allow these to be individually disabled since the integration can be disabled instead. E.g. Project Integrations for GitHub, Bugzilla, Asana, Pipeline emails and Gemnasium Allows integrations to override which triggers are configurable
This commit is contained in:
parent
ef15668d82
commit
93af1af67f
|
@ -129,6 +129,17 @@ class Service < ActiveRecord::Base
|
|||
fields
|
||||
end
|
||||
|
||||
def configurable_events
|
||||
events = self.class.supported_events
|
||||
|
||||
# No need to disable individual triggers when there is only one
|
||||
if events.count == 1
|
||||
[]
|
||||
else
|
||||
events
|
||||
end
|
||||
end
|
||||
|
||||
def supported_events
|
||||
self.class.supported_events
|
||||
end
|
||||
|
|
|
@ -13,12 +13,12 @@
|
|||
.col-sm-10
|
||||
= form.check_box :active, disabled: disable_fields_service?(@service)
|
||||
|
||||
- if @service.supported_events.present?
|
||||
- if @service.configurable_events.present?
|
||||
.form-group
|
||||
= form.label :url, "Trigger", class: 'control-label'
|
||||
|
||||
.col-sm-10
|
||||
- @service.supported_events.each do |event|
|
||||
- @service.configurable_events.each do |event|
|
||||
%div
|
||||
= form.check_box service_event_field_name(event), class: 'pull-left'
|
||||
.prepend-left-20
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
title: Avoid showing unnecessary Trigger checkboxes for project Integrations with
|
||||
only one event
|
||||
merge_request: 17607
|
||||
author:
|
||||
type: changed
|
|
@ -0,0 +1,35 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'Disable individual triggers' do
|
||||
let(:project) { create(:project) }
|
||||
let(:user) { project.owner }
|
||||
let(:checkbox_selector) { 'input[type=checkbox][id$=_events]' }
|
||||
|
||||
before do
|
||||
sign_in(user)
|
||||
|
||||
visit(project_settings_integrations_path(project))
|
||||
|
||||
click_link(service_name)
|
||||
end
|
||||
|
||||
context 'service has multiple supported events' do
|
||||
let(:service_name) { 'HipChat' }
|
||||
|
||||
it 'shows trigger checkboxes' do
|
||||
event_count = HipchatService.supported_events.count
|
||||
|
||||
expect(page).to have_content "Trigger"
|
||||
expect(page).to have_css(checkbox_selector, count: event_count)
|
||||
end
|
||||
end
|
||||
|
||||
context 'services only has one supported event' do
|
||||
let(:service_name) { 'Asana' }
|
||||
|
||||
it "doesn't show unnecessary Trigger checkboxes" do
|
||||
expect(page).not_to have_content "Trigger"
|
||||
expect(page).not_to have_css(checkbox_selector)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue