Commit 31f2788f authored by Paul Slaughter's avatar Paul Slaughter

Merge branch '332280-integration-settings-template-refactor-vue-app' into 'master'

Use provide instead of props for IntegrationForm

See merge request gitlab-org/gitlab!81811
parents b52d73ca 425890c6
import { s__, __ } from '~/locale'; import { s__, __ } from '~/locale';
export const integrationLevels = { export const integrationLevels = {
PROJECT: 'project',
GROUP: 'group', GROUP: 'group',
INSTANCE: 'instance', INSTANCE: 'instance',
}; };
......
...@@ -3,6 +3,7 @@ import { GlButton, GlModalDirective, GlSafeHtmlDirective as SafeHtml, GlForm } f ...@@ -3,6 +3,7 @@ import { GlButton, GlModalDirective, GlSafeHtmlDirective as SafeHtml, GlForm } f
import axios from 'axios'; import axios from 'axios';
import * as Sentry from '@sentry/browser'; import * as Sentry from '@sentry/browser';
import { mapState, mapActions, mapGetters } from 'vuex'; import { mapState, mapActions, mapGetters } from 'vuex';
import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin'; import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import { import {
I18N_FETCH_TEST_SETTINGS_DEFAULT_ERROR_MESSAGE, I18N_FETCH_TEST_SETTINGS_DEFAULT_ERROR_MESSAGE,
...@@ -41,10 +42,8 @@ export default { ...@@ -41,10 +42,8 @@ export default {
SafeHtml, SafeHtml,
}, },
mixins: [glFeatureFlagsMixin()], mixins: [glFeatureFlagsMixin()],
props: { inject: {
helpHtml: { helpHtml: {
type: String,
required: false,
default: '', default: '',
}, },
}, },
...@@ -81,28 +80,28 @@ export default { ...@@ -81,28 +80,28 @@ export default {
disableButtons() { disableButtons() {
return Boolean(this.isSaving || this.isResetting || this.isTesting); return Boolean(this.isSaving || this.isResetting || this.isTesting);
}, },
form() {
return this.$refs.integrationForm.$el;
},
}, },
methods: { methods: {
...mapActions(['setOverride', 'requestJiraIssueTypes']), ...mapActions(['setOverride', 'requestJiraIssueTypes']),
form() {
return this.$refs.integrationForm.$el;
},
setIsValidated() { setIsValidated() {
this.isValidated = true; this.isValidated = true;
}, },
onSaveClick() { onSaveClick() {
this.isSaving = true; this.isSaving = true;
if (this.integrationActive && !this.form.checkValidity()) { if (this.integrationActive && !this.form().checkValidity()) {
this.isSaving = false; this.isSaving = false;
this.setIsValidated(); this.setIsValidated();
return; return;
} }
this.form.submit(); this.form().submit();
}, },
onTestClick() { onTestClick() {
if (!this.form.checkValidity()) { if (!this.form().checkValidity()) {
this.setIsValidated(); this.setIsValidated();
return; return;
} }
...@@ -147,7 +146,7 @@ export default { ...@@ -147,7 +146,7 @@ export default {
this.requestJiraIssueTypes(this.getFormData()); this.requestJiraIssueTypes(this.getFormData());
}, },
getFormData() { getFormData() {
return new FormData(this.form); return new FormData(this.form());
}, },
onToggleIntegrationState(integrationActive) { onToggleIntegrationState(integrationActive) {
this.integrationActive = integrationActive; this.integrationActive = integrationActive;
......
...@@ -116,13 +116,13 @@ export default function initIntegrationSettingsForm() { ...@@ -116,13 +116,13 @@ export default function initIntegrationSettingsForm() {
return new Vue({ return new Vue({
el: customSettingsEl, el: customSettingsEl,
name: 'IntegrationEditRoot',
store: createStore(initialState), store: createStore(initialState),
render(createElement) { provide: {
return createElement(IntegrationForm, {
props: {
helpHtml, helpHtml,
}, },
}); render(createElement) {
return createElement(IntegrationForm);
}, },
}); });
} }
import { integrationLevels } from '~/integrations/constants';
export const isInheriting = (state) => (state.defaultState === null ? false : !state.override); export const isInheriting = (state) => (state.defaultState === null ? false : !state.override);
export const isProjectLevel = (state) =>
state.customState.integrationLevel === integrationLevels.PROJECT;
export const propsSource = (state, getters) => export const propsSource = (state, getters) =>
getters.isInheriting ? state.defaultState : state.customState; getters.isInheriting ? state.defaultState : state.customState;
......
...@@ -113,7 +113,7 @@ export default { ...@@ -113,7 +113,7 @@ export default {
return ''; return '';
}, },
}, },
created() { mounted() {
if (this.initialIsEnabled) { if (this.initialIsEnabled) {
this.requestJiraIssueTypes(); this.requestJiraIssueTypes();
} }
......
...@@ -37,7 +37,7 @@ describe('IntegrationForm', () => { ...@@ -37,7 +37,7 @@ describe('IntegrationForm', () => {
const createComponent = ({ const createComponent = ({
customStateProps = {}, customStateProps = {},
initialState = {}, initialState = {},
props = {}, provide = {},
mountFn = shallowMountExtended, mountFn = shallowMountExtended,
} = {}) => { } = {}) => {
const store = createStore({ const store = createStore({
...@@ -47,7 +47,7 @@ describe('IntegrationForm', () => { ...@@ -47,7 +47,7 @@ describe('IntegrationForm', () => {
dispatch = jest.spyOn(store, 'dispatch').mockImplementation(); dispatch = jest.spyOn(store, 'dispatch').mockImplementation();
wrapper = mountFn(IntegrationForm, { wrapper = mountFn(IntegrationForm, {
propsData: { ...props }, provide,
store, store,
stubs: { stubs: {
OverrideDropdown, OverrideDropdown,
...@@ -300,7 +300,7 @@ describe('IntegrationForm', () => { ...@@ -300,7 +300,7 @@ describe('IntegrationForm', () => {
}); });
}); });
describe('with `helpHtml` prop', () => { describe('with `helpHtml` provided', () => {
const mockTestId = 'jest-help-html-test'; const mockTestId = 'jest-help-html-test';
setHTMLFixture(` setHTMLFixture(`
...@@ -316,7 +316,7 @@ describe('IntegrationForm', () => { ...@@ -316,7 +316,7 @@ describe('IntegrationForm', () => {
const mockHelpHtml = document.querySelector(`[data-testid="${mockTestId}"]`); const mockHelpHtml = document.querySelector(`[data-testid="${mockTestId}"]`);
createComponent({ createComponent({
props: { provide: {
helpHtml: mockHelpHtml.outerHTML, helpHtml: mockHelpHtml.outerHTML,
}, },
}); });
......
...@@ -13,6 +13,7 @@ export const mockIntegrationProps = { ...@@ -13,6 +13,7 @@ export const mockIntegrationProps = {
fields: [], fields: [],
type: '', type: '',
inheritFromId: 25, inheritFromId: 25,
integrationLevel: 'project',
}; };
export const mockJiraIssueTypes = [ export const mockJiraIssueTypes = [
......
import { currentKey, isInheriting, propsSource } from '~/integrations/edit/store/getters'; import {
currentKey,
isInheriting,
isProjectLevel,
propsSource,
} from '~/integrations/edit/store/getters';
import createState from '~/integrations/edit/store/state'; import createState from '~/integrations/edit/store/state';
import { integrationLevels } from '~/integrations/constants';
import { mockIntegrationProps } from '../mock_data'; import { mockIntegrationProps } from '../mock_data';
describe('Integration form store getters', () => { describe('Integration form store getters', () => {
...@@ -45,6 +52,18 @@ describe('Integration form store getters', () => { ...@@ -45,6 +52,18 @@ describe('Integration form store getters', () => {
}); });
}); });
describe('isProjectLevel', () => {
it.each`
integrationLevel | expected
${integrationLevels.PROJECT} | ${true}
${integrationLevels.GROUP} | ${false}
${integrationLevels.INSTANCE} | ${false}
`('when integrationLevel is `$integrationLevel`', ({ integrationLevel, expected }) => {
state.customState.integrationLevel = integrationLevel;
expect(isProjectLevel(state)).toBe(expected);
});
});
describe('propsSource', () => { describe('propsSource', () => {
beforeEach(() => { beforeEach(() => {
state.defaultState = defaultState; state.defaultState = defaultState;
......
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