Commit b48537f5 authored by Justin Ho Tuan Duong's avatar Justin Ho Tuan Duong Committed by Simon Knox

Use integrationLevel to show different copy

- Show different copy in OverrideDropdown depending
on value of integrationLevel as "group" / "instance".
- Add specs and constants.js file.
parent ecf1a375
<script> <script>
import { mapState } from 'vuex';
import { GlNewDropdown, GlNewDropdownItem, GlLink } from '@gitlab/ui'; import { GlNewDropdown, GlNewDropdownItem, GlLink } from '@gitlab/ui';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import { defaultIntegrationLevel, overrideDropdownDescriptions } from '../constants';
const dropdownOptions = [ const dropdownOptions = [
{ {
...@@ -41,6 +43,16 @@ export default { ...@@ -41,6 +43,16 @@ export default {
selected: dropdownOptions.find(x => x.value === this.override), selected: dropdownOptions.find(x => x.value === this.override),
}; };
}, },
computed: {
...mapState(['adminState']),
description() {
const level = this.adminState.integrationLevel;
return (
overrideDropdownDescriptions[level] || overrideDropdownDescriptions[defaultIntegrationLevel]
);
},
},
methods: { methods: {
onClick(option) { onClick(option) {
this.selected = option; this.selected = option;
...@@ -55,7 +67,7 @@ export default { ...@@ -55,7 +67,7 @@ export default {
class="gl-display-flex gl-justify-content-space-between gl-align-items-baseline gl-py-4 gl-mt-5 gl-mb-6 gl-border-t-1 gl-border-t-solid gl-border-b-1 gl-border-b-solid gl-border-gray-100" class="gl-display-flex gl-justify-content-space-between gl-align-items-baseline gl-py-4 gl-mt-5 gl-mb-6 gl-border-t-1 gl-border-t-solid gl-border-b-1 gl-border-b-solid gl-border-gray-100"
> >
<span <span
>{{ s__('Integrations|Default settings are inherited from the instance level.') }} >{{ description }}
<gl-link v-if="learnMorePath" :href="learnMorePath" target="_blank">{{ <gl-link v-if="learnMorePath" :href="learnMorePath" target="_blank">{{
__('Learn more') __('Learn more')
}}</gl-link> }}</gl-link>
......
import { s__ } from '~/locale';
export const integrationLevels = {
GROUP: 'group',
INSTANCE: 'instance',
};
export const defaultIntegrationLevel = integrationLevels.INSTANCE;
export const overrideDropdownDescriptions = {
[integrationLevels.GROUP]: s__(
'Integrations|Default settings are inherited from the group level.',
),
[integrationLevels.INSTANCE]: s__(
'Integrations|Default settings are inherited from the instance level.',
),
};
...@@ -23,6 +23,7 @@ function parseDatasetToProps(data) { ...@@ -23,6 +23,7 @@ function parseDatasetToProps(data) {
triggerEvents, triggerEvents,
fields, fields,
inheritFromId, inheritFromId,
integrationLevel,
...booleanAttributes ...booleanAttributes
} = data; } = data;
const { const {
...@@ -56,6 +57,7 @@ function parseDatasetToProps(data) { ...@@ -56,6 +57,7 @@ function parseDatasetToProps(data) {
triggerEvents: JSON.parse(triggerEvents), triggerEvents: JSON.parse(triggerEvents),
fields: JSON.parse(fields), fields: JSON.parse(fields),
inheritFromId: parseInt(inheritFromId, 10), inheritFromId: parseInt(inheritFromId, 10),
integrationLevel,
id: parseInt(id, 10), id: parseInt(id, 10),
}; };
} }
......
...@@ -11,6 +11,12 @@ module Groups ...@@ -11,6 +11,12 @@ module Groups
@integrations = Service.find_or_initialize_all(Service.for_group(group)).sort_by(&:title) @integrations = Service.find_or_initialize_all(Service.for_group(group)).sort_by(&:title)
end end
def edit
@admin_integration = Service.instance_for(integration.type)
super
end
private private
def find_or_initialize_integration(name) def find_or_initialize_integration(name)
......
...@@ -95,7 +95,8 @@ module ServicesHelper ...@@ -95,7 +95,8 @@ module ServicesHelper
learn_more_path: integrations_help_page_path, learn_more_path: integrations_help_page_path,
trigger_events: trigger_events_for_service(integration), trigger_events: trigger_events_for_service(integration),
fields: fields_for_service(integration), fields: fields_for_service(integration),
inherit_from_id: integration.inherit_from_id inherit_from_id: integration.inherit_from_id,
integration_level: integration_level(integration)
} }
end end
...@@ -120,6 +121,18 @@ module ServicesHelper ...@@ -120,6 +121,18 @@ module ServicesHelper
end end
extend self extend self
private
def integration_level(integration)
if integration.instance
'instance'
elsif integration.group_id
'group'
else
'project'
end
end
end end
ServicesHelper.prepend_if_ee('EE::ServicesHelper') ServicesHelper.prepend_if_ee('EE::ServicesHelper')
......
...@@ -13270,6 +13270,9 @@ msgstr "" ...@@ -13270,6 +13270,9 @@ msgstr ""
msgid "Integrations|Comment settings:" msgid "Integrations|Comment settings:"
msgstr "" msgstr ""
msgid "Integrations|Default settings are inherited from the group level."
msgstr ""
msgid "Integrations|Default settings are inherited from the instance level." msgid "Integrations|Default settings are inherited from the instance level."
msgstr "" msgstr ""
......
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import { GlNewDropdown, GlLink } from '@gitlab/ui'; import { GlNewDropdown, GlLink } from '@gitlab/ui';
import { createStore } from '~/integrations/edit/store';
import { integrationLevels, overrideDropdownDescriptions } from '~/integrations/edit/constants';
import OverrideDropdown from '~/integrations/edit/components/override_dropdown.vue'; import OverrideDropdown from '~/integrations/edit/components/override_dropdown.vue';
describe('OverrideDropdown', () => { describe('OverrideDropdown', () => {
...@@ -11,9 +13,16 @@ describe('OverrideDropdown', () => { ...@@ -11,9 +13,16 @@ describe('OverrideDropdown', () => {
override: true, override: true,
}; };
const createComponent = (props = {}) => { const defaultAdminStateProps = {
integrationLevel: 'group',
};
const createComponent = (props = {}, adminStateProps = {}) => {
wrapper = shallowMount(OverrideDropdown, { wrapper = shallowMount(OverrideDropdown, {
propsData: { ...defaultProps, ...props }, propsData: { ...defaultProps, ...props },
store: createStore({
adminState: { ...defaultAdminStateProps, ...adminStateProps },
}),
}); });
}; };
...@@ -44,6 +53,45 @@ describe('OverrideDropdown', () => { ...@@ -44,6 +53,45 @@ describe('OverrideDropdown', () => {
}); });
}); });
describe('integrationLevel is "project"', () => {
it('renders copy mentioning instance (as default fallback)', () => {
createComponent(
{},
{
integrationLevel: 'project',
},
);
expect(wrapper.text()).toContain(overrideDropdownDescriptions[integrationLevels.INSTANCE]);
});
});
describe('integrationLevel is "group"', () => {
it('renders copy mentioning group', () => {
createComponent(
{},
{
integrationLevel: 'group',
},
);
expect(wrapper.text()).toContain(overrideDropdownDescriptions[integrationLevels.GROUP]);
});
});
describe('integrationLevel is "instance"', () => {
it('renders copy mentioning instance', () => {
createComponent(
{},
{
integrationLevel: 'instance',
},
);
expect(wrapper.text()).toContain(overrideDropdownDescriptions[integrationLevels.INSTANCE]);
});
});
describe('learnMorePath is present', () => { describe('learnMorePath is present', () => {
it('renders GlLink with correct link', () => { it('renders GlLink with correct link', () => {
createComponent({ createComponent({
......
...@@ -21,7 +21,8 @@ RSpec.describe ServicesHelper do ...@@ -21,7 +21,8 @@ RSpec.describe ServicesHelper do
:comment_detail, :comment_detail,
:trigger_events, :trigger_events,
:fields, :fields,
:inherit_from_id :inherit_from_id,
:integration_level
) )
end 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