Commit 5f0e9379 authored by Martin Wortschack's avatar Martin Wortschack

Add mergeRequests module to store

- Move existing store implementation
to mergeRequests module.
parent 5360564b
...@@ -29,7 +29,7 @@ export default { ...@@ -29,7 +29,7 @@ export default {
}, },
}, },
computed: { computed: {
...mapState({ ...mapState('mergeRequests', {
isLoading: 'isLoading', isLoading: 'isLoading',
perPage: state => state.pageInfo.perPage, perPage: state => state.pageInfo.perPage,
totalItems: state => state.pageInfo.total, totalItems: state => state.pageInfo.total,
...@@ -58,7 +58,7 @@ export default { ...@@ -58,7 +58,7 @@ export default {
this.fetchMergeRequests(); this.fetchMergeRequests();
}, },
methods: { methods: {
...mapActions(['setProjectId', 'fetchMergeRequests', 'setPage']), ...mapActions('mergeRequests', ['setProjectId', 'fetchMergeRequests', 'setPage']),
}, },
}; };
</script> </script>
......
...@@ -20,7 +20,7 @@ export default { ...@@ -20,7 +20,7 @@ export default {
GlTooltip: GlTooltipDirective, GlTooltip: GlTooltipDirective,
}, },
computed: { computed: {
...mapState(['mergeRequests']), ...mapState('mergeRequests', ['mergeRequests']),
}, },
methods: { methods: {
getTimeAgoString(createdAt) { getTimeAgoString(createdAt) {
......
...@@ -21,6 +21,6 @@ export default class FilteredSearchCodeReviewAnalytics extends FilteredSearchMan ...@@ -21,6 +21,6 @@ export default class FilteredSearchCodeReviewAnalytics extends FilteredSearchMan
*/ */
updateObject = path => { updateObject = path => {
const filters = urlParamsToObject(path); const filters = urlParamsToObject(path);
store.dispatch('setFilters', filters); store.dispatch('mergeRequests/setFilters', filters);
}; };
} }
import Vue from 'vue'; import Vue from 'vue';
import Vuex from 'vuex'; import Vuex from 'vuex';
import * as actions from './actions'; import mergeRequests from './modules/merge_requests/index';
import mutations from './mutations';
import state from './state';
Vue.use(Vuex); Vue.use(Vuex);
const createStore = () => const createStore = () =>
new Vuex.Store({ new Vuex.Store({
state: state(), modules: {
actions, mergeRequests,
mutations, },
}); });
export default createStore(); export default createStore();
...@@ -15,11 +15,15 @@ export const setFilters = ({ commit, dispatch }, { label_name, milestone_title } ...@@ -15,11 +15,15 @@ export const setFilters = ({ commit, dispatch }, { label_name, milestone_title }
export const fetchMergeRequests = ({ dispatch, state }) => { export const fetchMergeRequests = ({ dispatch, state }) => {
dispatch('requestMergeRequests'); dispatch('requestMergeRequests');
const { projectId, filters, pageInfo } = state; const {
projectId,
filters: { milestoneTitle, labelName },
pageInfo,
} = state;
const params = { const params = {
project_id: projectId, project_id: projectId,
milestone_title: filters.milestoneTitle, milestone_title: milestoneTitle,
label_name: filters.labelName, label_name: labelName,
page: pageInfo.page, page: pageInfo.page,
}; };
......
import * as actions from './actions';
import mutations from './mutations';
import state from './state';
export default {
namespaced: true,
state: state(),
actions,
mutations,
};
...@@ -3,7 +3,7 @@ import Vuex from 'vuex'; ...@@ -3,7 +3,7 @@ import Vuex from 'vuex';
import { GlLoadingIcon, GlEmptyState, GlBadge, GlPagination } from '@gitlab/ui'; import { GlLoadingIcon, GlEmptyState, GlBadge, GlPagination } from '@gitlab/ui';
import CodeReviewAnalyticsApp from 'ee/analytics/code_review_analytics/components/app.vue'; import CodeReviewAnalyticsApp from 'ee/analytics/code_review_analytics/components/app.vue';
import MergeRequestTable from 'ee/analytics/code_review_analytics/components/merge_request_table.vue'; import MergeRequestTable from 'ee/analytics/code_review_analytics/components/merge_request_table.vue';
import createState from 'ee/analytics/code_review_analytics/store/state'; import createState from 'ee/analytics/code_review_analytics/store/modules/merge_requests/state';
jest.mock('ee/analytics/code_review_analytics/filtered_search_code_review_analytics', () => jest.mock('ee/analytics/code_review_analytics/filtered_search_code_review_analytics', () =>
jest.fn().mockImplementation(() => ({ jest.fn().mockImplementation(() => ({
...@@ -29,18 +29,23 @@ describe('CodeReviewAnalyticsApp component', () => { ...@@ -29,18 +29,23 @@ describe('CodeReviewAnalyticsApp component', () => {
const createStore = (initialState = {}, getters = {}) => const createStore = (initialState = {}, getters = {}) =>
new Vuex.Store({ new Vuex.Store({
state: { modules: {
...createState(), mergeRequests: {
...initialState, namespaced: true,
}, state: {
actions: { ...createState(),
setProjectId: jest.fn(), ...initialState,
setPage, },
fetchMergeRequests, actions: {
}, setProjectId: jest.fn(),
getters: { setPage,
showMrCount: () => false, fetchMergeRequests,
...getters, },
getters: {
showMrCount: () => false,
...getters,
},
},
}, },
}); });
......
...@@ -2,7 +2,7 @@ import { createLocalVue, mount } from '@vue/test-utils'; ...@@ -2,7 +2,7 @@ import { createLocalVue, mount } from '@vue/test-utils';
import Vuex from 'vuex'; import Vuex from 'vuex';
import { GlTable } from '@gitlab/ui'; import { GlTable } from '@gitlab/ui';
import MergeRequestTable from 'ee/analytics/code_review_analytics/components/merge_request_table.vue'; import MergeRequestTable from 'ee/analytics/code_review_analytics/components/merge_request_table.vue';
import createState from 'ee/analytics/code_review_analytics/store/state'; import createState from 'ee/analytics/code_review_analytics/store/modules/merge_requests/state';
import mergeRequests from '../mock_data'; import mergeRequests from '../mock_data';
const localVue = createLocalVue(); const localVue = createLocalVue();
...@@ -14,9 +14,14 @@ describe('MergeRequestTable component', () => { ...@@ -14,9 +14,14 @@ describe('MergeRequestTable component', () => {
const createStore = (initialState = {}) => const createStore = (initialState = {}) =>
new Vuex.Store({ new Vuex.Store({
state: { modules: {
...createState(), mergeRequests: {
...initialState, namespaced: true,
state: {
...createState(),
...initialState,
},
},
}, },
}); });
......
import axios from 'axios'; import axios from 'axios';
import MockAdapter from 'axios-mock-adapter'; import MockAdapter from 'axios-mock-adapter';
import testAction from 'helpers/vuex_action_helper'; import testAction from 'helpers/vuex_action_helper';
import * as actions from 'ee/analytics/code_review_analytics/store/actions'; import * as actions from 'ee/analytics/code_review_analytics/store/modules/merge_requests/actions';
import * as types from 'ee/analytics/code_review_analytics/store/mutation_types'; import * as types from 'ee/analytics/code_review_analytics/store/modules/merge_requests/mutation_types';
import getInitialState from 'ee/analytics/code_review_analytics/store/state'; import getInitialState from 'ee/analytics/code_review_analytics/store/modules/merge_requests/state';
import createFlash from '~/flash'; import createFlash from '~/flash';
import mockMergeRequests from '../mock_data'; import mockMergeRequests from '../../../mock_data';
jest.mock('~/flash', () => jest.fn()); jest.mock('~/flash', () => jest.fn());
......
import * as types from 'ee/analytics/code_review_analytics/store/mutation_types'; import * as types from 'ee/analytics/code_review_analytics/store/modules/merge_requests/mutation_types';
import mutations from 'ee/analytics/code_review_analytics/store/mutations'; import mutations from 'ee/analytics/code_review_analytics/store/modules/merge_requests/mutations';
import getInitialState from 'ee/analytics/code_review_analytics/store/state'; import getInitialState from 'ee/analytics/code_review_analytics/store/modules/merge_requests/state';
import { mockMergeRequests } from '../../productivity_analytics/mock_data'; import mockMergeRequests from '../../../mock_data';
describe('Code review analytics mutations', () => { describe('Code review analytics mutations', () => {
let state; let state;
......
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