Commit 93af1af6 authored by James Edwards-Jones's avatar James Edwards-Jones

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
parent ef15668d
...@@ -129,6 +129,17 @@ class Service < ActiveRecord::Base ...@@ -129,6 +129,17 @@ class Service < ActiveRecord::Base
fields fields
end 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 def supported_events
self.class.supported_events self.class.supported_events
end end
......
...@@ -13,12 +13,12 @@ ...@@ -13,12 +13,12 @@
.col-sm-10 .col-sm-10
= form.check_box :active, disabled: disable_fields_service?(@service) = form.check_box :active, disabled: disable_fields_service?(@service)
- if @service.supported_events.present? - if @service.configurable_events.present?
.form-group .form-group
= form.label :url, "Trigger", class: 'control-label' = form.label :url, "Trigger", class: 'control-label'
.col-sm-10 .col-sm-10
- @service.supported_events.each do |event| - @service.configurable_events.each do |event|
%div %div
= form.check_box service_event_field_name(event), class: 'pull-left' = form.check_box service_event_field_name(event), class: 'pull-left'
.prepend-left-20 .prepend-left-20
......
---
title: Avoid showing unnecessary Trigger checkboxes for project Integrations with
only one event
merge_request: 17607
author:
type: changed
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
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