Commit 8f145c96 authored by Kushal Pandya's avatar Kushal Pandya

Merge branch 'psi-error-tracking-mapstate' into 'master'

Move error_tracking state closer to component

See merge request gitlab-org/gitlab!19542
parents 71780b50 e6e96890
...@@ -43,16 +43,7 @@ export default { ...@@ -43,16 +43,7 @@ export default {
'isProjectInvalid', 'isProjectInvalid',
'projectSelectionLabel', 'projectSelectionLabel',
]), ]),
...mapState([ ...mapState(['enabled', 'projects', 'selectedProject', 'settingsLoading', 'token']),
'apiHost',
'connectError',
'connectSuccessful',
'enabled',
'projects',
'selectedProject',
'settingsLoading',
'token',
]),
}, },
created() { created() {
this.setInitialState({ this.setInitialState({
...@@ -65,15 +56,7 @@ export default { ...@@ -65,15 +56,7 @@ export default {
}); });
}, },
methods: { methods: {
...mapActions([ ...mapActions(['setInitialState', 'updateEnabled', 'updateSelectedProject', 'updateSettings']),
'fetchProjects',
'setInitialState',
'updateApiHost',
'updateEnabled',
'updateSelectedProject',
'updateSettings',
'updateToken',
]),
handleSubmit() { handleSubmit() {
this.updateSettings(); this.updateSettings();
}, },
...@@ -95,15 +78,7 @@ export default { ...@@ -95,15 +78,7 @@ export default {
s__('ErrorTracking|Active') s__('ErrorTracking|Active')
}}</label> }}</label>
</div> </div>
<error-tracking-form <error-tracking-form />
:api-host="apiHost"
:connect-error="connectError"
:connect-successful="connectSuccessful"
:token="token"
@handle-connect="fetchProjects"
@update-api-host="updateApiHost"
@update-token="updateToken"
/>
<div class="form-group"> <div class="form-group">
<project-dropdown <project-dropdown
:has-projects="hasProjects" :has-projects="hasProjects"
......
<script> <script>
import { mapActions, mapState } from 'vuex';
import { GlButton, GlFormInput } from '@gitlab/ui'; import { GlButton, GlFormInput } from '@gitlab/ui';
import Icon from '~/vue_shared/components/icon.vue'; import Icon from '~/vue_shared/components/icon.vue';
export default { export default {
components: { GlButton, GlFormInput, Icon }, components: { GlButton, GlFormInput, Icon },
props: {
apiHost: {
type: String,
required: true,
},
connectError: {
type: Boolean,
required: true,
},
connectSuccessful: {
type: Boolean,
required: true,
},
token: {
type: String,
required: true,
},
},
computed: { computed: {
...mapState(['apiHost', 'connectError', 'connectSuccessful', 'token']),
tokenInputState() { tokenInputState() {
return this.connectError ? false : null; return this.connectError ? false : null;
}, },
}, },
methods: {
...mapActions(['fetchProjects', 'updateApiHost', 'updateToken']),
},
}; };
</script> </script>
...@@ -41,7 +28,7 @@ export default { ...@@ -41,7 +28,7 @@ export default {
id="error-tracking-api-host" id="error-tracking-api-host"
:value="apiHost" :value="apiHost"
placeholder="https://mysentryserver.com" placeholder="https://mysentryserver.com"
@input="$emit('update-api-host', $event)" @input="updateApiHost"
/> />
<!-- eslint-enable @gitlab/vue-i18n/no-bare-attribute-strings --> <!-- eslint-enable @gitlab/vue-i18n/no-bare-attribute-strings -->
</div> </div>
...@@ -60,15 +47,13 @@ export default { ...@@ -60,15 +47,13 @@ export default {
id="error-tracking-token" id="error-tracking-token"
:value="token" :value="token"
:state="tokenInputState" :state="tokenInputState"
@input="$emit('update-token', $event)" @input="updateToken"
/> />
</div> </div>
<div class="col-4 col-md-3 gl-pl-0"> <div class="col-4 col-md-3 gl-pl-0">
<gl-button <gl-button class="js-error-tracking-connect prepend-left-5" @click="fetchProjects">{{
class="js-error-tracking-connect prepend-left-5" __('Connect')
@click="$emit('handle-connect')" }}</gl-button>
>{{ __('Connect') }}</gl-button
>
<icon <icon
v-show="connectSuccessful" v-show="connectSuccessful"
class="js-error-tracking-connect-success prepend-left-5 text-success align-middle" class="js-error-tracking-connect-success prepend-left-5 text-success align-middle"
......
...@@ -2,6 +2,7 @@ import Vuex from 'vuex'; ...@@ -2,6 +2,7 @@ import Vuex from 'vuex';
import { createLocalVue, shallowMount } from '@vue/test-utils'; import { createLocalVue, shallowMount } from '@vue/test-utils';
import { GlButton, GlFormInput } from '@gitlab/ui'; import { GlButton, GlFormInput } from '@gitlab/ui';
import ErrorTrackingForm from '~/error_tracking_settings/components/error_tracking_form.vue'; import ErrorTrackingForm from '~/error_tracking_settings/components/error_tracking_form.vue';
import createStore from '~/error_tracking_settings/store';
import { defaultProps } from '../mock'; import { defaultProps } from '../mock';
const localVue = createLocalVue(); const localVue = createLocalVue();
...@@ -9,15 +10,18 @@ localVue.use(Vuex); ...@@ -9,15 +10,18 @@ localVue.use(Vuex);
describe('error tracking settings form', () => { describe('error tracking settings form', () => {
let wrapper; let wrapper;
let store;
function mountComponent() { function mountComponent() {
wrapper = shallowMount(ErrorTrackingForm, { wrapper = shallowMount(ErrorTrackingForm, {
localVue, localVue,
store,
propsData: defaultProps, propsData: defaultProps,
}); });
} }
beforeEach(() => { beforeEach(() => {
store = createStore();
mountComponent(); mountComponent();
}); });
...@@ -61,7 +65,7 @@ describe('error tracking settings form', () => { ...@@ -61,7 +65,7 @@ describe('error tracking settings form', () => {
describe('after a successful connection', () => { describe('after a successful connection', () => {
beforeEach(() => { beforeEach(() => {
wrapper.setProps({ connectSuccessful: true }); store.state.connectSuccessful = true;
}); });
it('shows the success checkmark', () => { it('shows the success checkmark', () => {
...@@ -77,7 +81,7 @@ describe('error tracking settings form', () => { ...@@ -77,7 +81,7 @@ describe('error tracking settings form', () => {
describe('after an unsuccessful connection', () => { describe('after an unsuccessful connection', () => {
beforeEach(() => { beforeEach(() => {
wrapper.setProps({ connectError: true }); store.state.connectError = true;
}); });
it('does not show the check mark', () => { it('does not show the check mark', () => {
......
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