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>
import { mapState } from 'vuex';
import { GlNewDropdown, GlNewDropdownItem, GlLink } from '@gitlab/ui';
import { s__ } from '~/locale';
import { defaultIntegrationLevel, overrideDropdownDescriptions } from '../constants';
const dropdownOptions = [
{
......@@ -41,6 +43,16 @@ export default {
selected: dropdownOptions.find(x => x.value === this.override),
};
},
computed: {
...mapState(['adminState']),
description() {
const level = this.adminState.integrationLevel;
return (
overrideDropdownDescriptions[level] || overrideDropdownDescriptions[defaultIntegrationLevel]
);
},
},
methods: {
onClick(option) {
this.selected = option;
......@@ -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"
>
<span
>{{ s__('Integrations|Default settings are inherited from the instance level.') }}
>{{ description }}
<gl-link v-if="learnMorePath" :href="learnMorePath" target="_blank">{{
__('Learn more')
}}</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) {
triggerEvents,
fields,
inheritFromId,
integrationLevel,
...booleanAttributes
} = data;
const {
......@@ -56,6 +57,7 @@ function parseDatasetToProps(data) {
triggerEvents: JSON.parse(triggerEvents),
fields: JSON.parse(fields),
inheritFromId: parseInt(inheritFromId, 10),
integrationLevel,
id: parseInt(id, 10),
};
}
......
......@@ -11,6 +11,12 @@ module Groups
@integrations = Service.find_or_initialize_all(Service.for_group(group)).sort_by(&:title)
end
def edit
@admin_integration = Service.instance_for(integration.type)
super
end
private
def find_or_initialize_integration(name)
......
......@@ -95,7 +95,8 @@ module ServicesHelper
learn_more_path: integrations_help_page_path,
trigger_events: trigger_events_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
......@@ -120,6 +121,18 @@ module ServicesHelper
end
extend self
private
def integration_level(integration)
if integration.instance
'instance'
elsif integration.group_id
'group'
else
'project'
end
end
end
ServicesHelper.prepend_if_ee('EE::ServicesHelper')
......
......@@ -13270,6 +13270,9 @@ msgstr ""
msgid "Integrations|Comment settings:"
msgstr ""
msgid "Integrations|Default settings are inherited from the group level."
msgstr ""
msgid "Integrations|Default settings are inherited from the instance level."
msgstr ""
......
import { shallowMount } from '@vue/test-utils';
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';
describe('OverrideDropdown', () => {
......@@ -11,9 +13,16 @@ describe('OverrideDropdown', () => {
override: true,
};
const createComponent = (props = {}) => {
const defaultAdminStateProps = {
integrationLevel: 'group',
};
const createComponent = (props = {}, adminStateProps = {}) => {
wrapper = shallowMount(OverrideDropdown, {
propsData: { ...defaultProps, ...props },
store: createStore({
adminState: { ...defaultAdminStateProps, ...adminStateProps },
}),
});
};
......@@ -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', () => {
it('renders GlLink with correct link', () => {
createComponent({
......
......@@ -21,7 +21,8 @@ RSpec.describe ServicesHelper do
:comment_detail,
:trigger_events,
:fields,
:inherit_from_id
:inherit_from_id,
:integration_level
)
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