Commit bea71761 authored by Peter Hegman's avatar Peter Hegman

Merge branch 'define-integration-form-events-as-constants' into 'master'

Define integration form events as constants

See merge request gitlab-org/gitlab!71518
parents bdde0c34 619c78b6
export const TEST_INTEGRATION_EVENT = 'testIntegration';
export const SAVE_INTEGRATION_EVENT = 'saveIntegration';
export const GET_JIRA_ISSUE_TYPES_EVENT = 'getJiraIssueTypes';
export const TOGGLE_INTEGRATION_EVENT = 'toggleIntegration';
export const VALIDATE_INTEGRATION_FORM_EVENT = 'validateIntegrationForm';
<script> <script>
import { GlFormGroup, GlFormCheckbox } from '@gitlab/ui'; import { GlFormGroup, GlFormCheckbox } from '@gitlab/ui';
import { mapGetters } from 'vuex'; import { mapGetters } from 'vuex';
import { TOGGLE_INTEGRATION_EVENT } from '~/integrations/constants';
import eventHub from '../event_hub'; import eventHub from '../event_hub';
export default { export default {
...@@ -26,7 +27,7 @@ export default { ...@@ -26,7 +27,7 @@ export default {
}, },
methods: { methods: {
onChange(e) { onChange(e) {
eventHub.$emit('toggle', e); eventHub.$emit(TOGGLE_INTEGRATION_EVENT, e);
}, },
}, },
}; };
......
...@@ -9,6 +9,7 @@ import { ...@@ -9,6 +9,7 @@ import {
} from '@gitlab/ui'; } from '@gitlab/ui';
import { capitalize, lowerCase, isEmpty } from 'lodash'; import { capitalize, lowerCase, isEmpty } from 'lodash';
import { mapGetters } from 'vuex'; import { mapGetters } from 'vuex';
import { VALIDATE_INTEGRATION_FORM_EVENT } from '~/integrations/constants';
import eventHub from '../event_hub'; import eventHub from '../event_hub';
export default { export default {
...@@ -121,10 +122,10 @@ export default { ...@@ -121,10 +122,10 @@ export default {
if (this.isNonEmptyPassword) { if (this.isNonEmptyPassword) {
this.model = null; this.model = null;
} }
eventHub.$on('validateForm', this.validateForm); eventHub.$on(VALIDATE_INTEGRATION_FORM_EVENT, this.validateForm);
}, },
beforeDestroy() { beforeDestroy() {
eventHub.$off('validateForm', this.validateForm); eventHub.$off(VALIDATE_INTEGRATION_FORM_EVENT, this.validateForm);
}, },
methods: { methods: {
validateForm() { validateForm() {
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
import { GlButton, GlModalDirective, GlSafeHtmlDirective as SafeHtml } from '@gitlab/ui'; import { GlButton, GlModalDirective, GlSafeHtmlDirective as SafeHtml } from '@gitlab/ui';
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 { TEST_INTEGRATION_EVENT, SAVE_INTEGRATION_EVENT } from '~/integrations/constants';
import { integrationLevels } from '../constants'; import { integrationLevels } from '../constants';
import eventHub from '../event_hub'; import eventHub from '../event_hub';
...@@ -75,11 +76,11 @@ export default { ...@@ -75,11 +76,11 @@ export default {
]), ]),
onSaveClick() { onSaveClick() {
this.setIsSaving(true); this.setIsSaving(true);
eventHub.$emit('saveIntegration'); eventHub.$emit(SAVE_INTEGRATION_EVENT);
}, },
onTestClick() { onTestClick() {
this.setIsTesting(true); this.setIsTesting(true);
eventHub.$emit('testIntegration'); eventHub.$emit(TEST_INTEGRATION_EVENT);
}, },
onResetClick() { onResetClick() {
this.fetchResetIntegration(); this.fetchResetIntegration();
......
<script> <script>
import { GlFormGroup, GlFormCheckbox, GlFormInput, GlSprintf, GlLink } from '@gitlab/ui'; import { GlFormGroup, GlFormCheckbox, GlFormInput, GlSprintf, GlLink } from '@gitlab/ui';
import { mapGetters } from 'vuex'; import { mapGetters } from 'vuex';
import {
VALIDATE_INTEGRATION_FORM_EVENT,
GET_JIRA_ISSUE_TYPES_EVENT,
} from '~/integrations/constants';
import eventHub from '../event_hub'; import eventHub from '../event_hub';
import JiraUpgradeCta from './jira_upgrade_cta.vue'; import JiraUpgradeCta from './jira_upgrade_cta.vue';
...@@ -77,17 +81,17 @@ export default { ...@@ -77,17 +81,17 @@ export default {
}, },
}, },
created() { created() {
eventHub.$on('validateForm', this.validateForm); eventHub.$on(VALIDATE_INTEGRATION_FORM_EVENT, this.validateForm);
}, },
beforeDestroy() { beforeDestroy() {
eventHub.$off('validateForm', this.validateForm); eventHub.$off(VALIDATE_INTEGRATION_FORM_EVENT, this.validateForm);
}, },
methods: { methods: {
validateForm() { validateForm() {
this.validated = true; this.validated = true;
}, },
getJiraIssueTypes() { getJiraIssueTypes() {
eventHub.$emit('getJiraIssueTypes'); eventHub.$emit(GET_JIRA_ISSUE_TYPES_EVENT);
}, },
}, },
}; };
......
...@@ -9,6 +9,7 @@ import { ...@@ -9,6 +9,7 @@ import {
} from '@gitlab/ui'; } from '@gitlab/ui';
import { mapGetters } from 'vuex'; import { mapGetters } from 'vuex';
import { helpPagePath } from '~/helpers/help_page_helper'; import { helpPagePath } from '~/helpers/help_page_helper';
import { VALIDATE_INTEGRATION_FORM_EVENT } from '~/integrations/constants';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import eventHub from '../event_hub'; import eventHub from '../event_hub';
...@@ -118,10 +119,10 @@ export default { ...@@ -118,10 +119,10 @@ export default {
}, },
}, },
created() { created() {
eventHub.$on('validateForm', this.validateForm); eventHub.$on(VALIDATE_INTEGRATION_FORM_EVENT, this.validateForm);
}, },
beforeDestroy() { beforeDestroy() {
eventHub.$off('validateForm', this.validateForm); eventHub.$off(VALIDATE_INTEGRATION_FORM_EVENT, this.validateForm);
}, },
methods: { methods: {
validateForm() { validateForm() {
......
...@@ -4,6 +4,13 @@ import toast from '~/vue_shared/plugins/global_toast'; ...@@ -4,6 +4,13 @@ import toast from '~/vue_shared/plugins/global_toast';
import axios from '../lib/utils/axios_utils'; import axios from '../lib/utils/axios_utils';
import initForm from './edit'; import initForm from './edit';
import eventHub from './edit/event_hub'; import eventHub from './edit/event_hub';
import {
TEST_INTEGRATION_EVENT,
SAVE_INTEGRATION_EVENT,
GET_JIRA_ISSUE_TYPES_EVENT,
TOGGLE_INTEGRATION_EVENT,
VALIDATE_INTEGRATION_FORM_EVENT,
} from './constants';
export default class IntegrationSettingsForm { export default class IntegrationSettingsForm {
constructor(formSelector) { constructor(formSelector) {
...@@ -22,21 +29,19 @@ export default class IntegrationSettingsForm { ...@@ -22,21 +29,19 @@ export default class IntegrationSettingsForm {
document.querySelector('.js-vue-integration-settings'), document.querySelector('.js-vue-integration-settings'),
document.querySelector('.js-vue-default-integration-settings'), document.querySelector('.js-vue-default-integration-settings'),
); );
eventHub.$on('toggle', (active) => { eventHub.$on(TOGGLE_INTEGRATION_EVENT, (active) => {
this.formActive = active; this.formActive = active;
this.toggleServiceState(); this.toggleServiceState();
}); });
eventHub.$on('testIntegration', () => { eventHub.$on(TEST_INTEGRATION_EVENT, () => {
this.testIntegration(); this.testIntegration();
}); });
eventHub.$on('saveIntegration', () => { eventHub.$on(SAVE_INTEGRATION_EVENT, () => {
this.saveIntegration(); this.saveIntegration();
}); });
eventHub.$on('getJiraIssueTypes', () => { eventHub.$on(GET_JIRA_ISSUE_TYPES_EVENT, () => {
this.getJiraIssueTypes(new FormData(this.$form)); this.getJiraIssueTypes(new FormData(this.$form));
}); });
eventHub.$emit('formInitialized');
} }
saveIntegration() { saveIntegration() {
...@@ -52,7 +57,7 @@ export default class IntegrationSettingsForm { ...@@ -52,7 +57,7 @@ export default class IntegrationSettingsForm {
this.$form.submit(); this.$form.submit();
}, 100); }, 100);
} else { } else {
eventHub.$emit('validateForm'); eventHub.$emit(VALIDATE_INTEGRATION_FORM_EVENT);
this.vue.$store.dispatch('setIsSaving', false); this.vue.$store.dispatch('setIsSaving', false);
} }
} }
...@@ -66,7 +71,7 @@ export default class IntegrationSettingsForm { ...@@ -66,7 +71,7 @@ export default class IntegrationSettingsForm {
if (this.$form.checkValidity()) { if (this.$form.checkValidity()) {
this.testSettings(new FormData(this.$form)); this.testSettings(new FormData(this.$form));
} else { } else {
eventHub.$emit('validateForm'); eventHub.$emit(VALIDATE_INTEGRATION_FORM_EVENT);
this.vue.$store.dispatch('setIsTesting', false); this.vue.$store.dispatch('setIsTesting', false);
} }
} }
...@@ -106,7 +111,7 @@ export default class IntegrationSettingsForm { ...@@ -106,7 +111,7 @@ export default class IntegrationSettingsForm {
}, },
}) => { }) => {
if (error || !issuetypes?.length) { if (error || !issuetypes?.length) {
eventHub.$emit('validateForm'); eventHub.$emit(VALIDATE_INTEGRATION_FORM_EVENT);
throw new Error(message); throw new Error(message);
} }
......
import { GlFormCheckbox, GlFormInput } from '@gitlab/ui'; import { GlFormCheckbox, GlFormInput } from '@gitlab/ui';
import { mountExtended } from 'helpers/vue_test_utils_helper'; import { mountExtended } from 'helpers/vue_test_utils_helper';
import { GET_JIRA_ISSUE_TYPES_EVENT } from '~/integrations/constants';
import JiraIssuesFields from '~/integrations/edit/components/jira_issues_fields.vue'; import JiraIssuesFields from '~/integrations/edit/components/jira_issues_fields.vue';
import eventHub from '~/integrations/edit/event_hub'; import eventHub from '~/integrations/edit/event_hub';
import { createStore } from '~/integrations/edit/store'; import { createStore } from '~/integrations/edit/store';
...@@ -207,7 +208,7 @@ describe('JiraIssuesFields', () => { ...@@ -207,7 +208,7 @@ describe('JiraIssuesFields', () => {
await setEnableCheckbox(true); await setEnableCheckbox(true);
await findJiraForVulnerabilities().vm.$emit('request-get-issue-types'); await findJiraForVulnerabilities().vm.$emit('request-get-issue-types');
expect(eventHubEmitSpy).toHaveBeenCalledWith('getJiraIssueTypes'); expect(eventHubEmitSpy).toHaveBeenCalledWith(GET_JIRA_ISSUE_TYPES_EVENT);
}); });
}); });
}); });
......
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