Commit 88589d27 authored by Phil Hughes's avatar Phil Hughes

Merge branch 'mw-cr-add-filter-module' into 'master'

Code Review Analytics: Add filters module

See merge request gitlab-org/gitlab!30054
parents 48171f4f e03e7ad3
...@@ -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('mergeRequests/setFilters', filters); store.dispatch('filters/setFilters', filters);
}; };
} }
import Vue from 'vue'; import Vue from 'vue';
import Vuex from 'vuex'; import Vuex from 'vuex';
import filters from './modules/filters/index';
import mergeRequests from './modules/merge_requests/index'; import mergeRequests from './modules/merge_requests/index';
Vue.use(Vuex); Vue.use(Vuex);
...@@ -7,6 +8,7 @@ Vue.use(Vuex); ...@@ -7,6 +8,7 @@ Vue.use(Vuex);
const createStore = () => const createStore = () =>
new Vuex.Store({ new Vuex.Store({
modules: { modules: {
filters,
mergeRequests, mergeRequests,
}, },
}); });
......
import * as types from './mutation_types';
// eslint-disable-next-line import/prefer-default-export
export const setFilters = ({ commit, dispatch }, { label_name, milestone_title }) => {
commit(types.SET_FILTERS, { labelName: label_name, milestoneTitle: milestone_title });
dispatch('mergeRequests/setPage', 1, { root: true });
dispatch('mergeRequests/fetchMergeRequests', null, { root: true });
};
import state from './state';
import * as actions from './actions';
import mutations from './mutations';
export default {
namespaced: true,
actions,
mutations,
state: state(),
};
// eslint-disable-next-line import/prefer-default-export
export const SET_FILTERS = 'SET_FILTERS';
import * as types from './mutation_types';
export default {
[types.SET_FILTERS](state, { labelName, milestoneTitle }) {
state.labelName = labelName;
state.milestoneTitle = milestoneTitle;
},
};
export default () => ({
labelName: [],
milestoneTitle: null,
});
...@@ -6,23 +6,16 @@ import { normalizeHeaders, parseIntPagination } from '~/lib/utils/common_utils'; ...@@ -6,23 +6,16 @@ import { normalizeHeaders, parseIntPagination } from '~/lib/utils/common_utils';
export const setProjectId = ({ commit }, projectId) => commit(types.SET_PROJECT_ID, projectId); export const setProjectId = ({ commit }, projectId) => commit(types.SET_PROJECT_ID, projectId);
export const setFilters = ({ commit, dispatch }, { label_name, milestone_title }) => { export const fetchMergeRequests = ({ dispatch, state, rootState }) => {
commit(types.SET_FILTERS, { labelName: label_name, milestoneTitle: milestone_title }); dispatch('requestMergeRequests');
dispatch('fetchMergeRequests'); const { projectId, pageInfo } = state;
};
export const fetchMergeRequests = ({ dispatch, state }) => { const { milestoneTitle, labelName } = rootState.filters;
dispatch('requestMergeRequests');
const {
projectId,
filters: { milestoneTitle, labelName },
pageInfo,
} = state;
const params = { const params = {
project_id: projectId, project_id: projectId,
milestone_title: milestoneTitle, milestone_title: Array.isArray(milestoneTitle) ? milestoneTitle.join('') : milestoneTitle,
label_name: labelName, label_name: labelName,
page: pageInfo.page, page: pageInfo.page,
}; };
......
export const SET_PROJECT_ID = 'SET_PROJECT_ID'; export const SET_PROJECT_ID = 'SET_PROJECT_ID';
export const SET_FILTERS = 'SET_FILTERS';
export const REQUEST_MERGE_REQUESTS = 'REQUEST_MERGE_REQUESTS'; export const REQUEST_MERGE_REQUESTS = 'REQUEST_MERGE_REQUESTS';
export const RECEIVE_MERGE_REQUESTS_SUCCESS = 'RECEIVE_MERGE_REQUESTS_SUCCESS'; export const RECEIVE_MERGE_REQUESTS_SUCCESS = 'RECEIVE_MERGE_REQUESTS_SUCCESS';
......
...@@ -4,11 +4,6 @@ export default { ...@@ -4,11 +4,6 @@ export default {
[types.SET_PROJECT_ID](state, projectId) { [types.SET_PROJECT_ID](state, projectId) {
state.projectId = projectId; state.projectId = projectId;
}, },
[types.SET_FILTERS](state, { labelName, milestoneTitle }) {
state.filters.labelName = labelName;
state.filters.milestoneTitle = milestoneTitle;
state.pageInfo.page = 1;
},
[types.REQUEST_MERGE_REQUESTS](state) { [types.REQUEST_MERGE_REQUESTS](state) {
state.isLoading = true; state.isLoading = true;
}, },
......
...@@ -4,8 +4,4 @@ export default () => ({ ...@@ -4,8 +4,4 @@ export default () => ({
errorCode: null, errorCode: null,
mergeRequests: [], mergeRequests: [],
pageInfo: {}, pageInfo: {},
filters: {
labelName: [],
milestoneTitle: null,
},
}); });
import axios from 'axios';
import MockAdapter from 'axios-mock-adapter';
import testAction from 'helpers/vuex_action_helper';
import * as actions from 'ee/analytics/code_review_analytics/store/modules/filters/actions';
import * as types from 'ee/analytics/code_review_analytics/store/modules/filters/mutation_types';
import getInitialState from 'ee/analytics/code_review_analytics/store/modules/filters/state';
describe('Code review analytics filters actions', () => {
let state;
let mock;
beforeEach(() => {
state = getInitialState();
mock = new MockAdapter(axios);
});
afterEach(() => {
mock.restore();
});
describe('setFilters', () => {
const milestoneTitle = 'my milestone';
const labelName = ['first label', 'second label'];
it('commits the SET_FILTERS mutation', () => {
testAction(
actions.setFilters,
{ milestone_title: milestoneTitle, label_name: labelName },
state,
[
{
type: types.SET_FILTERS,
payload: { milestoneTitle, labelName },
},
],
[
{ type: 'mergeRequests/setPage', payload: 1 },
{ type: 'mergeRequests/fetchMergeRequests', payload: null },
],
);
});
});
});
import * as types from 'ee/analytics/code_review_analytics/store/modules/filters/mutation_types';
import mutations from 'ee/analytics/code_review_analytics/store/modules/filters/mutations';
import getInitialState from 'ee/analytics/code_review_analytics/store/modules/filters/state';
describe('Code review analytics filters mutations', () => {
let state;
const milestoneTitle = 'my milestone';
const labelName = ['first label', 'second label'];
beforeEach(() => {
state = getInitialState();
});
describe(types.SET_FILTERS, () => {
it('updates milestoneTitle and labelName', () => {
mutations[types.SET_FILTERS](state, { milestoneTitle, labelName });
expect(state.milestoneTitle).toBe(milestoneTitle);
expect(state.labelName).toBe(labelName);
});
});
});
...@@ -9,7 +9,7 @@ import mockMergeRequests from '../../../mock_data'; ...@@ -9,7 +9,7 @@ import mockMergeRequests from '../../../mock_data';
jest.mock('~/flash', () => jest.fn()); jest.mock('~/flash', () => jest.fn());
describe('Code review analytics actions', () => { describe('Code review analytics mergeRequests actions', () => {
let state; let state;
let mock; let mock;
...@@ -32,7 +32,13 @@ describe('Code review analytics actions', () => { ...@@ -32,7 +32,13 @@ describe('Code review analytics actions', () => {
}; };
beforeEach(() => { beforeEach(() => {
state = getInitialState(); state = {
filters: {
milestoneTitle: null,
labelName: [],
},
...getInitialState(),
};
mock = new MockAdapter(axios); mock = new MockAdapter(axios);
}); });
...@@ -142,26 +148,6 @@ describe('Code review analytics actions', () => { ...@@ -142,26 +148,6 @@ describe('Code review analytics actions', () => {
})); }));
}); });
describe('setFilters', () => {
const milestoneTitle = 'my milestone';
const labelName = ['first label', 'second label'];
it('commits the SET_FILTERS mutation', () => {
testAction(
actions.setFilters,
{ milestone_title: milestoneTitle, label_name: labelName },
state,
[
{
type: types.SET_FILTERS,
payload: { milestoneTitle, labelName },
},
],
[{ type: 'fetchMergeRequests' }],
);
});
});
describe('setPage', () => { describe('setPage', () => {
it('commits SET_PAGE mutation', () => { it('commits SET_PAGE mutation', () => {
testAction(actions.setPage, 2, state, [{ type: types.SET_PAGE, payload: 2 }], []); testAction(actions.setPage, 2, state, [{ type: types.SET_PAGE, payload: 2 }], []);
......
...@@ -3,12 +3,9 @@ import mutations from 'ee/analytics/code_review_analytics/store/modules/merge_re ...@@ -3,12 +3,9 @@ import mutations from 'ee/analytics/code_review_analytics/store/modules/merge_re
import getInitialState from 'ee/analytics/code_review_analytics/store/modules/merge_requests/state'; import getInitialState from 'ee/analytics/code_review_analytics/store/modules/merge_requests/state';
import mockMergeRequests from '../../../mock_data'; import mockMergeRequests from '../../../mock_data';
describe('Code review analytics mutations', () => { describe('Code review analytics mergeRequests mutations', () => {
let state; let state;
const milestoneTitle = 'my milestone';
const labelName = ['first label', 'second label'];
const pageInfo = { const pageInfo = {
page: 1, page: 1,
nextPage: 2, nextPage: 2,
...@@ -30,16 +27,6 @@ describe('Code review analytics mutations', () => { ...@@ -30,16 +27,6 @@ describe('Code review analytics mutations', () => {
}); });
}); });
describe(types.SET_FILTERS, () => {
it('updates milestoneTitle and labelName', () => {
mutations[types.SET_FILTERS](state, { milestoneTitle, labelName });
expect(state.filters.milestoneTitle).toBe(milestoneTitle);
expect(state.filters.labelName).toBe(labelName);
expect(state.pageInfo.page).toBe(1);
});
});
describe(types.REQUEST_MERGE_REQUESTS, () => { describe(types.REQUEST_MERGE_REQUESTS, () => {
it('sets isLoading to true', () => { it('sets isLoading to true', () => {
mutations[types.REQUEST_MERGE_REQUESTS](state); mutations[types.REQUEST_MERGE_REQUESTS](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