Commit 009829e5 authored by Justin Ho's avatar Justin Ho

Extract TriggerFields to Vue component

Pass data on form schema and values from backend
parent b7d15b5f
<script> <script>
import ActiveToggle from './active_toggle.vue'; import ActiveToggle from './active_toggle.vue';
import JiraTriggerFields from './jira_trigger_fields.vue'; import JiraTriggerFields from './jira_trigger_fields.vue';
import TriggerFields from './trigger_fields.vue';
export default { export default {
name: 'IntegrationForm', name: 'IntegrationForm',
components: { components: {
ActiveToggle, ActiveToggle,
JiraTriggerFields, JiraTriggerFields,
TriggerFields,
}, },
props: { props: {
activeToggleProps: { activeToggleProps: {
...@@ -21,6 +23,11 @@ export default { ...@@ -21,6 +23,11 @@ export default {
type: Object, type: Object,
required: true, required: true,
}, },
triggerEvents: {
type: Array,
required: false,
default: () => [],
},
type: { type: {
type: String, type: String,
required: true, required: true,
...@@ -38,5 +45,6 @@ export default { ...@@ -38,5 +45,6 @@ export default {
<div> <div>
<active-toggle v-if="showActive" v-bind="activeToggleProps" /> <active-toggle v-if="showActive" v-bind="activeToggleProps" />
<jira-trigger-fields v-if="isJira" v-bind="triggerFieldsProps" /> <jira-trigger-fields v-if="isJira" v-bind="triggerFieldsProps" />
<trigger-fields v-else :events="triggerEvents" :type="type" />
</div> </div>
</template> </template>
<script>
import { startCase } from 'lodash';
import { __ } from '~/locale';
import { GlFormGroup, GlFormCheckbox, GlFormInput } from '@gitlab/ui';
export default {
name: 'TriggerFields',
components: {
GlFormGroup,
GlFormCheckbox,
GlFormInput,
},
props: {
events: {
type: Array,
required: false,
default: null,
},
type: {
type: String,
required: true,
},
},
computed: {
placeholder() {
if (this.type === 'slack') {
return __('Slack channels (e.g. general, development)');
} else if (this.type === 'mattermost') {
return __('Channel handle (e.g. town-square)');
}
return null;
},
},
methods: {
checkboxName(name) {
return `service[${name}]`;
},
checkboxTitle(title) {
return startCase(title);
},
fieldName(name) {
return `service[${name}]`;
},
},
};
</script>
<template>
<gl-form-group label="Trigger" label-for="trigger-fields">
<div id="trigger-fields">
<gl-form-group v-for="event in events" :key="event.title" :description="event.description">
<input :name="checkboxName(event.name)" type="hidden" value="false" />
<gl-form-checkbox v-model="event.value" :name="checkboxName(event.name)">
{{ checkboxTitle(event.title) }}
</gl-form-checkbox>
<gl-form-input
v-if="event.field.name"
v-model="event.field.value"
:name="fieldName(event.field.name)"
:placeholder="placeholder"
/>
</gl-form-group>
</div>
</gl-form-group>
</template>
...@@ -15,7 +15,7 @@ export default el => { ...@@ -15,7 +15,7 @@ export default el => {
return result; return result;
} }
const { type, commentDetail, ...booleanAttributes } = el.dataset; const { type, commentDetail, triggerEvents, ...booleanAttributes } = el.dataset;
const { const {
showActive, showActive,
activated, activated,
...@@ -40,6 +40,7 @@ export default el => { ...@@ -40,6 +40,7 @@ export default el => {
initialEnableComments: enableComments, initialEnableComments: enableComments,
initialCommentDetail: commentDetail, initialCommentDetail: commentDetail,
}, },
triggerEvents: JSON.parse(triggerEvents),
}, },
}); });
}, },
......
...@@ -170,6 +170,19 @@ class Service < ApplicationRecord ...@@ -170,6 +170,19 @@ class Service < ApplicationRecord
end end
end end
def configurable_events_json
configurable_events.map do |event|
event_method = ServicesHelper.service_event_field_name(event)
result = { title: event, name: event_method, value: send(event_method), description: self.class.event_description(event) } # rubocop:disable GitlabSecurity/PublicSend
field = event_field(event)
if field
result.merge({ field: { name: field[:name], value: send(field[:name]) } }) # rubocop:disable GitlabSecurity/PublicSend
else
result
end
end.to_json
end
def configurable_event_actions def configurable_event_actions
self.class.supported_event_actions self.class.supported_event_actions
end end
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
.service-settings .service-settings
.js-vue-integration-settings{ data: { show_active: @service.show_active_box?.to_s, activated: (@service.active || @service.new_record?).to_s, type: @service.to_param, merge_request_events: @service.merge_requests_events.to_s, .js-vue-integration-settings{ data: { show_active: @service.show_active_box?.to_s, activated: (@service.active || @service.new_record?).to_s, type: @service.to_param, merge_request_events: @service.merge_requests_events.to_s,
commit_events: @service.commit_events.to_s, enable_comments: @service.comment_on_event_enabled.to_s, comment_detail: @service.comment_detail } } commit_events: @service.commit_events.to_s, enable_comments: @service.comment_on_event_enabled.to_s, comment_detail: @service.comment_detail, trigger_events: @service.configurable_events_json } }
- if @service.configurable_events.present? && !@service.is_a?(JiraService) - if @service.configurable_events.present? && !@service.is_a?(JiraService)
.form-group.row .form-group.row
......
...@@ -3760,6 +3760,9 @@ msgstr "" ...@@ -3760,6 +3760,9 @@ msgstr ""
msgid "Changing group path can have unintended side effects." msgid "Changing group path can have unintended side effects."
msgstr "" msgstr ""
msgid "Channel handle (e.g. town-square)"
msgstr ""
msgid "Charts" msgid "Charts"
msgstr "" msgstr ""
......
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